Index: lib/CodeGen/LLVMTargetMachine.cpp =================================================================== --- lib/CodeGen/LLVMTargetMachine.cpp +++ lib/CodeGen/LLVMTargetMachine.cpp @@ -34,6 +34,10 @@ #include "llvm/Target/TargetOptions.h" using namespace llvm; +static cl::opt EnableTrapUnreachable("trap-unreachable", + cl::Hidden, cl::ZeroOrMore, cl::init(false), + cl::desc("Enable generating trap for unreachable")); + void LLVMTargetMachine::initAsmInfo() { MRI = TheTarget.createMCRegInfo(getTargetTriple().str()); MII = TheTarget.createMCInstrInfo(); @@ -79,6 +83,9 @@ this->RM = RM; this->CMModel = CM; this->OptLevel = OL; + + if (EnableTrapUnreachable) + this->Options.TrapUnreachable = true; } TargetTransformInfo Index: test/CodeGen/ARM/trap-unreachable.ll =================================================================== --- /dev/null +++ test/CodeGen/ARM/trap-unreachable.ll @@ -0,0 +1,8 @@ +; RUN: llc -mtriple=thumbv7 -trap-unreachable < %s | FileCheck %s +; CHECK: .inst.n 0xdefe + +define void @test() #0 { + unreachable +} + +attributes #0 = { nounwind }