Bug 109341 - [12/13/14/15 Regression] ICE in merge, at ipa-modref-tree.cc:176 since r12-3142-g5c85f29537662f
Summary: [12/13/14/15 Regression] ICE in merge, at ipa-modref-tree.cc:176 since r12-31...
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: ipa (show other bugs)
Version: 13.0
: P2 normal
Target Milestone: 12.5
Assignee: Jan Hubicka
URL:
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: 2024-06-20 09:12 UTC (History)
6 users (show)

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


Attachments

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".

Reproducer:
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;
  }
}

Error:
>$ 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)
        /testing/gcc/gcc_src_master/gcc/ipa-modref-tree.cc:176
0x10147cc modref_access_node::try_merge_with(vec<modref_access_node, va_gc, vl_embed>*&, unsigned long)
        /testing/gcc/gcc_src_master/gcc/ipa-modref-tree.cc:457
0x1016562 modref_access_node::insert(vec<modref_access_node, va_gc, vl_embed>*&, modref_access_node, unsigned long, bool)
        /testing/gcc/gcc_src_master/gcc/ipa-modref-tree.cc:562
0x101220b modref_ref_node<int>::insert_access(modref_access_node, unsigned long, bool)
        /testing/gcc/gcc_src_master/gcc/ipa-modref-tree.h:194
0x101220b modref_tree<int>::insert(unsigned int, unsigned int, unsigned int, int, int, modref_access_node, bool)
        /testing/gcc/gcc_src_master/gcc/ipa-modref-tree.h:444
0x1004eac modref_tree<int>::insert(tree_node*, int, int, modref_access_node const&, bool)
        /testing/gcc/gcc_src_master/gcc/ipa-modref-tree.h:471
0x1004eac record_access
        /testing/gcc/gcc_src_master/gcc/ipa-modref.cc:1076
0x1005958 analyze_load
        /testing/gcc/gcc_src_master/gcc/ipa-modref.cc:1707
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*))
        /testing/gcc/gcc_src_master/gcc/gimple-walk.cc:813
0x100ba01 analyze_stmt
        /testing/gcc/gcc_src_master/gcc/ipa-modref.cc:1788
0x100d1e9 analyze
        /testing/gcc/gcc_src_master/gcc/ipa-modref.cc:1900
0x100d1e9 analyze_function
        /testing/gcc/gcc_src_master/gcc/ipa-modref.cc:3220
0x100ecae execute
        /testing/gcc/gcc_src_master/gcc/ipa-modref.cc:4187

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
mine.
Comment 5 Richard Biener 2023-05-08 12:26:52 UTC
GCC 12.3 is being released, retargeting bugs to GCC 12.4.
Comment 6 Richard Biener 2024-06-20 09:12:11 UTC
GCC 12.4 is being released, retargeting bugs to GCC 12.5.