[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:45:41 PDT 2024


https://github.com/nickdesaulniers updated https://github.com/llvm/llvm-project/pull/112415

>From 4f006329ddcbfc9a73d64365fa251542b2e70425 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)) {
          |                         ^~~~~~

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
---
 libc/src/setjmp/setjmp_impl.h     | 1 +
 libc/src/setjmp/x86_64/setjmp.cpp | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

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)

>From bd70c1d5e01f59c74bfef0a1f1c4f75dcdc2342f Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Tue, 15 Oct 2024 12:45:28 -0700
Subject: [PATCH 2/2] formatting fixes

---
 libc/src/setjmp/x86_64/setjmp.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libc/src/setjmp/x86_64/setjmp.cpp b/libc/src/setjmp/x86_64/setjmp.cpp
index 7854132a83583c..5cc8df4843a9a1 100644
--- a/libc/src/setjmp/x86_64/setjmp.cpp
+++ b/libc/src/setjmp/x86_64/setjmp.cpp
@@ -17,12 +17,13 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::setjmp) __setjmp_impl__ __asm__("setjmp");
+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) {
+int __setjmp_impl__(__jmp_buf *buf) {
 
   asm(R"(
       mov %%rbx, %c[rbx](%%rdi)



More information about the libc-commits mailing list