[Ada] Only one of Priority or Interrupt_Priority can be specified

Message ID 20121029101743.GA26164@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 29, 2012, 10:17 a.m.
ARM D.1.7 states that only one pragma priority or interrupt_priority can be
given for a given entity. This patch recognizes some illegal instances of these
two pragmas or aspects, that were previously undiagnosed.

Compiling tasking.ads in Ada 2012 mode must yield:

       pragma "Interrupt_Priority" for "Monitor" duplicates pragma at line 16
       aspect "Priority" for "Lock" previously given at line 29

with System;
with Ada.Real_Time; use Ada.Real_Time;
package Tasking is

   procedure Last_Chance_Handler (Msg : System.Address; Line : Integer);
   pragma Export (C, Last_Chance_Handler, "__gnat_last_chance_handler");

   procedure Wait_Forever;

   task Test_Driver is
      pragma Interrupt_Priority (System.Interrupt_Priority'Last);
   end Test_Driver;

   protected Monitor is

      pragma Priority (System.Priority'Last);
      pragma Interrupt_Priority (System.Interrupt_Priority'Last);

      procedure Handler;
      pragma Attach_Handler (Handler, 12);

      entry Wait;
      Signaled : Boolean := False;
   end Monitor;

   protected type Lock
      interrupt_priority => System.priority'last,
      priority => System.priority'last
      procedure Seize;
      procedure Release;
      In_Use : Boolean := False;
   end Lock;

end Tasking;

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

2012-10-29  Ed Schonberg  <schonberg@adacore.com>

	* sem_aux.adb (Get_Rep_Item): Treat Priority and Interrupt_Priority
	as equivalent, because only one of them can be specified for a
	task, protected definition, or subprogram body.
	* aspects.adb ((Same_Aspect): The canonical aspect of
	Interrupt_Priority is Priority.


Index: sem_aux.adb
--- sem_aux.adb	(revision 192908)
+++ sem_aux.adb	(working copy)
@@ -431,11 +431,17 @@ 
       N := First_Rep_Item (E);
       while Present (N) loop
+         --  Only one of Priority / Interrupt_Priority can be specified, so
+         --  return whichever one is present to catch illegal duplication.
          if Nkind (N) = N_Pragma
            and then
              (Pragma_Name (N) = Nam
                or else (Nam = Name_Priority
-                         and then Pragma_Name (N) = Name_Interrupt_Priority))
+                         and then Pragma_Name (N) = Name_Interrupt_Priority)
+               or else (Nam = Name_Interrupt_Priority
+                         and then Pragma_Name (N) = Name_Priority))
             if Check_Parents then
                return N;
Index: aspects.adb
--- aspects.adb	(revision 192908)
+++ aspects.adb	(working copy)
@@ -275,7 +275,7 @@ 
     Aspect_Inline_Always                => Aspect_Inline,
     Aspect_Input                        => Aspect_Input,
     Aspect_Interrupt_Handler            => Aspect_Interrupt_Handler,
-    Aspect_Interrupt_Priority           => Aspect_Interrupt_Priority,
+    Aspect_Interrupt_Priority           => Aspect_Priority,
     Aspect_Invariant                    => Aspect_Invariant,
     Aspect_Iterator_Element             => Aspect_Iterator_Element,
     Aspect_Link_Name                    => Aspect_Link_Name,