public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/108725] New: -Wanalyzer-use-of-uninitialized-value on ternary pointer access seen in qemu-7.2.0's dump/win_dump.c
Date: Wed, 08 Feb 2023 19:57:27 +0000	[thread overview]
Message-ID: <bug-108725-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108725
           Summary: -Wanalyzer-use-of-uninitialized-value on ternary
                    pointer access seen in qemu-7.2.0's dump/win_dump.c
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 54438
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54438&action=edit
Reproducer

We get two false positives from the attached at -O1 and above, with both trunk
and gcc 12:

Trunk: https://godbolt.org/z/KboceYY7q
GCC 12.2: https://godbolt.org/z/jEPa6vaPd

<source>: In function 'cpu_read_ptr':
<source>:15:24: warning: use of uninitialized value 'ptr64' [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
   15 |     *ptr = x64 ? ptr64 : ptr32;
      |            ~~~~~~~~~~~~^~~~~~~
  'cpu_read_ptr': events 1-5
    |
    |   11 |     uint64_t ptr64;
    |      |              ^~~~~
    |      |              |
    |      |              (1) region created on stack here
    |      |              (2) capacity: 8 bytes
    |......
    |   15 |     *ptr = x64 ? ptr64 : ptr32;
    |      |            ~~~~~~~~~~~~~~~~~~~
    |      |                        |
    |      |                        (3) following 'true' branch (when 'x64 !=
0')...
    |      |                        (4) ...to here
    |      |                        (5) use of uninitialized value 'ptr64' here
    |
<source>:15:24: warning: use of uninitialized value 'ptr32' [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
   15 |     *ptr = x64 ? ptr64 : ptr32;
      |            ~~~~~~~~~~~~^~~~~~~
  'cpu_read_ptr': events 1-5
    |
    |   10 |     uint32_t ptr32;
    |      |              ^~~~~
    |      |              |
    |      |              (1) region created on stack here
    |      |              (2) capacity: 4 bytes
    |......
    |   15 |     *ptr = x64 ? ptr64 : ptr32;
    |      |            ~~~~~~~~~~~~~~~~~~~
    |      |                        |
    |      |                        (3) following 'false' branch (when 'x64 ==
0')...
    |      |                        (4) ...to here
    |      |                        (5) use of uninitialized value 'ptr32' here
    |
Compiler returned: 0

where the analyzer isn't treating the argument pointer as potentially having
been written through (presumably confused by the ternary operator).

             reply	other threads:[~2023-02-08 19:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 19:57 dmalcolm at gcc dot gnu.org [this message]
2023-02-15 19:53 ` [Bug analyzer/108725] " cvs-commit at gcc dot gnu.org
2023-02-15 20:00 ` dmalcolm at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108725-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).