Skip to content

Commit 46200fc

Browse files
[libc] fix -Wmissing-attributes in setjmp (#112415)
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
1 parent 685bec7 commit 46200fc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

libc/src/setjmp/setjmp_impl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,22 @@
1313
// public header setjmp.h which is also included. here.
1414
#include "hdr/types/jmp_buf.h"
1515
#include "src/__support/macros/config.h"
16+
#include "src/__support/macros/properties/compiler.h"
1617

1718
namespace LIBC_NAMESPACE_DECL {
1819

20+
// TODO(https://github.com/llvm/llvm-project/issues/112427)
21+
// Some of the architecture-specific definitions are marked `naked`, which in
22+
// GCC implies `nothrow`.
23+
//
24+
// Right now, our aliases aren't marked `nothrow`, so we wind up in a situation
25+
// where clang will emit -Wmissing-exception-spec if we add `nothrow` here, but
26+
// GCC will emit -Wmissing-attributes here without `nothrow`. We need to update
27+
// LLVM_LIBC_FUNCTION to denote when a function throws or not.
28+
29+
#ifdef LIBC_COMPILER_IS_GCC
30+
[[gnu::nothrow]]
31+
#endif
1932
int setjmp(jmp_buf buf);
2033

2134
} // namespace LIBC_NAMESPACE_DECL

libc/src/setjmp/x86_64/setjmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace LIBC_NAMESPACE_DECL {
1919

2020
[[gnu::naked]]
21-
LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
21+
LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
2222
asm(R"(
2323
mov %%rbx, %c[rbx](%%rdi)
2424
mov %%rbp, %c[rbp](%%rdi)

0 commit comments

Comments
 (0)