[Bug tree-optimization/90710] Bogus Wmaybe-uninitialized caused by __builtin_expect when compiled with -Og

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Apr 6 23:16:50 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90710

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Here's a smaller test case showing both the problem (first gcc invocation) and
how it can be avoided (second invocation):

$ (set -x && cat pr90710.c && gcc -Og -S -Wall pr90710.c && gcc -Dint=long -Og
-S -Wall pr90710.c)
+ cat pr90710.c
static inline int f (int x, int *p)
{
  if (x == 0)
    return 0;

  *p = x;
  return 1;
}

volatile int z;

void g (int x)
{
  int b, a = f (x, &b);

  if (a)
    z = b;

  if (__builtin_expect (a, 1))
    z = b;
}
+ gcc -Og -S -Wall pr90710.c
pr90710.c: In function ‘g’:
pr90710.c:20:7: warning: ‘b’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
   20 |     z = b;
      |     ~~^~~
pr90710.c:14:7: note: ‘b’ was declared here
   14 |   int b, a = f (x, &b);
      |       ^
+ gcc -Dint=long -Og -S -Wall pr90710.c


More information about the Gcc-bugs mailing list