Bug 120450 - GCN offloading: ICE 'during RTL pass: expand', 'in assign_temp, at function.cc:990' for C++ 'std::flat_map', 'std::flat_multimap'
Summary: GCN offloading: ICE 'during RTL pass: expand', 'in assign_temp, at function.c...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, needs-reduction, openmp
Depends on:
Blocks:
 
Reported: 2025-05-28 09:55 UTC by Thomas Schwinge
Modified: 2025-10-20 20:29 UTC (History)
4 users (show)

See Also:
Host:
Target: GCN
Build:
Known to work:
Known to fail:
Last reconfirmed: 2025-10-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schwinge 2025-05-28 09:55:28 UTC
In an OpenMP 'target' region, constructing a C++23-new 'std::flat_map', 'std::flat_multimap' is fine for host and nvptx offloading compilation (and appears to behave as expected), but we ICE for GCN offloading compilation.  More elaborate test cases to appear soon, but here's a simple '-O0' reproducer:

    #include <flat_map>
    int main (void)
    {
      #pragma omp target
      {
        std::flat_map<int,int> m;
      }
      return 0;
    }

    during RTL pass: expand
    In member function ‘__ct ’,
        inlined from ‘__ct ’ at [...]/install/include/c++/16.0.0/flat_map:156:54,
        inlined from ‘__ct ’ at [...]/install/include/c++/16.0.0/flat_map:1431:11,
        inlined from ‘main._omp_fn.0’ at source-gcc/libgomp/testsuite/libgomp.c++/concurrent-flat_multimap.C:41:48:
    [...]/install/include/c++/16.0.0/flat_map:160:9: internal compiler error: in assign_temp, at function.cc:990
      160 |       : _M_cont(), _M_comp(__comp)
          |         ^
    0x20b1426 internal_error(char const*, ...)
            [...]/source-gcc/gcc/diagnostic-global-context.cc:517
    0xa3b67c fancy_abort(char const*, int, char const*)
            [...]/source-gcc/gcc/diagnostic.cc:1815
    0x7ac610 assign_temp(tree_node*, int, int)
            [...]/source-gcc/gcc/function.cc:990
    0xc42857 expand_constructor
            [...]/source-gcc/gcc/expr.cc:9447
    0xc2dcd8 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
            [...]/source-gcc/gcc/expr.cc:11754
    0xc41da3 expand_expr_real(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool)
            [...]/source-gcc/gcc/expr.cc:9529
    0xc41da3 expand_normal(tree_node*)
            [...]/source-gcc/gcc/expr.h:329
    0xc41da3 store_field
            [...]/source-gcc/gcc/expr.cc:8246
    0xc3d2a9 expand_assignment(tree_node*, tree_node*, bool)
            [...]/source-gcc/gcc/expr.cc:6334
    0xaede1e expand_gimple_stmt_1
            [...]/source-gcc/gcc/cfgexpand.cc:4289
    0xaede1e expand_gimple_stmt
            [...]/source-gcc/gcc/cfgexpand.cc:4370
    0xaf2d98 expand_gimple_basic_block
            [...]/source-gcc/gcc/cfgexpand.cc:6433
    0xaf5186 execute
            [...]/source-gcc/gcc/cfgexpand.cc:7181

It appears to share some similarity with PR114572 '[OpenMP] "internal compiler error: in assign_temp" with assignment operator and lastprivate clause', but that one has been fixed long ago.
Comment 1 Richard Biener 2025-05-28 12:54:28 UTC
The question is what's the reason we end up here from expand_constructor.  There's

  /* Handle calls that pass values in multiple non-contiguous
     locations.  The Irix 6 ABI has examples of this.  */
  if (target == 0 || ! safe_from_p (target, exp, 1)
      || GET_CODE (target) == PARALLEL || modifier == EXPAND_STACK_PARM
      /* Also make a temporary if the store is to volatile memory, to
         avoid individual accesses to aggregate members.  */
      || (GET_CODE (target) == MEM
          && MEM_VOLATILE_P (target)
          && !TREE_ADDRESSABLE (TREE_TYPE (exp))))
    {
      if (avoid_temp_mem)
        return NULL_RTX;

      target = assign_temp (type, TREE_ADDRESSABLE (exp), 1);

I guess the && !TREE_ADDRESSABLE (TREE_TYPE (exp)) should be applied globally,
but then other cases might break(?)

So how does 'target' look like, is !safe_from_p true?
Comment 2 Richard Biener 2025-05-28 12:56:24 UTC
also needs reduction to not require the standard library.
Comment 3 GCC Commits 2025-10-20 19:29:48 UTC
The trunk branch has been updated by Thomas Schwinge <tschwinge@gcc.gnu.org>:

https://gcc.gnu.org/g:651df6b43e817a8e4b87eed9f338ea227da7bccb

commit r16-4520-g651df6b43e817a8e4b87eed9f338ea227da7bccb
Author: Thomas Schwinge <tschwinge@baylibre.com>
Date:   Mon Oct 20 17:36:49 2025 +0200

    c++, gimplify: Implement C++26 P2795R5 - Erroneous behavior for uninitialized reads: Adjust 'libgomp.c++/{target-flex-101.C,target-std__flat_map-concurrent.C,target-std__flat_multimap-concurrent.C}' [PR114457, PR122268, PR120450]
    
    With commit r16-4212-gf256a13f8aed833fe964a2ba541b7b30ad9b4a76
    "c++, gimplify: Implement C++26 P2795R5 - Erroneous behavior for uninitialized reads [PR114457]",
    we acquired:
    
        {+FAIL: libgomp.c++/target-flex-101.C (internal compiler error: in assign_temp, at function.cc:990)+}
        [-PASS:-]{+FAIL:+} libgomp.c++/target-flex-101.C (test for excess errors)
        [-PASS:-]{+UNRESOLVED:+} libgomp.c++/target-flex-101.C [-execution test-]{+compilation failed to produce executable+}
    
    ... for GCN, nvptx offloading compilation, and on the other hand:
    
        [-XFAIL:-]{+XPASS:+} libgomp.c++/target-std__flat_map-concurrent.C (internal compiler error[-: in assign_temp, at function.cc:990)-]
        [-XFAIL:-]{+XPASS:+} libgomp.c++/target-std__flat_map-concurrent.C (test for excess errors)
        [-UNRESOLVED:-]{+PASS:+} libgomp.c++/target-std__flat_map-concurrent.C [-compilation failed to produce executable-]{+execution test+}
    
        [-XFAIL:-]{+XPASS:+} libgomp.c++/target-std__flat_multimap-concurrent.C (internal compiler error[-: in assign_temp, at function.cc:990)-]
        [-XFAIL:-]{+XPASS:+} libgomp.c++/target-std__flat_multimap-concurrent.C (test for excess errors)
        [-UNRESOLVED:-]{+PASS:+} libgomp.c++/target-std__flat_multimap-concurrent.C [-compilation failed to produce executable-]{+execution test+}
    
    ... for GCN offloading compilation (already PASSed for nvptx).
    
    Note that these test cases explicitly use '-std=c++23', so don't undergo the
    new C++26 P2795R5 functionality.  Yet, comparing before vs. after that commit,
    in the 'gimple' dumps (that is, early host compilation), there are a lot of
    changes where 'gimple_assign <constructor, [...], {CLOBBER(bob)}, NULL, NULL>'s
    and relatedly 'gimple_bind's newly appear/no longer appear elsewhere.  This
    leads to correspondingly different code at the beginning of offloading
    compilation.  Why/how that now ('libgomp.c++/target-flex-101.C') vs. before
    ('libgomp.c++/{target-std__flat_map-concurrent.C,target-std__flat_multimap-concurrent.C}')
    translates into 'expand' ICEs, I can't tell.
    
            PR c++/114457
            PR c++/122268
            PR c++/120450
            libgomp/
            * testsuite/libgomp.c++/target-flex-101.C: XFAIL GCN, nvptx
            offloading compilation.
            * testsuite/libgomp.c++/target-std__flat_map-concurrent.C:
            Un-XFAIL GCN offloading compilation.
            * testsuite/libgomp.c++/target-std__flat_multimap-concurrent.C:
            Likewise.
Comment 4 Thomas Schwinge 2025-10-20 20:29:06 UTC
Via commit r16-4212-gf256a13f8aed833fe964a2ba541b7b30ad9b4a76 "c++, gimplify: Implement C++26 P2795R5 - Erroneous behavior for uninitialized reads [PR114457]", 'libgomp.c++/target-std__flat_map-concurrent.C' and 'libgomp.c++/target-std__flat_multimap-concurrent.C' now PASS on trunk (but presumably still ICE on releases/gcc-15 branch).  And in return, we've got 'libgomp.c++/target-flex-101.C' ICEing for GCN and nvptx offloading compilation: PR122268 "[OpenMP][offload:gcn/nvptx lto1] ICE (during RTL pass: expand) in assign_temp, at function.cc:990 for libgomp.c++/target-flex-101.C (c++/16.0.0/flat_map:185:1) since r16-4212-gf256a13f8aed83".

The "simple '-O0' reproducer" posted above still ICEs, too -- now for both GCN and nvptx offloading compilation.

Chances are that it's all the same underlying issue.  (I've not yet had a chance to look into Richi's suggestions.)