Author: baloghadamsoftware Date: Thu Jun 14 23:45:39 2018 New Revision: 334804
URL: http://llvm.org/viewvc/llvm-project?rev=334804&view=rev Log: [ASTImporter] Corrected diagnostic client handling in tests. ASTImporter tests may produce source file related warnings, the diagnostic client should be in correct state to handle it. Added 'beginSourceFile' to set the client state. Patch by: Balázs Kéri Differential Revision: https://reviews.llvm.org/D47445 Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/unittests/AST/ASTImporterTest.cpp Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=334804&r1=334803&r2=334804&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/ASTUnit.h (original) +++ cfe/trunk/include/clang/Frontend/ASTUnit.h Thu Jun 14 23:45:39 2018 @@ -438,6 +438,15 @@ public: void setASTContext(ASTContext *ctx) { Ctx = ctx; } void setPreprocessor(std::shared_ptr<Preprocessor> pp); + /// Enable source-range based diagnostic messages. + /// + /// If diagnostic messages with source-range information are to be expected + /// and AST comes not from file (e.g. after LoadFromCompilerInvocation) this + /// function has to be called. + /// The function is to be called only once and the AST should be associated + /// with the same source file afterwards. + void enableSourceFileDiagnostics(); + bool hasSema() const { return (bool)TheSema; } Sema &getSema() const { Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=334804&r1=334803&r2=334804&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Jun 14 23:45:39 2018 @@ -275,6 +275,12 @@ void ASTUnit::setPreprocessor(std::share this->PP = std::move(PP); } +void ASTUnit::enableSourceFileDiagnostics() { + assert(getDiagnostics().getClient() && Ctx && + "Bad context for source file"); + getDiagnostics().getClient()->BeginSourceFile(Ctx->getLangOpts(), PP.get()); +} + /// Determine the set of code-completion contexts in which this /// declaration should be shown. static unsigned getDeclShowContexts(const NamedDecl *ND, Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=334804&r1=334803&r2=334804&view=diff ============================================================================== --- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original) +++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Thu Jun 14 23:45:39 2018 @@ -98,6 +98,9 @@ testImport(const std::string &FromCode, ASTContext &FromCtx = FromAST->getASTContext(), &ToCtx = ToAST->getASTContext(); + FromAST->enableSourceFileDiagnostics(); + ToAST->enableSourceFileDiagnostics(); + ASTImporter Importer(ToCtx, ToAST->getFileManager(), FromCtx, FromAST->getFileManager(), false); @@ -172,7 +175,9 @@ class ASTImporterTestBase : public ::tes : Code(Code), FileName(FileName), Unit(tooling::buildASTFromCodeWithArgs(this->Code, Args, this->FileName)), - TUDecl(Unit->getASTContext().getTranslationUnitDecl()) {} + TUDecl(Unit->getASTContext().getTranslationUnitDecl()) { + Unit->enableSourceFileDiagnostics(); + } }; // We may have several From contexts and related translation units. In each @@ -214,6 +219,7 @@ public: ToCode = ToSrcCode; assert(!ToAST); ToAST = tooling::buildASTFromCodeWithArgs(ToCode, ToArgs, OutputFileName); + ToAST->enableSourceFileDiagnostics(); ASTContext &FromCtx = FromTU.Unit->getASTContext(), &ToCtx = ToAST->getASTContext(); @@ -261,6 +267,7 @@ public: ToCode = ToSrcCode; assert(!ToAST); ToAST = tooling::buildASTFromCodeWithArgs(ToCode, ToArgs, OutputFileName); + ToAST->enableSourceFileDiagnostics(); return ToAST->getASTContext().getTranslationUnitDecl(); } @@ -274,6 +281,7 @@ public: // Build the AST from an empty file. ToAST = tooling::buildASTFromCodeWithArgs(/*Code=*/"", ToArgs, "empty.cc"); + ToAST->enableSourceFileDiagnostics(); } // Create a virtual file in the To Ctx which corresponds to the file from _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits