public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions)
@ 2023-05-10 17:41 colomar.6.4.3 at gmail dot com
  2023-05-10 17:45 ` [Bug analyzer/109802] " colomar.6.4.3 at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2023-05-10 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109802
           Summary: [regression] during IPA pass: analyzer: internal
                    compiler error (using dubious flexible arrays in
                    unions)
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: colomar.6.4.3 at gmail dot com
  Target Milestone: ---

Created attachment 55039
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55039&action=edit
preprocessed_source

Hi!

I was compiling some reduced version of some nasty code I found in a project,
to see
what GCC has to say about it.  I'm not sure if it has defined behavior or not,
according to strict-aliasing rules.  That code managed to get GCC on its knees
:)


$ cat flexi.c 
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

union u {
        char       base[0];
        ptrdiff_t  off;
};

struct s {
        int x;
        union u u[0];
};

int
main(void)
{
        char      *p;
        struct s  *s;

        s = malloc(sizeof(struct s) +
                   sizeof(union u) * 2 +
                   sizeof("foo") + sizeof("bar"));

        p = (void *) s + sizeof(struct s) + sizeof(union u) * 2;

        s->u[0].off = p - s->u[0].base;
        p = stpcpy(p, "foo") + 1;
        s->u[1].off = p - s->u[1].base;
        p = stpcpy(p, "bar") + 1;

        puts(s->u[0].base + s->u[0].off);
        puts(s->u[1].base + s->u[1].off);
}


$ gcc-12 -Wall -Wextra -Werror -fanalyzer -O3 flexi.c
$ ./a.out 
foo
bar


$ gcc-13 -Wall -Wextra -Werror -fanalyzer -O3 flexi.c -freport-bug
during IPA pass: analyzer
flexi.c: In function ‘main’:
flexi.c:34:36: internal compiler error: in make, at analyzer/store.cc:132
   34 |         puts(s->u[1].base + s->u[1].off);
      |                             ~~~~~~~^~~~
0xcec8a5 ana::binding_key::make(ana::store_manager*, ana::region const*)
        ../../src/gcc/analyzer/store.cc:132
0xcf9533 ana::binding_cluster::get_binding(ana::store_manager*, ana::region
const*) const
        ../../src/gcc/analyzer/store.cc:1567
0xcf95eb ana::binding_cluster::get_binding_recursive(ana::store_manager*,
ana::region const*) const
        ../../src/gcc/analyzer/store.cc:1604
0xd05e49 ana::binding_cluster::get_any_binding(ana::store_manager*, ana::region
const*) const
        ../../src/gcc/analyzer/store.cc:1627
0xcd45f7 ana::region_model::get_store_value(ana::region const*,
ana::region_model_context*) const
        ../../src/gcc/analyzer/region-model.cc:2407
0xcd4e72 ana::region_model::get_rvalue(ana::path_var,
ana::region_model_context*) const
        ../../src/gcc/analyzer/region-model.cc:2297
0xcd6a5c ana::region_model::on_assignment(gassign const*,
ana::region_model_context*)
        ../../src/gcc/analyzer/region-model.cc:1156
0xcdc2da ana::exploded_node::on_stmt(ana::exploded_graph&, ana::supernode
const*, gimple const*, ana::program_state*, ana::uncertainty_t*,
ana::path_context*)
        ../../src/gcc/analyzer/engine.cc:1471
0xcdc877 ana::exploded_graph::process_node(ana::exploded_node*)
        ../../src/gcc/analyzer/engine.cc:4063
0xcdd8b9 ana::exploded_graph::process_worklist()
        ../../src/gcc/analyzer/engine.cc:3466
0xcddc57 ana::impl_run_checkers(ana::logger*)
        ../../src/gcc/analyzer/engine.cc:6125
0xcde4ff ana::run_checkers()
        ../../src/gcc/analyzer/engine.cc:6213
0xcde54b execute
        ../../src/gcc/analyzer/analyzer-pass.cc:87
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-13/README.Bugs> for instructions.
Preprocessed source stored into /tmp/ccZKUz79.out file, please attach this to
your bugreport.


You'll find attached the file produced by GCC, as per its own instructions.

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

* [Bug analyzer/109802] [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions)
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
@ 2023-05-10 17:45 ` colomar.6.4.3 at gmail dot com
  2023-05-10 18:07 ` colomar.6.4.3 at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2023-05-10 17:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
Please use this:

Reported-by: Alejandro Colomar <alx@nginx.com>

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

* [Bug analyzer/109802] [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions)
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
  2023-05-10 17:45 ` [Bug analyzer/109802] " colomar.6.4.3 at gmail dot com
@ 2023-05-10 18:07 ` colomar.6.4.3 at gmail dot com
  2023-05-10 18:24 ` alx at kernel dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2023-05-10 18:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
Here's a simplified version that will cause the same internal compiler error.
This one will probably cause less brain damage to readers,
as it has significantly less magic.


$ cat flexi2.c 
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

struct s {
        int x;
        ptrdiff_t off[0];
};

int
main(void)
{
        char      *p;
        struct s  *s;

        s = malloc(sizeof(struct s) +
                   sizeof(ptrdiff_t) * 2 +
                   sizeof("foo") + sizeof("bar"));

        p = (void *) s + sizeof(struct s) + sizeof(ptrdiff_t) * 2;

        s->off[0] = p - (char *) s;
        p = stpcpy(p, "foo") + 1;
        s->off[1] = p - (char *) s;
        p = stpcpy(p, "bar") + 1;

        puts((char *) s + s->off[0]);
        puts((char *) s + s->off[1]);
}


$ gcc-12 -Wall -Wextra -Werror -fanalyzer -O3 flexi2.c 
$ ./a.out 
foo
bar
$ gcc-13 -Wall -Wextra -Werror -O3 flexi2.c 
$ ./a.out 
foo
bar
$ gcc-13 -Wall -Wextra -Werror -fanalyzer -O3 flexi2.c 
during IPA pass: analyzer
flexi2.c: In function ‘main’:
flexi2.c:29:33: internal compiler error: in make, at analyzer/store.cc:132
   29 |         puts((char *) s + s->off[1]);
      |                           ~~~~~~^~~
0xcec8a5 ana::binding_key::make(ana::store_manager*, ana::region const*)
        ../../src/gcc/analyzer/store.cc:132
0xcf9533 ana::binding_cluster::get_binding(ana::store_manager*, ana::region
const*) const
        ../../src/gcc/analyzer/store.cc:1567
0xcf95eb ana::binding_cluster::get_binding_recursive(ana::store_manager*,
ana::region const*) const
        ../../src/gcc/analyzer/store.cc:1604
0xd05e49 ana::binding_cluster::get_any_binding(ana::store_manager*, ana::region
const*) const
        ../../src/gcc/analyzer/store.cc:1627
0xcd45f7 ana::region_model::get_store_value(ana::region const*,
ana::region_model_context*) const
        ../../src/gcc/analyzer/region-model.cc:2407
0xcd4e72 ana::region_model::get_rvalue(ana::path_var,
ana::region_model_context*) const
        ../../src/gcc/analyzer/region-model.cc:2297
0xcd6a5c ana::region_model::on_assignment(gassign const*,
ana::region_model_context*)
        ../../src/gcc/analyzer/region-model.cc:1156
0xcdc2da ana::exploded_node::on_stmt(ana::exploded_graph&, ana::supernode
const*, gimple const*, ana::program_state*, ana::uncertainty_t*,
ana::path_context*)
        ../../src/gcc/analyzer/engine.cc:1471
0xcdc877 ana::exploded_graph::process_node(ana::exploded_node*)
        ../../src/gcc/analyzer/engine.cc:4063
0xcdd8b9 ana::exploded_graph::process_worklist()
        ../../src/gcc/analyzer/engine.cc:3466
0xcddc57 ana::impl_run_checkers(ana::logger*)
        ../../src/gcc/analyzer/engine.cc:6125
0xcde4ff ana::run_checkers()
        ../../src/gcc/analyzer/engine.cc:6213
0xcde54b execute
        ../../src/gcc/analyzer/analyzer-pass.cc:87
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-13/README.Bugs> for instructions.


I didn't attach the preprocessed source of this simplified example, since I
guess it would be repetitive with the previous one.

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

* [Bug analyzer/109802] [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions)
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
  2023-05-10 17:45 ` [Bug analyzer/109802] " colomar.6.4.3 at gmail dot com
  2023-05-10 18:07 ` colomar.6.4.3 at gmail dot com
@ 2023-05-10 18:24 ` alx at kernel dot org
  2023-05-10 18:27 ` alx at kernel dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: alx at kernel dot org @ 2023-05-10 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Alejandro Colomar <alx at kernel dot org> ---
Hmm, I should have used offsetof(3) in a few placed to avoid issues due to
padding, but I was lucky :).

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

* [Bug analyzer/109802] [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions)
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-05-10 18:24 ` alx at kernel dot org
@ 2023-05-10 18:27 ` alx at kernel dot org
  2024-02-16 21:24 ` [Bug analyzer/109802] [13 Regression] ICE using dubious flexible arrays in unions dmalcolm at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: alx at kernel dot org @ 2023-05-10 18:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Alejandro Colomar <alx at kernel dot org> ---
(In reply to Alejandro Colomar from comment #3)
> Hmm, I should have used offsetof(3) in a few placed to avoid issues due to
> padding, but I was lucky :).

Oh, no, I didn't need it.  I got it right.  Never mind.

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

* [Bug analyzer/109802] [13 Regression] ICE using dubious flexible arrays in unions
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-05-10 18:27 ` alx at kernel dot org
@ 2024-02-16 21:24 ` dmalcolm at gcc dot gnu.org
  2024-04-14  5:21 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2024-02-16 21:24 UTC (permalink / raw)
  To: gcc-bugs

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

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-02-16
            Summary|[regression] during IPA     |[13 Regression] ICE using
                   |pass: analyzer: internal    |dubious flexible arrays in
                   |compiler error (using       |unions
                   |dubious flexible arrays in  |
                   |unions)                     |

--- Comment #5 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks for filing this bug report.

(In reply to Alejandro Colomar from comment #2)
> Here's a simplified version that will cause the same internal compiler error.
  Trunk (GCC 14): ok:  https://godbolt.org/z/4cjf6Khh3
  GCC 13.2:       ICE: https://godbolt.org/z/K4j97a4eb
  GCC 12.3:       ok:  https://godbolt.org/z/1jfz8YTPj

...so it seems like this is fixed on trunk (for GCC 14) but still affects GCC
13.

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

* [Bug analyzer/109802] [13 Regression] ICE using dubious flexible arrays in unions
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
                   ` (4 preceding siblings ...)
  2024-02-16 21:24 ` [Bug analyzer/109802] [13 Regression] ICE using dubious flexible arrays in unions dmalcolm at gcc dot gnu.org
@ 2024-04-14  5:21 ` pinskia at gcc dot gnu.org
  2024-04-14 11:11 ` alx at kernel dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-14  5:21 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.3

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

* [Bug analyzer/109802] [13 Regression] ICE using dubious flexible arrays in unions
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
                   ` (5 preceding siblings ...)
  2024-04-14  5:21 ` pinskia at gcc dot gnu.org
@ 2024-04-14 11:11 ` alx at kernel dot org
  2024-05-13 11:34 ` rguenth at gcc dot gnu.org
  2024-05-21  9:15 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: alx at kernel dot org @ 2024-04-14 11:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Alejandro Colomar <alx at kernel dot org> ---
Thanks for fixing it!

Would you mind showing which commit fixed this?  I'm curious about it.  I
searched in the git log, but nothing mentioned this bug number.

Now I can come to my original intent, which is asking if this code is supported
by GCC, as in

Does this code have defined behavior under GCC?
Does it need and -f flags to be defined?
Or is it just undefined behavior?

I ask because this code exists in a real project.

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

* [Bug analyzer/109802] [13 Regression] ICE using dubious flexible arrays in unions
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
                   ` (6 preceding siblings ...)
  2024-04-14 11:11 ` alx at kernel dot org
@ 2024-05-13 11:34 ` rguenth at gcc dot gnu.org
  2024-05-21  9:15 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-13 11:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug analyzer/109802] [13 Regression] ICE using dubious flexible arrays in unions
  2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
                   ` (7 preceding siblings ...)
  2024-05-13 11:34 ` rguenth at gcc dot gnu.org
@ 2024-05-21  9:15 ` jakub at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-21  9:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.3                        |13.4

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 13.3 is being released, retargeting bugs to GCC 13.4.

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

end of thread, other threads:[~2024-05-21  9:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-10 17:41 [Bug analyzer/109802] New: [regression] during IPA pass: analyzer: internal compiler error (using dubious flexible arrays in unions) colomar.6.4.3 at gmail dot com
2023-05-10 17:45 ` [Bug analyzer/109802] " colomar.6.4.3 at gmail dot com
2023-05-10 18:07 ` colomar.6.4.3 at gmail dot com
2023-05-10 18:24 ` alx at kernel dot org
2023-05-10 18:27 ` alx at kernel dot org
2024-02-16 21:24 ` [Bug analyzer/109802] [13 Regression] ICE using dubious flexible arrays in unions dmalcolm at gcc dot gnu.org
2024-04-14  5:21 ` pinskia at gcc dot gnu.org
2024-04-14 11:11 ` alx at kernel dot org
2024-05-13 11:34 ` rguenth at gcc dot gnu.org
2024-05-21  9:15 ` jakub 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).