Re: [Bug jit/99126] New: Compilation ICE trying insert trap

2021-02-16 Thread Andrea Corallo via Gcc-bugs
This is the bt of how the C front-end is initializing these
declarations:

#0  set_builtin_decl (implicit_p=, 
decl=, 
fncode=) at ../../gcc/tree.h:5662
#1  def_builtin_1 (fncode=, name=, 
fntype=, libtype=, both_p=, 
fallback_p=, nonansi_p=false, 
fnattrs=, implicit_p=true, 
fnclass=BUILT_IN_NORMAL)
at ../../gcc/c-family/c-common.c:4729
#2  0x00a291c9 in c_define_builtins (
va_list_arg_type_node=, va_list_ref_type_node=)
at ../../gcc/builtins.def:933

Thinking loud: I guess in jit-builtins.c we should loop once over all
the builtins calling 'set_builtin_decl'?  Probably in the constructor
for gcc::jit::builtins_manager?


[Bug jit/99126] New: Compilation ICE trying insert trap

2021-02-16 Thread akrl at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99126

Bug ID: 99126
   Summary: Compilation ICE trying insert trap
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: jit
  Assignee: dmalcolm at gcc dot gnu.org
  Reporter: akrl at gcc dot gnu.org
  Target Milestone: ---

Created attachment 50205
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50205=edit
reproducer

Hi all,

to reproduce with the attached:

=
$ gcc libgccjit_repro.c -lgccjit
$ ./a.out
Segmentation fault (core dumped)
=

This is my understanding of what is going on here: we have a some
generated code that in GIMPLE is proved to dereference a null pointer
(BTW this code should be unreachable).

MEM[(struct comp_Lisp_Cons *)0B].u.s.car = _35;

>From the 'F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_0'
function.

Running pass 'isolate-paths' we try to inject a trap but
'builtin_decl_explicit (BUILT_IN_TRAP)' is returning NULL as the
builtin declaration that we should find in 'builtin_info' is never
initialized by the frontend (libgccjit).  As a consequence we ICE in
'gimple_build_call'.

Here the backtrace:

#0  gimple_build_call (fn=0x0, nargs=nargs@entry=0) at ../../gcc/gimple.c:264
#1  0x77450cf8 in insert_trap (si_p=si_p@entry=0x7fffde20,
op=0x75654fc0) at ../../gcc/gimple-ssa-isolate-paths.c:93
#2  0x7745302b in find_explicit_erroneous_behavior () at
../../gcc/gimple-ssa-isolate-paths.c:863
#3  gimple_ssa_isolate_erroneous_paths () at
../../gcc/gimple-ssa-isolate-paths.c:928
#4  (anonymous namespace)::pass_isolate_erroneous_paths::execute
(this=) at ../../gcc/gimple-ssa-isolate-paths.c:979
#5  0x76a7fc3d in execute_one_pass (pass=0x6255a0) at
../../gcc/passes.c:2509
#6  0x76a803a8 in execute_pass_list_1 (pass=0x6255a0) at
../../gcc/passes.c:2597
#7  0x76a803ba in execute_pass_list_1 (pass=0x624990) at
../../gcc/passes.c:2598
#8  0x76a80405 in execute_pass_list (fn=0x75849790, pass=) at ../../gcc/passes.c:2608
#9  0x76790428 in cgraph_node::expand (this=0x75850ca8) at
../../gcc/context.h:48
#10 0x76791a6d in expand_all_functions () at
../../gcc/cgraphunit.c:2476
[...]

This ICE breaks Emacs bootstrap on 32bit machines configuring with
'--with-wide-int'.

A reduced reduced should be writable (manually as there's no creduce
for libgccjit) ATM I'm posting what I have from Emacs.

GCC 10 is likely to be affected too, I'll try it soon, GCC 9 is
working and does not show this bug.

  Andrea