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

            Bug ID: 90710
           Summary: Bogus Wmaybe-uninitialized caused by __builtin_expect
                    when compiled with -Og
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sagebar at web dot de
  Target Milestone: ---

Created attachment 46442
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46442&action=edit
Copy of the code already contained in the description

Use of `__builtin_expect()` within `testFunction()` below causes a warning to
be falsely emit when compiled as `gcc -Og -Wall test.c':
```
test.c: In function 'testfunction':
test.c:22:3: warning: 'value' may be used uninitialized in this function
[-Wmaybe-uninitialized]
   22 |   printf("My if() causes -Wmaybe-uninitialized for my use of `value':
%d\n",value);
      |  
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/
```


Code (`test.c`):
```
#include <stdio.h>

/* A simple store-value-in-pointer-or-return-error function */
static __inline__ __attribute__((__always_inline__))
unsigned int getValueIfNotZero(unsigned int value, unsigned int *result) {
        if (value == 0)
                goto err;
        *result = value;
        return 1;
err:
        return 0;
}

__attribute__((__noinline__)) void
testFunction(void) {
        volatile unsigned int x = 1;
        unsigned int value;
        int was_ok = getValueIfNotZero(x, &value);
        if (was_ok)
                printf("My if() compiles fine: %d\n",value);
        if (__builtin_expect(was_ok, 1))
                printf("My if() causes -Wmaybe-uninitialized for my use of
`value': %d\n",value);
}
```

This problem seems to be related to the `-Og` flag, as I was unable to
reproduce it with `-O[0-4]`

I can personally confirm this warning being emit the same way with:
    - i686-pc-cygwin-gcc.exe  (gcc version 6.4.0)
    - i686-elf-gcc.exe        (gcc version 9.1.0)
I can only assume that this also affects all versions between these two
My host is a windows 10 machine and I'm using cygwin to run GCC

Reply via email to