[llvm] 929499e - Updated the test to include addtional details

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


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

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

LOG: Updated the test to include addtional details

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 2ba3d9817013..8876fbc2ac0d 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -224,10 +224,10 @@ namespace llvm {
     /// Create debugging information entry for Fortran
     /// assumed length string type.
     /// \param Name            Type name.
-    /// \param StringLength    String length expressed as Metadata *.
+    /// \param StringLength    String length expressed as DIVariable *.
     /// \param StrLocationExp  Optional memory location of the string.
-    DIStringType *createStringType(StringRef Name, Metadata *StringLength,
-                                   Metadata *StrLocationExp = nullptr);
+    DIStringType *createStringType(StringRef Name, DIVariable *StringLength,
+                                   DIExpression *StrLocationExp = nullptr);
 
     /// Create debugging information entry for Fortran
     /// assumed length string type.
@@ -236,7 +236,7 @@ namespace llvm {
     /// \param StrLocationExp   Optional memory location of the string.
     DIStringType *createStringTypeExp(StringRef Name,
                                       DIExpression *StringLengthExp,
-                                      Metadata *StrLocationExp = nullptr);
+                                      DIExpression *StrLocationExp = nullptr);
 
     /// 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 1e8ebd7e24d3..aec200486f78 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -294,8 +294,8 @@ DIStringType *DIBuilder::createStringType(StringRef Name, uint64_t SizeInBits) {
 }
 
 DIStringType *DIBuilder::createStringType(StringRef Name,
-                                          Metadata *StringLength,
-                                          Metadata *StrLocationExp) {
+                                          DIVariable *StringLength,
+                                          DIExpression *StrLocationExp) {
   assert(!Name.empty() && "Unable to create type without name");
   return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name,
                            StringLength, nullptr, StrLocationExp, 0, 0, 0);
@@ -303,7 +303,7 @@ DIStringType *DIBuilder::createStringType(StringRef Name,
 
 DIStringType *DIBuilder::createStringTypeExp(StringRef Name,
                                              DIExpression *StringLengthExp,
-                                             Metadata *StrLocationExp) {
+                                             DIExpression *StrLocationExp) {
   assert(!Name.empty() && "Unable to create type without name");
   return DIStringType::get(VMContext, dwarf::DW_TAG_string_type, Name, nullptr,
                            StringLengthExp, StrLocationExp, 0, 0, 0);

diff  --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp
index 682211535333..0d08cff21de5 100644
--- a/llvm/unittests/IR/DebugInfoTest.cpp
+++ b/llvm/unittests/IR/DebugInfoTest.cpp
@@ -251,12 +251,33 @@ TEST(DIBuilder, CreateStringType) {
   LLVMContext Ctx;
   std::unique_ptr<Module> M(new Module("MyModule", Ctx));
   DIBuilder DIB(*M);
+  DIScope *Scope = DISubprogram::getDistinct(
+      Ctx, nullptr, "", "", nullptr, 0, nullptr, 0, nullptr, 0, 0,
+      DINode::FlagZero, DISubprogram::SPFlagZero, nullptr);
+  DIFile *F = DIB.createFile("main.c", "/");
   StringRef StrName = "string";
-  DIStringType *StringType = DIB.createStringType(StrName, nullptr);
+  DIVariable *StringLen = DIB.createAutoVariable(Scope, StrName, F, 0, nullptr,
+                                                 false, DINode::FlagZero, 0);
+  DIExpression *StringLocationExp = DIB.createExpression();
+  DIExpression *StringLengthExp = DIB.createExpression();
+  DIStringType *StringType =
+      DIB.createStringType(StrName, StringLen, StringLocationExp);
 
   EXPECT_TRUE(isa_and_nonnull<DIStringType>(StringType));
   EXPECT_EQ(StringType->getName(), "string");
-  EXPECT_EQ(StringType->getStringLength(), nullptr);
+  EXPECT_EQ(StringType,
+            DIStringType::get(Ctx, dwarf::DW_TAG_string_type, StrName,
+                              StringLen, StringLocationExp, nullptr, 0, 0, 0));
+
+  DIStringType *StringTypeExp =
+      DIB.createStringTypeExp(StrName, StringLengthExp, StringLocationExp);
+
+  EXPECT_TRUE(isa_and_nonnull<DIStringType>(StringTypeExp));
+  EXPECT_EQ(StringTypeExp->getName(), "string");
+  EXPECT_EQ(StringTypeExp,
+            DIStringType::get(Ctx, dwarf::DW_TAG_string_type, StrName,
+                              StringLengthExp, StringLocationExp, nullptr, 0, 0,
+                              0));
 }
 
 TEST(DIBuilder, DIEnumerator) {


        


More information about the llvm-commits mailing list