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

            Bug ID: 106062
           Summary: [13 Regression] ICE in build_builtin_unreachable since
                    r13-1204-gd68d366425369649
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: jason at gcc dot gnu.org
  Target Milestone: ---

Since the revision the following fails:

$ cat loop.f90
call test (reshape ((/ 'a', 'b', 'c', 'd' /), (/ 2, 2 /)))
contains
  subroutine test (a)
    character (*), dimension (:, :) :: a
    if (len (a) .ne. 1) STOP 
  end  
end

$ gcc loop.f90 -fsanitize=unreachable -O2 -c
during GIMPLE pass: einline
loop.f90:1:58:

    1 | call test (reshape ((/ 'a', 'b', 'c', 'd' /), (/ 2, 2 /)))
      |                                                          ^
internal compiler error: Segmentation fault
0xfe3e1a crash_signal
        /home/marxin/Programming/gcc/gcc/toplev.cc:322
0x7ffff78567bf ???
       
/usr/src/debug/glibc-2.35-4.2.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x12d6c45 contains_struct_check(tree_node*, tree_node_structure_enum, char
const*, int, char const*)
        /home/marxin/Programming/gcc/gcc/tree.h:3629
0x12d6c45 build_call_expr_loc_array(unsigned int, tree_node*, int, tree_node**)
        /home/marxin/Programming/gcc/gcc/tree.cc:10634
0x12d6da0 build_call_expr_loc(unsigned int, tree_node*, int, ...)
        /home/marxin/Programming/gcc/gcc/tree.cc:10667
0x12d6de8 build_builtin_unreachable(unsigned int)
        /home/marxin/Programming/gcc/gcc/tree.cc:10819
0xac0aad fold_builtin_0
        /home/marxin/Programming/gcc/gcc/builtins.cc:9270
0xac0aad fold_builtin_n
        /home/marxin/Programming/gcc/gcc/builtins.cc:9578
0xac31a2 fold_call_stmt(gcall*, bool)
        /home/marxin/Programming/gcc/gcc/builtins.cc:10836
0xcb7c34 gimple_fold_builtin
        /home/marxin/Programming/gcc/gcc/gimple-fold.cc:5151
0xcb7c34 gimple_fold_call
        /home/marxin/Programming/gcc/gcc/gimple-fold.cc:5551
0xcba373 fold_stmt_1
        /home/marxin/Programming/gcc/gcc/gimple-fold.cc:6295
0x1066af8 fold_marked_statements
        /home/marxin/Programming/gcc/gcc/tree-inline.cc:5366
0x107afd3 optimize_inline_calls(tree_node*)
        /home/marxin/Programming/gcc/gcc/tree-inline.cc:5514
0x1e6077f early_inliner(function*)
        /home/marxin/Programming/gcc/gcc/ipa-inline.cc:3038
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.

Can be fixed with:

 gcc/ubsan.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ubsan.cc b/gcc/ubsan.cc
index f15026872a1..b6c4301dfaf 100644
--- a/gcc/ubsan.cc
+++ b/gcc/ubsan.cc
@@ -654,9 +654,10 @@ sanitize_unreachable_fn (tree *data, location_t loc)
     }
   else if (san)
     {
-      fn = builtin_decl_explicit (BUILT_IN_UBSAN_HANDLE_BUILTIN_UNREACHABLE);
+      /* Call ubsan_create_data first as it initializes SANITIZER built-ins. 
*/
       *data = ubsan_create_data ("__ubsan_unreachable_data", 1, &loc,
                                 NULL_TREE, NULL_TREE);
+      fn = builtin_decl_explicit (BUILT_IN_UBSAN_HANDLE_BUILTIN_UNREACHABLE);
       *data = build_fold_addr_expr_loc (loc, *data);
     }
   else

Reply via email to