[llvm] c226a5c - [DebugInfo] Use DW_ATE_signed encoding when creating a Fortran

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 04:01:58 PDT 2022


Author: Chih-Ping Chen
Date: 2022-04-07T07:00:56-04:00
New Revision: c226a5c4d7ea82814dbdbbe9807997c56a5f6d58

URL: https://github.com/llvm/llvm-project/commit/c226a5c4d7ea82814dbdbbe9807997c56a5f6d58
DIFF: https://github.com/llvm/llvm-project/commit/c226a5c4d7ea82814dbdbbe9807997c56a5f6d58.diff

LOG: [DebugInfo] Use DW_ATE_signed encoding when creating a Fortran
array index type.

Added: 
    llvm/test/DebugInfo/X86/fortran-array-index-type.ll

Modified: 
    llvm/include/llvm/BinaryFormat/Dwarf.h
    llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 4473f506d3711..e288c5191bdb5 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -320,6 +320,10 @@ inline bool isFortran(SourceLanguage S) {
   return result;
 }
 
+inline TypeKind getArrayIndexTypeEncoding(SourceLanguage S) {
+  return isFortran(S) ? DW_ATE_signed : DW_ATE_unsigned;
+}
+
 enum CaseSensitivity {
   // Identifier case codes
   DW_ID_case_sensitive = 0x00,

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 1657c73f873bc..c2fd61ee18471 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1436,7 +1436,8 @@ DIE *DwarfUnit::getIndexTyDie() {
   addString(*IndexTyDie, dwarf::DW_AT_name, Name);
   addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
   addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
-          dwarf::DW_ATE_unsigned);
+          dwarf::getArrayIndexTypeEncoding(
+              (dwarf::SourceLanguage)getLanguage()));
   DD->addAccelType(*CUNode, Name, *IndexTyDie, /*Flags*/ 0);
   return IndexTyDie;
 }

diff  --git a/llvm/test/DebugInfo/X86/fortran-array-index-type.ll b/llvm/test/DebugInfo/X86/fortran-array-index-type.ll
new file mode 100644
index 0000000000000..0bc75513ddc88
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/fortran-array-index-type.ll
@@ -0,0 +1,36 @@
+; This test checks that the array index type has signed encoding when
+; the source language is Fortran.
+
+; RUN: llc -O0 -filetype=obj -o %t < %s
+; RUN: llvm-dwarfdump %t | FileCheck %s
+
+; CHECK:      DW_TAG_subrange_type
+; CHECK-NEXT:     DW_AT_type ([[INDEX_TYPE:0x[0-9a-f]+]] "__ARRAY_SIZE_TYPE__")
+; CHECK-NEXT:     DW_AT_lower_bound (-2)
+; CHECK-NEXT:     DW_AT_upper_bound (2)
+
+; CHECK:      [[INDEX_TYPE]]: DW_TAG_base_type
+; CHECK-NEXT:     DW_AT_name ("__ARRAY_SIZE_TYPE__")
+; CHECK-NEXT:     DW_AT_byte_size (0x08)
+; CHECK-NEXT:     DW_AT_encoding (DW_ATE_signed)
+
+source_filename = "test/DebugInfo/X86/fortran-array-index-type.ll"
+target triple = "x86_64-unknown-linux-gnu"
+
+@"test_$ARRAY_1D" = internal global [5 x i32] zeroinitializer, align 16, !dbg !0
+
+!llvm.module.flags = !{!13, !14}
+!llvm.dbg.cu = !{!6}
+!omp_offload.info = !{}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "array_1d", linkageName: "test_$ARRAY_1D", scope: !6, file: !3, line: 2, type: !9, isLocal: true, isDefinition: true)
+!3 = !DIFile(filename: "test.f90", directory: "/tests")
+!6 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Fortran Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !7, splitDebugInlining: false, nameTableKind: None)
+!7 = !{!0}
+!9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, elements: !11)
+!10 = !DIBasicType(name: "INTEGER*4", size: 32, encoding: DW_ATE_signed)
+!11 = !{!12}
+!12 = !DISubrange(lowerBound: -2, upperBound: 2)
+!13 = !{i32 2, !"Debug Info Version", i32 3}
+!14 = !{i32 2, !"Dwarf Version", i32 4}


        


More information about the llvm-commits mailing list