public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95136] New: missing -Wuninitialized on an array access with a variable offset
@ 2020-05-14 15:30 msebor at gcc dot gnu.org
  2020-05-14 15:31 ` [Bug middle-end/95136] " msebor at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-05-14 15:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95136
           Summary: missing -Wuninitialized on an array access with a
                    variable offset
           Product: gcc
           Version: 10.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 successfully reports uninitialized reads from arrays involving variable
indices but it fails to find the same bugs when besides the index the array
reference also includes an offset.  The test case below shows the difference.

In addition, the issued warning in these cases is missing essential detail such
as the name or location of the declaration of the variable.

$ cat x.c && gcc -O2 -S -Wall -fdump-tree-uninit=/dev/stdout x.c
int f (int i)
{ 
  int a[4];
  int *p = &a[i + 1];
  return *p;             // -Wuninitialized
}

int g (int i)
{
  int a[4];
  int *p = &a[i] + 1;
  return *p;             // missing warning
}

;; Function f (f, funcdef_no=0, decl_uid=1930, cgraph_uid=1, symbol_order=0)

x.c: In function ‘f’:
x.c:5:10: warning: ‘a[<unknown>]’ is used uninitialized in this function
[-Wuninitialized]
    5 |   return *p;             // -Wuninitialized
      |          ^~
f (int i)
{
  int a[4];
  int _1;
  int _4;

  <bb 2> [local count: 1073741824]:
  _1 = i_2(D) + 1;
  _4 = MEM <int[4]> [(int *)&a][_1];
  a ={v} {CLOBBER};
  return _4;

}



;; Function g (g, funcdef_no=1, decl_uid=1935, cgraph_uid=2, symbol_order=1)

g (int i)
{
  int a[4];
  int * _1;
  int _4;
  sizetype _6;
  sizetype _7;

  <bb 2> [local count: 1073741824]:
  _6 = (sizetype) i_2(D);
  _7 = _6 * 4;
  _1 = &a + _7;
  _4 = MEM[(int *)_1 + 4B];
  a ={v} {CLOBBER};
  return _4;

}

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

* [Bug middle-end/95136] missing -Wuninitialized on an array access with a variable offset
  2020-05-14 15:30 [Bug middle-end/95136] New: missing -Wuninitialized on an array access with a variable offset msebor at gcc dot gnu.org
@ 2020-05-14 15:31 ` msebor at gcc dot gnu.org
  2020-06-04 22:10 ` cvs-commit at gcc dot gnu.org
  2020-06-04 22:14 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-05-14 15:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
             Blocks|                            |24639
   Last reconfirmed|                            |2020-05-14
           Keywords|                            |diagnostic

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'm testing a fix.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues

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

* [Bug middle-end/95136] missing -Wuninitialized on an array access with a variable offset
  2020-05-14 15:30 [Bug middle-end/95136] New: missing -Wuninitialized on an array access with a variable offset msebor at gcc dot gnu.org
  2020-05-14 15:31 ` [Bug middle-end/95136] " msebor at gcc dot gnu.org
@ 2020-06-04 22:10 ` cvs-commit at gcc dot gnu.org
  2020-06-04 22:14 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-04 22:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 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:b825a22890740f341eae566af27e18e528cd29a7

commit r11-959-gb825a22890740f341eae566af27e18e528cd29a7
Author: Martin Sebor <msebor@redhat.com>
Date:   Thu Jun 4 16:06:10 2020 -0600

    Implement a solution for PR middle-end/10138 and PR middle-end/95136.

    PR middle-end/10138 - warn for uninitialized arrays passed as const
arguments
    PR middle-end/95136 - missing -Wuninitialized on an array access with a
variable offset

    gcc/c-family/ChangeLog:

            PR middle-end/10138
            PR middle-end/95136
            * c-attribs.c (append_access_attrs): Handle attr_access::none.
            (handle_access_attribute): Same.

    gcc/ChangeLog:

            PR middle-end/10138
            PR middle-end/95136
            * attribs.c (init_attr_rdwr_indices): Move function here.
            * attribs.h (rdwr_access_hash, rdwr_map): Define.
            (attr_access): Add 'none'.
            (init_attr_rdwr_indices): Declared function.
            * builtins.c (warn_for_access)): New function.
            (check_access): Call it.
            * builtins.h (checK-access): Add an optional argument.
            * calls.c (rdwr_access_hash, rdwr_map): Move to attribs.h.
            (init_attr_rdwr_indices): Declare extern.
            (append_attrname): Handle attr_access::none.
            (maybe_warn_rdwr_sizes): Same.
            (initialize_argument_information): Update comments.
            * doc/extend.texi (attribute access): Document 'none'.
            * tree-ssa-uninit.c (struct wlimits): New.
            (maybe_warn_operand): New function.
            (maybe_warn_pass_by_reference): Same.
            (warn_uninitialized_vars): Refactor code into maybe_warn_operand.
            Also call for function calls.
            (pass_late_warn_uninitialized::execute): Adjust comments.
            (execute_early_warn_uninitialized): Same.

    gcc/testsuite/ChangeLog:

            PR middle-end/10138
            PR middle-end/95136
            * c-c++-common/Wsizeof-pointer-memaccess1.c: Prune out valid
            Wuninitialized.
            * c-c++-common/uninit-pr51010.c: Adjust expected warning format.
            * c-c++-common/goacc/uninit-dim-clause.c: Same.
            * c-c++-common/goacc/uninit-firstprivate-clause.c: Same.
            * c-c++-common/goacc/uninit-if-clause.c: Same.
            * c-c++-common/gomp/pr70550-1.c: Same.
            * c-c++-common/gomp/pr70550-2.c: Adjust.
            * g++.dg/20090107-1.C: Same.
            * g++.dg/20090121-1.C: Same.
            * g++.dg/ext/attr-access.C: Avoid -Wuninitialized.
            * gcc.dg/tree-ssa/forwprop-6.c: Prune out -Wuninitialized.
            * gcc.dg/Warray-bounds-52.c: Prune out valid -Wuninitialized.
            * gcc.dg/Warray-bounds-53.c: Same.
            * gcc.dg/Warray-bounds-54.c: Same.
            * gcc.dg/Wstringop-overflow-33.c: New test.
            * gcc.dg/attr-access-none.c: New test.
            * gcc.dg/attr-access-read-only.c: Adjust.
            * gcc.dg/attr-access-read-write.c: Same.
            * gcc.dg/attr-access-write-only.c: Same.
            * gcc.dg/pr71581.c: Adjust text of expected warning.
            * gcc.dg/uninit-15.c: Same.
            * gcc.dg/uninit-32.c: New test.
            * gcc.dg/uninit-33.c: New test.
            * gcc.dg/uninit-34.c: New test.
            * gcc.dg/uninit-36.c: New test.
            * gcc.dg/uninit-B-O0.c: Adjust text of expected warning.
            * gcc.dg/uninit-I-O0.c: Same.
            * gcc.dg/uninit-pr19430-O0.c: Same.
            * gcc.dg/uninit-pr19430.c: Same.
            * gcc.dg/uninit-pr95136.c: New test.
            * gfortran.dg/assignment_4.f90: Expect -Wuninitialized.
            * gfortran.dg/goacc/uninit-dim-clause.f95: Adjust text of expected
            warning.
            * gfortran.dg/goacc/uninit-firstprivate-clause.f95
            * gfortran.dg/goacc/uninit-if-clause.f95
            * gfortran.dg/pr66545_2.f90

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

* [Bug middle-end/95136] missing -Wuninitialized on an array access with a variable offset
  2020-05-14 15:30 [Bug middle-end/95136] New: missing -Wuninitialized on an array access with a variable offset msebor at gcc dot gnu.org
  2020-05-14 15:31 ` [Bug middle-end/95136] " msebor at gcc dot gnu.org
  2020-06-04 22:10 ` cvs-commit at gcc dot gnu.org
@ 2020-06-04 22:14 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-04 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |11.0

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC 11 detects both accesses:

pr95136.c: In function ‘f’:
pr95136.c:5:10: warning: ‘a’ is used uninitialized [-Wuninitialized]
    5 |   return *p;             // -Wuninitialized
      |          ^~
pr95136.c:3:7: note: ‘a’ declared here
    3 |   int a[4];
      |       ^
pr95136.c: In function ‘g’:
pr95136.c:12:10: warning: ‘a’ is used uninitialized [-Wuninitialized]
   12 |   return *p;             // missing warning
      |          ^~
pr95136.c:10:7: note: ‘a’ declared here
   10 |   int a[4];
      |       ^

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

end of thread, other threads:[~2020-06-04 22:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 15:30 [Bug middle-end/95136] New: missing -Wuninitialized on an array access with a variable offset msebor at gcc dot gnu.org
2020-05-14 15:31 ` [Bug middle-end/95136] " msebor at gcc dot gnu.org
2020-06-04 22:10 ` cvs-commit at gcc dot gnu.org
2020-06-04 22:14 ` 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).