Author: Brett Wilson Date: 2022-10-25T13:47:24-07:00 New Revision: 7231c9966e523a6fa20aa63b9a9245aff49cf881
URL: https://github.com/llvm/llvm-project/commit/7231c9966e523a6fa20aa63b9a9245aff49cf881 DIFF: https://github.com/llvm/llvm-project/commit/7231c9966e523a6fa20aa63b9a9245aff49cf881.diff LOG: [clang-doc] Fix typedef/using output. Provides an initializer for the TypedefInfo.IsUsing member. Previously this member was uninitialized and would produce random output. Adds the Description (code comments) to the bitcode reader/writer. Previously the typedef/using descriptions were lost during the bitcode round-trip. Adds a test for this. Differential Revision: https://reviews.llvm.org/D136638 Added: Modified: clang-tools-extra/clang-doc/BitcodeReader.cpp clang-tools-extra/clang-doc/BitcodeWriter.cpp clang-tools-extra/clang-doc/Representation.h clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 8e1db35532a05..524b82d9fcc53 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -368,28 +368,27 @@ template <typename T> llvm::Expected<CommentInfo *> getCommentInfo(T I) { } template <> llvm::Expected<CommentInfo *> getCommentInfo(FunctionInfo *I) { - I->Description.emplace_back(); - return &I->Description.back(); + return &I->Description.emplace_back(); } template <> llvm::Expected<CommentInfo *> getCommentInfo(NamespaceInfo *I) { - I->Description.emplace_back(); - return &I->Description.back(); + return &I->Description.emplace_back(); } template <> llvm::Expected<CommentInfo *> getCommentInfo(RecordInfo *I) { - I->Description.emplace_back(); - return &I->Description.back(); + return &I->Description.emplace_back(); } template <> llvm::Expected<CommentInfo *> getCommentInfo(MemberTypeInfo *I) { - I->Description.emplace_back(); - return &I->Description.back(); + return &I->Description.emplace_back(); } template <> llvm::Expected<CommentInfo *> getCommentInfo(EnumInfo *I) { - I->Description.emplace_back(); - return &I->Description.back(); + return &I->Description.emplace_back(); +} + +template <> llvm::Expected<CommentInfo *> getCommentInfo(TypedefInfo *I) { + return &I->Description.emplace_back(); } template <> llvm::Expected<CommentInfo *> getCommentInfo(CommentInfo *I) { diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp b/clang-tools-extra/clang-doc/BitcodeWriter.cpp index 7768f4b06519b..bb0698a5a4028 100644 --- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp +++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp @@ -432,6 +432,8 @@ void ClangDocBitcodeWriter::emitBlock(const TypedefInfo &T) { emitRecord(T.Name, TYPEDEF_NAME); for (const auto &N : T.Namespace) emitBlock(N, FieldId::F_namespace); + for (const auto &CI : T.Description) + emitBlock(CI); if (T.DefLoc) emitRecord(*T.DefLoc, TYPEDEF_DEFLOCATION); emitRecord(T.IsUsing, TYPEDEF_IS_USING); diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index d416306704611..7d76844462885 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -365,7 +365,7 @@ struct TypedefInfo : public SymbolInfo { // using MyVector = std::vector<int> // False means it's a C-style typedef: // typedef std::vector<int> MyVector; - bool IsUsing; + bool IsUsing = false; }; struct BaseRecordInfo : public RecordInfo { diff --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp index db6569419d579..53e84b1814453 100644 --- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp @@ -183,11 +183,33 @@ TEST(BitcodeTest, emitTypedefInfoBitcode) { I.Underlying = TypeInfo("unsigned"); I.IsUsing = true; + CommentInfo Top; + Top.Kind = "FullComment"; + + Top.Children.emplace_back(std::make_unique<CommentInfo>()); + CommentInfo *BlankLine = Top.Children.back().get(); + BlankLine->Kind = "ParagraphComment"; + BlankLine->Children.emplace_back(std::make_unique<CommentInfo>()); + BlankLine->Children.back()->Kind = "TextComment"; + + I.Description.emplace_back(std::move(Top)); + std::string WriteResult = writeInfo(&I); EXPECT_TRUE(WriteResult.size() > 0); std::vector<std::unique_ptr<Info>> ReadResults = readInfo(WriteResult, 1); CheckTypedefInfo(&I, InfoAsTypedef(ReadResults[0].get())); + + // Check one with no IsUsing set, no description, and no definition location. + TypedefInfo I2; + I2.Name = "SomethingElse"; + I2.IsUsing = false; + I2.Underlying = TypeInfo("int"); + + WriteResult = writeInfo(&I2); + EXPECT_TRUE(WriteResult.size() > 0); + ReadResults = readInfo(WriteResult, 1); + CheckTypedefInfo(&I2, InfoAsTypedef(ReadResults[0].get())); } TEST(SerializeTest, emitInfoWithCommentBitcode) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits