[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 12:52:33 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] [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)
More information about the libc-commits
mailing list