[libc-commits] [libc] [libc] Add `returns_twice` attribute to `setjmp(3)` (PR #124370)
via libc-commits
libc-commits at lists.llvm.org
Fri Jan 24 15:53:59 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Alan Zhao (alanzhao1)
<details>
<summary>Changes</summary>
This is to work around a clang bug where clang will incorrectly add a tail call optimization to `setjmp(3)` if `-fno-builtins` is set (#<!-- -->122840).
---
Full diff: https://github.com/llvm/llvm-project/pull/124370.diff
2 Files Affected:
- (modified) libc/include/__llvm-libc-common.h (+6)
- (modified) libc/include/setjmp.yaml (+2)
``````````diff
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index b5a23c5765f4d8..58006a1ffc24fc 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -45,6 +45,9 @@
#define __NOEXCEPT throw()
#endif
+#undef _Returns_twice
+#define _Returns_twice [[gnu::returns_twice]]
+
#else // not __cplusplus
#undef __BEGIN_C_DECLS
@@ -80,6 +83,9 @@
#define __NOEXCEPT
#endif
+#undef _Returns_twice
+#define _Returns_twice __attribute__((returns_twice))
+
#endif // __cplusplus
#endif // LLVM_LIBC_COMMON_H
diff --git a/libc/include/setjmp.yaml b/libc/include/setjmp.yaml
index 2c4f7fb6dfcc70..5fbb9eb2a47e5b 100644
--- a/libc/include/setjmp.yaml
+++ b/libc/include/setjmp.yaml
@@ -17,5 +17,7 @@ functions:
standards:
- stdc
return_type: int
+ attributes:
+ - _Returns_twice
arguments:
- type: jmp_buf
``````````
</details>
https://github.com/llvm/llvm-project/pull/124370
More information about the libc-commits
mailing list