Re: [PATCH 1/1] newlib/libc/include/setjmp.h: Add returns_twice attribute to setjmp()

Joel Sherrill <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CAF9ehCWrRq92vJL5uvTvHF4y4eiup4wTLy639WRL62Hw2KWoTA@mail.gmail.com>
On Wed, Oct 1, 2025 at 4:03 AM Brian Inglis <[email protected]>
wrote:

> On 2025-10-01 01:22, Torbjorn SVENSSON wrote:
> > On 2025-09-30 16:49, Joel Sherrill wrote:
> >> The setjmp() function needs this attribute to help GCC avoid false
> >> positives for the -Wclobbered warning. The -Wclobbered warning is
> >> part of -Wextra.
> >> ---
> >>   newlib/libc/include/setjmp.h | 7 ++++++-
> >>   1 file changed, 6 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/newlib/libc/include/setjmp.h b/newlib/libc/include/setjmp.h
> >> index a2830b275..5c16321a4 100644
> >> --- a/newlib/libc/include/setjmp.h
> >> +++ b/newlib/libc/include/setjmp.h
> >> @@ -17,7 +17,12 @@ void    longjmp (jmp_buf __jmpb, int __retval)
> >>   #else
> >>   void    longjmp (jmp_buf __jmpb, int __retval);
> >>   #endif
> >> -int    setjmp (jmp_buf __jmpb);
> >> +
> >> +#ifdef __GNUC__
> >> +int    setjmp (jmp_buf __jmpb)
> >> +            __attribute__ ((returns_twice));;
> > I suppose you only want a single semi-colon here.
> >> +#else
> > I think you should also drop the empty "#else" block.
> >> +#endif
> >>   _END_STD_C
>
> Shouldn't the conditional be around the attribute only?
>

That's not the way setjmp() was. It has this (tabs lost with copy and
paste):

#ifdef __GNUC__
void longjmp (jmp_buf __jmpb, int __retval)
__attribute__ ((__noreturn__));
#else
void longjmp (jmp_buf __jmpb, int __retval);
#endif

I just copied the style of what was there.


>
> -int    setjmp (jmp_buf __jmpb);
> +int    setjmp (jmp_buf __jmpb)
> +#ifdef __GNUC__
> +               __attribute__ ((returns_twice))
> +#endif
> +               ;
>
>
Do you want longjmp() changed to match this also?

--joel


> --
> Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada
>
> La perfection est atteinte                   Perfection is achieved
> non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to
> add
> mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to
> cut
>                                  -- Antoine de Saint-Exupéry
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.