public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "geoffreydgr at icloud dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug analyzer/111305] New: GCC Static Analyzer -Wanalyzer-out-of-bounds FP and ICE problem
Date: Wed, 06 Sep 2023 12:18:19 +0000	[thread overview]
Message-ID: <bug-111305-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111305
           Summary: GCC Static Analyzer -Wanalyzer-out-of-bounds FP and
                    ICE problem
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: geoffreydgr at icloud dot com
  Target Milestone: ---

ICE bug when analyzing the folowing program. And there also is a FP report of
out-of-bounds. 

cmd: gcc -O0 -fanalyzer
gcc version: x86-64 gcc (trunk)
see it live:
https://godbolt.org/z/qKxde131e

```
#include <stdio.h>
#include <stdint.h>

struct a {
  uint32_t b;
};
union c {
  int8_t b;
};

int32_t *d( int32_t *j, int32_t k, struct a l) {
  int64_t m[1]= {0};
  for (l.b = 0; l.b <= 0; l.b++) {
    printf("FLAG\n");
    l.b == 12 && m[l.b];
  }
}

```

out:
```
<source>: In function 'd':
<source>:15:19: warning: stack-based buffer over-read [CWE-121]
[-Wanalyzer-out-of-bounds]
   15 |     l.b == 12 && m[l.b];
      |                  ~^~~~~
  'd': events 1-10
    |
    |   12 |   int64_t m[1]= {0};
    |      |           ^
    |      |           |
    |      |           (1) capacity: 8 bytes
    |   13 |   for (l.b = 0; l.b <= 0; l.b++) {
    |      |                 ~~~~~~~~
    |      |                     |
    |      |                     (2) following 'true' branch...
    |      |                     (6) following 'true' branch...
    |   14 |     printf("FLAG\n");
    |      |     ~~~~~~~~~~~~~~~~
    |      |     |
    |      |     (3) ...to here
    |      |     (7) ...to here
    |   15 |     l.b == 12 && m[l.b];
    |      |     ~~~~~~~~~~~~~~~~~~~
    |      |               |   | |
    |      |               |   | (9) ...to here
    |      |               |   (10) read of 8 bytes at offset 'l.b * 8' exceeds
'm'
    |      |               (4) following 'false' branch...
    |      |               (5) ...to here
    |      |               (8) following 'true' branch...
    |
<source>:15:19: note: valid subscripts for 'm' are '[0]' to '[0]'
   15 |     l.b == 12 && m[l.b];
      |                  ~^~~~~
during IPA pass: analyzer
<source>:15:15: internal compiler error: in decompose, at wide-int.h:990
   15 |     l.b == 12 && m[l.b];
      |     ~~~~~~~~~~^~~~~~~~~
0x21af71e internal_error(char const*, ...)
        ???:0
0x9dd814 fancy_abort(char const*, int, char const*)
        ???:0
0x185a343 tree_zero_one_valued_p(tree_node*)
        ???:0
0x214b222 generic_simplify_MULT_EXPR(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*)
        ???:0
0xce1d05 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
        ???:0
0xce96cd fold_build2_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
        ???:0
0x18f3716 generic_simplify_23(unsigned int, tree_node*, tree_node*, tree_node*,
tree_node**, tree_code)
        ???:0
0x186889c generic_simplify_PLUS_EXPR(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*)
        ???:0
0xce1d05 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
        ???:0
0xce96cd fold_build2_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
        ???:0
0x21505bf generic_simplify_MULT_EXPR(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*)
        ???:0
0xce1d05 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
        ???:0
0xce96cd fold_build2_loc(unsigned int, tree_code, tree_node*, tree_node*,
tree_node*)
        ???:0
0x14d2c3f ana::region_offset::calc_symbolic_bit_offset(ana::region_model
const&) const
        ???:0
0x217faff ana::access_range::get_size(ana::region_model const&,
ana::bit_size_expr*) const
        ???:0
0x218cad3 ana::access_diagram_impl::access_diagram_impl(ana::access_operation
const&, diagnostic_event_id_t, text_art::style_manager&, text_art::theme
const&, ana::logger*)
        ???:0
0x2180abb ana::access_diagram::access_diagram(ana::access_operation const&,
diagnostic_event_id_t, text_art::style_manager&, text_art::theme const&,
ana::logger*)
        ???:0
0x2111f43 ana::symbolic_buffer_over_read::emit(rich_location*, ana::logger*)
        ???:0
0x2139d1e ana::diagnostic_manager::emit_saved_diagnostic(ana::exploded_graph
const&, ana::saved_diagnostic&)
        ???:0
0x213a520 ana::diagnostic_manager::emit_saved_diagnostics(ana::exploded_graph
const&)
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```

             reply	other threads:[~2023-09-06 12:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-06 12:18 geoffreydgr at icloud dot com [this message]
2024-02-26 22:30 ` [Bug analyzer/111305] [13/14 Regression] " dmalcolm at gcc dot gnu.org
2024-03-04 13:01 ` rguenth at gcc dot gnu.org
2024-03-07 23:21 ` law at gcc dot gnu.org
2024-03-12 13:25 ` jakub at gcc dot gnu.org
2024-03-18 22:47 ` cvs-commit at gcc dot gnu.org
2024-03-18 22:53 ` [Bug analyzer/111305] [13/14 Regression] GCC Static Analyzer -Wanalyzer-out-of-bounds false postive dmalcolm at gcc dot gnu.org
2024-03-22 13:39 ` law at gcc dot gnu.org
2024-05-21  9:17 ` [Bug analyzer/111305] [13/14/15 " jakub 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-111305-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).