Skip to content

Commit b2b8539

Browse files
committed
Merge branch 'topic/variants-v2' into 'master'
Basic variant types See merge request eng/toolchain/gnat-llvm!365
2 parents 2e86b9c + 1683181 commit b2b8539

10 files changed

+565
-123
lines changed

llvm-interface/check_for_llvm_apis.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ api_test HAVE_TYPE_FN_SCOPE "void call(DebugInfoFinder *f, DILocalVariable *v) {
4242
# Test that checks if sizes and offsets can be dynamic.
4343
api_test HAVE_DYNAMIC_OFFSETS "void call(DIBuilder *b) { b->createMemberType(nullptr, StringRef(), nullptr, 0, nullptr, 0, nullptr, DINode::FlagZero, nullptr); }"
4444

45+
# Test whether multiple members can be included in a variant.
46+
api_test HAVE_MULTI_MEMBER_VARIANT "void call(DIBuilder *b) { b->createVariantMemberType(nullptr, DINodeArray(), (Constant*)nullptr, (DIType*)nullptr); }"
47+
4548
for def in $haves; do
4649
echo "#define GNAT_LLVM_$def"
4750
done > obj/tmp-gnat-llvm-config.h

llvm-interface/gnatllvm-debuginfo.adb

Lines changed: 24 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@ with Table; use Table;
2323
with Uintp.LLVM; use Uintp.LLVM;
2424
with Urealp; use Urealp;
2525

26-
with GNATLLVM.Arrays; use GNATLLVM.Arrays;
27-
with GNATLLVM.Codegen; use GNATLLVM.Codegen;
28-
with GNATLLVM.Environment; use GNATLLVM.Environment;
29-
with GNATLLVM.GLType; use GNATLLVM.GLType;
30-
with GNATLLVM.Helper; use GNATLLVM.Helper;
31-
with GNATLLVM.MDType; use GNATLLVM.MDType;
32-
with GNATLLVM.Records; use GNATLLVM.Records;
33-
with GNATLLVM.Subprograms; use GNATLLVM.Subprograms;
34-
with GNATLLVM.Types; use GNATLLVM.Types;
35-
with GNATLLVM.Utils; use GNATLLVM.Utils;
36-
with GNATLLVM.Wrapper; use GNATLLVM.Wrapper;
26+
with GNATLLVM.Arrays; use GNATLLVM.Arrays;
27+
with GNATLLVM.Codegen; use GNATLLVM.Codegen;
28+
with GNATLLVM.Environment; use GNATLLVM.Environment;
29+
with GNATLLVM.GLType; use GNATLLVM.GLType;
30+
with GNATLLVM.Helper; use GNATLLVM.Helper;
31+
with GNATLLVM.MDType; use GNATLLVM.MDType;
32+
with GNATLLVM.Records; use GNATLLVM.Records;
33+
with GNATLLVM.Records.Debug; use GNATLLVM.Records.Debug;
34+
with GNATLLVM.Subprograms; use GNATLLVM.Subprograms;
35+
with GNATLLVM.Types; use GNATLLVM.Types;
36+
with GNATLLVM.Utils; use GNATLLVM.Utils;
37+
with GNATLLVM.Wrapper; use GNATLLVM.Wrapper;
3738

3839
package body GNATLLVM.DebugInfo is
3940

@@ -115,11 +116,6 @@ package body GNATLLVM.DebugInfo is
115116
Post => Present (Create_Array_Type'Result);
116117
-- Create metadata corresponding to the array type GT.
117118

118-
function Create_Type_Data (GT : GL_Type) return Metadata_T
119-
with Pre => Present (GT);
120-
-- Create metadata corresponding to the type of GT. Return
121-
-- No_Metadata_T if the type is too complex.
122-
123119
function Create_Type_Data (V : GL_Value) return Metadata_T
124120
with Pre => Present (V);
125121
-- Create metadata for the type and relationship of R. Don't return
@@ -953,9 +949,7 @@ package body GNATLLVM.DebugInfo is
953949
if Is_Unchecked_Union (TE) then
954950
-- Allow.
955951
null;
956-
elsif Ekind (TE) in Record_Kind or
957-
else not Types_Can_Have_Dynamic_Offsets
958-
then
952+
elsif not Types_Can_Have_Dynamic_Offsets then
959953
return DI_Create_Unspecified_Type (Name);
960954
end if;
961955
end if;
@@ -1113,111 +1107,19 @@ package body GNATLLVM.DebugInfo is
11131107
-- for the type and the position and size are known and static,
11141108
-- add that field as a member.
11151109

1116-
when Record_Kind => Record_Type : declare
1117-
1118-
package Member_Table is new Table.Table
1119-
(Table_Component_Type => Metadata_T,
1120-
Table_Index_Type => Int,
1121-
Table_Low_Bound => 1,
1122-
Table_Initial => 20,
1123-
Table_Increment => 5,
1124-
Table_Name => "Member_Table");
1125-
1126-
F : Opt_Record_Field_Kind_Id;
1127-
1110+
when Record_Kind => declare
11281111
Original_Type : constant Entity_Id :=
1129-
(if Is_Packed (TE)
1130-
then Etype (TE)
1131-
elsif Ekind (TE) = E_Record_Subtype
1132-
then Implementation_Base_Type (TE)
1133-
else Get_Fullest_View (TE));
1134-
1135-
Empty_Fields : Metadata_Array (1 .. 0);
1136-
1112+
(if Ekind (TE) = E_Record_Subtype
1113+
then Implementation_Base_Type (TE)
1114+
else Get_Fullest_View (TE));
11371115
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-
1159-
F := First_Component_Or_Discriminant (TE);
1160-
while Present (F) loop
1161-
if Get_Fullest_View (Scope (Ancestor_Field (F)))
1162-
/= Original_Type
1163-
then
1164-
-- Inherited component, so we can skip it here.
1165-
null;
1166-
elsif Known_Static_Component_Bit_Offset (F)
1167-
and then Known_Static_Esize (F)
1168-
then
1169-
declare
1170-
F_GT : constant GL_Type := Field_Type (F);
1171-
Mem_MD : constant Metadata_T :=
1172-
Create_Type_Data (F_GT);
1173-
Name : constant String := Get_Name (F);
1174-
F_S : constant Source_Ptr := Sloc (F);
1175-
File : constant Metadata_T :=
1176-
Get_Debug_File_Node (Get_Source_File_Index (F_S));
1177-
Offset : constant ULL :=
1178-
UI_To_ULL (Component_Bit_Offset (F));
1179-
Storage_Offset : constant ULL :=
1180-
(Offset / UBPU) * UBPU;
1181-
MD : constant Metadata_T :=
1182-
(if Is_Bitfield (F)
1183-
then DI_Create_Bit_Field_Member_Type
1184-
(No_Metadata_T, Name, File,
1185-
Get_Physical_Line_Number (F_S),
1186-
UI_To_ULL (Esize (F)), Offset,
1187-
Storage_Offset, Mem_MD)
1188-
else DI_Create_Member_Type
1189-
(No_Metadata_T, Name, File,
1190-
Get_Physical_Line_Number (F_S),
1191-
UI_To_ULL (Esize (F)),
1192-
Get_Type_Alignment (F_GT), Offset, Mem_MD));
1193-
1194-
begin
1195-
-- Add the member type to the table
1196-
1197-
Member_Table.Append (MD);
1198-
end;
1199-
end if;
1200-
1201-
Next_Component_Or_Discriminant (F);
1202-
end loop;
1203-
1204-
declare
1205-
Members : Metadata_Array (1 .. Member_Table.Last);
1206-
1207-
begin
1208-
for J in Members'Range loop
1209-
Members (J) := Member_Table.Table (J);
1210-
end loop;
1211-
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);
1218-
end;
1219-
1220-
end Record_Type;
1116+
Result :=
1117+
Create_Record_Debug_Info
1118+
(TE, Original_Type,
1119+
Get_Scope_For (Original_Type),
1120+
Get_Possibly_Local_Name (Original_Type),
1121+
Size, Align, S);
1122+
end;
12211123

12221124
-- For an enumeration type, make an enumerator metadata for each
12231125
-- entry. The code below is a bit convoluted to avoid needing a

llvm-interface/gnatllvm-debuginfo.ads

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ package GNATLLVM.DebugInfo is
9191
with Pre => Present (N);
9292
-- Add debugging info for the "use" clause N.
9393

94+
function Create_Type_Data (GT : GL_Type) return Metadata_T
95+
with Pre => Present (GT);
96+
-- Create metadata corresponding to the type of GT. Return
97+
-- No_Metadata_T if the type is too complex.
98+
9499
Empty_DI_Expr : Metadata_T;
95100
-- An empty DI_Expr
96101

llvm-interface/gnatllvm-records-create.adb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ package body GNATLLVM.Records.Create is
678678
Num_Bits => Num_Bits,
679679
TBAA_Type => No_Metadata_T,
680680
Array_Bitfield => Array_Bitfield,
681-
Large_Array_Bitfield => Large_Array_Bitfield));
681+
Large_Array_Bitfield => Large_Array_Bitfield,
682+
Is_Inherited => Full_Scope (E) /= TE));
682683

683684
if No (Last_Field_Id) then
684685
First_Field_Id := Field_Info_Table.Last;

0 commit comments

Comments
 (0)