diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2351,8 +2351,24 @@ Function *F = CGM.getIntrinsic(Intrinsic::clear_cache); return RValue::get(Builder.CreateCall(F, {Begin, End})); } - case Builtin::BI__builtin_trap: - return RValue::get(EmitTrapCall(Intrinsic::trap)); + case Builtin::BI__builtin_trap: { + RValue::get(EmitTrapCall(Intrinsic::trap)); + Builder.CreateUnreachable(); + + // We do need to preserve an insertion point. + EmitBlock(createBasicBlock("trap.cont")); + + return RValue::get(nullptr); + } + case Builtin::BI__builtin_debugtrap: { + RValue::get(EmitTrapCall(Intrinsic::debugtrap)); + Builder.CreateUnreachable(); + + // We do need to preserve an insertion point. + EmitBlock(createBasicBlock("debugtrap.cont")); + + return RValue::get(nullptr); + } case Builtin::BI__debugbreak: return RValue::get(EmitTrapCall(Intrinsic::debugtrap)); case Builtin::BI__builtin_unreachable: { diff --git a/clang/test/CodeGen/builtins-ppc.c b/clang/test/CodeGen/builtins-ppc.c --- a/clang/test/CodeGen/builtins-ppc.c +++ b/clang/test/CodeGen/builtins-ppc.c @@ -27,3 +27,23 @@ // CHECK: call double @llvm.ppc.setrnd(i32 %2) res = __builtin_setrnd(x); } + +void test_builtin_trap() { + volatile int i = 0; + __builtin_trap(); + volatile int j = i; + + // CHECK-LABEL: test_builtin_trap + // CHECK: call void @llvm.trap() + // CHECK: unreachable +} + +void test_builtin_debugtrap() { + volatile int i = 0; + __builtin_debugtrap(); + volatile int j = i; + + // CHECK-LABEL: test_builtin_debugtrap + // CHECK: call void @llvm.debugtrap() + // CHECK: unreachable +} diff --git a/clang/test/CodeGenCXX/vararg-non-pod.cpp b/clang/test/CodeGenCXX/vararg-non-pod.cpp --- a/clang/test/CodeGenCXX/vararg-non-pod.cpp +++ b/clang/test/CodeGenCXX/vararg-non-pod.cpp @@ -12,5 +12,5 @@ void test(X x) { // CHECK: call void @llvm.trap() vararg(x); - // CHECK: ret void + // CHECK: unreachable } diff --git a/compiler-rt/test/profile/gcov-__gcov_flush-terminate.c b/compiler-rt/test/profile/gcov-__gcov_flush-terminate.c --- a/compiler-rt/test/profile/gcov-__gcov_flush-terminate.c +++ b/compiler-rt/test/profile/gcov-__gcov_flush-terminate.c @@ -19,6 +19,6 @@ __gcov_reset(); // CHECK-NEXT: 1: [[#@LINE]]: i = 42; // CHECK-NEXT: 1: [[#@LINE]]: __builtin_trap(); // CHECK-NEXT: 1: [[#@LINE]]: - i = 84; // CHECK-NEXT: 1: [[#@LINE]]: - return 0; // CHECK-NEXT: 1: [[#@LINE]]: + i = 84; // CHECK-NEXT: -: [[#@LINE]]: + return 0; // CHECK-NEXT: -: [[#@LINE]]: }