public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/29033] New: Calling 'error' on ppc64le can lead to spurious compiler error with -Wnull-dereference -Werror
@ 2022-04-06 14:19 arjun.is at lostca dot se
  2022-04-06 14:25 ` [Bug libc/29033] " arjun.is at lostca dot se
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: arjun.is at lostca dot se @ 2022-04-06 14:19 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29033

            Bug ID: 29033
           Summary: Calling 'error' on ppc64le can lead to spurious
                    compiler error with -Wnull-dereference -Werror
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: arjun.is at lostca dot se
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

misc/bits/error.h has:

/* If we know the function will never return make sure the compiler
   realizes that, too.  */
__extern_always_inline void
error (int __status, int __errnum, const char *__format, ...)
{ 
  if (__builtin_constant_p (__status) && __status != 0)
    __error_noreturn (__status, __errnum, __format, __va_arg_pack ());
  else
    __error_alias (__status, __errnum, __format, __va_arg_pack ());
}


But misc/bits/error-ldbl.h does not have this kind of handling.

Because of this, the following bit of code:

#include <error.h>
#include <stddef.h>
#include <stdlib.h>

struct S
{
  int i;
};

int
main (int argc, char **argv)
{
  struct S ss;
  struct S *s = argv[argc - 1] == NULL ? &ss : NULL;
  if (s == NULL)
    error (EXIT_FAILURE, 0, "frob");

  if (s->i == 0)
    return 1;

  return 0;
}

... when compiled with -Wnull-dereference leads to a warning/error:

$ gcc -Wnull-dereference -Werror -O2 -g test.c
w.c: In function ‘main’:
w.c:18:8: error: potential null pointer dereference [-Werror=null-dereference]
   18 |   if (s->i == 0)
      |       ~^~~
cc1: all warnings being treated as errors

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2024-03-21 11:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-06 14:19 [Bug libc/29033] New: Calling 'error' on ppc64le can lead to spurious compiler error with -Wnull-dereference -Werror arjun.is at lostca dot se
2022-04-06 14:25 ` [Bug libc/29033] " arjun.is at lostca dot se
2022-04-06 14:59 ` mark at klomp dot org
2022-04-06 18:49 ` fweimer at redhat dot com
2022-04-12 13:25 ` carlos at redhat dot com
2024-03-21 11:27 ` mmatti at linux dot vnet.ibm.com
2024-03-21 11:48 ` fweimer at redhat dot com

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 read-only IMAP folder(s) and NNTP newsgroup(s).