There is no point in validating 'Alignment or 'Size of an entity
declared in a generic unit after the back-end has been run, since such
an entity is not passed to the back-end, and this can even lead to an
assertion failure.

Tested on x86_64-pc-linux-gnu, committed on trunk

2018-11-14  Eric Botcazou  <ebotca...@adacore.com>

gcc/ada/

        * sem_prag.adb (Process_Compile_Time_Warning_Or_Error): Don't
        register a compile-time warning or error for 'Alignment or 'Size
        of an entity declared in a generic unit.

gcc/testsuite/

        * gnat.dg/compile_time_error1.adb,
        gnat.dg/compile_time_error1.ads,
        gnat.dg/compile_time_error1_pkg.ads: New testcase.
--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -7545,6 +7545,7 @@ package body Sem_Prag is
          begin
             if Nkind (N) = N_Attribute_Reference
               and then Is_Entity_Name (Prefix (N))
+              and then not Is_Generic_Unit (Scope (Entity (Prefix (N))))
             then
                declare
                   Attr_Id : constant Attribute_Id :=

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/compile_time_error1.adb
@@ -0,0 +1,7 @@
+--  { dg-do compile }
+
+package body Compile_Time_Error1 is
+
+  procedure Dummy is null;
+
+end Compile_Time_Error1;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/compile_time_error1.ads
@@ -0,0 +1,13 @@
+with Compile_Time_Error1_Pkg;
+
+package Compile_Time_Error1 is
+
+  type Rec is record
+    I : Integer;
+  end record;
+
+  package Inst is new Compile_Time_Error1_Pkg (Rec);
+
+  procedure Dummy;
+
+end Compile_Time_Error1;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/compile_time_error1_pkg.ads
@@ -0,0 +1,11 @@
+generic
+
+  type T is private;
+
+package Compile_Time_Error1_Pkg is
+
+  pragma Compile_Time_Error (T'Size not in 8 | 16 | 32, "type too large");
+
+  Data : T;
+
+end Compile_Time_Error1_Pkg;

Reply via email to