public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/94580] New: missing warning accessing an interior flexible array member
Date: Mon, 13 Apr 2020 17:46:28 +0000	[thread overview]
Message-ID: <bug-94580-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 94580
           Summary: missing warning accessing an interior flexible array
                    member
           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: ---

In the following (invalid) test case -Warray-bounds only diagnoses one of the
four out-of-bounds references, although it eliminates the seemingly redundant
stores on the (clearly incorrect in this case) assumption that they don't alias
with the reads.  It's fine to eliminate the stores (or take whatever other
reasonable action) as long as the out-of-bounds accesses are diagnosed.

GCC warns about declarations of interior flexible array members, but only with
-Wpedantic, so this kind of bugs can easily go undetected.

$ cat t.c && gcc -O2 -S -Wall -Wextra -fdump-tree-vrp=/dev/stdout t.c
struct A { int n, a[]; };
struct B { struct A a; int x; };

struct B b;

int f0 (void)
{
  b.a.a[1] = 1;   // missing -Warray-bounds (store eliminated)
  int t = b.x;
  b.a.a[1] = 0;   // -Warray-bounds (good)
  return b.x - t;
}

int f1 (struct B *p)
{
  p->a.a[1] = 1;  // missing -Warray-bounds (store eliminated)
  int t = p->x;
  p->a.a[1] = 0;  // missing -Warray-bounds
  return p->x - t;
}


;; Function f0 (f0, funcdef_no=0, decl_uid=1937, cgraph_uid=1, symbol_order=1)

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2
;; 2 succs { 1 }

Value ranges after VRP:



t.c: In function ‘f0’:
t.c:10:8: warning: array subscript 1 is above array bounds of ‘int[0]’
[-Warray-bounds]
   10 |   b.a.a[1] = 0;   // -Warray-bounds (good)
      |   ~~~~~^~~
t.c:1:19: note: while referencing ‘a’
    1 | struct A { int n, a[]; };
      |                   ^
f0 ()
{
  <bb 2> [local count: 1073741824]:
  b.a.a[1] = 0;
  return 0;

}



;; Function f0 (f0, funcdef_no=0, decl_uid=1937, cgraph_uid=1, symbol_order=1)

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2
;; 2 succs { 1 }

Value ranges after VRP:



f0 ()
{
  <bb 2> [local count: 1073741824]:
  b.a.a[1] = 0;
  return 0;

}



;; Function f1 (f1, funcdef_no=1, decl_uid=1941, cgraph_uid=2, symbol_order=2)

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2
;; 2 succs { 1 }

Value ranges after VRP:



f1 (struct B * p)
{
  <bb 2> [local count: 1073741824]:
  p_2(D)->a.a[1] = 0;
  return 0;

}



;; Function f1 (f1, funcdef_no=1, decl_uid=1941, cgraph_uid=2, symbol_order=2)

;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2
;; 2 succs { 1 }

Value ranges after VRP:



f1 (struct B * p)
{
  <bb 2> [local count: 1073741824]:
  p_2(D)->a.a[1] = 0;
  return 0;

}

             reply	other threads:[~2020-04-13 17:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13 17:46 msebor at gcc dot gnu.org [this message]
2020-04-13 17:48 ` [Bug middle-end/94580] " msebor 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-94580-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).