Skip to content

Commit c226a5c

Browse files
cchen15chih-ping.chen
authored and
chih-ping.chen
committed
[DebugInfo] Use DW_ATE_signed encoding when creating a Fortran
array index type.
1 parent be572e1 commit c226a5c

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

llvm/include/llvm/BinaryFormat/Dwarf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ inline bool isFortran(SourceLanguage S) {
320320
return result;
321321
}
322322

323+
inline TypeKind getArrayIndexTypeEncoding(SourceLanguage S) {
324+
return isFortran(S) ? DW_ATE_signed : DW_ATE_unsigned;
325+
}
326+
323327
enum CaseSensitivity {
324328
// Identifier case codes
325329
DW_ID_case_sensitive = 0x00,

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,8 @@ DIE *DwarfUnit::getIndexTyDie() {
14361436
addString(*IndexTyDie, dwarf::DW_AT_name, Name);
14371437
addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
14381438
addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
1439-
dwarf::DW_ATE_unsigned);
1439+
dwarf::getArrayIndexTypeEncoding(
1440+
(dwarf::SourceLanguage)getLanguage()));
14401441
DD->addAccelType(*CUNode, Name, *IndexTyDie, /*Flags*/ 0);
14411442
return IndexTyDie;
14421443
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; This test checks that the array index type has signed encoding when
2+
; the source language is Fortran.
3+
4+
; RUN: llc -O0 -filetype=obj -o %t < %s
5+
; RUN: llvm-dwarfdump %t | FileCheck %s
6+
7+
; CHECK: DW_TAG_subrange_type
8+
; CHECK-NEXT: DW_AT_type ([[INDEX_TYPE:0x[0-9a-f]+]] "__ARRAY_SIZE_TYPE__")
9+
; CHECK-NEXT: DW_AT_lower_bound (-2)
10+
; CHECK-NEXT: DW_AT_upper_bound (2)
11+
12+
; CHECK: [[INDEX_TYPE]]: DW_TAG_base_type
13+
; CHECK-NEXT: DW_AT_name ("__ARRAY_SIZE_TYPE__")
14+
; CHECK-NEXT: DW_AT_byte_size (0x08)
15+
; CHECK-NEXT: DW_AT_encoding (DW_ATE_signed)
16+
17+
source_filename = "test/DebugInfo/X86/fortran-array-index-type.ll"
18+
target triple = "x86_64-unknown-linux-gnu"
19+
20+
@"test_$ARRAY_1D" = internal global [5 x i32] zeroinitializer, align 16, !dbg !0
21+
22+
!llvm.module.flags = !{!13, !14}
23+
!llvm.dbg.cu = !{!6}
24+
!omp_offload.info = !{}
25+
26+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
27+
!1 = distinct !DIGlobalVariable(name: "array_1d", linkageName: "test_$ARRAY_1D", scope: !6, file: !3, line: 2, type: !9, isLocal: true, isDefinition: true)
28+
!3 = !DIFile(filename: "test.f90", directory: "/tests")
29+
!6 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Fortran Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !7, splitDebugInlining: false, nameTableKind: None)
30+
!7 = !{!0}
31+
!9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, elements: !11)
32+
!10 = !DIBasicType(name: "INTEGER*4", size: 32, encoding: DW_ATE_signed)
33+
!11 = !{!12}
34+
!12 = !DISubrange(lowerBound: -2, upperBound: 2)
35+
!13 = !{i32 2, !"Debug Info Version", i32 3}
36+
!14 = !{i32 2, !"Dwarf Version", i32 4}

0 commit comments

Comments
 (0)