@@ -126,6 +126,7 @@ class SimplifyStructRegSignatures : public ModulePass {
126
126
DenseSet<Function *> FunctionsToDelete;
127
127
SetVector<CallInst *> CallsToPatch;
128
128
SetVector<InvokeInst *> InvokesToPatch;
129
+ SetVector<BitCastInst *> BitCastsToPatch;
129
130
DenseMap<Function *, Function *> FunctionMap;
130
131
131
132
struct FunctionAddressing {
@@ -436,6 +437,10 @@ void SimplifyStructRegSignatures::scheduleInstructionsForCleanup(
436
437
CallsToPatch.insert (Call);
437
438
} else if (InvokeInst *Invoke = dyn_cast<InvokeInst>(&IIter)) {
438
439
InvokesToPatch.insert (Invoke);
440
+ } else if (BitCastInst *BitCast = dyn_cast<BitCastInst>(&IIter)) {
441
+ if (isa<Function>(BitCast->getOperand (0 ))) {
442
+ BitCastsToPatch.insert (BitCast);
443
+ }
439
444
}
440
445
}
441
446
}
@@ -537,6 +542,16 @@ bool SimplifyStructRegSignatures::runOnModule(Module &M) {
537
542
fixCallSite (Ctx, InvokeToFix, PreferredAlignment);
538
543
}
539
544
545
+ // BitCasts of a function we are modifying must be corrected
546
+ for (auto &BitCastToFix : BitCastsToPatch) {
547
+ auto *Old = cast<Function>(BitCastToFix->getOperand (0 ));
548
+ if (FunctionMap.find (Old) != FunctionMap.end ()) {
549
+ auto *New = FunctionMap[Old];
550
+ IRBuilder<> Builder (BitCastToFix);
551
+ BitCastToFix->setOperand (0 , Builder.CreateBitCast (New, Old->getType (), " bitcastfixcast" ));
552
+ }
553
+ }
554
+
540
555
// Update taking of a function's address from a parameter
541
556
for (auto &Addressing : FunctionAddressings) {
542
557
Value *Temp = Addressing.Temp ;
0 commit comments