[libc-commits] [libc] [libc] fix -Wmissing-attributes in setjmp (PR #112415)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Tue Oct 15 13:02:59 PDT 2024
https://github.com/nickdesaulniers updated https://github.com/llvm/llvm-project/pull/112415
>From 519fcc57f83953fcc7d67c02ee4ded0935c0cc2a Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Tue, 15 Oct 2024 11:31:11 -0700
Subject: [PATCH 1/2] [libc] fix -Wmissing-attributes in setjmp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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: #88054
---
libc/src/setjmp/setjmp_impl.h | 4 ++++
libc/src/setjmp/x86_64/setjmp.cpp | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/libc/src/setjmp/setjmp_impl.h b/libc/src/setjmp/setjmp_impl.h
index 4175a7397ae187..97801d896b1bf5 100644
--- a/libc/src/setjmp/setjmp_impl.h
+++ b/libc/src/setjmp/setjmp_impl.h
@@ -13,9 +13,13 @@
// public header setjmp.h which is also included. here.
#include "hdr/types/jmp_buf.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/compiler.h"
namespace LIBC_NAMESPACE_DECL {
+#ifdef LIBC_COMPILER_IS_GCC
+[[gnu::nothrow]]
+#endif
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..f6e82642edd7da 100644
--- a/libc/src/setjmp/x86_64/setjmp.cpp
+++ b/libc/src/setjmp/x86_64/setjmp.cpp
@@ -18,7 +18,7 @@
namespace LIBC_NAMESPACE_DECL {
[[gnu::naked]]
-LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
+LLVM_LIBC_FUNCTION(int, setjmp, (jmp_buf buf)) {
asm(R"(
mov %%rbx, %c[rbx](%%rdi)
mov %%rbp, %c[rbp](%%rdi)
>From cef25394b9e09e84f3a0c484f5fc343d61581063 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Tue, 15 Oct 2024 13:02:44 -0700
Subject: [PATCH 2/2] add comment
---
libc/src/setjmp/setjmp_impl.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libc/src/setjmp/setjmp_impl.h b/libc/src/setjmp/setjmp_impl.h
index 97801d896b1bf5..d035409e581954 100644
--- a/libc/src/setjmp/setjmp_impl.h
+++ b/libc/src/setjmp/setjmp_impl.h
@@ -17,6 +17,15 @@
namespace LIBC_NAMESPACE_DECL {
+// TODO(https://github.com/llvm/llvm-project/issues/112427)
+// Some of the architecture-specific definitions are marked `naked`, which in
+// GCC implies `nothrow`.
+//
+// Right now, our aliases aren't marked `nothrow`, so we wind up in a situation
+// where clang will emit -Wmissing-exception-spec if we add `nothrow` here, but
+// GCC will emit -Wmissing-attributes here without `nothrow`. We need to update
+// LLVM_LIBC_FUNCTION to denote when a function throws or not.
+
#ifdef LIBC_COMPILER_IS_GCC
[[gnu::nothrow]]
#endif
More information about the libc-commits
mailing list