@@ -3123,7 +3123,16 @@ package body Tree_Walk is
3123
3123
Variant_Disc_Value := Disc_Actual;
3124
3124
end if ;
3125
3125
3126
- New_Expr := Do_Expression (Disc_Actual);
3126
+ if Present (Disc_Actual) then
3127
+ New_Expr := Do_Expression (Disc_Actual);
3128
+ else
3129
+ -- Default initialize to 0
3130
+ New_Expr := Make_Constant_Expr
3131
+ (Source_Location => Get_Source_Location (E),
3132
+ I_Type => Do_Type_Reference (Etype (Iter)),
3133
+ Range_Check => False,
3134
+ Value => " 0" );
3135
+ end if ;
3127
3136
Append_Struct_Member (Ret, New_Expr);
3128
3137
-- Substitute uses of the discriminant in the record
3129
3138
-- initialiser for its actual value:
@@ -3196,7 +3205,7 @@ package body Tree_Walk is
3196
3205
elsif Ekind (E) in Record_Kind then
3197
3206
return Make_Record_Default_Initialiser (E, DCs);
3198
3207
else
3199
- return Report_Unhandled_Node_Irep (N , " Make_Default_Initialiser" ,
3208
+ return Report_Unhandled_Node_Irep (E , " Make_Default_Initialiser" ,
3200
3209
" Unknown Ekind" );
3201
3210
end if ;
3202
3211
end Make_Default_Initialiser ;
@@ -3214,7 +3223,10 @@ package body Tree_Walk is
3214
3223
3215
3224
if Has_Init_Expression (N) or Present (Expression (N)) then
3216
3225
Init_Expr := Do_Expression (Expression (N));
3217
- elsif Needs_Default_Initialisation (Etype (Defined)) then
3226
+ elsif Needs_Default_Initialisation (Etype (Defined)) or
3227
+ (Present (Object_Definition (N)) and then
3228
+ Nkind (Object_Definition (N)) = N_Subtype_Indication)
3229
+ then
3218
3230
declare
3219
3231
Defn : constant Node_Id := Object_Definition (N);
3220
3232
Discriminant_Constraint : constant Node_Id :=
@@ -4458,8 +4470,21 @@ package body Tree_Walk is
4458
4470
function Do_Selected_Component (N : Node_Id) return Irep is
4459
4471
Root : constant Irep := Do_Expression (Prefix (N));
4460
4472
Component : constant Entity_Id := Entity (Selector_Name (N));
4473
+
4474
+ -- Example:
4475
+ -- struct Foo { int a; };
4476
+ -- struct Foo bar;
4477
+ -- bar.a = 5;
4478
+ --
4479
+ -- The Unique_Name of the struct-component in declaration is Foo__a. But
4480
+ -- when parsing the assignment the component is that of the entity bar,
4481
+ -- thus it's unique-name is bar__a: which is not present in Foo. That's
4482
+ -- why we have to use the component of the original-record to get the
4483
+ -- right name.
4484
+ Orig_Component : constant Entity_Id :=
4485
+ Original_Record_Component (Component);
4461
4486
Component_Type : constant Irep := Do_Type_Reference (Etype (Component));
4462
- Component_Name : constant String := Unique_Name (Component );
4487
+ Component_Name : constant String := Unique_Name (Orig_Component );
4463
4488
Source_Location : constant Irep := Get_Source_Location (N);
4464
4489
begin
4465
4490
if Do_Discriminant_Check (N) then
0 commit comments