[Ada] Validity check failure with packed array and pragma
Pierre-Marie de Rodat
derodat@adacore.com
Mon Sep 18 09:54:00 GMT 2017
Fix a bug in which if validity checking is enabled, Initialize_Scalars
is enabled, optimization is turned on, and inlining is enabled, the
initialization of a packed array can cause Constraint_Error to be
incorrectly raised.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
2017-09-18 Bob Duff <duff@adacore.com>
* exp_ch3.adb (Build_Array_Init_Proc): If validity checking is enabled,
and it's a bit-packed array, pass False to the Consider_IS parameter of
Needs_Simple_Initialization.
gcc/testsuite/
2017-09-18 Bob Duff <duff@adacore.com>
* gnat.dg/validity_check.adb: New testcase.
-------------- next part --------------
Index: exp_ch3.adb
===================================================================
--- exp_ch3.adb (revision 252913)
+++ exp_ch3.adb (working copy)
@@ -517,6 +517,10 @@
procedure Build_Array_Init_Proc (A_Type : Entity_Id; Nod : Node_Id) is
Comp_Type : constant Entity_Id := Component_Type (A_Type);
+ Comp_Type_Simple : constant Boolean :=
+ Needs_Simple_Initialization
+ (Comp_Type, Consider_IS =>
+ not (Validity_Check_Copies and Is_Bit_Packed_Array (A_Type)));
Body_Stmts : List_Id;
Has_Default_Init : Boolean;
Index_List : List_Id;
@@ -557,7 +561,7 @@
Convert_To (Comp_Type,
Default_Aspect_Component_Value (First_Subtype (A_Type)))));
- elsif Needs_Simple_Initialization (Comp_Type) then
+ elsif Comp_Type_Simple then
Set_Assignment_OK (Comp);
return New_List (
Make_Assignment_Statement (Loc,
@@ -589,7 +593,7 @@
-- the dummy Init_Proc needed for Initialize_Scalars processing.
if not Has_Non_Null_Base_Init_Proc (Comp_Type)
- and then not Needs_Simple_Initialization (Comp_Type)
+ and then not Comp_Type_Simple
and then not Has_Task (Comp_Type)
and then not Has_Default_Aspect (A_Type)
then
@@ -679,7 +683,7 @@
-- init_proc.
Has_Default_Init := Has_Non_Null_Base_Init_Proc (Comp_Type)
- or else Needs_Simple_Initialization (Comp_Type)
+ or else Comp_Type_Simple
or else Has_Task (Comp_Type)
or else Has_Default_Aspect (A_Type);
Index: ../testsuite/gnat.dg/validity_check.adb
===================================================================
--- ../testsuite/gnat.dg/validity_check.adb (revision 0)
+++ ../testsuite/gnat.dg/validity_check.adb (revision 0)
@@ -0,0 +1,18 @@
+-- { dg-do run }
+-- { dg-options "-cargs -O -gnatn -gnatVa -gnatws -margs" }
+
+pragma Initialize_Scalars;
+
+procedure Validity_Check is
+
+ type Small_Int is mod 2**6;
+
+ type Arr is array (1 .. 16) of Small_Int;
+ pragma Pack (Arr);
+
+ S : Small_Int;
+ A : Arr;
+
+begin
+ null;
+end;
More information about the Gcc-patches
mailing list