mailing list of musl libc
 help / color / mirror / code / Atom feed
* assert_fail without Noreturn
@ 2016-08-30  0:05 Assaf Gordon
  2016-08-30 20:54 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Assaf Gordon @ 2016-08-30  0:05 UTC (permalink / raw)
  To: musl

Hello,

It seems "assert_fail()"  does not have a "noreturn" attribute - it was removed in this commit:

   commit 2c1f8fd5da3306fd7c8a2267467e44eb61f12dd4
   Author: rofl0r <retnyg@gmx.net>
   Date:   Tue Jan 1 07:59:11 2013 +0100

   __assert_fail(): remove _Noreturn, to get proper stack traces

   for _Noreturn functions, gcc generates code that trashes the
   stack frame, and so it makes it impossible to inspect the causes
   of an assert error in gdb.

   abort() is not affected (i have not yet investigated why).


However, in recent GCC versions (at least 5.2.0) this causes a compiler warning (or error with -Werror).

A contrived example:

   $ cat 2.c

   #include <assert.h>
   #include <stdio.h>

   FILE* foo (int i)
   {
     FILE *f;
     if (i>0)
       f = fopen("foo.bar","r");
     else
       assert(!"error");
     return f;
   }

   $ musl-gcc -O2 -Wall -Wextra -c 2.c
   2.c: In function ‘foo’:
   2.c:12:11: error: ‘f’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
       return f;
          ^
   cc1: some warnings being treated as errors

Using 'gcc' instead of 'musl-gcc' shows no warnings.

The compiler is:

   $ musl-gcc -v
   Using built-in specs.
   Reading specs from /usr/local/musl/lib/musl-gcc.specs
   rename spec cpp_options to old_cpp_options
   COLLECT_GCC=gcc
   COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
   Target: x86_64-unknown-linux-gnu
   Configured with: ../gcc-5.2.0/configure --enable-languages=c,c++
   Thread model: posix
   gcc version 5.2.0 (GCC)

Using musk-libc version 1.1.15 from tarball.

Perhaps putting "_Noreturn" in "assert_fail" can be reconsidered ?
Or perhaps there's another way to avoid this warning ?

Thanks,
- assaf







^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: assert_fail without Noreturn
  2016-08-30  0:05 assert_fail without Noreturn Assaf Gordon
@ 2016-08-30 20:54 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2016-08-30 20:54 UTC (permalink / raw)
  To: musl

On Mon, Aug 29, 2016 at 08:05:00PM -0400, Assaf Gordon wrote:
> Hello,
> 
> It seems "assert_fail()"  does not have a "noreturn" attribute - it was removed in this commit:
> 
>    commit 2c1f8fd5da3306fd7c8a2267467e44eb61f12dd4
>    Author: rofl0r <retnyg@gmx.net>
>    Date:   Tue Jan 1 07:59:11 2013 +0100
> 
>    __assert_fail(): remove _Noreturn, to get proper stack traces
> 
>    for _Noreturn functions, gcc generates code that trashes the
>    stack frame, and so it makes it impossible to inspect the causes
>    of an assert error in gdb.
> 
>    abort() is not affected (i have not yet investigated why).
> 
> 
> However, in recent GCC versions (at least 5.2.0) this causes a compiler warning (or error with -Werror).
> 
> A contrived example:
> 
>    $ cat 2.c
> 
>    #include <assert.h>
>    #include <stdio.h>
> 
>    FILE* foo (int i)
>    {
>      FILE *f;
>      if (i>0)
>        f = fopen("foo.bar","r");
>      else
>        assert(!"error");
>      return f;
>    }
> 
>    $ musl-gcc -O2 -Wall -Wextra -c 2.c
>    2.c: In function ‘foo’:
>    2.c:12:11: error: ‘f’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>        return f;
>           ^
>    cc1: some warnings being treated as errors
> 
> Using 'gcc' instead of 'musl-gcc' shows no warnings.
> 
> The compiler is:
> 
>    $ musl-gcc -v
>    Using built-in specs.
>    Reading specs from /usr/local/musl/lib/musl-gcc.specs
>    rename spec cpp_options to old_cpp_options
>    COLLECT_GCC=gcc
>    COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
>    Target: x86_64-unknown-linux-gnu
>    Configured with: ../gcc-5.2.0/configure --enable-languages=c,c++
>    Thread model: posix
>    gcc version 5.2.0 (GCC)
> 
> Using musk-libc version 1.1.15 from tarball.
> 
> Perhaps putting "_Noreturn" in "assert_fail" can be reconsidered ?
> Or perhaps there's another way to avoid this warning ?

I'm reverting commit 2c1f8fd5da3306fd7c8a2267467e44eb61f12dd4 based on
discussion with the patch contributor and testing. Further details
will be in the commit message. Thanks!

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-30 20:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-30  0:05 assert_fail without Noreturn Assaf Gordon
2016-08-30 20:54 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).