[PATCH] D85599: [Clang] Consider __builtin_trap() and __builtin_debugtrap() as terminator
Zhang Kang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 9 20:11:00 PDT 2020
ZhangKang updated this revision to Diff 284250.
ZhangKang added a comment.
Fix the case.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85599/new/
https://reviews.llvm.org/D85599
Files:
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-ppc.c
clang/test/CodeGenCXX/vararg-non-pod.cpp
compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
Index: compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
===================================================================
--- compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
+++ 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]]:
}
Index: clang/test/CodeGenCXX/vararg-non-pod.cpp
===================================================================
--- clang/test/CodeGenCXX/vararg-non-pod.cpp
+++ 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
}
Index: clang/test/CodeGen/builtins-ppc.c
===================================================================
--- clang/test/CodeGen/builtins-ppc.c
+++ 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
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ 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: {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85599.284250.patch
Type: text/x-patch
Size: 2876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200810/ca490474/attachment-0001.bin>
More information about the llvm-commits
mailing list