diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-11-12 04:53:19 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-11-12 04:53:19 +0000 |
commit | 0196a1d98f8a206259a4b5ce93c21807243af92f (patch) | |
tree | 52a726555abc4d5c953de268f9b1bb914ad0d927 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | b470652431078092cfd55bc3ebf93f3fe4fd02a3 (diff) | |
download | bcm5719-llvm-0196a1d98f8a206259a4b5ce93c21807243af92f.tar.gz bcm5719-llvm-0196a1d98f8a206259a4b5ce93c21807243af92f.zip |
Keep the old function order in CodeGenModule::applyReplacements.
The original decls are created when used. The replacements are created at the
end of the TU in reverse order.
This makes the original order far better for testing. This is particularly
important since the replacement logic could be used even when
-mconstructor-aliases is not used, but that would make many tests hard to read.
This is a fixed version of r194357 which handles replacing a destructor with
another which is an alias to a third one.
llvm-svn: 194452
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 74f3bbb0459..1f2f4bbde3c 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -181,8 +181,22 @@ void CodeGenModule::applyReplacements() { llvm::GlobalValue *Entry = GetGlobalValue(MangledName); if (!Entry) continue; - Entry->replaceAllUsesWith(Replacement); - Entry->eraseFromParent(); + llvm::Function *OldF = cast<llvm::Function>(Entry); + llvm::Function *NewF = dyn_cast<llvm::Function>(Replacement); + if (!NewF) { + llvm::ConstantExpr *CE = cast<llvm::ConstantExpr>(Replacement); + assert(CE->getOpcode() == llvm::Instruction::BitCast || + CE->getOpcode() == llvm::Instruction::GetElementPtr); + NewF = dyn_cast<llvm::Function>(CE->getOperand(0)); + } + + // Replace old with new, but keep the old order. + OldF->replaceAllUsesWith(Replacement); + if (NewF) { + NewF->removeFromParent(); + OldF->getParent()->getFunctionList().insertAfter(OldF, NewF); + } + OldF->eraseFromParent(); } } |