This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Missing range checks on the expression for Priority in protected types


This patch fixes a missing check on the priority of a protected type, when
it is set by a pragma or an aspect. A static value for priority that is out
of the bounds of the corresponding System type is an error. A dynamic value
that is out of bounds must raise a runtime exception.

Compiling t.adb must yield:

   t.adb:6:26: warning: value not in range of type "System.Priority"
   t.adb:6:26: warning: "Constraint_Error" will be raised at run time
   t.adb:14:04: value not in range of type "System.Any_Priority"
   t.adb:14:04: static expression fails Constraint_Check

---
with System; use System;
with Text_IO; use Text_IO;
procedure t is

   task T is
      pragma Priority (2 * Any_Priority'Last);
      entry E;
   end T;
   task body T is
   begin
      accept E;
   end;

   protected P is
      pragma Priority (2 * Any_Priority'Last);
      procedure Set (To : Boolean);
      function Get return Boolean;
   private
      Value : Boolean;
   end p;

   protected body P is
      procedure Set (To : Boolean) is
      begin
         Value := To;
      end Set;

      function Get return Boolean is
      begin
         return Value;
      end Get;
   end p;
begin
   P.Set (True);
   pragma Assert (P.Get);
end t;
---

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

2013-04-11  Ed Schonberg  <schonberg@adacore.com>

	* sem_prag.adb (Analyze_Pragma, case Priority): pre-analyze
	expression with type Any_Priority.
	* exp_ch9.adb (Initialize_Protection): Check that the value
	of the priority expression is within the bounds of the proper
	priority type.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]