https://github.com/chestnykh created https://github.com/llvm/llvm-project/pull/101689
- `_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 >From b83615c58c85f5723dff26e40f356473fb5d4eda Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh <dm.chestn...@gmail.com> Date: Fri, 2 Aug 2024 18:28:38 +0300 Subject: [PATCH] [Clang] Adjust `exit()` builtin impl - `_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 --- clang/include/clang/Basic/Builtins.td | 6 ++++-- clang/test/CodeGen/attributes.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) 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 {{.*}}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits