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

Chih-Ping Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 06:58:23 PDT 2022


cchen15 created this revision.
cchen15 added a reviewer: aprantl.
cchen15 added a project: debug-info.
Herald added subscribers: ormris, arphaman, hiraditya.
Herald added a project: All.
cchen15 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.

An array index type is currently encoded as DW_ATE_unsigned regardless of the source language. That doesn't work for Fortran as it allows a negative array index. This change corrects that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122584

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/X86/fortran-array-index-type.ll


Index: llvm/test/DebugInfo/X86/fortran-array-index-type.ll
===================================================================
--- /dev/null
+++ 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}
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1438,7 +1438,8 @@
   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::isFortran((dwarf::SourceLanguage)getLanguage())
+              ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned);
   DD->addAccelType(*CUNode, Name, *IndexTyDie, /*Flags*/ 0);
   return IndexTyDie;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122584.418573.patch
Type: text/x-patch
Size: 2581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220328/cabbb9af/attachment.bin>


More information about the llvm-commits mailing list