[llvm] 159abe0 - [DebugInfo][flang] DISubrange support for fortran assumed size array

Alok Kumar Sharma via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 01:46:18 PDT 2020


Author: Alok Kumar Sharma
Date: 2020-09-16T14:15:53+05:30
New Revision: 159abe09d25b19c24bf23ce50757987c0f25abe4

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

LOG: [DebugInfo][flang] DISubrange support for fortran assumed size array

This is needed to support assumed size array of fortran which can have missing upperBound/count
, contrary to current DISubrange support.
Example:
subroutine sub (array1, array2)
  integer :: array1 (*)
  integer :: array2 (4:9, 10:*)

  array1(7:8) = 9
  array2(5, 10) = 10
end subroutine
Now the validation check is relaxed for fortran.

Reviewed By: aprantl

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

Added: 
    llvm/test/DebugInfo/X86/assumed_size_array.ll

Modified: 
    llvm/include/llvm/BinaryFormat/Dwarf.h
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index bcc447a84a4d..28cbc2c6a0e4 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -183,6 +183,7 @@ enum SourceLanguage {
 };
 
 inline bool isCPlusPlus(SourceLanguage S) {
+  bool result = false;
   // Deliberately enumerate all the language options so we get a warning when
   // new language options are added (-Wswitch) that'll hopefully help keep this
   // switch up-to-date when new C++ versions are added.
@@ -191,7 +192,8 @@ inline bool isCPlusPlus(SourceLanguage S) {
   case DW_LANG_C_plus_plus_03:
   case DW_LANG_C_plus_plus_11:
   case DW_LANG_C_plus_plus_14:
-    return true;
+    result = true;
+    break;
   case DW_LANG_C89:
   case DW_LANG_C:
   case DW_LANG_Ada83:
@@ -230,9 +232,68 @@ inline bool isCPlusPlus(SourceLanguage S) {
   case DW_LANG_BORLAND_Delphi:
   case DW_LANG_lo_user:
   case DW_LANG_hi_user:
-    return false;
+    result = false;
+    break;
+  }
+
+  return result;
+}
+
+inline bool isFortran(SourceLanguage S) {
+  bool result = false;
+  // Deliberately enumerate all the language options so we get a warning when
+  // new language options are added (-Wswitch) that'll hopefully help keep this
+  // switch up-to-date when new Fortran versions are added.
+  switch (S) {
+  case DW_LANG_Fortran77:
+  case DW_LANG_Fortran90:
+  case DW_LANG_Fortran95:
+  case DW_LANG_Fortran03:
+  case DW_LANG_Fortran08:
+    result = true;
+    break;
+  case DW_LANG_C89:
+  case DW_LANG_C:
+  case DW_LANG_Ada83:
+  case DW_LANG_C_plus_plus:
+  case DW_LANG_Cobol74:
+  case DW_LANG_Cobol85:
+  case DW_LANG_Pascal83:
+  case DW_LANG_Modula2:
+  case DW_LANG_Java:
+  case DW_LANG_C99:
+  case DW_LANG_Ada95:
+  case DW_LANG_PLI:
+  case DW_LANG_ObjC:
+  case DW_LANG_ObjC_plus_plus:
+  case DW_LANG_UPC:
+  case DW_LANG_D:
+  case DW_LANG_Python:
+  case DW_LANG_OpenCL:
+  case DW_LANG_Go:
+  case DW_LANG_Modula3:
+  case DW_LANG_Haskell:
+  case DW_LANG_C_plus_plus_03:
+  case DW_LANG_C_plus_plus_11:
+  case DW_LANG_OCaml:
+  case DW_LANG_Rust:
+  case DW_LANG_C11:
+  case DW_LANG_Swift:
+  case DW_LANG_Julia:
+  case DW_LANG_Dylan:
+  case DW_LANG_C_plus_plus_14:
+  case DW_LANG_RenderScript:
+  case DW_LANG_BLISS:
+  case DW_LANG_Mips_Assembler:
+  case DW_LANG_GOOGLE_RenderScript:
+  case DW_LANG_BORLAND_Delphi:
+  case DW_LANG_lo_user:
+  case DW_LANG_hi_user:
+    result = false;
+    break;
   }
-  llvm_unreachable("Invalid source language");
+
+  return result;
 }
 
 enum CaseSensitivity {

diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index a5baa2bf1631..3fed0bf64b6e 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -282,6 +282,9 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
   /// Whether the current function has a DISubprogram attached to it.
   bool HasDebugInfo = false;
 
+  /// The current source language.
+  dwarf::SourceLanguage CurrentSourceLang = dwarf::DW_LANG_lo_user;
+
   /// Whether source was present on the first DIFile encountered in each CU.
   DenseMap<const DICompileUnit *, bool> HasSourceDebugInfo;
 
@@ -895,7 +898,9 @@ void Verifier::visitDIScope(const DIScope &N) {
 
 void Verifier::visitDISubrange(const DISubrange &N) {
   AssertDI(N.getTag() == dwarf::DW_TAG_subrange_type, "invalid tag", &N);
-  AssertDI(N.getRawCountNode() || N.getRawUpperBound(),
+  bool HasAssumedSizedArraySupport = dwarf::isFortran(CurrentSourceLang);
+  AssertDI(HasAssumedSizedArraySupport || N.getRawCountNode() ||
+               N.getRawUpperBound(),
            "Subrange must contain count or upperBound", &N);
   AssertDI(!N.getRawCountNode() || !N.getRawUpperBound(),
            "Subrange can have any one of count or upperBound", &N);
@@ -1100,6 +1105,8 @@ void Verifier::visitDICompileUnit(const DICompileUnit &N) {
   AssertDI(!N.getFile()->getFilename().empty(), "invalid filename", &N,
            N.getFile());
 
+  CurrentSourceLang = (dwarf::SourceLanguage)N.getSourceLanguage();
+
   verifySourceDebugInfo(N, *N.getFile());
 
   AssertDI((N.getEmissionKind() <= DICompileUnit::LastEmissionKind),

diff  --git a/llvm/test/DebugInfo/X86/assumed_size_array.ll b/llvm/test/DebugInfo/X86/assumed_size_array.ll
new file mode 100644
index 000000000000..cad7afdd68b5
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/assumed_size_array.ll
@@ -0,0 +1,122 @@
+;; Check whether fortran assumed size array is accepted
+;; which has upperBound absent in DISubrange
+
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu %s -filetype=obj -o %t.o
+; RUN: llvm-dwarfdump  %t.o | FileCheck %s
+
+; CHECK-LABEL: DW_TAG_formal_parameter
+; CHECK: DW_AT_name    ("array1")
+; CHECK: DW_AT_type    ([[type1:0x[0-9a-f]+]]
+; CHECK-LABEL: DW_TAG_formal_parameter
+; CHECK: DW_AT_name    ("array2")
+; CHECK: DW_AT_type    ([[type2:0x[0-9a-f]+]]
+; CHECK: [[type1]]:   DW_TAG_array_type
+; CHECK: DW_TAG_subrange_type
+; CHECK: [[type2]]:   DW_TAG_array_type
+; CHECK: DW_TAG_subrange_type
+; CHECK: DW_AT_lower_bound     (4)
+; CHECK: DW_AT_upper_bound     (9)
+; CHECK: DW_TAG_subrange_type
+; CHECK: DW_AT_lower_bound     (10)
+;
+;
+;; original fortran program
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;subroutine sub (array1, array2)
+;;  integer :: array1 (*)
+;;  integer :: array2 (4:9, 10:*)
+;;
+;;  array1(7:8) = 9
+;;  array2(5, 10) = 10
+;;end subroutine
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; ModuleID = 'assumed_size_array.ll'
+source_filename = "assumed_size_array.ll"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at .C344_sub_ = internal constant i32 10
+ at .C345_sub_ = internal constant i64 10
+ at .C351_sub_ = internal constant i64 5
+ at .C341_sub_ = internal constant i32 9
+ at .C322_sub_ = internal constant i64 1
+ at .C350_sub_ = internal constant i64 8
+ at .C349_sub_ = internal constant i64 7
+
+define void @sub_(i64* noalias %array1, i64* noalias %array2) #0 !dbg !5 {
+L.entry:
+  %.dY0001_361 = alloca i64, align 8
+  %"i$a_357" = alloca i64, align 8
+  call void @llvm.dbg.declare(metadata i64* %array1, metadata !16, metadata !DIExpression()), !dbg !17
+  call void @llvm.dbg.declare(metadata i64* %array2, metadata !18, metadata !DIExpression()), !dbg !17
+  br label %L.LB1_364
+
+L.LB1_364:                                        ; preds = %L.entry
+  store i64 2, i64* %.dY0001_361, align 8, !dbg !19
+  call void @llvm.dbg.declare(metadata i64* %"i$a_357", metadata !20, metadata !DIExpression()), !dbg !17
+  store i64 7, i64* %"i$a_357", align 8, !dbg !19
+  br label %L.LB1_359
+
+L.LB1_359:                                        ; preds = %L.LB1_359, %L.LB1_364
+  %0 = load i64, i64* %"i$a_357", align 8, !dbg !19
+  call void @llvm.dbg.value(metadata i64 %0, metadata !22, metadata !DIExpression()), !dbg !17
+  %1 = bitcast i64* %array1 to i8*, !dbg !19
+  %2 = getelementptr i8, i8* %1, i64 -4, !dbg !19
+  %3 = bitcast i8* %2 to i32*, !dbg !19
+  %4 = getelementptr i32, i32* %3, i64 %0, !dbg !19
+  store i32 9, i32* %4, align 4, !dbg !19
+  %5 = load i64, i64* %"i$a_357", align 8, !dbg !19
+  call void @llvm.dbg.value(metadata i64 %5, metadata !23, metadata !DIExpression()), !dbg !17
+  %6 = add nsw i64 %5, 1, !dbg !19
+  store i64 %6, i64* %"i$a_357", align 8, !dbg !19
+  %7 = load i64, i64* %.dY0001_361, align 8, !dbg !19
+  %8 = sub nsw i64 %7, 1, !dbg !19
+  store i64 %8, i64* %.dY0001_361, align 8, !dbg !19
+  %9 = load i64, i64* %.dY0001_361, align 8, !dbg !19
+  %10 = icmp sgt i64 %9, 0, !dbg !19
+  br i1 %10, label %L.LB1_359, label %L.LB1_383, !dbg !19
+
+L.LB1_383:                                        ; preds = %L.LB1_359
+  %11 = bitcast i64* %array2 to i8*, !dbg !24
+  %12 = getelementptr i8, i8* %11, i64 4, !dbg !24
+  %13 = bitcast i8* %12 to i32*, !dbg !24
+  store i32 10, i32* %13, align 4, !dbg !24
+  ret void, !dbg !25
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.module.flags = !{!0, !1}
+!llvm.dbg.cu = !{!2}
+
+!0 = !{i32 2, !"Dwarf Version", i32 4}
+!1 = !{i32 2, !"Debug Info Version", i32 3}
+!2 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !4, globals: !4, imports: !4)
+!3 = !DIFile(filename: "assumed_size_array.f90", directory: "/tmp")
+!4 = !{}
+!5 = distinct !DISubprogram(name: "sub", scope: !2, file: !3, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !2)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null, !8, !12}
+!8 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, align: 32, elements: !10)
+!9 = !DIBasicType(name: "integer", size: 32, align: 32, encoding: DW_ATE_signed)
+!10 = !{!11}
+!11 = !DISubrange(lowerBound: 1)
+!12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, align: 32, elements: !13)
+!13 = !{!14, !15}
+!14 = !DISubrange(lowerBound: 4, upperBound: 9)
+!15 = !DISubrange(lowerBound: 10)
+!16 = !DILocalVariable(name: "array1", arg: 1, scope: !5, file: !3, line: 1, type: !8)
+!17 = !DILocation(line: 0, scope: !5)
+!18 = !DILocalVariable(name: "array2", arg: 2, scope: !5, file: !3, line: 1, type: !12)
+!19 = !DILocation(line: 5, column: 1, scope: !5)
+!20 = distinct !DILocalVariable(scope: !5, file: !3, type: !21, flags: DIFlagArtificial)
+!21 = !DIBasicType(name: "integer*8", size: 64, align: 64, encoding: DW_ATE_signed)
+!22 = distinct !DILocalVariable(scope: !5, file: !3, type: !21, flags: DIFlagArtificial)
+!23 = distinct !DILocalVariable(scope: !5, file: !3, type: !21, flags: DIFlagArtificial)
+!24 = !DILocation(line: 6, column: 1, scope: !5)
+!25 = !DILocation(line: 7, column: 1, scope: !5)


        


More information about the llvm-commits mailing list