aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface/decl.c
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2018-10-09 15:06:55 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-10-09 15:06:55 +0000
commitc743425fce5517242dd67761fea298cd3459b4cc (patch)
tree8681015a93c746718344e21e388debb458823320 /gcc/ada/gcc-interface/decl.c
parent4b9e1bc78110d65377acdf23ee3733f8c69baef9 (diff)
downloadgcc-c743425fce5517242dd67761fea298cd3459b4cc.zip
gcc-c743425fce5517242dd67761fea298cd3459b4cc.tar.gz
gcc-c743425fce5517242dd67761fea298cd3459b4cc.tar.bz2
[Ada] Fix spurious -Wuninitialized warnings for small records
This change is aimed at getting rid of spurious -Wuninitialized warnings issued for small records passed by copy and containing default values for some of their components. The source of the problem is that the _Init parameter of the initialization routine is declared as an in/out parameter, so the uninitialized object is passed by copy to it and this can be flagged by -Wuninitialized. That's why the mode of the parameter is changed to out, except for the cases where information really needs to be passed in: unconstrained array types, protected and task types. For the following record type Rec! type Rec is record B : Boolean := True; end record; the initialization routine must now be: procedure r__recIP (_init : out r__rec1) is begin _init.b := true; return; end r__recIP; 2018-10-09 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_ch3.adb (Is_Null_Statement_List): New predicate. (Build_Array_Init_Proc): Use it to find out whether the initialization procedure Is_Null_Init_Proc; if so, set Warnings_Off on the parameter. (Build_Init_Procedure): Likewise. (Init_Formals): Use an in/out first parameter only for unconstrained arrays and for records either containing or built for proteced types or task types; use an out parameter in all the other cases. * fe.h (Is_Init_Proc): Declare. * gcc-interface/decl.c (type_requires_init_of_formal): Do not return true for a discriminant in an unchecked union. (gnat_to_gnu_param): Do not create a PARM_DECL for the Out parameter of an initialization procedure. From-SVN: r264984
Diffstat (limited to 'gcc/ada/gcc-interface/decl.c')
-rw-r--r--gcc/ada/gcc-interface/decl.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
index a0d2cbe..c658aac 100644
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -5153,7 +5153,7 @@ type_requires_init_of_formal (Entity_Id type)
Present (field);
field = Next_Entity (field))
{
- if (Ekind (field) == E_Discriminant)
+ if (Ekind (field) == E_Discriminant && !Is_Unchecked_Union (type))
return true;
if (Ekind (field) == E_Component
@@ -5334,11 +5334,14 @@ gnat_to_gnu_param (Entity_Id gnat_param, tree gnu_param_type, bool first,
type doesn't require the initialization of formals, we don't make a
PARM_DECL for it. Instead, it will be a VAR_DECL created when we
process the procedure, so just return its type here. Likewise for
- the special parameter of a valued procedure, never pass it in. */
+ the _Init parameter of an initialization procedure or the special
+ parameter of a valued procedure, never pass them in. */
if (Ekind (gnat_param) == E_Out_Parameter
&& !by_ref
&& !by_component_ptr
- && (!type_requires_init_of_formal (Etype (gnat_param)) || by_return))
+ && (!type_requires_init_of_formal (Etype (gnat_param))
+ || Is_Init_Proc (gnat_subprog)
+ || by_return))
return gnu_param_type;
gnu_param = create_param_decl (gnu_param_name, gnu_param_type);