Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit b077029

Browse files
committed
handle bitcasts of a function that is changed in SimplifyStructRegSignatures
1 parent adba5d1 commit b077029

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/Target/JSBackend/NaCl/SimplifyStructRegSignatures.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class SimplifyStructRegSignatures : public ModulePass {
126126
DenseSet<Function *> FunctionsToDelete;
127127
SetVector<CallInst *> CallsToPatch;
128128
SetVector<InvokeInst *> InvokesToPatch;
129+
SetVector<BitCastInst *> BitCastsToPatch;
129130
DenseMap<Function *, Function *> FunctionMap;
130131

131132
struct FunctionAddressing {
@@ -436,6 +437,10 @@ void SimplifyStructRegSignatures::scheduleInstructionsForCleanup(
436437
CallsToPatch.insert(Call);
437438
} else if (InvokeInst *Invoke = dyn_cast<InvokeInst>(&IIter)) {
438439
InvokesToPatch.insert(Invoke);
440+
} else if (BitCastInst *BitCast = dyn_cast<BitCastInst>(&IIter)) {
441+
if (isa<Function>(BitCast->getOperand(0))) {
442+
BitCastsToPatch.insert(BitCast);
443+
}
439444
}
440445
}
441446
}
@@ -537,6 +542,16 @@ bool SimplifyStructRegSignatures::runOnModule(Module &M) {
537542
fixCallSite(Ctx, InvokeToFix, PreferredAlignment);
538543
}
539544

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+
540555
// Update taking of a function's address from a parameter
541556
for (auto &Addressing : FunctionAddressings) {
542557
Value *Temp = Addressing.Temp;

0 commit comments

Comments
 (0)