[libc-commits] [libc] [libc] Add _Returns_twice to C++ code (PR #153602)

William Huynh via libc-commits libc-commits at lists.llvm.org
Fri Aug 15 02:10:54 PDT 2025


https://github.com/saturn691 updated https://github.com/llvm/llvm-project/pull/153602

>From c908ee044cf0a7be6a1dd60333f6fcda73c5ec77 Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Thu, 14 Aug 2025 16:39:47 +0100
Subject: [PATCH 1/2] [libc] Add _Returns_twice to C++ code

Fixes issue with <csetjmp> which requires _Returns_twice but in
C++ mode
---
 libc/include/__llvm-libc-common.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index c6fd33a55532c..b376b05df1678 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -47,6 +47,9 @@
 #define __NOEXCEPT throw()
 #endif
 
+#undef _Returns_twice
+#define _Returns_twice [[gnu::returns_twice]]
+
 // This macro serves as a generic cast implementation for use in both C and C++,
 // similar to `__BIONIC_CAST` in Android.
 #undef __LLVM_LIBC_CAST

>From f196fc0a226f61cd46001c91ad3b6bd756f0b98d Mon Sep 17 00:00:00 2001
From: William Huynh <William.Huynh at arm.com>
Date: Fri, 15 Aug 2025 10:10:43 +0100
Subject: [PATCH 2/2] Unify _Returns_twice

---
 libc/include/__llvm-libc-common.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index b376b05df1678..fb340c29a5a07 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -11,6 +11,9 @@
 
 #define __LLVM_LIBC__ 1
 
+#undef _Returns_twice
+#define _Returns_twice [[gnu::returns_twice]]
+
 #ifdef __cplusplus
 
 #undef __BEGIN_C_DECLS
@@ -47,9 +50,6 @@
 #define __NOEXCEPT throw()
 #endif
 
-#undef _Returns_twice
-#define _Returns_twice [[gnu::returns_twice]]
-
 // This macro serves as a generic cast implementation for use in both C and C++,
 // similar to `__BIONIC_CAST` in Android.
 #undef __LLVM_LIBC_CAST
@@ -90,9 +90,6 @@
 #define __NOEXCEPT
 #endif
 
-#undef _Returns_twice
-#define _Returns_twice __attribute__((returns_twice))
-
 #undef __LLVM_LIBC_CAST
 #define __LLVM_LIBC_CAST(cast, type, value) ((type)(value))
 



More information about the libc-commits mailing list