[PATCH] D118276: Adding a DIBuilder interface for Fortran's assumed length string

ykhatav via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 26 12:07:00 PST 2022


ykhatav created this revision.
ykhatav added reviewers: echristo, bwyma, smerritt, cchen15.
Herald added subscribers: dexonsmith, hiraditya.
ykhatav requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently DIBuilder supports constant length strings only. In this review I have added  a new interface called createStringType() which is capable of generating the debug info metadata for an assumed length string.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118276

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
@@ -247,6 +247,18 @@
   EXPECT_TRUE(isa_and_nonnull<DIDerivedType>(SetType));
 }
 
+TEST(DIBuilder, CreateStringType) {
+  LLVMContext Ctx;
+  std::unique_ptr<Module> M(new Module("MyModule", Ctx));
+  DIBuilder DIB(*M);
+  StringRef StrName = "string";
+  DIStringType *StringType = DIB.createStringType(StrName,nullptr);
+
+  EXPECT_TRUE(isa_and_nonnull<DIStringType>(StringType));
+  EXPECT_EQ(StringType->getName(),"string");
+  EXPECT_EQ(StringType->getStringLength(),nullptr);
+}
+
 TEST(DIBuilder, DIEnumerator) {
   LLVMContext Ctx;
   std::unique_ptr<Module> M(new Module("MyModule", Ctx));
Index: llvm/lib/IR/DIBuilder.cpp
===================================================================
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -295,6 +295,20 @@
                            SizeInBits, 0);
 }
 
+DIStringType *DIBuilder::createStringType(StringRef Name,
+                                          Metadata *stringLength) {
+  assert(!Name.empty() && "Unable to create type without name");
+  return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name,
+                           stringLength, nullptr, 0, 0, 0);
+}
+
+DIStringType *DIBuilder::createStringTypeExp(StringRef Name,
+                                             DIExpression *stringLengthExp) {
+  assert(!Name.empty() && "Unable to create type without name");
+  return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name, nullptr,
+                           stringLengthExp, 0, 0, 0);
+}
+
 DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {
   return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
                             0, 0, None, DINode::FlagZero);
Index: llvm/include/llvm/IR/DIBuilder.h
===================================================================
--- llvm/include/llvm/IR/DIBuilder.h
+++ llvm/include/llvm/IR/DIBuilder.h
@@ -220,6 +220,19 @@
     /// \param Name        Type name.
     /// \param SizeInBits  Size of the type.
     DIStringType *createStringType(StringRef Name, uint64_t SizeInBits);
+    
+    /// Create debugging information entry for Fortran
+    /// assumed length string type.
+    /// \param Name          Type name.
+    /// \param stringLength  Metadata refrencing string length.
+    DIStringType *createStringType(StringRef Name, Metadata *stringLength);
+    
+    /// Create debugging information entry for Fortran
+    /// assumed length string type.
+    /// \param Name          Type name.
+    /// \param stringLength  String length expressed in DIExpression form
+    DIStringType *createStringTypeExp(StringRef Name,
+                                      DIExpression *stringLengthExp);
 
     /// Create debugging information entry for a qualified
     /// type, e.g. 'const int'.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118276.403363.patch
Type: text/x-patch
Size: 3002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220126/c822920d/attachment.bin>


More information about the llvm-commits mailing list