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

            Bug ID: 91995
           Summary: gnat miscompilation and bootstrap failure on
                    m68k-linux
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikpelinux at gmail dot com
  Target Milestone: ---

Attempting to bootstrap gnat on m68k-linux fails due to a SEGV in stage3:

/mnt/scratch/objdir10/./prev-gcc/xgcc -B/mnt/scratch/objdir10/./prev-gcc/
-B/home/mikpe/pkgs/linux-m68k/gcc-10.0/m68k-unknown-linux-gnu/bin/
-B/home/mikpe/pkgs/linux-m68k/gcc-10.0/m68k-unknown-linux-gnu/bin/
-B/home/mikpe/pkgs/linux-m68k/gcc-10.0/m68k-unknown-linux-gnu/lib/ -isystem
/home/mikpe/pkgs/linux-m68k/gcc-10.0/m68k-unknown-linux-gnu/include -isystem
/home/mikpe/pkgs/linux-m68k/gcc-10.0/m68k-unknown-linux-gnu/sys-include  
-fchecking=1 -c -g -O2 -fchecking=1  -gnatpg  -W -Wall -g -O1 -fno-inline \
 -nostdinc -I- -I. -Iada/generated -Iada -I/mnt/scratch/gcc-10-20190915/gcc/ada
-I/mnt/scratch/gcc-10-20190915/gcc/ada/gcc-interface -Iada/libgnat
-I/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-except.adb -o
ada/libgnat/a-except.o
+===========================GNAT BUG DETECTED==============================+
| 10.0.0 20190915 (experimental) (m68k-unknown-linux-gnu) Storage_Error stack
overflow or erroneous memory access|
| Error detected at a-exexda.adb:625:13                                    |
| Please submit a bug report; see https://gcc.gnu.org/bugs/ .              |
| Use a subject line meaningful to you and us to track the bug.            |
| Include the entire contents of this bug box in the report.               |
| Include the exact command that you entered.                              |
| Also include sources listed below.                                       |
+==========================================================================+

Please include these source files with error report
Note that list may not be accurate in some cases,
so please double check that the problem can still
be reproduced with the set of files listed.
Consider also -gnatd.n switch (see debug.adb).

/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/system.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-except.adb
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-except.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/ada.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-parame.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-stalib.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-unccon.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-traent.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-except.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-excdeb.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-soflin.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-secsta.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-stoele.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-stache.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-wchcon.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-wchstw.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-traceb.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-trasym.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-exctab.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-excpol.adb
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-excach.adb
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-exexda.adb
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-exexpr.adb
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-uncdea.ads
ada/libgnat/s-excmac.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-exextr.adb
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-elchha.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-imgint.ads
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/a-exstat.adb
/mnt/scratch/gcc-10-20190915/gcc/ada/libgnat/s-stoele.adb

compilation abandoned
make[3]: *** [ada/libgnat/a-except.o] Error 1
make[3]: Leaving directory `/mnt/scratch/objdir10/gcc'
make[2]: *** [all-stage3-gcc] Error 2
make[2]: Leaving directory `/mnt/scratch/objdir10'
make[1]: *** [stage3-bubble] Error 2
make[1]: Leaving directory `/mnt/scratch/objdir10'
make: *** [bootstrap] Error 2

Running that under gdb shows a NULL pointer dereference:

Program received signal SIGSEGV, Segmentation fault.
0x8006bbdc in build_unary_op(tree_code, tree_node*, tree_node*) ()

(gdb) print/x $pc
$1 = 0x8006bbdc
(gdb) disassemble 0x8006bbd0, 0x8006bbf0 
Dump of assembler code from 0x8006bbd0 to 0x8006bbf0:
   0x8006bbd0 <_Z14build_unary_op9tree_codeP9tree_nodeS1_+1030>:        jsr
0x805582d8 <_Z27build_fold_indirect_ref_locjP9tree_node>
   0x8006bbd6 <_Z14build_unary_op9tree_codeP9tree_nodeS1_+1036>:        moveal
%a0,%a2
   0x8006bbd8 <_Z14build_unary_op9tree_codeP9tree_nodeS1_+1038>:        moveal
%a5@(8),%a0
=> 0x8006bbdc <_Z14build_unary_op9tree_codeP9tree_nodeS1_+1042>:        bfextu
%a0@(2),4,1,%d0
   0x8006bbe2 <_Z14build_unary_op9tree_codeP9tree_nodeS1_+1048>:        bfins
%d0,%a2@(2),4,1
   0x8006bbe8 <_Z14build_unary_op9tree_codeP9tree_nodeS1_+1054>:        addql
#8,%sp
   0x8006bbea <_Z14build_unary_op9tree_codeP9tree_nodeS1_+1056>:        movew
%a2@,%d0
   0x8006bbec <_Z14build_unary_op9tree_codeP9tree_nodeS1_+1058>:        cmpiw
#17,%a5@
End of assembler dump.
(gdb) print/x $a0
$2 = 0x0

This failure affects gcc-6 through gcc-10, gcc-5 was fine (though needed an
add-on patch, see PR48835).

A bisection identified this fragment of r229421 as the culprit:

2015-10-27  Javier Miranda  <mira...@adacore.com>

        * sem_util.ads, sem_util.adb (Defining_Identifier): Adding a formal to
        indicate the needed behavior in case of nodes with errors.

The new formal has a default value, and only a few callers pass an explicit
value for it.  Replacing this formal-with-default with new functions that only
have plain formals without defaults, and adjusting the few affected callers to
use these new functions instead, avoids the miscompilation.

The host compiler is gcc-9 updated with a version of this patch.

Reply via email to