Bug 109341 - [12/13/14 Regression] ICE in merge, at ipa-modref-tree.cc:176 since r12-3142-g5c85f29537662f
Summary: [12/13/14 Regression] ICE in merge, at ipa-modref-tree.cc:176 since r12-3142-...
Alias: None
Product: gcc
Classification: Unclassified
Component: ipa (show other bugs)
Version: 13.0
: P2 normal
Target Milestone: 12.4
Assignee: Jan Hubicka
Keywords: ice-checking, ice-on-valid-code
Depends on:
Blocks: yarpgen
  Show dependency treegraph
Reported: 2023-03-30 07:05 UTC by Vsevolod Livinskii
Modified: 2023-05-08 12:26 UTC (History)
6 users (show)

See Also:
Known to work: 11.3.1
Known to fail: 12.2.1, 13.0
Last reconfirmed: 2023-03-30 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Vsevolod Livinskii 2023-03-30 07:05:23 UTC
Link to the Compiler Explorer: https://godbolt.org/z/9zY57K3Yh

GCC also warns about UB, but I think it is incorrect. The code is well-defined if "h" is equal to "1".

unsigned c;
int e, f;
void g(long h, long j[][9]) {
  for (long d = 1; d; d += -(h ?: 600000000000000000)) {
      int a = j[d][d];
      f = h ?: a;
    int i = f;
      int a = c, b = i;
      e = b ?: a;
    c = e;

>$ g++ -O3 -c func.cpp
func.cpp: In function 'void g(long int, long int (*)[9])':
func.cpp:6:18: warning: iteration 7 invokes undefined behavior [-Waggressive-loop-optimizations]
    6 |       int a = j[d][d];
      |                  ^
func.cpp:4:20: note: within this loop
    4 |   for (long d = 1; d; d += -(h ?: 600000000000000000)) {
      |                    ^
during GIMPLE pass: modref
func.cpp:3:6: internal compiler error: in merge, at ipa-modref-tree.cc:176
    3 | void g(long h, long j[][9]) {
      |      ^
0x84f1a9 modref_access_node::merge(modref_access_node const&, bool)
0x10147cc modref_access_node::try_merge_with(vec<modref_access_node, va_gc, vl_embed>*&, unsigned long)
0x1016562 modref_access_node::insert(vec<modref_access_node, va_gc, vl_embed>*&, modref_access_node, unsigned long, bool)
0x101220b modref_ref_node<int>::insert_access(modref_access_node, unsigned long, bool)
0x101220b modref_tree<int>::insert(unsigned int, unsigned int, unsigned int, int, int, modref_access_node, bool)
0x1004eac modref_tree<int>::insert(tree_node*, int, int, modref_access_node const&, bool)
0x1004eac record_access
0x1005958 analyze_load
0xf57cb4 walk_stmt_load_store_addr_ops(gimple*, void*, bool (*)(gimple*, tree_node*, tree_node*, void*), bool (*)(gimple*, tree_node*, tree_node*, void*), bool (*)(gimple*, tree_node*, tree_node*, void*))
0x100ba01 analyze_stmt
0x100d1e9 analyze
0x100d1e9 analyze_function
0x100ecae execute

gcc version 13.0.1 20230329 (3be4e43a6a0f429648ea188c8e110b74268fed27)
Comment 1 Richard Biener 2023-03-30 07:24:54 UTC
Confirmed, also ICEs on the 12 branch.
Comment 2 Martin Liška 2023-03-30 07:42:33 UTC
Started with r12-3142-g5c85f29537662f.
Comment 3 Jakub Jelinek 2023-03-30 10:25:24 UTC
The warning is because we unswitch the loop, so we have a separate loop for h != 0 and separate loop for h == 0.  And the latter obviously invokes undefined behavior (though I get it for iteration 3 rather than 7).
Comment 4 Jan Hubicka 2023-03-30 11:10:24 UTC
Comment 5 Richard Biener 2023-05-08 12:26:52 UTC
GCC 12.3 is being released, retargeting bugs to GCC 12.4.