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

            Bug ID: 117051
           Summary: Specifying alignment based on another type in a
                    generic unit sometimes crashes the compiler
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jhb.chat at gmail dot com
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 59302
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59302&action=edit
single file reproducer

x86-64 GNAT v14.2.0 (10.2.0 - 15/trunk)
switches: none specified
tested on Godbolt online compiler

When using a generic package and specifying a types alignment as the same
alignment as another type in the package, the compiler can sometime crash. 
This usually happens if the source type has no alignment specified.  Consider
the code:

----------------------------------------------
procedure Example is
    generic
    package Tester is
        type Thing_1 is mod 2**64;
        type Thing_2 is new Thing_1
            with Alignment => Thing_1'Alignment;
    end Tester;
begin
    null;
end Example;
----------------------------------------------

This crashes the compiler with the message:
----------------------------------------------
Compiler stderr

+===========================GNAT BUG DETECTED==============================+
| 15.0.0 20241009 (experimental) (x86_64-linux-gnu) Program_Error
sem_eval.adb:4667 explicit raise|
| Error detected at example.adb:6:18                                       |
| Compiling <source>                                               |
| 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).

<source>

compilation abandoned
----------------------------------------------

This crashes for versions between 10.2 - Trunk on Godbolt.  Version 9.5 throws
an error saying:
----------------------------------------------
Compiler stderr

example.adb:6:38: alignment value must be positive
----------------------------------------------

I tried specifying the alignment for Thing_1 as 8 and the crash goes away, so I
think GNAT is having trouble resolving the alignment of type Thing_1

Reply via email to