@@ -1132,7 +1132,30 @@ package body GNATLLVM.DebugInfo is
1132
1132
then Implementation_Base_Type (TE)
1133
1133
else Get_Fullest_View (TE));
1134
1134
1135
+ Empty_Fields : Metadata_Array (1 .. 0 );
1136
+
1135
1137
begin
1138
+ -- A type might be self-referential. For example, a
1139
+ -- record may have a member whose type refers back to the
1140
+ -- same record type. To handle this case, we construct a
1141
+ -- empty composite type and record it; then later we
1142
+ -- update the members of the type.
1143
+ if Is_Unchecked_Union (TE) then
1144
+ Result := DI_Create_Union_Type
1145
+ (Get_Scope_For (TE), Get_Possibly_Local_Name (TE),
1146
+ Get_Debug_File_Node (Get_Source_File_Index (S)),
1147
+ Get_Physical_Line_Number (S), Size, Align, DI_Flag_Zero,
1148
+ Empty_Fields, 0 , " " );
1149
+ else
1150
+ Result := DI_Create_Struct_Type
1151
+ (Get_Scope_For (TE), Get_Possibly_Local_Name (TE),
1152
+ Get_Debug_File_Node (Get_Source_File_Index (S)),
1153
+ Get_Physical_Line_Number (S), Size, Align, DI_Flag_Zero,
1154
+ No_Metadata_T, Empty_Fields, 0 , No_Metadata_T, " " );
1155
+ end if ;
1156
+
1157
+ Set_Debug_Metadata (TE, Result);
1158
+
1136
1159
F := First_Component_Or_Discriminant (TE);
1137
1160
while Present (F) loop
1138
1161
if Get_Fullest_View (Scope (Ancestor_Field (F)))
@@ -1186,20 +1209,14 @@ package body GNATLLVM.DebugInfo is
1186
1209
Members (J) := Member_Table.Table (J);
1187
1210
end loop ;
1188
1211
1189
- if Is_Unchecked_Union (TE) then
1190
- Result := DI_Create_Union_Type
1191
- (Get_Scope_For (TE), Get_Possibly_Local_Name (TE),
1192
- Get_Debug_File_Node (Get_Source_File_Index (S)),
1193
- Get_Physical_Line_Number (S), Size, Align, DI_Flag_Zero,
1194
- Members, 0 , " " );
1195
- else
1196
- Result := DI_Create_Struct_Type
1197
- (Get_Scope_For (TE), Get_Possibly_Local_Name (TE),
1198
- Get_Debug_File_Node (Get_Source_File_Index (S)),
1199
- Get_Physical_Line_Number (S), Size, Align, DI_Flag_Zero,
1200
- No_Metadata_T, Members, 0 , No_Metadata_T, " " );
1201
- end if ;
1212
+ -- At least in theory it seems that LLVM may replace
1213
+ -- the object entirely, so don't assume Result will be
1214
+ -- the same, and be sure to clear it from the cache.
1215
+ Result := Replace_Composite_Elements (DI_Builder, Result,
1216
+ Members);
1217
+ Clear_Debug_Metadata (TE);
1202
1218
end ;
1219
+
1203
1220
end Record_Type ;
1204
1221
1205
1222
-- For an enumeration type, make an enumerator metadata for each
0 commit comments