public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern
@ 2023-01-14  5:42 pefoley2 at pefoley dot com
  2023-01-14  5:49 ` [Bug tree-optimization/108402] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: pefoley2 at pefoley dot com @ 2023-01-14  5:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108402
           Summary: False positive Wuninitialized with
                    ftrivial-auto-var-init=pattern
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pefoley2 at pefoley dot com
  Target Milestone: ---

Created attachment 54271
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54271&action=edit
Reduced test case

This error showed up when compiling the upstream Linux kernel with ARCH=um
allyesconfig.
It appears to be specific to the -ftrivial-auto-var-init=pattern option.

Reduced test case attached, extracted from
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/spi/spi-stm32-qspi.c#n519

e.g.
gcc -v -O2 -ftrivial-auto-var-init=pattern -Werror=uninitialized -c qspi.i -o
/dev/null
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-12.2.1_p20221231/work/gcc-12-20221231/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/12
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/12/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/12
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/12/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/12/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/12/python
--enable-languages=c,c++,d,go,fortran,ada --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--disable-libunwind-exceptions --enable-checking=release
--with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo
12.2.1_p20221231 p8' --with-gcc-major-version-only --disable-esp
--enable-libstdcxx-time --disable-libstdcxx-pch --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point
--enable-targets=all --enable-libgomp --disable-libssp --disable-libada
--disable-cet --disable-systemtap --disable-valgrind-annotations
--enable-vtable-verify --with-zstd --enable-lto --with-isl
--disable-isl-version-check --enable-default-pie --enable-default-ssp
--with-build-config=bootstrap-lto
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.1 20221231 (Gentoo 12.2.1_p20221231 p8)
COLLECT_GCC_OPTIONS='-v' '-O2' '-ftrivial-auto-var-init=pattern'
'-Werror=uninitialized' '-c' '-o' '/dev/null' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/12/cc1 -fpreprocessed qspi.i -quiet
-dumpbase qspi.i -dumpbase-ext .i -mtune=generic -march=x86-64 -O2
-Werror=uninitialized -version -ftrivial-auto-var-init=pattern -o
/tmp/ccMHYckL.s
GNU C17 (Gentoo 12.2.1_p20221231 p8) version 12.2.1 20221231
(x86_64-pc-linux-gnu)
        compiled by GNU C version 12.2.1 20221231, GMP version 6.2.1, MPFR
version 4.2.0, MPC version 1.3.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (Gentoo 12.2.1_p20221231 p8) version 12.2.1 20221231
(x86_64-pc-linux-gnu)
        compiled by GNU C version 12.2.1 20221231, GMP version 6.2.1, MPFR
version 4.2.0, MPC version 1.3.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0fe3c6b2f620dfca480d344f2a96d9ed
qspi.i: In function ‘stm32_qspi_dirmap_read’:
qspi.i:40:20: error: ‘op’ is used uninitialized [-Werror=uninitialized]
   40 |  struct spi_mem_op op;
      |                    ^~
qspi.i:40:20: note: ‘op’ declared here
   40 |  struct spi_mem_op op;
      |                    ^~
cc1: some warnings being treated as errors


-fanalyzer additionally reports:
qspi.i: In function ‘stm32_qspi_dirmap_read’:
qspi.i:40:20: warning: use of uninitialized value ‘*(long int *)((char *)&op +
offsetof(struct spi_mem_op, addr.nbytes))’ [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
   40 |  struct spi_mem_op op;
      |                    ^~
  ‘stm32_qspi_dirmap_read’: events 1-2
    |
    |   40 |  struct spi_mem_op op;
    |      |                    ^~
    |      |                    |
    |      |                    (1) region created on stack here
    |      |                    (2) use of uninitialized value ‘*(long int
*)((char *)&op + offsetof(struct spi_mem_op, addr.nbytes))’ here
    |
qspi.i:40:20: warning: use of uninitialized value ‘*(long int *)((char *)&op +
offsetof(struct spi_mem_op, dummy.nbytes))’ [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
   40 |  struct spi_mem_op op;
      |                    ^~
  ‘stm32_qspi_dirmap_read’: events 1-2
    |
    |   40 |  struct spi_mem_op op;
    |      |                    ^~
    |      |                    |
    |      |                    (1) region created on stack here
    |      |                    (2) use of uninitialized value ‘*(long int
*)((char *)&op + offsetof(struct spi_mem_op, dummy.nbytes))’ here
    |
qspi.i:40:20: warning: use of uninitialized value ‘*(long int *)((char *)&op +
offsetof(struct spi_mem_op, cmd.nbytes))’ [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
   40 |  struct spi_mem_op op;
      |                    ^~
  ‘stm32_qspi_dirmap_read’: events 1-2
    |
    |   40 |  struct spi_mem_op op;
    |      |                    ^~
    |      |                    |
    |      |                    (1) region created on stack here
    |      |                    (2) use of uninitialized value ‘*(long int
*)((char *)&op + offsetof(struct spi_mem_op, cmd.nbytes))’ here
    |

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

* [Bug tree-optimization/108402] False positive Wuninitialized with ftrivial-auto-var-init=pattern
  2023-01-14  5:42 [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern pefoley2 at pefoley dot com
@ 2023-01-14  5:49 ` pinskia at gcc dot gnu.org
  2023-01-14  6:56 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-14  5:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This has nothing to do with ftrivial-auto-var-init=pattern . But rather you are
passing an uninitiated struct to a function that takes a pointer to a const
type. That causes the warning.

Can you attach the original source as the reduced one has a correct warning.

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

* [Bug tree-optimization/108402] False positive Wuninitialized with ftrivial-auto-var-init=pattern
  2023-01-14  5:42 [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern pefoley2 at pefoley dot com
  2023-01-14  5:49 ` [Bug tree-optimization/108402] " pinskia at gcc dot gnu.org
@ 2023-01-14  6:56 ` pinskia at gcc dot gnu.org
  2023-01-15 18:46 ` pefoley2 at pefoley dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-14  6:56 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-01-14

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can you attach the preprocessed source of the original non-reduced testcase
since the reduced testcase has a valid warning in it?

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

* [Bug tree-optimization/108402] False positive Wuninitialized with ftrivial-auto-var-init=pattern
  2023-01-14  5:42 [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern pefoley2 at pefoley dot com
  2023-01-14  5:49 ` [Bug tree-optimization/108402] " pinskia at gcc dot gnu.org
  2023-01-14  6:56 ` pinskia at gcc dot gnu.org
@ 2023-01-15 18:46 ` pefoley2 at pefoley dot com
  2023-01-15 18:51 ` pefoley2 at pefoley dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pefoley2 at pefoley dot com @ 2023-01-15 18:46 UTC (permalink / raw)
  To: gcc-bugs

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

pefoley2 at pefoley dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #54271|0                           |1
        is obsolete|                            |

--- Comment #3 from pefoley2 at pefoley dot com ---
Created attachment 54275
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54275&action=edit
Partially reduced testcase

Testcase reduced via creduce/delta to the point that it fits in the attachment
size.

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

* [Bug tree-optimization/108402] False positive Wuninitialized with ftrivial-auto-var-init=pattern
  2023-01-14  5:42 [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern pefoley2 at pefoley dot com
                   ` (2 preceding siblings ...)
  2023-01-15 18:46 ` pefoley2 at pefoley dot com
@ 2023-01-15 18:51 ` pefoley2 at pefoley dot com
  2023-01-15 19:23 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pefoley2 at pefoley dot com @ 2023-01-15 18:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from pefoley2 at pefoley dot com ---
Yeah, I had a lot of trouble getting creduce to do something sane with the
testcase that didn't wind up just deleting everything.
I wound up trying delta, which got me a smaller, but still enormous repo.
It should also be reproducible via make O=um ARCH=um allyesconfig
drivers/spi/spi-stm32-qspi.o in a 6.1 linux kernel tree.

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

* [Bug tree-optimization/108402] False positive Wuninitialized with ftrivial-auto-var-init=pattern
  2023-01-14  5:42 [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern pefoley2 at pefoley dot com
                   ` (3 preceding siblings ...)
  2023-01-15 18:51 ` pefoley2 at pefoley dot com
@ 2023-01-15 19:23 ` pinskia at gcc dot gnu.org
  2023-01-16 22:47 ` pefoley2 at pefoley dot com
  2023-07-19 16:03 ` arnd at linaro dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-15 19:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to pefoley2 from comment #4)
> Yeah, I had a lot of trouble getting creduce to do something sane with the
> testcase that didn't wind up just deleting everything.

You could compress it using either bzip or gzip (or xz). We are ok with the
file being compressed if it goes over the attachment size limit.

> It should also be reproducible via make O=um ARCH=um allyesconfig
> drivers/spi/spi-stm32-qspi.o in a 6.1 linux kernel tree.
from https://gcc.gnu.org/bugs/ (What we do not want):
```
The location (URL) of the package that failed to build (we won't download it,
anyway, since you've already given us what we need to duplicate the bug,
haven't you? :-)
```

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

* [Bug tree-optimization/108402] False positive Wuninitialized with ftrivial-auto-var-init=pattern
  2023-01-14  5:42 [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern pefoley2 at pefoley dot com
                   ` (4 preceding siblings ...)
  2023-01-15 19:23 ` pinskia at gcc dot gnu.org
@ 2023-01-16 22:47 ` pefoley2 at pefoley dot com
  2023-07-19 16:03 ` arnd at linaro dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pefoley2 at pefoley dot com @ 2023-01-16 22:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from pefoley2 at pefoley dot com ---
The attached file repos the issue for me.
I avoided trying to compress it per https://gcc.gnu.org/bugs/ "An attached
archive (tar, zip, shar, whatever) containing all (or some) of the above."
being listed under "What we do not want".

And yeah, the steps to repo from a kernel checkout were added mostly for
completeness, I didn't expect people to need to use them.

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

* [Bug tree-optimization/108402] False positive Wuninitialized with ftrivial-auto-var-init=pattern
  2023-01-14  5:42 [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern pefoley2 at pefoley dot com
                   ` (5 preceding siblings ...)
  2023-01-16 22:47 ` pefoley2 at pefoley dot com
@ 2023-07-19 16:03 ` arnd at linaro dot org
  6 siblings, 0 replies; 8+ messages in thread
From: arnd at linaro dot org @ 2023-07-19 16:03 UTC (permalink / raw)
  To: gcc-bugs

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

Arnd Bergmann <arnd at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arnd at linaro dot org

--- Comment #7 from Arnd Bergmann <arnd at linaro dot org> ---
I ran into a probably related issue and opened bug #110743 for it, with a
reduced test case. I also found another variation in bug #104550, but that
testcase was fixed by the referenced commit.

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

end of thread, other threads:[~2023-07-19 16:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-14  5:42 [Bug c/108402] New: False positive Wuninitialized with ftrivial-auto-var-init=pattern pefoley2 at pefoley dot com
2023-01-14  5:49 ` [Bug tree-optimization/108402] " pinskia at gcc dot gnu.org
2023-01-14  6:56 ` pinskia at gcc dot gnu.org
2023-01-15 18:46 ` pefoley2 at pefoley dot com
2023-01-15 18:51 ` pefoley2 at pefoley dot com
2023-01-15 19:23 ` pinskia at gcc dot gnu.org
2023-01-16 22:47 ` pefoley2 at pefoley dot com
2023-07-19 16:03 ` arnd at linaro dot org

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).