[PATCH] D89817: [DebugInfo] Expose Fortran array debug info attributes through DIBuilder.

Chih-Ping Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 21 08:29:05 PDT 2020


cchen15 updated this revision to Diff 299702.
cchen15 added a comment.

Added a unit test for the patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89817/new/

https://reviews.llvm.org/D89817

Files:
  llvm/include/llvm/IR/DIBuilder.h
  llvm/lib/IR/DIBuilder.cpp
  llvm/unittests/IR/DebugInfoTest.cpp


Index: llvm/unittests/IR/DebugInfoTest.cpp
===================================================================
--- llvm/unittests/IR/DebugInfoTest.cpp
+++ llvm/unittests/IR/DebugInfoTest.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/DIBuilder.h"
 #include "llvm/AsmParser/Parser.h"
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/IntrinsicInst.h"
@@ -185,4 +186,37 @@
   EXPECT_TRUE(isa<UndefValue>(DVIs[0]->getValue()));
 }
 
+TEST(DIBuilder, CreateFortranArrayTypeWithAttributes) {
+  LLVMContext Ctx;
+  std::unique_ptr<Module> M(new Module("MyModule", Ctx));
+  DIBuilder DIB(*M);
+
+  DISubrange *Subrange = DIB.getOrCreateSubrange(1,1);
+  SmallVector<Metadata*, 4> Subranges;
+  Subranges.push_back(Subrange);
+  DINodeArray Subscripts = DIB.getOrCreateArray(Subranges);
+
+  auto getDIExpression = [&DIB](int offset) {
+    SmallVector<uint64_t, 4> ops;
+    ops.push_back(llvm::dwarf::DW_OP_push_object_address);
+    DIExpression::appendOffset(ops, offset);
+    ops.push_back(llvm::dwarf::DW_OP_deref);
+
+    return DIB.createExpression(ops);
+  };
+
+  Metadata *DataLocation = getDIExpression(0);
+  Metadata *Associated = getDIExpression(1);
+  Metadata *Allocated = getDIExpression(2);
+
+  DICompositeType *ArrayType = DIB.createArrayType(0, 0, nullptr, Subscripts,
+                                                   DataLocation, Associated,
+                                                   Allocated);
+
+  EXPECT_TRUE(isa_and_nonnull<DICompositeType>(ArrayType));
+  EXPECT_EQ(ArrayType->getRawDataLocation(), DataLocation);
+  EXPECT_EQ(ArrayType->getRawAssociated(), Associated);
+  EXPECT_EQ(ArrayType->getRawAllocated(), Allocated);
+}
+   
 } // end namespace
Index: llvm/lib/IR/DIBuilder.cpp
===================================================================
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -527,10 +527,15 @@
 
 DICompositeType *DIBuilder::createArrayType(uint64_t Size,
                                             uint32_t AlignInBits, DIType *Ty,
-                                            DINodeArray Subscripts) {
+                                            DINodeArray Subscripts,
+                                            Metadata *DataLocation,
+                                            Metadata *Associated,
+                                            Metadata *Allocated) {
   auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
                                  nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
-                                 DINode::FlagZero, Subscripts, 0, nullptr);
+                                 DINode::FlagZero, Subscripts, 0, nullptr,
+                                 nullptr, "", nullptr, DataLocation,
+                                 Associated, Allocated);
   trackIfUnresolved(R);
   return R;
 }
Index: llvm/include/llvm/IR/DIBuilder.h
===================================================================
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -494,8 +494,17 @@
     /// \param AlignInBits  Alignment.
     /// \param Ty           Element type.
     /// \param Subscripts   Subscripts.
+    /// \param DataLocation The location of the raw data of a descriptor-based
+    ///                     Fortran array. Typically a DIExpression*.
+    /// \param Associated   The associated attribute of a descriptor-based
+    ///                     Fortran array. Typically a DIExpression*.
+    /// \param Allocated    The allocated attribute of a descriptor-based
+    ///                     Fortran array. Typically a DIExpression*.
     DICompositeType *createArrayType(uint64_t Size, uint32_t AlignInBits,
-                                     DIType *Ty, DINodeArray Subscripts);
+                                     DIType *Ty, DINodeArray Subscripts,
+                                     Metadata *DataLocation = nullptr,
+                                     Metadata *Associated = nullptr,
+                                     Metadata *Allocated = nullptr);
 
     /// Create debugging information entry for a vector type.
     /// \param Size         Array size.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89817.299702.patch
Type: text/x-patch
Size: 4268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201021/dc0abcea/attachment.bin>


More information about the llvm-commits mailing list