-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[libc] fix -Wmissing-attributes in setjmp #112415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libc Author: Nick Desaulniers (nickdesaulniers) ChangesFixes:
observed in the GCC build by manually expanding LLVM_LIBC_FUNCTION to add We probably need to revisit adding nothrow throughout our declarations, so Link: #88054 Full diff: https://github.com/llvm/llvm-project/pull/112415.diff 2 Files Affected:
diff --git a/libc/src/setjmp/setjmp_impl.h b/libc/src/setjmp/setjmp_impl.h
index 4175a7397ae187..a9f330d4722e10 100644
--- a/libc/src/setjmp/setjmp_impl.h
+++ b/libc/src/setjmp/setjmp_impl.h
@@ -16,6 +16,7 @@
namespace LIBC_NAMESPACE_DECL {
+[[gnu::nothrow]]
int setjmp(jmp_buf buf);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/setjmp/x86_64/setjmp.cpp b/libc/src/setjmp/x86_64/setjmp.cpp
index c9ca578fb1e6db..7854132a83583c 100644
--- a/libc/src/setjmp/x86_64/setjmp.cpp
+++ b/libc/src/setjmp/x86_64/setjmp.cpp
@@ -17,8 +17,13 @@
namespace LIBC_NAMESPACE_DECL {
-[[gnu::naked]]
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::setjmp) __setjmp_impl__ __asm__("setjmp");
+
+decltype(LIBC_NAMESPACE::setjmp) setjmp [[gnu::alias("setjmp"), gnu::nothrow]];
+
+[[gnu::naked, gnu::nothrow]]
+int __setjmp_impl__ (__jmp_buf *buf) {
+
asm(R"(
mov %%rbx, %c[rbx](%%rdi)
mov %%rbp, %c[rbp](%%rdi)
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
It seems that naked functions are implicitly nothrow in GCC: https://godbolt.org/z/3Yv1ae5rv |
bd70c1d
to
9469d65
Compare
Fixes: llvm-project/libc/src/setjmp/x86_64/setjmp.cpp:21:25: error: ‘int __llvm_libc_19_0_0_git::setjmp(__jmp_buf*)’ specifies less restrictive attribute than its target ‘int __llvm_libc_19_0_0_git::__setjmp_impl__(__jmp_buf*)’: ‘nothrow’ [-Werror=missing-attributes] 21 | LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) { | ^~~~~~ Marking functions as 'naked' implies 'nothrow', so the function declaration should be marked nothrow. Only do this conditionally for GCC for now, otherwise clang with diagnose -Wmissing-exception-spec on the __ ## name ## _impl__ alias. We probably need to revisit adding nothrow throughout our definitions, so there is probably a better way to clean this up in the future. Link: llvm#88054
9469d65
to
519fcc5
Compare
Fixes: llvm-project/libc/src/setjmp/x86_64/setjmp.cpp:21:25: error: ‘int __llvm_libc_19_0_0_git::setjmp(__jmp_buf*)’ specifies less restrictive attribute than its target ‘int __llvm_libc_19_0_0_git::__setjmp_impl__(__jmp_buf*)’: ‘nothrow’ [-Werror=missing-attributes] 21 | LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) { | ^~~~~~ observed in the GCC build by manually expanding LLVM_LIBC_FUNCTION to add `gnu::nothrow` to the alias. We probably need to revisit adding nothrow throughout our declarations, so there is probably a better way to clean this up in the future. Link: llvm#88054
Fixes:
observed in the GCC build by manually expanding LLVM_LIBC_FUNCTION to add
gnu::nothrow
to the alias.We probably need to revisit adding nothrow throughout our declarations, so
there is probably a better way to clean this up in the future.
Link: #88054