[Ada] Crash on Descriptor_Size attribute

Message ID 20191212100430.GA114707@adacore.com
State New
Headers show
  • [Ada] Crash on Descriptor_Size attribute
Related show

Commit Message

Pierre-Marie de Rodat Dec. 12, 2019, 10:04 a.m.
This patch fixes the following bug: If the Descriptor_Size attribute is
used in the private part of a generic package, then the compiler crashes
when compiling an instance of that generic.

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

2019-12-12  Bob Duff  <duff@adacore.com>


	* sem_attr.adb (Eval_Attribute): Never mark T'Descriptor_Size as
	static, even if T is a static subtype, because otherwise we will
	request the value of the attribute, which will crash because we
	have not evaluated it.


--- gcc/ada/sem_attr.adb
+++ gcc/ada/sem_attr.adb
@@ -7852,6 +7852,8 @@  package body Sem_Attr is
       --  is legal, since here this expression appears in a statically
       --  unevaluated position, so it does not actually raise an exception.
+      --
+      --  T'Descriptor_Size is never static, even if T is static.
       if Is_Scalar_Type (P_Entity)
         and then (not Is_Generic_Type (P_Entity))
@@ -7865,6 +7867,7 @@  package body Sem_Attr is
           (No (E2)
             or else (Is_Static_Expression (E2)
                       and then Is_Scalar_Type (Etype (E1))))
+        and then Id /= Attribute_Descriptor_Size
          Static := True;
          Set_Is_Static_Expression (N, True);