public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/104308] no location info provided for [-Wanalyzer-use-of-uninitialized-value] warnings
Date: Mon, 28 Mar 2022 13:44:10 +0000	[thread overview]
Message-ID: <bug-104308-4-S8xAVYGlit@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104308-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:

https://gcc.gnu.org/g:875342766d42988fa2f8eb7d34ef562ba69e340a

commit r12-7856-g875342766d42988fa2f8eb7d34ef562ba69e340a
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Mon Mar 28 09:43:07 2022 -0400

    gimple-fold: fix location of loads for memory ops [PR104308]

    PR analyzer/104308 reports that when -Wanalyzer-use-of-uninitialized-value
    complains about certain memmove operations where the source is
    uninitialized, the diagnostic uses UNKNOWN_LOCATION:

    In function 'main':
    cc1: warning: use of uninitialized value '*(short unsigned int *)&s + 1'
[CWE-457] [-Wanalyzer-use-of-uninitialized-value]
      'main': event 1
        |
        |pr104308.c:5:8:
        |    5 |   char s[5]; /* { dg-message "region created on stack here" }
*/
        |      |        ^
        |      |        |
        |      |        (1) region created on stack here
        |
      'main': event 2
        |
        |cc1:
        | (2): use of uninitialized value '*(short unsigned int *)&s + 1' here
        |

    The issue is that gimple_fold_builtin_memory_op converts a memmove to:

      _3 = MEM <unsigned short> [(char * {ref-all})_1];
      MEM <unsigned short> [(char * {ref-all})&s] = _3;

    but only sets the location of the 2nd stmt, not the 1st.

    Fixed thusly, giving:

    pr104308.c: In function 'main':
    pr104308.c:6:3: warning: use of uninitialized value '*(short unsigned int
*)&s + 1' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
        6 |   memmove(s, s + 1, 2); /* { dg-warning "use of uninitialized
value" } */
          |   ^~~~~~~~~~~~~~~~~~~~
      'main': events 1-2
        |
        |    5 |   char s[5]; /* { dg-message "region created on stack here" }
*/
        |      |        ^
        |      |        |
        |      |        (1) region created on stack here
        |    6 |   memmove(s, s + 1, 2); /* { dg-warning "use of uninitialized
value" } */
        |      |   ~~~~~~~~~~~~~~~~~~~~
        |      |   |
        |      |   (2) use of uninitialized value '*(short unsigned int *)&s +
1' here
        |

    One side-effect of this change is a change in part of the output of
    gcc.dg/uninit-40.c from:

      uninit-40.c:47:3: warning: â*(long unsigned int *)(&u[1][0][0])â is
used uninitialized [-Wuninitialized]
         47 |   __builtin_memcpy (&v[1], &u[1], sizeof (V));
            |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      uninit-40.c:45:5: note: â*(long unsigned int *)(&u[1][0][0])â was
declared here
         45 |   V u[2], v[2];
            |     ^

    to:

      uninit-40.c:47:3: warning: âuâ is used uninitialized
[-Wuninitialized]
         47 |   __builtin_memcpy (&v[1], &u[1], sizeof (V));
            |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      uninit-40.c:45:5: note: âuâ declared here
         45 |   V u[2], v[2];
            |     ^

    What's happening is that pass "early_uninit"(29)'s call to
    maybe_warn_operand is guarded by this condition:
      1051            else if (gimple_assign_load_p (stmt)
      1052                     && gimple_has_location (stmt))

    Before the patch, the stmt:
      _3 = MEM <unsigned long> [(char * {ref-all})&u + 8B];
    has no location, and so early_uninit skips this operand at line
    1052 above.  Later, pass "uninit"(217) tests the var_decl "u$8", and
    emits a warning for it.

    With the patch, the stmt has a location, and so early_uninit emits a
    warning for "u" and sets a NW_UNINIT warning suppression at that
    location.  Later, pass "uninit"(217)'s test of "u$8" is rejected
    due to that per-location suppression of uninit warnings, from the
    earlier warning.

    gcc/ChangeLog:
            PR analyzer/104308
            * gimple-fold.cc (gimple_fold_builtin_memory_op): When optimizing
            to loads then stores, set the location of the new load stmt.

    gcc/testsuite/ChangeLog:
            PR analyzer/104308
            * gcc.dg/analyzer/pr104308.c: New test.
            * gcc.dg/uninit-40.c (foo): Update expression in expected message.

    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

  parent reply	other threads:[~2022-03-28 13:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-31 15:09 [Bug analyzer/104308] New: " kdudka at redhat dot com
2022-01-31 15:56 ` [Bug analyzer/104308] " dmalcolm at gcc dot gnu.org
2022-01-31 15:57 ` dmalcolm at gcc dot gnu.org
2022-01-31 16:40 ` kdudka at redhat dot com
2022-01-31 16:50 ` dmalcolm at gcc dot gnu.org
2022-03-25 21:52 ` dmalcolm at gcc dot gnu.org
2022-03-25 21:52 ` dmalcolm at gcc dot gnu.org
2022-03-28 13:44 ` cvs-commit at gcc dot gnu.org [this message]
2022-03-28 13:52 ` dmalcolm at gcc dot gnu.org
2022-04-13  7:51 ` kdudka at redhat dot com
2022-04-13 22:05 ` dmalcolm at gcc dot gnu.org
2022-04-14 13:27 ` dmalcolm at gcc dot gnu.org
2022-04-25 23:36 ` cvs-commit at gcc dot gnu.org
2022-04-25 23:39 ` 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-104308-4-S8xAVYGlit@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).