http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48395

           Summary: [AVR] ICE: segmentation fault when compiling
                    libgcc2.c, SVN trunk r171783
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: middle-end
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: j...@uriah.heep.sax.de


Created attachment 23842
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23842
GDB transcript

trunk r171783 cannot compile its own libgcc2.c for the AVR target:

gmake[4]: Entering directory `/junk/gcc/trunk/build-avr/avr/avr25/libgcc'
# If this is the top-level multilib, build all the other
# multilibs.
/junk/gcc/trunk/build-avr/./gcc/xgcc -B/junk/gcc/trunk/build-avr/./gcc/
-B/junk/testroot/avr/bin/ -B/junk/testroot/avr/lib/ -isystem
/junk/testroot/avr/include -isystem /junk/testroot/avr/sys-include    -g -O2
-mmcu=avr25 -O2  -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE  -W -Wall
-Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition  -isystem ./include  -DDF=SF -Dinhibit_libc
-mcall-prologues -Os -g  -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED
-fno-stack-protector -Dinhibit_libc  -I. -I. -I../../.././gcc
-I../../../../libgcc -I../../../../libgcc/. -I../../../../libgcc/../gcc
-I../../../../libgcc/../include  -DHAVE_CC_TLS -DUSE_EMUTLS -o _negdi2.o -MT
_negdi2.o -MD -MP -MF _negdi2.dep -DL_negdi2 -c
../../../../libgcc/../gcc/libgcc2.c \

../../../../libgcc/../gcc/libgcc2.c: In function ‘__negdi2’:
../../../../libgcc/../gcc/libgcc2.c:68:17: internal compiler error:
Segmentation fault: 11
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
gmake[4]: *** [_negdi2.o] Error 1
gmake[4]: Leaving directory `/junk/gcc/trunk/build-avr/avr/avr25/libgcc'
gmake[3]: *** [multi-do] Error 1
gmake[3]: Leaving directory `/junk/gcc/trunk/build-avr/avr/libgcc'
gmake[2]: *** [all-multi] Error 2
gmake[2]: Leaving directory `/junk/gcc/trunk/build-avr/avr/libgcc'
gmake[1]: *** [all-target-libgcc] Error 2
gmake[1]: Leaving directory `/junk/gcc/trunk/build-avr'
gmake: *** [all] Error 2

(Also attaching the GDB transcript separately for better readability.
See below for my conclusion about the nature of the bug.)

The debugger shows the following stack trace:
(gdb) bt
#0  scratch_operand (op=0x959, mode=HImode) at ../../gcc/recog.c:1078
#1  0x08375db4 in insn_operand_matches (icode=CODE_FOR_setmemhi, opno=4,
operand=0x959) at ../../gcc/optabs.c:6999
#2  0x083760d9 in maybe_legitimize_operands (icode=CODE_FOR_setmemhi, opno=0,
nops=5, ops=0xbfbfda2c) at ../../gcc/optabs.c:7074
#3  0x083762c3 in maybe_gen_insn (icode=CODE_FOR_setmemhi, nops=5,
ops=0xbfbfda2c) at ../../gcc/optabs.c:7124
#4  0x083764cf in maybe_expand_insn (icode=CODE_FOR_setmemhi, nops=5,
ops=0xbfbfda2c) at ../../gcc/optabs.c:7155
#5  0x08231f19 in set_storage_via_setmem (object=0x28b4f2dc, size=0x28a1b2f8,
val=0x28a1b2b8, align=Variable "align" is not available.
) at ../../gcc/expr.c:2738
#6  0x08246b41 in clear_storage_hints (object=0x28b4f2dc, size=0x28a1b2f8,
method=BLOCK_OP_NORMAL, expected_align=0, 
    expected_size=-1) at ../../gcc/expr.c:2579
#7  0x08246c7f in clear_storage (object=0x28b4f2dc, size=0x28a1b2f8,
method=BLOCK_OP_NORMAL) at ../../gcc/expr.c:2594
#8  0x08239a1d in store_constructor (exp=0x28b10848, target=0x28b4f2dc,
cleared=0, size=8) at ../../gcc/expr.c:5196
#9  0x0823a729 in expand_constructor (exp=0x28b10848, target=0x28b4f2dc,
modifier=EXPAND_NORMAL, avoid_temp_mem=0 '\0')
    at ../../gcc/expr.c:7100
#10 0x0823d56a in expand_expr_real_1 (exp=0x28b10848, target=0x28b4f2dc,
tmode=BLKmode, modifier=EXPAND_NORMAL, alt_rtl=0xbfbfdd9c)
    at ../../gcc/expr.c:8659
#11 0x08246d53 in store_expr (exp=0x28b10848, target=0x28b4f2dc,
call_param_p=0, nontemporal=0 '\0') at ../../gcc/expr.c:4653
#12 0x08236f47 in expand_assignment (to=0x28b2b120, from=0x28b10848,
nontemporal=Variable "nontemporal" is not available.
) at ../../gcc/expr.c:4441
#13 0x081950a1 in expand_gimple_stmt (stmt=0x28b2f6c0) at
../../gcc/cfgexpand.c:1972
#14 0x08195a98 in expand_gimple_basic_block (bb=0x28a926c0) at
../../gcc/cfgexpand.c:3637
#15 0x08197028 in gimple_expand_cfg () at ../../gcc/cfgexpand.c:4120
#16 0x08391a57 in execute_one_pass (pass=0x881b120) at ../../gcc/passes.c:1555
#17 0x08391e9d in execute_pass_list (pass=0x881b120) at ../../gcc/passes.c:1610
#18 0x0847174a in tree_rest_of_compilation (fndecl=0x28afea00) at
../../gcc/tree-optimize.c:422
#19 0x0861c209 in cgraph_expand_function (node=0x28b09f24) at
../../gcc/cgraphunit.c:1575
#20 0x0861f842 in cgraph_optimize () at ../../gcc/cgraphunit.c:1634
#21 0x0861fd2a in cgraph_finalize_compilation_unit () at
../../gcc/cgraphunit.c:1095
#22 0x080a3998 in c_write_global_declarations () at ../../gcc/c-decl.c:9879
#23 0x0840af90 in do_compile () at ../../gcc/toplev.c:591
#24 0x0840b73d in toplev_main (argc=83, argv=0xbfbfe240) at
../../gcc/toplev.c:1963
#25 0x08140292 in main (argc=Error accessing memory address 0x959: Bad address.
) at ../../gcc/main.c:36

By browsing through the individual functions, I eventually stumbled
upon set_storage_via_setmem() setting up the "ops" table which causes
the segfault:

(gdb) up 5
#5  0x08231f19 in set_storage_via_setmem (object=0x28b4f2dc, size=0x28a1b2f8,
val=0x28a1b2b8, align=Variable "align" is not available.
) at ../../gcc/expr.c:2738
2738              if (maybe_expand_insn (code, nops, ops))
(gdb) l set_storage_via_setmem 
2689    /* Expand a setmem pattern; return true if successful.  */
2690
2691    bool
2692    set_storage_via_setmem (rtx object, rtx size, rtx val, unsigned int
align,
2693                            unsigned int expected_align, HOST_WIDE_INT
expected_size)
2694    {
2695      /* Try the most limited insn first, because there's no point
2696         including more than one in the machine description unless
2697         the more limited one has some advantage.  */
2698
(gdb) l
2699      enum machine_mode mode;
2700
2701      if (expected_align < align)
2702        expected_align = align;
2703
2704      for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
2705           mode = GET_MODE_WIDER_MODE (mode))
2706        {
2707          enum insn_code code = direct_optab_handler (setmem_optab, mode);
2708
(gdb) l
2709          if (code != CODE_FOR_nothing
2710              /* We don't need MODE to be narrower than
2711                 BITS_PER_HOST_WIDE_INT here because if SIZE is less than
2712                 the mode mask, as it is returned by the macro, it will
2713                 definitely be less than the actual mode mask.  */
2714              && ((CONST_INT_P (size)
2715                   && ((unsigned HOST_WIDE_INT) INTVAL (size)
2716                       <= (GET_MODE_MASK (mode) >> 1)))
2717                  || GET_MODE_BITSIZE (mode) >= BITS_PER_WORD))
2718            {
(gdb) l
2719              struct expand_operand ops[6];
2720              unsigned int nops;
2721
2722              nops = insn_data[(int) code].n_operands;
2723              /* ??? n_operands includes match_scratches; find some other
2724                 way to select the 6 operand variant, or force all targets
2725                 to have exactly 6 operands.  */
2726              gcc_assert (nops >= 4 && nops <= 6);
2727
2728              create_fixed_operand (&ops[0], object);
(gdb) l
2729              /* The check above guarantees that this size conversion is
valid.  */
2730              create_convert_operand_to (&ops[1], size, mode, true);
2731              create_convert_operand_from (&ops[2], val, byte_mode, true);
2732              create_integer_operand (&ops[3], align / BITS_PER_UNIT);
2733              if (nops == 6)
2734                {
2735                  create_integer_operand (&ops[4], expected_align /
BITS_PER_UNIT);
2736                  create_integer_operand (&ops[5], expected_size);
2737                }
2738              if (maybe_expand_insn (code, nops, ops))
(gdb) l
2739                return true;
2740            }
2741        }
2742
2743      return false;
2744    }
2745
2746    ^L
2747    /* Write to one of the components of the complex value CPLX.  Write VAL
to
2748       the real part if IMAG_P is false, and the imaginary part if its
true.  */
(gdb) p ops
$27 = {{type = EXPAND_FIXED, unsigned_p = 0, unused = 0, mode = VOIDmode, value
= 0x28b4f2dc}, {type = EXPAND_CONVERT_TO, 
    unsigned_p = 1, unused = 0, mode = HImode, value = 0x28a1b2f8}, {type =
EXPAND_CONVERT_FROM, unsigned_p = 1, unused = 0, 
    mode = QImode, value = 0x28a1b2b8}, {type = EXPAND_INTEGER, unsigned_p = 0,
unused = 0, mode = VOIDmode, value = 0x28a1b2c0}, {
    type = 48, unsigned_p = 1, unused = 93, mode = 2140, value = 0x959}, {type
= 7, unsigned_p = 0, unused = 113, mode = 16068, 
    value = 0x2}}
(gdb) p nops
$28 = 5

Note that for nops == 5, the code in lines 2735/2736 is not executed,
so ops[4] and ops[5] remain undefined.  The assertion in line 2726,
however, explicitly allows for nops being 4, 5, or 6.

Reply via email to