[clang] [Clang] Adjust `exit()` builtin impl (PR #101689)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 2 08:30:43 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Dmitry Chestnykh (chestnykh)
<details>
<summary>Changes</summary>
- `_Exit` is an alias to `_exit` and `_exit` is declared in unistd.h header, so don't mix
`_Exit` and `exit`. Only `exit` decl placed in stdlib.h.
- Add `__builtin_` variants for exit functions like GC does
---
Full diff: https://github.com/llvm/llvm-project/pull/101689.diff
2 Files Affected:
- (modified) clang/include/clang/Basic/Builtins.td (+4-2)
- (modified) clang/test/CodeGen/attributes.c (+21)
``````````diff
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index ccddeb9396284..bd0632c573412 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -2660,9 +2660,10 @@ def Calloc : LibBuiltin<"stdlib.h"> {
}
def Exit : LibBuiltin<"stdlib.h"> {
- let Spellings = ["exit", "_Exit"];
+ let Spellings = ["exit"];
let Attributes = [NoReturn];
let Prototype = "void(int)";
+ let AddBuiltinPrefixedAlias = 1;
}
def Malloc : LibBuiltin<"stdlib.h"> {
@@ -3266,9 +3267,10 @@ def StrnCaseCmp : GNULibBuiltin<"strings.h"> {
}
def GNU_Exit : GNULibBuiltin<"unistd.h"> {
- let Spellings = ["_exit"];
+ let Spellings = ["_exit", "_Exit"];
let Attributes = [NoReturn];
let Prototype = "void(int)";
+ let AddBuiltinPrefixedAlias = 1;
}
def VFork : LibBuiltin<"unistd.h"> {
diff --git a/clang/test/CodeGen/attributes.c b/clang/test/CodeGen/attributes.c
index 5afef72b747af..9fa43edbcf7c6 100644
--- a/clang/test/CodeGen/attributes.c
+++ b/clang/test/CodeGen/attributes.c
@@ -113,6 +113,27 @@ void t24(f_t f1) {
(*p)();
}
+// CHECK:define{{.*}} void @t25() [[NUW]] {
+// CHECK: call void @exit(i32 noundef 1)
+// CHECK-NEXT: unreachable
+void t25(void) {
+ __builtin_exit(1);
+}
+
+// CHECK:define{{.*}} void @t26() [[NUW]] {
+// CHECK: call void @_exit(i32 noundef 2)
+// CHECK-NEXT: unreachable
+void t26(void) {
+ __builtin__exit(2);
+}
+
+// CHECK:define{{.*}} void @t27() [[NUW]] {
+// CHECK: call void @_Exit(i32 noundef 3)
+// CHECK-NEXT: unreachable
+void t27(void) {
+ __builtin__Exit(3);
+}
+
// CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
// CHECK: attributes [[NR]] = { noinline noreturn nounwind{{.*}} }
// CHECK: attributes [[COLDDEF]] = { cold {{.*}}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/101689
More information about the cfe-commits
mailing list