]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Crash on improper use of GNAT attribute Type_Key
authorEd Schonberg <schonberg@adacore.com>
Thu, 12 Aug 2021 14:39:21 +0000 (10:39 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 1 Oct 2021 06:13:38 +0000 (06:13 +0000)
gcc/ada/

* sem_attr.adb (Analyze_Attribute, case Type_Key): Attribute can
be applied to a formal type.
* sem_ch5.adb (Analyze_Case_Statement): If Extensions_Allowed is
not enabled, verify that the type of the expression is discrete.

gcc/ada/sem_attr.adb
gcc/ada/sem_ch5.adb

index 7b6dc21b6f0beab35a06044dbc785c68e80b7233..4265df6b8c025ed2828b1db8490de26ef972b2b2 100644 (file)
@@ -6643,7 +6643,9 @@ package body Sem_Attr is
          Initialize (CRC);
          Compute_Type_Key (Entity (P));
 
-         if not Is_Frozen (Entity (P)) then
+         if not Is_Frozen (Entity (P))
+           and then not Is_Generic_Type (Entity (P))
+         then
             Error_Msg_N ("premature usage of Type_Key?", N);
          end if;
 
index 63bb80c129143a47c9348851f8ef00f62e6b8c3c..45d24574c28f2e3a39a83c5842dd2615122dcf6f 100644 (file)
@@ -1681,6 +1681,13 @@ package body Sem_Ch5 is
          Error_Msg_N
            ("(Ada 83) case expression cannot be of a generic type", Exp);
          return;
+
+      elsif not Extensions_Allowed
+        and then not Is_Discrete_Type (Exp_Type)
+      then
+         Error_Msg_N
+           ("expression in case statement must be of a discrete_Type", Exp);
+         return;
       end if;
 
       --  If the case expression is a formal object of mode in out, then treat