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

            Bug ID: 123503
           Summary: ICE: in gimple_add_tmp_var, at gimplify.cc with
                    invalid reinterpret_cast to a concept
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 522024330006 at smail dot nju.edu.cn
  Target Milestone: ---

To reproduce: https://godbolt.org/z/rMrWKf1ec

The compiler triggers an ICE when a concept is incorrectly used as a pointer
type in a reinterpret_cast within a context involving auto deduction and
subsequent code in the same scope.

Program:
```c
template<class T>
concept C = true; 

int main() {
    void* ptr_void = nullptr;
    const auto& ref = reinterpret_cast<C*>(ptr_void); 
    int a = 0, b = 1; // must introduce some unnecessary code to trigger the
crash
    return (a != b);
}
```

Part of the traceback:
```
internal compiler error: in gimple_add_tmp_var, at gimplify.cc:834
   46 |    const auto& ref_invalid =
reinterpret_cast<InvalidConceptsSyntax*>(ptr_void); // Triggers type mismatch
      |                                                                        
      ^
0x5da1dc8 internal_error(char const*, ...)
        /workspace/install/gcc/src/gcc/gcc/diagnostic-global-context.cc:517
0x5d3f858 fancy_abort(char const*, int, char const*)
        /workspace/install/gcc/src/gcc/gcc/diagnostic.cc:1749
0x1ee8a22 gimple_add_tmp_var(tree_node*)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:834
0x1ef1bd3 gimplify_decl_expr
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:2194
0x1f7342c gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:19727
0x1f1a2a6 gimplify_stmt(tree_node**, gimple**)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:8458
0x1ef2276 gimplify_statement_list
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:2285
0x1f752e1 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:19981
0x1f1a2a6 gimplify_stmt(tree_node**, gimple**)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:8458
0x1eee39b gimplify_bind_expr
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:1680
0x1f73475 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:19731
0x1f1a2a6 gimplify_stmt(tree_node**, gimple**)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:8458
0x1ef2276 gimplify_statement_list
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:2285
0x1f752e1 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:19981
0x1f1a2a6 gimplify_stmt(tree_node**, gimple**)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:8458
0x1f7a46a gimplify_body(tree_node*, bool)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:20833
0x1f7b748 gimplify_function_tree(tree_node*)
        /workspace/install/gcc/src/gcc/gcc/gimplify.cc:21042
0x1a64ddf cgraph_node::analyze()
        /workspace/install/gcc/src/gcc/gcc/cgraphunit.cc:689
0x1a6900b analyze_functions
        /workspace/install/gcc/src/gcc/gcc/cgraphunit.cc:1265
0x1a6f5c9 symbol_table::finalize_compilation_unit()
        /workspace/install/gcc/src/gcc/gcc/cgraphunit.cc:2574
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.
```

Reply via email to