[Ada] Avoid junk validity check for OUT parameter of 'Read or 'Input

Arnaud Charlet charlet@adacore.com
Fri Aug 22 12:44:00 GMT 2008


If the following program is compiled with -gnatVa and an empty file
inputfile.dat, then it should terminate with an End_Error exception:

raised ADA.IO_EXCEPTIONS.END_ERROR : s-stratt.adb:250

But before this patch, it gets a validity check, since there is a junk
validity check on the OUT parameter for the Read attribute.

pragma Initialize_Scalars;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
procedure Tic_Read is
   Test_File   : File_Type;
   Test_Stream : Stream_Access;
   Float_Value : Long_Float;
begin
   Open (Test_File, In_File, "inputfile.dat");
   Test_Stream := Stream (Test_File);
   Long_Float'Read (Test_Stream, Float_Value);
   Close (Test_File);
end Tic_Read;

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

2008-08-22  Robert Dewar  <dewar@adacore.com>

	* exp_attr.adb:
	(Expand_N_Attribute_Reference): No validity checking on OUT parameter of
	Read or Input attribute.

-------------- next part --------------
Index: exp_attr.adb
===================================================================
--- exp_attr.adb	(revision 139432)
+++ exp_attr.adb	(working copy)
@@ -607,10 +607,14 @@
    begin
       --  Do required validity checking, if enabled. Do not apply check to
       --  output parameters of an Asm instruction, since the value of this
-      --  is not set till after the attribute has been elaborated.
+      --  is not set till after the attribute has been elaborated, and do
+      --  not apply the check to the arguments of a 'Read or 'Input attribute
+      --  reference since the scalar argument is an OUT scalar.
 
       if Validity_Checks_On and then Validity_Check_Operands
         and then Id /= Attribute_Asm_Output
+        and then Id /= Attribute_Read
+        and then Id /= Attribute_Input
       then
          declare
             Expr : Node_Id;


More information about the Gcc-patches mailing list