Bug 49084 - [4.7 regression] bootstrap failure with Ada enabled
Summary: [4.7 regression] bootstrap failure with Ada enabled
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.7.0
: P4 normal
Target Milestone: 4.7.0
Assignee: Eric Botcazou
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2011-05-20 15:57 UTC by Anh Vo
Modified: 2011-12-16 16:24 UTC (History)
3 users (show)

See Also:
Host: i686-pc-mingw32
Target: i686-pc-mingw32
Build: i686-pc-mingw32
Known to work:
Known to fail:
Last reconfirmed: 2011-05-22 08:32:06


Attachments
Debug log of PR49084 (2.61 KB, text/plain)
2011-11-27 20:55 UTC, Cesar Strauss
Details
Tentative fix (641 bytes, patch)
2011-12-13 10:07 UTC, Eric Botcazou
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anh Vo 2011-05-20 15:57:53 UTC
Snapshot gcc-4.7-20110514 fails bootstrap in stage 3 with bug box indicating error detected at system.ads:175:5. This build was configured as ../gcc-4.7-20110514/configure --without-build-config --disable-werror --enable-languages=ada,c. The trailing error message is shown below.

/c/Gcc/Build-4.7.x/./prev-gcc/xgcc -B/c/Gcc/Build-4.7.x/./prev-gcc/ -B/usr/local/i686-pc-mingw32/bin/ -L/c/Gcc/Build-4.7.x/i686-pc-mingw32/winsup/mingw -L/c/Gcc/Build-4.7.x/i686-pc-mingw32/winsup/w32api/lib -isystem /c/Gcc/gcc-4.7-20110514/winsup/mingw/include -isystem /c/Gcc/gcc-4.7-20110514/winsup/w32api/include -B/usr/local/i686-pc-mingw32/bin/ -B/usr/local/i686-pc-mingw32/lib/ -isystem /usr/local/i686-pc-mingw32/include -isystem /usr/local/i686-pc-mingw32/sys-include    -c -g -O2 -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format  -gnatpg -gnata -nostdinc -I- -I. -Iada -I../../gcc-4.7-20110514/gcc/ada -I../../gcc-4.7-20110514/gcc/ada/gcc-interface ../../gcc-4.7-20110514/gcc/ada/a-charac.ads -o ada/a-charac.o
gnat1.exe: warning: command line option '-Wno-pedantic-ms-format' is valid for C
/C++/ObjC/ObjC++ but not for Ada [enabled by default]
+===========================GNAT BUG DETECTED==============================+
| 4.7.0 20110514 (experimental) (i686-pc-mingw32) Program_Error EXCEPTION_ACCESS
_VIOLATION|
| Error detected at system.ads:175:5                                       |
| Please submit a bug report; see http://gcc.gnu.org/bugs.html.            |
| 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 gcc or gnatmake command that you entered.              |
| Also include sources listed below in gnatchop format                     |
| (concatenated together with no headers between files).                   |
+==========================================================================+

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).

../../gcc-4.7-20110514/gcc/ada\system.ads
../../gcc-4.7-20110514/gcc/ada/a-charac.ads
../../gcc-4.7-20110514/gcc/ada\ada.ads

compilation abandoned
make[3]: *** [ada/a-charac.o] Error 1
make[3]: Leaving directory `/c/Gcc/Build-4.7.x/gcc'
make[2]: *** [all-stage3-gcc] Error 2
make[2]: Leaving directory `/c/Gcc/Build-4.7.x'
make[1]: *** [stage3-bubble] Error 2
make[1]: Leaving directory `/c/Gcc/Build-4.7.x'
make: *** [all] Error 2
Comment 1 Eric Botcazou 2011-05-22 08:32:06 UTC
This looks like a miscompilation of the stage2 compiler.  Linux is fine so I'm afraid nobody will look into this in the immediate future.

Please try with newer snapshots.
Comment 2 Anh Vo 2011-05-23 18:49:10 UTC
It will be fine if the fix goes into the latest snapshot.
Comment 3 Richard Biener 2011-08-02 14:12:01 UTC
Does it work now?
Comment 4 Anh Vo 2011-08-02 15:40:34 UTC
On Tue, Aug 2, 2011 at 7:18 AM, rguenth at gcc dot gnu.org
<gcc-bugzilla@gcc.gnu.org> wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49084
>
> --- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-02 14:12:01 UTC ---
> Does it work now?

It still fails with snapshot gcc-4.7-20110716. I am downloading
gcc-4.7-20110730 at this minute. I will report the result of it once
the build is complete.
Comment 5 Anh Vo 2011-08-02 20:28:03 UTC
On Tue, Aug 2, 2011 at 8:41 AM, anhvofrcaus at gmail dot com
<gcc-bugzilla@gcc.gnu.org> wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49084
>
> --- Comment #4 from Anh Vo <anhvofrcaus at gmail dot com> 2011-08-02 15:40:34 UTC ---
> On Tue, Aug 2, 2011 at 7:18 AM, rguenth at gcc dot gnu.org
> <gcc-bugzilla@gcc.gnu.org> wrote:
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49084
>>
>> --- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-02 14:12:01 UTC ---
>> Does it work now?
>
> It still fails with snapshot gcc-4.7-20110716. I am downloading
> gcc-4.7-20110730 at this minute. I will report the result of it once
> the build is complete.

It fails once again. However, it fails at different point (in stage 2)
and with different error message compared to the past failure. Below
is the error message:

[...]
/c/Gcc/Build-4.7.x/./prev-gcc/g++ -B/c/Gcc/Build-4.7.x/./prev-gcc/
-B/usr/local/i686-pc-mingw32/bin/ -nostdinc++
-B/c/Gcc/Build-4.7.x/prev-i686-pc-mingw32/libstdc++-v3/src/.libs
-B/c/Gcc/Build-4.7.x/prev-i686-pc-mingw32/libstdc++-v3/libsupc++/.libs
-I/c/Gcc/Build-4.7.x/prev-i686-pc-mingw32/libstdc++-v3/include/i686-pc-
mingw32 -I/c/Gcc/Build-4.7.x/prev-i686-pc-mingw32/libstdc++-v3/include
-I/c/Gcc/gcc-4.7-20110730/libstdc++-v3/libsupc++
-L/c/Gcc/Build-4.7.x/prev-i686-pc-mingw32/libstdc++-v3/src/.libs
-L/c/Gcc/Build-4.7.x/prev-i686-pc-mingw32/libstdc++-v3/libsupc++/.libs
-c  -g -O2 -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format -DIN_GCC
   -W -Wall -Wwrite-strings -Wcast-qual  -Wmissing-format-attribute
-Wno-long-long -Wno-variadic-macros -Wno-overlength-strings
-fno-common -Wno-error -DHAVE_CONFIG_H -I. -Iada
-I../../gcc-4.7-20110730/gcc -I../../gcc-4.7-20110730/gcc/ada
-I../../gcc-4.7-20110730/gcc/../include -I./../intl
-I../../gcc-4.7-20110730/gcc/../libcpp/include
-I../../gcc-4.7-20110730/gcc/../libdecnumber
-I../../gcc-4.7-20110730/gcc/../libdecnumber/bid -I../libdecnumber
../../gcc-4.7-20110730/gcc/ada/adaint.c -o ada/adaint.o
../../gcc-4.7-20110730/gcc/ada/adaint.c: In function 'OS_Time __gnat_file_time_n
ame_attr(char*, file_attributes*)':
../../gcc-4.7-20110730/gcc/ada/adaint.c:1373:73: warning: suggest parentheses ar
ound assignment used as truth value [-Wparentheses]
../../gcc-4.7-20110730/gcc/ada/adaint.c: In function 'void __gnat_set_OWNER_ACL(
TCHAR*, DWORD, DWORD)':
../../gcc-4.7-20110730/gcc/ada/adaint.c:2004:66: error: invalid conversion from
'DWORD {aka long unsigned int}' to 'ACCESS_MODE {aka _ACCESS_MODE}'
[-fpermissive]
/mingw/include/aclapi.h:15:23: error:   initializing argument 4 of
'void BuildExplicitAccessWithNameW(PEXPLICIT_ACCESS_W, LPWSTR, DWORD,
ACCESS_MODE, DWORD)' [-fpermissive]
../../gcc-4.7-20110730/gcc/ada/adaint.c: At global scope:
../../gcc-4.7-20110730/gcc/ada/adaint.c:2263:1: warning: unused
parameter 'name' [-Wunused-parameter]
../../gcc-4.7-20110730/gcc/ada/adaint.c: In function 'void
add_handle(HANDLE, int)':
../../gcc-4.7-20110730/gcc/ada/adaint.c:2461:67: error: invalid
conversion from'void*' to 'void**' [-fpermissive]
../../gcc-4.7-20110730/gcc/ada/adaint.c:2463:60: error: invalid conversion from
'void*' to 'int*' [-fpermissive]
../../gcc-4.7-20110730/gcc/ada/adaint.c: In function 'char*
__gnat_locate_exec_on_path(char*)':
../../gcc-4.7-20110730/gcc/ada/adaint.c:2833:16: error: invalid
conversion from'void*' to 'TCHAR* {aka wchar_t*}' [-fpermissive]
../../gcc-4.7-20110730/gcc/ada/adaint.c:2843:15: error: invalid
conversion from'void*' to 'char*' [-fpermissive]
make[3]: *** [ada/adaint.o] Error 1
make[3]: Leaving directory `/c/Gcc/Build-4.7.x/gcc'
make[2]: *** [all-stage2-gcc] Error 2
make[2]: Leaving directory `/c/Gcc/Build-4.7.x'
make[1]: *** [stage2-bubble] Error 2
make[1]: Leaving directory `/c/Gcc/Build-4.7.x'
make: *** [all] Error 2
Comment 6 Anh Vo 2011-08-04 16:01:59 UTC
The configuration --enable-languages=ada --without-build-config --disable-werror was used.


Now it causes gcc to fail when configuration --enable-languages=ada,c,c++ is used. Below is the trailing error message.

[...]
/c/Gcc/Build/./prev-gcc/g++ -B/c/Gcc/Build/./prev-gcc/ -B/usr/local/i686-pc-mingw32/bin/ -nostdinc++ -B/c/Gcc/Build/prev-i686-pc-mingw32/libstdc++-v3/src/.libs -B/c/Gcc/Build/prev-i686-pc-mingw32/libstdc++-v3/libsupc++/.libs -I/c/Gcc/Build/prev-i686-pc-mingw32/libstdc++-v3/include/i686-pc-mingw32 -I/c/Gcc/Build/prev-i686-pc-mingw32/libstdc++-v3/include -I/c/Gcc/gcc-4.7-20110730/libstdc++-v3/libsup
c++ -L/c/Gcc/Build/prev-i686-pc-mingw32/libstdc++-v3/src/.libs -L/c/Gcc/Build/prev-i686-pc-mingw32/libstdc++-v3/libsupc++/.libs -c  -g -O2 -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format -gtoggle -DIN_GCC   -W -Wall -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-o
verlength-strings -Werror -fno-common  -DHAVE_CONFIG_H -I. -I. -I../../gcc-4.7-20110730/gcc -I../../gcc-4.7-20110730/gcc/. -I../../gcc-4.7-20110730/gcc/../include -I./../intl -I../../gcc-4.7-20110730/gcc/../libcpp/include  -I../../gcc-4.7-20110730/gcc/../libdecnumber -I../../gcc-4.7-20110730/gcc/../libdecnumber/bid -I../libdecnumber    ../../gcc-4.7-20110730/gcc/implicit-zee.c -o implicit-zee.o ../../gcc-4.7-20110730/gcc/implicit-zee.c: In function 'unsigned int find_and_re
move_ze()':
../../gcc-4.7-20110730/gcc/implicit-zee.c:950:59: error: unknown conversion type
 character 'l' in format [-Werror=format]
../../gcc-4.7-20110730/gcc/implicit-zee.c:950:59: error: unknown conversion type
 character 'l' in format [-Werror=format]
../../gcc-4.7-20110730/gcc/implicit-zee.c:950:59: error: too many arguments for
format [-Werror=format-extra-args]
cc1plus.exe: all warnings being treated as errors

make[3]: *** [implicit-zee.o] Error 1
make[3]: Leaving directory `/c/Gcc/Build/gcc'
make[2]: *** [all-stage2-gcc] Error 2
make[2]: Leaving directory `/c/Gcc/Build'
make[1]: *** [stage2-bubble] Error 2
make[1]: Leaving directory `/c/Gcc/Build'
make: *** [all] Error 2
Comment 7 Kai Tietz 2011-11-13 06:00:35 UTC
Hmm, this is due usage of "%lld" in printf-formatter.  Does following patch fix your issue?

Index: implicit-zee.c
===================================================================
--- implicit-zee.c      (revision 180840)
+++ implicit-zee.c      (working copy)
@@ -944,10 +944,12 @@
   VEC_free (rtx, heap, zeinsn_del_list);

   if (dump_file && num_ze_opportunities > 0)
-    fprintf (dump_file, "\n %s : num_zee_opportunities = %lld "
-                        "num_realized = %lld \n",
+    fprintf (dump_file, "\n %s : num_zee_opportunities = "
+                       HOST_WIDEST_INT_PRINT_DEC
+                        " num_realized = "HOST_WIDEST_INT_PRINT_DEC "\n",
                         current_function_name (),
-                        num_ze_opportunities, num_realized);
+                        (HOST_WIDEST_INT) num_ze_opportunities,
+                        (HOST_WIDEST_INT) num_realized);

   df_finish_pass (false);
   return 0;
Comment 8 Anh Vo 2011-11-15 01:09:00 UTC
with snapshot gcc-4.7-20111105, there are syntax errors in adainit.c, initialize.c, seh_init.c and tracebak.c. These files are located at /gcc/ada directory which is part of Ada compiler.

I fixed these errors with my own ways (mostly adding explicit conversion), the bootstrap went further and finally crashed with a bug box as originally report as shown below. Thus, implicit-zee.c may not be an issue regarding this snapshot.


/c/Gcc/Build-4.7.x/./prev-gcc/xgcc -B/c/Gcc/Build-4.7.x/./prev-gcc/ -B/usr/local
/i686-pc-mingw32/bin/ -L/c/Gcc/Build-4.7.x/i686-pc-mingw32/winsup/mingw -L/c/Gcc
/Build-4.7.x/i686-pc-mingw32/winsup/w32api/lib -isystem /c/Gcc/gcc-4.7-20111105/
winsup/mingw/include -isystem /c/Gcc/gcc-4.7-20111105/winsup/w32api/include -B/u
sr/local/i686-pc-mingw32/bin/ -B/usr/local/i686-pc-mingw32/lib/ -isystem /usr/lo
cal/i686-pc-mingw32/include -isystem /usr/local/i686-pc-mingw32/sys-include    -
c -g -O2 -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format  -gnatpg -gnata -W -Wall -
nostdinc -I- -I. -Iada -I../../gcc-4.7-20111105/gcc/ada -I../../gcc-4.7-20111105
/gcc/ada/gcc-interface ../../gcc-4.7-20111105/gcc/ada/a-charac.ads -o ada/a-char
ac.o
gnat1.exe: warning: command line option '-Wno-pedantic-ms-format' is valid for C
/C++/ObjC/ObjC++ but not for Ada [enabled by default]
+===========================GNAT BUG DETECTED==============================+
| 4.7.0 20111105 (experimental) (i686-pc-mingw32) Program_Error EXCEPTION_ACCESS
_VIOLATION|
| Error detected at system.ads:175:5                                       |
| Please submit a bug report; see http://gcc.gnu.org/bugs.html.            |
| 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 gcc or gnatmake command that you entered.              |
| Also include sources listed below in gnatchop format                     |
| (concatenated together with no headers between files).                   |
+==========================================================================+

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).

../../gcc-4.7-20111105/gcc/ada\system.ads
../../gcc-4.7-20111105/gcc/ada/a-charac.ads
../../gcc-4.7-20111105/gcc/ada\ada.ads

compilation abandoned
make[3]: *** [ada/a-charac.o] Error 1
make[3]: Leaving directory `/c/Gcc/Build-4.7.x/gcc'
make[2]: *** [all-stage3-gcc] Error 2
make[2]: Leaving directory `/c/Gcc/Build-4.7.x'
make[1]: *** [stage3-bubble] Error 2
make[1]: Leaving directory `/c/Gcc/Build-4.7.x'
make: *** [all] Error 2
Comment 9 Cesar Strauss 2011-11-22 21:49:37 UTC
(In reply to comment #7)
> Hmm, this is due usage of "%lld" in printf-formatter.  Does following patch 
> fix your issue?

I did encounter the build failure reported in comment #6 (unknown conversion type character 'l' in format) on i386-pc-mingw32, and the patch given in comment #7 did fix this failure for me.

A similar solution is also needed in gcc/ira-color.c (print_hard_regs_subforest), where %lld is also used.

This allowed the build to continue to the point where I could reproduce the failure described in comment #8.
Comment 10 Cesar Strauss 2011-11-24 00:22:11 UTC
(In reply to comment #9)
> (In reply to comment #7)
> > Hmm, this is due usage of "%lld" in printf-formatter.  Does following patch 
> > fix your issue?
> 
> I did encounter the build failure reported in comment #6 (unknown conversion
> type character 'l' in format) on i386-pc-mingw32,

BTW, this was on gcc trunk (svn 181641).

> and the patch given in
> comment #7 did fix this failure for me.
> 
> A similar solution is also needed in gcc/ira-color.c
> (print_hard_regs_subforest), where %lld is also used.

Also, in gcc/config/i386/i386.c (ix86_print_operand), where %08llx is used.
 
> This allowed the build to continue to the point where I could reproduce the
> failure described in comment #8.

Although, due to additional warnings in the Ada build, I had to force --disable-werror at this point.
Comment 11 Cesar Strauss 2011-11-27 20:55:15 UTC
Created attachment 25922 [details]
Debug log of PR49084

The cause of the access violation is due to an attempt to pass a null string pointer to asprintf in internal_error_function (gcc/ada/gcc-interface/misc.c:290):

(gdb) frame 2
#2  0x0042bfad in internal_error_function (context=0x1a15800, msgid=0x11e08df "in %s, at %s:%d", ap=0x722faa4) at ../../../../gcc-svn-fixada/gcc/ada/gcc-interface/misc.c:290
290         asprintf (&loc, "%s:%d", s.file, s.line);

(gdb) l
286       s = expand_location (input_location);
287       if (context->show_column && s.column != 0)
288         asprintf (&loc, "%s:%d:%d", s.file, s.line, s.column);
289       else
290         asprintf (&loc, "%s:%d", s.file, s.line);
291       temp_loc.Low_Bound = 1;
292       temp_loc.High_Bound = strlen (loc);
293       fp_loc.Bounds = &temp_loc;
294       fp_loc.Array = loc;

(gdb) p input_location
$1 = 0

(gdb) p s
$2 = {file = 0x0, line = 0, column = 0, sysp = <optimized out>}

It remains to be seen why input_location is zero. Maybe it's too early in the process execution?

Earlier in the stack trace, there is an assertion triggered in gigi (ada/gcc-interface/trans.c:300):

(gdb) fr 6
#6  0x00491875 in gigi (gnat_root=1707, max_gnat_node=2431, number_name=1656, nodes_ptr=0x7950020, next_node_ptr=0x78b52f8, prev_node_ptr=0x78e6050, elists_ptr=0x7708e78, elmts_ptr=0x77094d0, strings_ptr=0x7734818, string_chars_ptr=0x77320f0, list_headers_ptr=0x78a9760, number_file=3, file_info_ptr=0x722fb9c, standard_boolean=12, standard_integer=27, standard_character=72, standard_long_long_float=67, standard_exception_type=1281, gigi_operating_mode=0) at ../../../../gcc-svn-fixada/gcc/ada/gcc-interface/trans.c:300
300       gcc_assert (Nkind (gnat_root) == N_Compilation_Unit);

(gdb) l
295       String_Chars_Ptr = string_chars_ptr;
296       List_Headers_Ptr = list_headers_ptr;
297
298       type_annotate_only = (gigi_operating_mode == 1);
299
300       gcc_assert (Nkind (gnat_root) == N_Compilation_Unit);
301
302       /* Declare the name of the compilation unit as the first global
303          name in order to make the middle-end fully deterministic.  */
304       t = create_concat_name (Defining_Entity (Unit (gnat_root)), NULL);

(gdb) p gnat_root
$3 = 1707

(gdb) p (Nodes_Ptr[(gnat_root) - 0].U.K.kind)
$4 = 17 '\021'

It seems Nkind (gnat_root) is N_Op_Add (17) for some reason.

BTW this is trunk (svn 181738), with the stage 2 compiler (this bug is not manifest in the stage 1 compiler).

Full debug log is attached.
Comment 12 Eric Botcazou 2011-11-27 22:06:23 UTC
> The cause of the access violation is due to an attempt to pass a null string
> pointer to asprintf in internal_error_function
> (gcc/ada/gcc-interface/misc.c:290):

Thanks for the investigation.

> It remains to be seen why input_location is zero. Maybe it's too early in the
> process execution?

Zero is UNKNOWN_LOCATION.  The problem is probably that the location mapping isn't initialized yet.  What happens if you move the block in gigi:

  gcc_assert (Nkind (gnat_root) == N_Compilation_Unit);

  /* Declare the name of the compilation unit as the first global
     name in order to make the middle-end fully deterministic.  */
  t = create_concat_name (Defining_Entity (Unit (gnat_root)), NULL);
  first_global_object_name = ggc_strdup (IDENTIFIER_POINTER (t));

to after the immediately following loop?

> (gdb) p gnat_root
> $3 = 1707
> 
> (gdb) p (Nodes_Ptr[(gnat_root) - 0].U.K.kind)
> $4 = 17 '\021'

Use 'call pn(gnat_root)' instead.

> It seems Nkind (gnat_root) is N_Op_Add (17) for some reason.
> 
> BTW this is trunk (svn 181738), with the stage 2 compiler (this bug is not
> manifest in the stage 1 compiler).

This very likely means that the stage 1 compiler has miscompiled the stage 2 compiler.
Comment 13 Cesar Strauss 2011-11-28 00:46:16 UTC
(In reply to comment #12)
> Zero is UNKNOWN_LOCATION.  The problem is probably that the location mapping
> isn't initialized yet.  What happens if you move the block in gigi:
> 
>   gcc_assert (Nkind (gnat_root) == N_Compilation_Unit);
> 
>   /* Declare the name of the compilation unit as the first global
>      name in order to make the middle-end fully deterministic.  */
>   t = create_concat_name (Defining_Entity (Unit (gnat_root)), NULL);
>   first_global_object_name = ggc_strdup (IDENTIFIER_POINTER (t));
> 
> to after the immediately following loop?

+===========================GNAT BUG DETECTED==============================+
| 4.7.0 20111126 (experimental) [trunk revision 181738] (mingw32)          |
| Program_Error sem_util.adb:2551 explicit raise                           |
| Error detected at system.ads:175:5                                       |
| Please submit a bug report; see http://gcc.gnu.org/bugs.html.            |
| 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 gcc or gnatmake command that you entered.              |
| Also include sources listed below in gnatchop format                     |
| (concatenated together with no headers between files).                   |
+==========================================================================+

(gdb) b sem_util.adb:2551
Breakpoint 8 at 0x6b40f8: file ../../../../gcc-svn-fixada/gcc/ada/sem_util.adb, line 2551.
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) [answered Y; input not from terminal]
Starting program: c:\projetos\gcc\bld\svn\bld-fixada-3\gcc\gnat1.exe -I - -I . -I ada -I ../../../../gcc-svn-fixada/gcc/ada -I ../../../../gcc-svn-fixada/gcc/ada/gcc-interface -gnatwa -quiet -nostdinc -dumpbase a-charac.ads -auxbase-strip ada/a-charac.o -O2 -Wno-pedantic-ms-format -Wextra -Wall -g -gnatpg -gnata -mtune=i386 -march=i386 -gnatO ada/a-charac.o ../../../../gcc-svn-fixada/gcc/ada/a-charac.ads -o ccOjhV0T.s
[New Thread 3492.0x804]
gnat1.exe: warning: command line option '-Wno-pedantic-ms-format' is valid for C/C++/ObjC/ObjC++ but not for Ada [enabled by default]

Breakpoint 8, sem_util.defining_entity (n=0) at ../../../../gcc-svn-fixada/gcc/ada/sem_util.adb:2551
2551                raise Program_Error;

(gdb) p Nkind(N)
$1 = n_empty

(gdb) fr 1
#1  0x0048ff0c in gigi (gnat_root=1707, max_gnat_node=2431, number_name=1656, nodes_ptr=0x7950020, next_node_ptr=0x78b52f8, prev_node_ptr=0x78e6050, elists_ptr=0x7708e78, elmts_ptr=0x77094d0, strings_ptr=0x7734818, string_chars_ptr=0x77320f0, list_headers_ptr=0x78a9760, number_file=3, file_info_ptr=0x722fb9c, standard_boolean=12, standard_integer=27, standard_character=72, standard_long_long_float=67, standard_exception_type=1281, gigi_operating_mode=0) at ../../../../gcc-svn-fixada/gcc/ada/gcc-interface/trans.c:302
302       t = create_concat_name (Defining_Entity (Unit (gnat_root)), NULL);

> > (gdb) p gnat_root
> > $3 = 1707
> > 
> > (gdb) p (Nodes_Ptr[(gnat_root) - 0].U.K.kind)
> > $4 = 17 '\021'
> 
> Use 'call pn(gnat_root)' instead.

(gdb) call pn(gnat_root)
N_Compilation_Unit (Node_Id=1707) (source,analyzed)
 Parent = <empty>
 Sloc = 9966  a-charac.ads:16:12
 Context_Items = List (List_Id=-99999988)
 Unit = N_Package_Declaration (Node_Id=1722)
 Aux_Decls_Node = N_Compilation_Unit_Aux (Node_Id=1708)

It seems OK to me on the Ada side. I wonder what makes it trigger the assertion
gcc_assert (Nkind (gnat_root) == N_Compilation_Unit)

Maybe the C accessor "Nkind" is not working well for some reason?
Comment 14 Eric Botcazou 2011-12-04 21:59:13 UTC
> (gdb) call pn(gnat_root)
> N_Compilation_Unit (Node_Id=1707) (source,analyzed)
>  Parent = <empty>
>  Sloc = 9966  a-charac.ads:16:12
>  Context_Items = List (List_Id=-99999988)
>  Unit = N_Package_Declaration (Node_Id=1722)
>  Aux_Decls_Node = N_Compilation_Unit_Aux (Node_Id=1708)
> 
> It seems OK to me on the Ada side. I wonder what makes it trigger the assertion
> gcc_assert (Nkind (gnat_root) == N_Compilation_Unit)
> 
> Maybe the C accessor "Nkind" is not working well for some reason?

Yes, there is something really weird going on at the interface between C and Ada.
Unfortunately I don't seem to be able to reproduce on Linux.  Could you see what object code has been generated for the line

gcc_assert (Nkind (gnat_root) == N_Compilation_Unit);

in stage1-gcc/ada/trans.o and prev-gcc/ada/trans.o?
Comment 15 Cesar Strauss 2011-12-08 01:23:31 UTC
(In reply to comment #14)
> Unfortunately I don't seem to be able to reproduce on Linux.  Could you see
> what object code has been generated for the line
> 
> gcc_assert (Nkind (gnat_root) == N_Compilation_Unit);
> 
> in stage1-gcc/ada/trans.o and prev-gcc/ada/trans.o?

In stage 1:

	.loc 26 300 0
	movl	_Nodes_Ptr, %eax	 # Nodes_Ptr, Nodes_Ptr.1950
	movl	8(%ebp), %edx	 # gnat_root, gnat_root.1951
	sall	$5, %edx	 #, D.86803
	addl	%edx, %eax	 # D.86803, D.86804
	movb	3(%eax), %al	 # D.86804_24->U.K.kind, D.86805
	cmpb	$-87, %al	 #, D.86805
	je	L4598	 #,
	.loc 26 300 0 is_stmt 0 discriminator 1
	movl	$___FUNCTION__.42329, 8(%esp)	 #,
	movl	$300, 4(%esp)	 #,
	movl	$LC86, (%esp)	 #,
	call	_fancy_abort	 #
L4598:


In stage 2:

	.loc 2 300 0
	movl	80(%esp), %edx	 # gnat_root,
	leal	(%edx,%edx,8), %eax	 #, tmp414
	leal	(%ebx,%eax,4), %eax	 #, D.84548
	cmpb	$-87, 3(%eax)	 #, D.84548_25->U.K.kind
	jne	L8431	 #,

BTW, in stage 2, the following does seems to work:

(gdb) p atree__nkind(gnat_root)
info__n_compilation_unit

The object code is

LFE829:
	.p2align 2,,3
	.globl	_atree__nkind
	.def	_atree__nkind;	.scl	2;	.type	32;	.endef
_atree__nkind:
LFB831:
	.loc 2 1326 0
	.cfi_startproc
LVL2409:
	movl	4(%esp), %eax	 # n, tmp66
	.loc 2 1328 0
	sall	$5, %eax	 #, tmp66
	addl	_atree__atree_private_part__nodes__table, %eax	 # atree__atree_private_part__nodes__table, tmp66
	movb	3(%eax), %al	 # *atree__atree_private_part__nodes__table.89_1[n_2(D)].nkind, *atree__atree_private_part__nodes__table.89_1[n_2(D)].nkind
	.loc 2 1329 0
	ret
	.cfi_endproc
Comment 16 Cesar Strauss 2011-12-10 23:03:13 UTC
As can be seen in the assembler code above, the Ada compiler thinks the Node structure is 32 bytes in size, while the C compiler thinks its size is 36 bytes. 

The culprit is the struct Flag_Word (gcc/ada/atree.h:116), included in Node, which increased from 4 bytes to 6 bytes:

struct Flag_Word
{
  Boolean      flag73	    :  1;
  Boolean      flag74	    :  1;
  Boolean      flag75	    :  1;
  Boolean      flag76	    :  1;
  Boolean      flag77	    :  1;
  Boolean      flag78	    :  1;
  Boolean      flag79	    :  1;
  Boolean      flag80	    :  1;
  Boolean      flag81	    :  1;
  Boolean      flag82	    :  1;
  Boolean      flag83	    :  1;
  Boolean      flag84	    :  1;
  Boolean      flag85	    :  1;
  Boolean      flag86	    :  1;
  Boolean      flag87	    :  1;
  Boolean      flag88	    :  1;
  Boolean      flag89	    :  1;
  Boolean      flag90	    :  1;
  Boolean      flag91	    :  1;
  Boolean      flag92	    :  1;
  Boolean      flag93	    :  1;
  Boolean      flag94	    :  1;
  Boolean      flag95	    :  1;
  Boolean      flag96	    :  1;
  Short        convention   :  8;
};

On MinGW, the bitfield packing convention has changed in GCC 4.7: it now follows the Microsoft compiler (-mms-bitfields). Since the size of the "convention" field (16 bit short) is different from the previous one (8 bit unsigned char), padding is added until it starts on a new 16 bit boundary.

Indeed, rebuilding GCC with make 'BOOT_CFLAGS=-g -O2 -mno-ms-bitfields' allows the build to proceed to completion. Changing Short to Byte in Flag_Word also works.
Comment 17 Eric Botcazou 2011-12-11 08:29:01 UTC
> The culprit is the struct Flag_Word (gcc/ada/atree.h:116), included in Node,
> which increased from 4 bytes to 6 bytes:
> 
> struct Flag_Word
> {
>   Boolean      flag73        :  1;
>   Boolean      flag74        :  1;
>   Boolean      flag75        :  1;
>   Boolean      flag76        :  1;
>   Boolean      flag77        :  1;
>   Boolean      flag78        :  1;
>   Boolean      flag79        :  1;
>   Boolean      flag80        :  1;
>   Boolean      flag81        :  1;
>   Boolean      flag82        :  1;
>   Boolean      flag83        :  1;
>   Boolean      flag84        :  1;
>   Boolean      flag85        :  1;
>   Boolean      flag86        :  1;
>   Boolean      flag87        :  1;
>   Boolean      flag88        :  1;
>   Boolean      flag89        :  1;
>   Boolean      flag90        :  1;
>   Boolean      flag91        :  1;
>   Boolean      flag92        :  1;
>   Boolean      flag93        :  1;
>   Boolean      flag94        :  1;
>   Boolean      flag95        :  1;
>   Boolean      flag96        :  1;
>   Short        convention   :  8;
> };
> 
> On MinGW, the bitfield packing convention has changed in GCC 4.7: it now
> follows the Microsoft compiler (-mms-bitfields). Since the size of the
> "convention" field (16 bit short) is different from the previous one (8 bit
> unsigned char), padding is added until it starts on a new 16 bit boundary.

Nice work!

> Indeed, rebuilding GCC with make 'BOOT_CFLAGS=-g -O2 -mno-ms-bitfields' allows
> the build to proceed to completion. Changing Short to Byte in Flag_Word also
> works.

Let's do the latter.  Would you mind posting a patch on gcc-patches?  TIA.
Comment 18 Kai Tietz 2011-12-13 09:18:55 UTC
Hmm, other way to solve this might be to add to structure the optional attribute gcc_struct.  At least I used that to fix libquadmath for 32-bit IA Windows.
Comment 19 Eric Botcazou 2011-12-13 10:05:54 UTC
> Hmm, other way to solve this might be to add to structure the optional
> attribute gcc_struct.  At least I used that to fix libquadmath for 32-bit IA
> Windows.

Thanks.  Let's avoid gratuitous non-portable stuff though.
Comment 20 Eric Botcazou 2011-12-13 10:07:26 UTC
Created attachment 26068 [details]
Tentative fix
Comment 21 Eric Botcazou 2011-12-13 11:21:32 UTC
Author: ebotcazou
Date: Tue Dec 13 11:21:28 2011
New Revision: 182275

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182275
Log:
	PR ada/49084
	* types.h (Byte): Change typedef to 'unsigned char'.
	* atree.h (struct Flag_Word): Use Byte for 'convention' field.

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/atree.h
    trunk/gcc/ada/types.h
Comment 22 Eric Botcazou 2011-12-13 11:27:24 UTC
Patch applied.
Comment 23 Cesar Strauss 2011-12-14 01:03:39 UTC
(In reply to comment #22)
> Patch applied.

Thanks! Good to have Ada back on x86 MinGW.

Regards,

Cesar
Comment 24 Anh Vo 2011-12-16 16:24:19 UTC
Indeed, the build went smoothly. Thank you all specially Eric Botcazou for fixing this issue.