From 732c99c4ae6e309ea441f73f757c6990b7223f8e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sun, 10 Nov 2013 19:04:30 +0000 Subject: 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. llvm-svn: 194357 --- clang/lib/CodeGen/CodeGenModule.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 74f3bbb0459..ee700807437 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -181,8 +181,20 @@ void CodeGenModule::applyReplacements() { llvm::GlobalValue *Entry = GetGlobalValue(MangledName); if (!Entry) continue; - Entry->replaceAllUsesWith(Replacement); - Entry->eraseFromParent(); + llvm::Function *OldF = cast(Entry); + llvm::Function *NewF = dyn_cast(Replacement); + if (!NewF) { + llvm::ConstantExpr *CE = cast(Replacement); + assert(CE->getOpcode() == llvm::Instruction::BitCast || + CE->getOpcode() == llvm::Instruction::GetElementPtr); + NewF = cast(CE->getOperand(0)); + } + + // Replace old with new, but keep the old order. + OldF->replaceAllUsesWith(Replacement); + NewF->removeFromParent(); + OldF->getParent()->getFunctionList().insertAfter(OldF, NewF); + OldF->eraseFromParent(); } } -- cgit v1.2.3