Skip to content

Conversation

@nickdesaulniers
Copy link
Member

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: #88054

@llvmbot
Copy link
Member

llvmbot commented Oct 15, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

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: #88054


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

2 Files Affected:

  • (modified) libc/src/setjmp/setjmp_impl.h (+1)
  • (modified) libc/src/setjmp/x86_64/setjmp.cpp (+7-2)
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)

@github-actions
Copy link

github-actions bot commented Oct 15, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@nickdesaulniers
Copy link
Member Author

It seems that naked functions are implicitly nothrow in GCC: https://godbolt.org/z/3Yv1ae5rv

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
@nickdesaulniers nickdesaulniers merged commit 46200fc into llvm:main Oct 15, 2024
5 of 6 checks passed
@nickdesaulniers nickdesaulniers deleted the fix_gcc_setjmp branch October 15, 2024 20:07
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants