[Bug c/106992] New: aarch64: Unexpected maybe-uninitialized warning when compiling fdlibm

shqking at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Sep 21 05:45:54 GMT 2022


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

            Bug ID: 106992
           Summary: aarch64: Unexpected maybe-uninitialized warning when
                    compiling fdlibm
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shqking at gmail dot com
  Target Milestone: ---

Unexpected "maybe-uninitialized" warning was emitted when compiling fdlibm
library on Ubuntu 22.04 && AArch64 platform with GCC-12 and GCC-13.

How to reproduce it?

```
wget https://netlib.org/fdlibm/fdlibm.h
wget https://netlib.org/fdlibm/k_rem_pio2.c
gcc -Wall -Wextra -Werror -O2 -std=c11 -fno-strict-aliasing -c k_rem_pio2.c
```

The following warning would be produced.
```
k_rem_pio2.c: In function '__kernel_rem_pio2':
k_rem_pio2.c:188:13: error: this 'for' clause does not guard...
[-Werror=misleading-indentation]
  188 |             for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
      |             ^~~
k_rem_pio2.c:188:61: note: ...this statement, but the latter is misleadingly
indented as if it were guarded by the 'for'
  188 |             for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
      |                                                             ^
k_rem_pio2.c:293:24: error: 'fq' may be used uninitialized
[-Werror=maybe-uninitialized]
  293 |                 fw = fq[0]-fw;
      |                      ~~^~~
k_rem_pio2.c:171:27: note: 'fq' declared here
  171 |         double z,fw,f[20],fq[20],q[20];
      |                           ^~
k_rem_pio2.c:293:24: error: 'fq' may be used uninitialized
[-Werror=maybe-uninitialized]
  293 |                 fw = fq[0]-fw;
      |                      ~~^~~
k_rem_pio2.c:171:27: note: 'fq' declared here
  171 |         double z,fw,f[20],fq[20],q[20];
      |                           ^~
cc1: all warnings being treated as errors
```

Note-1: I think it's a false positive because 1) array fq[] is initialized by
the for-stmt at line 276. Elements at index 0 to index "jz" are initialized. 2)
"jz" should be a non-negative value from the comment at line 87.

Note-2: No warning is produced on Ubuntu 22.04 && x86 platform.

Note-3: Known to work: gcc-11. Known to fail: gcc-12.0.1, 12.1.0, 12.2.0,
13.0.0.

Note-4: I filed an example with the C case I mentioned, i.e. k_rem_pio2.c,
after the pre-processing. See https://godbolt.org/z/Ph6r7vWeP. You may try
different GCC versions and x86/aarch64 backends there.

Note-5: It's worth noting that GCC at x86 platform would also produce this
waring message if we remove the option "-fno-strict-aliasing".


More information about the Gcc-bugs mailing list