Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -27,6 +27,7 @@ #include "llvm/ADT/Hashing.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/InlineAsm.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/MDBuilder.h" @@ -2534,21 +2535,29 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked) { llvm::BasicBlock *Cont = createBasicBlock("cont"); - + llvm::InlineAsm *EmptyAsm = llvm::InlineAsm::get(llvm::FunctionType::get(CGM.VoidTy, false), + StringRef(""), StringRef(""), true); + // Collapsing all calls to trap down to one per function makes debugging + // these issues much more difficult. Eliminating this optimization for now, + // with the thought that control by either a debug flag or tying it to an + // optimization level/sanitizer may be a decent path for the future. + // RE: Bug: 25682 // If we're optimizing, collapse all calls to trap down to just one per // function to save on code size. - if (!CGM.getCodeGenOpts().OptimizationLevel || !TrapBB) { - TrapBB = createBasicBlock("trap"); - Builder.CreateCondBr(Checked, Cont, TrapBB); - EmitBlock(TrapBB); - llvm::CallInst *TrapCall = EmitTrapCall(llvm::Intrinsic::trap); - TrapCall->setDoesNotReturn(); - TrapCall->setDoesNotThrow(); - Builder.CreateUnreachable(); - } else { - Builder.CreateCondBr(Checked, Cont, TrapBB); - } - + // if (!CGM.getCodeGenOpts().OptimizationLevel || !TrapBB) { + TrapBB = createBasicBlock("trap"); + Builder.CreateCondBr(Checked, Cont, TrapBB); + EmitBlock(TrapBB); + llvm::CallInst *TrapCall = EmitTrapCall(llvm::Intrinsic::trap); + TrapCall->setDoesNotReturn(); + TrapCall->setDoesNotThrow(); + Builder.CreateUnreachable(); + //} else { + //Builder.CreateCondBr(Checked, Cont, TrapBB); + //} + //this stops the trap calls from being merged at the end of the function + Builder.CreateCall(EmptyAsm, {}); + EmitBlock(Cont); }