Bug 40185 - Segmentation fault on program with typo
Summary: Segmentation fault on program with typo
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-18 12:32 UTC by Ludovic Brenta
Modified: 2015-12-05 17:43 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ludovic Brenta 2009-05-18 12:32:22 UTC
(Debian bug #519336)

The following illegal program causes gnat1 to crash with a segmentation fault:

with Ada.Unchecked_Conversion;
package Essai is
   type Attributed_Character is record
      I : Integer;
   end record;
   type Video_Array is array (Integer range 0 .. 1) of Attributed_Character;
   type Video_Access is access Video_Array;
   function To_VA is new Ada.Unchecked_Conversion (Integer, Video_Access);
   Video : Video_Access := To_VA (0); -- line 9
end Essai;

/usr/lib/gcc/x86_64-linux-gnu/4.3.3/gnat1 -quiet -dumpbase essai.ads
- -mtune=generic essai.ads -o  tutu.s
segmentation fault

Removing line 9 causes GNAT not to segfault.

Also confirmed on GNAT GPL 2008 on x86_64-linux-gnu and with GCC 4.3.3 on powerpc-linux-gnu.
Comment 1 Ludovic Brenta 2009-05-19 06:30:37 UTC
There was a typo in the original program that I mistakenly corrected.  This typo is the trigger for the bug:

with Ada.Unchecked_Conversion;
package Essai is
   type Attributed_Chararcter is record -- line 3
      I : Integer;
   end record;
   type Video_Array is array (Integer range 0 .. 1) of Attributed_Character;
   type Video_Access is access Video_Array;
   function To_VA is new Ada.Unchecked_Conversion (Integer, Video_Access);
   Video : Video_Access := To_VA (0); -- line 9
end Essai;

So, either correcting the typo at line 3 or removing line 9 prevents the segmentation fault:

gnatmake essai.ads
gcc-4.3 -c essai.ads
gcc-4.3: Internal error: Segmentation fault (program gnat1)
Please submit a full bug report.
See <file:///usr/share/doc/gcc-4.3/README.Bugs> for instructions.
gnatmake: "essai.ads" compilation error

Now comment out line 9:
gnatmake essai.ads
gcc-4.3 -c essai.ads
essai.ads:6:56: "Attributed_Character" is undefined
essai.ads:6:56: possible misspelling of "Attributed_Chararcter"
gnatmake: "essai.ads" compilation error

Now restore line 9 and correct the typo at line 3:
gcc-4.3 -c essai.ads
essai.ads:8:04: warning: types for unchecked conversion have different sizes

Comment 2 Nicolas Boulenguez 2011-08-30 18:09:57 UTC
GCC 4.6.1 does not crash and successfully reports the type size mismatch.
Comment 3 Eric Botcazou 2015-12-05 17:43:20 UTC
.