public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98583] New: missing -Wuninitialized reading from a second VLA in its own block
@ 2021-01-07 16:20 msebor at gcc dot gnu.org
  2021-01-08  8:28 ` [Bug middle-end/98583] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-07 16:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98583
           Summary: missing -Wuninitialized reading from a second VLA in
                    its own block
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC diagnoses the uninitialized accessed in h1() but if fails to detect the
same invalid access in h2().

$ cat x.c && gcc -O2 -S -Wall x.c
void f (int*);
void g (int);

void h1 (int n)
{
  int a[n];
  f (a);

  int b[n];
  g (b[1]);        // -Wuninitialized (good)
}

void h2 (int n, int i, int j)
{
  if (i)   // ditto without this if...
    {
      int a[n];
      f (a);
    }

  if (j)   // ...or this if...
    {
      int b[n];
      g (b[1]);    // missing warning
    }
}

x.c: In function ‘h1’:
x.c:10:3: warning: ‘*b[1]’ is used uninitialized [-Wuninitialized]
   10 |   g (b[1]);        // -Wuninitialized (good)
      |   ^~~~~~~~

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

* [Bug middle-end/98583] missing -Wuninitialized reading from a second VLA in its own block
  2021-01-07 16:20 [Bug middle-end/98583] New: missing -Wuninitialized reading from a second VLA in its own block msebor at gcc dot gnu.org
@ 2021-01-08  8:28 ` rguenth at gcc dot gnu.org
  2021-05-11 19:51 ` msebor at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-08  8:28 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-01-08
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is that __builtin_stack_restore is considered a possible definition
by the alias machinery (it needs to be treated as barrier for code motion).
check_defs can probably skip __builtin_stack_restore unconditionally
(alternatively the uninit pass can stop walking at allocation sites but
it's run too early to not need its own tracking of which allocation an
object belongs to).

diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index 0800f596ab1..33a32eaaa37 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -216,6 +216,9 @@ check_defs (ao_ref *ref, tree vdef, void *data_)
        return true;
       return false;
     }
+  /* End of VLA scope is not a kill.  */
+  if (gimple_call_builtin_p (def_stmt, BUILT_IN_STACK_RESTORE))
+    return false;
   /* Found a may-def on this path.  */
   data->found_may_defs = true;
   return true;

fixes this bug (pre-approved if it tests OK).

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

* [Bug middle-end/98583] missing -Wuninitialized reading from a second VLA in its own block
  2021-01-07 16:20 [Bug middle-end/98583] New: missing -Wuninitialized reading from a second VLA in its own block msebor at gcc dot gnu.org
  2021-01-08  8:28 ` [Bug middle-end/98583] " rguenth at gcc dot gnu.org
@ 2021-05-11 19:51 ` msebor at gcc dot gnu.org
  2021-05-13 22:07 ` cvs-commit at gcc dot gnu.org
  2021-05-13 22:40 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-05-11 19:51 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
   Target Milestone|---                         |12.0
             Status|NEW                         |ASSIGNED
      Known to fail|                            |10.3.0, 11.1.0, 12.0, 9.2.0
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570117.html

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

* [Bug middle-end/98583] missing -Wuninitialized reading from a second VLA in its own block
  2021-01-07 16:20 [Bug middle-end/98583] New: missing -Wuninitialized reading from a second VLA in its own block msebor at gcc dot gnu.org
  2021-01-08  8:28 ` [Bug middle-end/98583] " rguenth at gcc dot gnu.org
  2021-05-11 19:51 ` msebor at gcc dot gnu.org
@ 2021-05-13 22:07 ` cvs-commit at gcc dot gnu.org
  2021-05-13 22:40 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-13 22:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:2efe245bb88bf4574e322ef7e6d2df83d9e13237

commit r12-783-g2efe245bb88bf4574e322ef7e6d2df83d9e13237
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu May 13 16:05:50 2021 -0600

    Avoid -Wuninitialized false negatives with sanitization and VLAs.

    Resolves:
    PR tree-optimization/93100 - gcc -fsanitize=address inhibits
-Wuninitialized
    PR middle-end/98583 - missing -Wuninitialized reading from a second VLA in
its own block

    gcc/ChangeLog:

            PR tree-optimization/93100
            PR middle-end/98583
            * tree-ssa-uninit.c (check_defs): Exclude intrinsic functions that
            don't modify referenced objects.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/93100
            PR middle-end/98583
            * g++.dg/warn/uninit-pr93100.C: New test.
            * gcc.dg/uninit-pr93100.c: New test.
            * gcc.dg/uninit-pr98583.c: New test.

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

* [Bug middle-end/98583] missing -Wuninitialized reading from a second VLA in its own block
  2021-01-07 16:20 [Bug middle-end/98583] New: missing -Wuninitialized reading from a second VLA in its own block msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-05-13 22:07 ` cvs-commit at gcc dot gnu.org
@ 2021-05-13 22:40 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-05-13 22:40 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Fixed in GCC 12.

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

end of thread, other threads:[~2021-05-13 22:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-07 16:20 [Bug middle-end/98583] New: missing -Wuninitialized reading from a second VLA in its own block msebor at gcc dot gnu.org
2021-01-08  8:28 ` [Bug middle-end/98583] " rguenth at gcc dot gnu.org
2021-05-11 19:51 ` msebor at gcc dot gnu.org
2021-05-13 22:07 ` cvs-commit at gcc dot gnu.org
2021-05-13 22:40 ` msebor at gcc dot gnu.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).