Re: [Ada] Validity check failure with packed array and pragma

2017-09-19 Thread Pierre-Marie de Rodat

On 09/18/2017 10:09 PM, Eric Botcazou wrote:

I'm not sure anyone really cares so it's up to you I'd say.


Ok, thanks. Done! Committed as r252971.

--
Pierre-Marie de Rodat


Re: [Ada] Validity check failure with packed array and pragma

2017-09-18 Thread Eric Botcazou
> That’s right, will do, thank you! Do I need to create a new ChangeLog
> entry in gcc/testsuite/ or is it fine if I just keep the current “New
> testcase.”?

I'm not sure anyone really cares so it's up to you I'd say.

-- 
Eric Botcazou


Re: [Ada] Validity check failure with packed array and pragma

2017-09-18 Thread Pierre-Marie de Rodat

On 09/18/2017 12:02 PM, Eric Botcazou wrote:

You don't need this, just use:

--  { dg-options "-O -gnatn -gnatVa -gnatws" }

The -cargs/-margs trick is only needed for special switches like -dA.


That’s right, will do, thank you! Do I need to create a new ChangeLog 
entry in gcc/testsuite/ or is it fine if I just keep the current “New 
testcase.”?


--
Pierre-Marie de Rodat


Re: [Ada] Validity check failure with packed array and pragma

2017-09-18 Thread Eric Botcazou
> 2017-09-18  Bob Duff  
> 
>   * gnat.dg/validity_check.adb: New testcase.

+--  { dg-options "-cargs -O -gnatn -gnatVa -gnatws -margs" }

You don't need this, just use:

--  { dg-options "-O -gnatn -gnatVa -gnatws" }

The -cargs/-margs trick is only needed for special switches like -dA.

-- 
Eric Botcazou


[Ada] Validity check failure with packed array and pragma

2017-09-18 Thread Pierre-Marie de Rodat
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  

* 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  

* gnat.dg/validity_check.adb: New testcase.
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;