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

login
register
mail settings
Submitter Arnaud Charlet
Date Oct. 29, 2012, 10:17 a.m.
Message ID <20121029101743.GA26164@adacore.com>
Download mbox | patch
Permalink /patch/194937/
State New
Headers show

Comments

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:

    tasking.ads:17:07:
       pragma "Interrupt_Priority" for "Monitor" duplicates pragma at line 16
    tasking.ads:30:07:
       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;
   private
      Signaled : Boolean := False;
   end Monitor;

   protected type Lock
   with
      interrupt_priority => System.priority'last,
      priority => System.priority'last
   is
      procedure Seize;
      procedure Release;
   private
      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.

Patch

Index: sem_aux.adb
===================================================================
--- sem_aux.adb	(revision 192908)
+++ sem_aux.adb	(working copy)
@@ -431,11 +431,17 @@ 
    begin
       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))
          then
             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,