[llvm] 43d421c - Adding DIBuilder interface for assumed length string

YASHASVI KHATAVKAR via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 10 12:25:23 PST 2022


Author: YASHASVI KHATAVKAR
Date: 2022-02-10T15:24:50-05:00
New Revision: 43d421cda395e965526a7e8c723449d742118742

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

LOG: Adding DIBuilder interface for assumed length string

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h
index d3aad3719900e..aca3f4c298953 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -220,6 +220,19 @@ namespace llvm {
     /// \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'.

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index dc5768dd4f26a..b0700b769fd83 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -293,6 +293,20 @@ DIStringType *DIBuilder::createStringType(StringRef Name, uint64_t SizeInBits) {
                            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);

diff  --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp
index 8605fbbcbd401..f8e5e891d5426 100644
--- a/llvm/unittests/IR/DebugInfoTest.cpp
+++ b/llvm/unittests/IR/DebugInfoTest.cpp
@@ -247,6 +247,18 @@ TEST(DIBuilder, CreateSetType) {
   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));


        


More information about the llvm-commits mailing list