[llvm] ab699d7 - [DebugInfo] llvm rejects DWARF operator DW_OP_push_object_address

Sourabh Singh Tomar via llvm-commits llvm-commits at lists.llvm.org
Thu May 14 22:41:13 PDT 2020


Author: Alok Kumar Sharma
Date: 2020-05-15T11:10:35+05:30
New Revision: ab699d78a26f147b56537326ecadc072f8f5a03b

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

LOG: [DebugInfo] llvm rejects DWARF operator DW_OP_push_object_address

llvm rejects DWARF operator DW_OP_push_object_address.This DWARF
operator is needed for Flang to support allocatable array.

Summary:
Currently llvm rejects DWARF operator DW_OP_push_object_address.
below error is produced when llvm finds this operator.

[..]
invalid expression
!DIExpression(151)
warning: ignoring invalid debug info in pushobj.ll
[..]

There are some parts missing in support of this operator, need to
be completed.

Testing
-added a unit testcase
-check-debuginfo
-check-llvm

Reviewed By: aprantl

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

Added: 
    llvm/test/DebugInfo/dwarfdump-pushobjectaddress.ll

Modified: 
    llvm/docs/LangRef.rst
    llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
    llvm/lib/IR/DebugInfoMetadata.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 5845c62a291d..8b5bc8f3a95f 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -5102,6 +5102,9 @@ The current supported opcode vocabulary is limited:
   signed offset of the specified register. The opcode is only generated by the
   ``AsmPrinter`` pass to describe call site parameter value which requires an
   expression over two registers.
+- ``DW_OP_push_object_address`` pushes the address of the object which can then
+  serve as a descriptor in subsequent calculation. This opcode can be used to
+  calculate bounds of fortran allocatable array which has array descriptors.
 
 DWARF specifies three kinds of simple location descriptions: Register, memory,
 and implicit location descriptions.  Note that a location description is

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index a65d2d74a8c7..69bc06cb9467 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -451,6 +451,7 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
     case dwarf::DW_OP_lit0:
     case dwarf::DW_OP_not:
     case dwarf::DW_OP_dup:
+    case dwarf::DW_OP_push_object_address:
       emitOp(OpNum);
       break;
     case dwarf::DW_OP_deref:

diff  --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index c176d27a52ac..83e0958e21f2 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -947,6 +947,7 @@ bool DIExpression::isValid() const {
     case dwarf::DW_OP_dup:
     case dwarf::DW_OP_regx:
     case dwarf::DW_OP_bregx:
+    case dwarf::DW_OP_push_object_address:
       break;
     }
   }

diff  --git a/llvm/test/DebugInfo/dwarfdump-pushobjectaddress.ll b/llvm/test/DebugInfo/dwarfdump-pushobjectaddress.ll
new file mode 100644
index 000000000000..012eab6d8465
--- /dev/null
+++ b/llvm/test/DebugInfo/dwarfdump-pushobjectaddress.ll
@@ -0,0 +1,59 @@
+;; This test checks whether DWARF operator DW_OP_push_object_address
+;; is accepted and processed.
+
+; RUN: %llc -mtriple=x86_64-unknown-linux-gnu %s -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
+
+;; Test whether DW_OP_push_object_address is accepted.
+
+; CHECK-LABEL:       DW_TAG_variable
+; CHECK:        DW_AT_location
+; CHECK-SAME:        DW_OP_push_object_address
+
+;; Below is the original test case this IR is generated from
+;;---------------------------
+;;int main() {
+;;int var;
+;;return var;
+;;}
+;;---------------------------
+;; step 1: generate IR using -g -O0 -S -emit-llvm
+;; step 2: insert DW_OP_push_object_address in dbg.declare instruction
+;; This is meaningless test case focused to test DW_OP_push_object_address.
+
+; ModuleID = 'dwarfdump-pushobjectaddress.c'
+source_filename = "dwarfdump-pushobjectaddress.c"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local i32 @main() !dbg !7 {
+entry:
+  %retval = alloca i32, align 4
+  %var = alloca i32, align 4
+  store i32 0, i32* %retval, align 4
+  call void @llvm.dbg.declare(metadata i32* %var, metadata !11, metadata !DIExpression(DW_OP_push_object_address)), !dbg !12
+  %0 = load i32, i32* %var, align 4, !dbg !13
+  ret i32 %0, !dbg !14
+}
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "dwarfdump-pushobjectaddress.c", directory: "/dir")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 11.0.0"}
+!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DILocalVariable(name: "var", scope: !7, file: !1, line: 2, type: !10)
+!12 = !DILocation(line: 2, column: 5, scope: !7)
+!13 = !DILocation(line: 3, column: 8, scope: !7)
+!14 = !DILocation(line: 3, column: 1, scope: !7)


        


More information about the llvm-commits mailing list