[libc-commits] [libc] [libc] Add `returns_twice` attribute to `setjmp(3)` (PR #124370)

Alan Zhao via libc-commits libc-commits at lists.llvm.org
Wed Feb 5 13:55:30 PST 2025


alanzhao1 wrote:

> The commit message here isn't really accurate. First, TCO is not the only thing that can't be done in the presence of setjmp -- it affects a variety of things. But more importantly, there's a stronger reason to add the attribute than just "workaround".
> 
> Fundamentally, any function which has setjmp-like behaviors _must_ have its declaration (and therefore the calls at the IR level) annotated with the returns_twice attribute -- without this, it will not generate correct code.
> 
> Clang has a builtin list of function names that get the attr applied automatically (unless -fno-builtin is specified), which usually covers things. But, llvm-libc actually defines and (at least in tests, calls) setjmp with a function name which is not in the list: `LIBC_NAMESPACE::setjmp`. That non-standard name will not ever get the magic behavior automatically.
> 
> libc/src/setjmp/setjmp_impl.h also needs the attribute applied.

PR description has been updated

https://github.com/llvm/llvm-project/pull/124370


More information about the libc-commits mailing list