Browse Source

[CodeGen/Dwarf] Rename the "sizetype" synthetic type and add it to the accelerator table

Summary:
This type is created on-demand and used as the base type for array
ranges. Since it is "special", its construction did not go through the
createTypeDIE function and so it was never inserted into the accelerator
table, although it clearly belongs there.

I add an explicit addAccelType call to insert it into the table.

During review, we also decided to rename the type to something more
unique to avoid confusion in case the user has own "sizetype" type. The
new name for the type size __ARRAY_SIZE_TYPE__.

Reviewers: JDevlieghere, aprantl, dblaikie

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D45445

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329705 91177308-0d34-0410-b5e6-96231b3b80d8
Pavel Labath 7 years ago
parent
commit
e6ac37f218

+ 3 - 1
lib/CodeGen/AsmPrinter/DwarfUnit.cpp

@@ -1404,10 +1404,12 @@ DIE *DwarfUnit::getIndexTyDie() {
     return IndexTyDie;
     return IndexTyDie;
   // Construct an integer type to use for indexes.
   // Construct an integer type to use for indexes.
   IndexTyDie = &createAndAddDIE(dwarf::DW_TAG_base_type, getUnitDie());
   IndexTyDie = &createAndAddDIE(dwarf::DW_TAG_base_type, getUnitDie());
-  addString(*IndexTyDie, dwarf::DW_AT_name, "sizetype");
+  StringRef Name = "__ARRAY_SIZE_TYPE__";
+  addString(*IndexTyDie, dwarf::DW_AT_name, Name);
   addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
   addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
   addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
   addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
           dwarf::DW_ATE_unsigned);
           dwarf::DW_ATE_unsigned);
+  DD->addAccelType(Name, *IndexTyDie, /*Flags*/ 0);
   return IndexTyDie;
   return IndexTyDie;
 }
 }
 
 

+ 38 - 0
test/DebugInfo/Generic/debug-names-index-type.ll

@@ -0,0 +1,38 @@
+; REQUIRES: object-emission
+; RUN: %llc_dwarf -accel-tables=Dwarf -filetype=obj -o %t < %s
+; RUN: llvm-dwarfdump -debug-names %t | FileCheck %s
+; RUN: llvm-dwarfdump -debug-names -verify %t | FileCheck --check-prefix=VERIFY %s
+
+; Check that the entry for the "__ARRAY_SIZE_TYPE__" index type is present in the
+; accelerator table.
+; CHECK: String: 0x{{[0-9a-f]*}} "__ARRAY_SIZE_TYPE__"
+; CHECK-NEXT: Entry
+; CHECK-NEXT: Abbrev
+; CHECK-NEXT: Tag: DW_TAG_base_type
+
+; VERIFY: No errors.
+
+; Generated by:
+; clang -g -x c - -o - -S -emit-llvm <<<"int a[1];"
+
+@a = common dso_local global [1 x i32] zeroinitializer, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !6, line: 1, type: !7, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 329543) (llvm/trunk 329575)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "-", directory: "/tmp")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIFile(filename: "<stdin>", directory: "/tmp")
+!7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 32, elements: !9)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{!10}
+!10 = !DISubrange(count: 1)
+!11 = !{i32 2, !"Dwarf Version", i32 4}
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = !{i32 1, !"wchar_size", i32 4}
+!14 = !{!"clang version 7.0.0 (trunk 329543) (llvm/trunk 329575)"}

+ 1 - 1
test/DebugInfo/X86/nondefault-subrange-array.ll

@@ -24,7 +24,7 @@ source_filename = "test/DebugInfo/X86/nondefault-subrange-array.ll"
 
 
 ; CHECK: [[BASE]]: DW_TAG_base_type
 ; CHECK: [[BASE]]: DW_TAG_base_type
 ; CHECK: [[BASE2]]: DW_TAG_base_type
 ; CHECK: [[BASE2]]: DW_TAG_base_type
-; CHECK-NEXT:                 DW_AT_name [DW_FORM_strp]       ( .debug_str[0x{{[0-9a-f]*}}] = "sizetype")
+; CHECK-NEXT:                 DW_AT_name [DW_FORM_strp]       ( .debug_str[0x{{[0-9a-f]*}}] = "__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:                 DW_AT_byte_size [DW_FORM_data1] (0x08)
 ; CHECK-NEXT:                 DW_AT_byte_size [DW_FORM_data1] (0x08)
 ; CHECK-NEXT:                 DW_AT_encoding [DW_FORM_data1]  (DW_ATE_unsigned)
 ; CHECK-NEXT:                 DW_AT_encoding [DW_FORM_data1]  (DW_ATE_unsigned)
 
 

+ 1 - 1
test/DebugInfo/X86/vla-dependencies.ll

@@ -7,7 +7,7 @@
 ; CHECK-NEXT:     DW_AT_type	{{.*}}"int"
 ; CHECK-NEXT:     DW_AT_type	{{.*}}"int"
 ; CHECK-NOT: DW_TAG
 ; CHECK-NOT: DW_TAG
 ; CHECK:        DW_TAG_subrange_type
 ; CHECK:        DW_TAG_subrange_type
-; CHECK-NEXT:     DW_AT_type {{.*}}"sizetype"
+; CHECK-NEXT:     DW_AT_type {{.*}}"__ARRAY_SIZE_TYPE__"
 ; CHECK-NEXT:     DW_AT_count	(0x00000[[VLAEXPR]]
 ; CHECK-NEXT:     DW_AT_count	(0x00000[[VLAEXPR]]
 ;
 ;
 ;
 ;

+ 1 - 1
test/DebugInfo/X86/vla-global.ll

@@ -5,7 +5,7 @@
 ; CHECK-NEXT:  DW_AT_type	({{.*}} "int")
 ; CHECK-NEXT:  DW_AT_type	({{.*}} "int")
 ; CHECK-NOT: DW_TAG
 ; CHECK-NOT: DW_TAG
 ; CHECK:       DW_TAG_subrange_type
 ; CHECK:       DW_TAG_subrange_type
-; CHECK-NEXT:     DW_AT_type	({{.*}} "sizetype")
+; CHECK-NEXT:     DW_AT_type	({{.*}} "__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:      DW_AT_count	(0x00000[[G]])
 ; CHECK-NEXT:      DW_AT_count	(0x00000[[G]])
 ; Test that a VLA referring to a global variable is handled correctly.
 ; Test that a VLA referring to a global variable is handled correctly.
 ; Clang doesn't generate this, but the verifier allows it.
 ; Clang doesn't generate this, but the verifier allows it.

+ 8 - 8
test/DebugInfo/X86/vla-multi.ll

@@ -11,37 +11,37 @@
 ; CHECK-NEXT:     DW_AT_type	(0x000000f8 "int")
 ; CHECK-NEXT:     DW_AT_type	(0x000000f8 "int")
 ; CHECK-NOT: TAG
 ; CHECK-NOT: TAG
 ; CHECK:          DW_TAG_subrange_type
 ; CHECK:          DW_TAG_subrange_type
-; CHECK-NEXT:       DW_AT_type	(0x{{.*}}"sizetype")
+; CHECK-NEXT:       DW_AT_type	(0x{{.*}}"__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NOT: TAG
 ; CHECK-NOT: TAG
 ; CHECK:          DW_TAG_subrange_type
 ; CHECK:          DW_TAG_subrange_type
-; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "sizetype")
+; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NOT: TAG
 ; CHECK-NOT: TAG
 ; CHECK:          DW_TAG_subrange_type
 ; CHECK:          DW_TAG_subrange_type
-; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "sizetype")
+; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NOT: TAG
 ; CHECK-NOT: TAG
 ; CHECK:          DW_TAG_subrange_type
 ; CHECK:          DW_TAG_subrange_type
-; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "sizetype")
+; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK:        DW_TAG_array_type
 ; CHECK:        DW_TAG_array_type
 ; CHECK-NEXT:     DW_AT_type	(0x000000f8 "int")
 ; CHECK-NEXT:     DW_AT_type	(0x000000f8 "int")
 ; CHECK-NOT: TAG
 ; CHECK-NOT: TAG
 ; CHECK:          DW_TAG_subrange_type
 ; CHECK:          DW_TAG_subrange_type
-; CHECK-NEXT:       DW_AT_type	(0x{{.*}}"sizetype")
+; CHECK-NEXT:       DW_AT_type	(0x{{.*}}"__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NOT: TAG
 ; CHECK-NOT: TAG
 ; CHECK:          DW_TAG_subrange_type
 ; CHECK:          DW_TAG_subrange_type
-; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "sizetype")
+; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NOT: TAG
 ; CHECK-NOT: TAG
 ; CHECK:          DW_TAG_subrange_type
 ; CHECK:          DW_TAG_subrange_type
-; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "sizetype")
+; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NOT: TAG
 ; CHECK-NOT: TAG
 ; CHECK:          DW_TAG_subrange_type
 ; CHECK:          DW_TAG_subrange_type
-; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "sizetype")
+; CHECK-NEXT:       DW_AT_type	(0x{{.*}} "__ARRAY_SIZE_TYPE__")
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})
 ; CHECK-NEXT:       DW_AT_count	(0x{{.*}})