diff mbox

[Ada] Do not assume that a volatile variable is valid

Message ID 20140122165341.GA24764@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Jan. 22, 2014, 4:53 p.m. UTC
Volatile variables are never considered valid for the purposes
of validity checking, since the assumption is they could change
unexpectedly at any time.

The following program, compiled with -gnatVa -gnatG

     1. procedure ValidVolatile is
     2.    type R is new Integer range 1 .. 10;
     3.    A : R;
     4.    pragma Volatile (A);
     5.    B : R;
     6. begin
     7.    A := 1;
     8.    B := A;
     9. end;

generates:

Source recreated from tree for Validvolatile (body)

with interfaces;

procedure validvolatile is
   [type validvolatile__TrB is new integer]
   freeze validvolatile__TrB []
   type validvolatile__r is new integer range 1 .. 10;
   a : validvolatile__r;
   pragma volatile (a);
   b : validvolatile__r;
begin
   a := 1;
   R1b : constant validvolatile__r := a;
   [constraint_error when
     not (interfaces__unsigned_32!(R1b) in 1 .. 10)
     "invalid data"]
   b := R1b;
   return;
end validvolatile;

Previously the constraint error check was not generated, because
A was assumed to have a value of 1 from the assignment at line 7

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

2014-01-22  Robert Dewar  <dewar@adacore.com>

	* checks.adb: Do not assume that a volatile variable is valid.
diff mbox

Patch

Index: checks.adb
===================================================================
--- checks.adb	(revision 206918)
+++ checks.adb	(working copy)
@@ -5257,6 +5257,10 @@ 
 
       elsif Is_Entity_Name (Expr)
         and then Is_Known_Valid (Entity (Expr))
+
+        --  Exclude volatile variables
+
+        and then not Treat_As_Volatile (Entity (Expr))
       then
          return True;