Index: llvm/include/llvm/IR/DIBuilder.h =================================================================== --- llvm/include/llvm/IR/DIBuilder.h +++ llvm/include/llvm/IR/DIBuilder.h @@ -224,10 +224,10 @@ /// 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 @@ /// \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'. Index: llvm/lib/IR/DIBuilder.cpp =================================================================== --- llvm/lib/IR/DIBuilder.cpp +++ llvm/lib/IR/DIBuilder.cpp @@ -296,8 +296,8 @@ } 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); @@ -305,7 +305,7 @@ 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); Index: llvm/unittests/IR/DebugInfoTest.cpp =================================================================== --- llvm/unittests/IR/DebugInfoTest.cpp +++ llvm/unittests/IR/DebugInfoTest.cpp @@ -251,12 +251,33 @@ LLVMContext Ctx; std::unique_ptr 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(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(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) {