Skip to content

Conversation

@W-50243
Copy link
Contributor

@W-50243 W-50243 commented Dec 8, 2023

Add __builtin_exit in clang/include/clang/Basic/Builtins.def . It works perfectly on arm64be and arm64le.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Dec 8, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 8, 2023

@llvm/pr-subscribers-clang

Author: None (W-50243)

Changes

Add __builtin_exit in clang/include/clang/Basic/Builtins.def . It works perfectly on arm64be and arm64le.


Full diff: https://github.com/llvm/llvm-project/pull/74803.diff

2 Files Affected:

  • (modified) clang/include/clang/Basic/Builtins.def (+1)
  • (added) clang/test/CodeGen/builtin-exit-test.c (+9)
diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def
index ec39e926889b9..8b73e9c5e3594 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -948,6 +948,7 @@ BUILTIN(__sync_fetch_and_umin, "UiUiD*Ui", "n")
 BUILTIN(__sync_fetch_and_umax, "UiUiD*Ui", "n")
 
 // Random libc builtins.
+BUILTIN(__builtin_exit, "vi", "Fnr")
 BUILTIN(__builtin_abort, "v", "Fnr")
 BUILTIN(__builtin_index, "c*cC*i", "Fn")
 BUILTIN(__builtin_rindex, "c*cC*i", "Fn")
diff --git a/clang/test/CodeGen/builtin-exit-test.c b/clang/test/CodeGen/builtin-exit-test.c
new file mode 100644
index 0000000000000..1ece90de1aa4f
--- /dev/null
+++ b/clang/test/CodeGen/builtin-exit-test.c
@@ -0,0 +1,9 @@
+//RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -Wno-strict-prototypes -triple aarch64-target-linux-gnu %s -o - | FileCheck %s
+
+//CHECK: define dso_local void @test() #0 {
+//CHECK: call void @exit(i32 noundef 1)
+//CHECK: unreachable
+
+void test(void){
+	__builtin_exit(1);
+}

@erichkeane
Copy link
Collaborator

This comes down to a question of 'why' from me? Typically we add builtins like this because libc++ need them, or libc/libstdc++ use them. In this case, I don't see any evidence of anyone really needing it.

While GCC supports it, I don't really see value here?

Also, this is adding for ALL platforms, so this is something that needs to be validated for all platforms as well (as far as runtime testing).

@W-50243
Copy link
Contributor Author

W-50243 commented Dec 21, 2023

I added __builtin_exit() because __builtin_exit() was used in some projects when I switched from GCC to LLVM. I don't think this is an isolated case, because the __builtin_exit() function is still widely used.https://sourcegraph.com/search?q=context:global+__builtin_exit&patternType=standard&sm=1&groupBy=repo

@philnik777
Copy link
Contributor

I'm not really convinced that __builtin_exit is widely used. If you filter for C/C++ and exclude GCC there aren't many matches: https://sourcegraph.com/search?q=context:global+__builtin_exit+count:all+-file:gcc/.*+%28lang:C+OR+lang:C%2B%2B%29&patternType=standard&sm=0&groupBy=repo

@tbaederr tbaederr removed their request for review June 6, 2024 07:00
@philnik777
Copy link
Contributor

Closing, since it seems to be abandoned.

@philnik777 philnik777 closed this Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants