Index: examples/clang-interpreter/CMakeLists.txt =================================================================== --- examples/clang-interpreter/CMakeLists.txt +++ examples/clang-interpreter/CMakeLists.txt @@ -26,6 +26,7 @@ clangCodeGen clangDriver clangFrontend + clangFrontendTool ) export_executable_symbols(clang-interpreter) Index: examples/clang-interpreter/main.cpp =================================================================== --- examples/clang-interpreter/main.cpp +++ examples/clang-interpreter/main.cpp @@ -10,8 +10,8 @@ #include "Invoke.h" #include "Manager.h" -#include "clang/CodeGen/CodeGenAction.h" #include "clang/Basic/DiagnosticOptions.h" +#include "clang/CodeGen/CodeGenAction.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/Tool.h" @@ -19,6 +19,7 @@ #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/SmallString.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/MCJIT.h" @@ -69,10 +70,11 @@ void *MainAddr = (void*) (intptr_t) interpreter::GetExecutablePath; std::string Path = interpreter::GetExecutablePath(argv[0], MainAddr); IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); + IntrusiveRefCntPtr DiagID = + AllDiagnostics(); TextDiagnosticPrinter *DiagClient = - new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); + new TextDiagnosticPrinter(llvm::errs(), DiagID, &*DiagOpts); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); const std::string TripleStr = llvm::sys::getProcessTriple(); @@ -139,7 +141,7 @@ Clang.setInvocation(std::move(CI)); // Create the compilers actual diagnostics engine. - Clang.createDiagnostics(); + Clang.createDiagnostics(DiagID); if (!Clang.hasDiagnostics()) return 1; Index: include/clang/ARCMigrate/ARCMT.h =================================================================== --- include/clang/ARCMigrate/ARCMT.h +++ include/clang/ARCMigrate/ARCMT.h @@ -15,12 +15,13 @@ #include "clang/Frontend/CompilerInvocation.h" namespace clang { - class ASTContext; - class DiagnosticConsumer; - class PCHContainerOperations; +class ASTContext; +class DiagnosticConsumer; +class DiagnosticIDs; +class PCHContainerOperations; namespace arcmt { - class MigrationPass; +class MigrationPass; /// \brief Creates an AST with the provided CompilerInvocation but with these /// changes: @@ -38,29 +39,27 @@ /// the pre-migration ARC diagnostics. /// /// \returns false if no error is produced, true otherwise. -bool -checkForManualIssues(CompilerInvocation &CI, const FrontendInputFile &Input, - std::shared_ptr PCHContainerOps, - DiagnosticConsumer *DiagClient, - bool emitPremigrationARCErrors = false, - StringRef plistOut = StringRef()); +bool checkForManualIssues( + CompilerInvocation &CI, const FrontendInputFile &Input, + std::shared_ptr PCHContainerOps, + DiagnosticsEngine &Diags, bool emitPremigrationARCErrors = false, + StringRef plistOut = StringRef()); /// \brief Works similar to checkForManualIssues but instead of checking, it /// applies automatic modifications to source files to conform to ARC. /// /// \returns false if no error is produced, true otherwise. -bool -applyTransformations(CompilerInvocation &origCI, - const FrontendInputFile &Input, - std::shared_ptr PCHContainerOps, - DiagnosticConsumer *DiagClient); +bool applyTransformations( + CompilerInvocation &origCI, const FrontendInputFile &Input, + std::shared_ptr PCHContainerOps, + DiagnosticsEngine &Diags); /// \brief Applies automatic modifications and produces temporary files /// and metadata into the \p outputDir path. /// /// \param emitPremigrationARCErrors if true all ARC errors will get emitted -/// even if the migrator can fix them, but the function will still return false -/// if all ARC errors can be fixed. +/// even if the migrator can fix them, but the function will still return +/// false if all ARC errors can be fixed. /// /// \param plistOut if non-empty, it is the file path to store the plist with /// the pre-migration ARC diagnostics. @@ -69,25 +68,24 @@ bool migrateWithTemporaryFiles( CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr PCHContainerOps, - DiagnosticConsumer *DiagClient, StringRef outputDir, + DiagnosticsEngine &Diags, StringRef outputDir, bool emitPremigrationARCErrors, StringRef plistOut); /// \brief Get the set of file remappings from the \p outputDir path that /// migrateWithTemporaryFiles produced. /// /// \returns false if no error is produced, true otherwise. -bool getFileRemappings(std::vector > &remap, - StringRef outputDir, - DiagnosticConsumer *DiagClient); +bool getFileRemappings(std::vector> &remap, + StringRef outputDir, DiagnosticConsumer *DiagClient, + IntrusiveRefCntPtr DiagIDs); /// \brief Get the set of file remappings from a list of files with remapping /// info. /// /// \returns false if no error is produced, true otherwise. bool getFileRemappingsFromFileList( - std::vector > &remap, - ArrayRef remapFiles, - DiagnosticConsumer *DiagClient); + std::vector> &remap, + ArrayRef remapFiles, DiagnosticConsumer *DiagClient); typedef void (*TransformFn)(MigrationPass &pass); @@ -97,7 +95,7 @@ class MigrationProcess { CompilerInvocation OrigCI; std::shared_ptr PCHContainerOps; - DiagnosticConsumer *DiagClient; + DiagnosticsEngine &OriginalDiags; FileRemapper Remapper; public: @@ -105,18 +103,18 @@ MigrationProcess(const CompilerInvocation &CI, std::shared_ptr PCHContainerOps, - DiagnosticConsumer *diagClient, + DiagnosticsEngine &OriginalDiags, StringRef outputDir = StringRef()); class RewriteListener { public: virtual ~RewriteListener(); - virtual void start(ASTContext &Ctx) { } - virtual void finish() { } + virtual void start(ASTContext &Ctx) {} + virtual void finish() {} - virtual void insert(SourceLocation loc, StringRef text) { } - virtual void remove(CharSourceRange range) { } + virtual void insert(SourceLocation loc, StringRef text) {} + virtual void remove(CharSourceRange range) {} }; bool applyTransform(TransformFn trans, RewriteListener *listener = nullptr); Index: include/clang/Basic/Diagnostic.h =================================================================== --- include/clang/Basic/Diagnostic.h +++ include/clang/Basic/Diagnostic.h @@ -292,7 +292,8 @@ return DiagMap.lookup(Diag); } - DiagnosticMapping &getOrAddMapping(diag::kind Diag); + DiagnosticMapping &getOrAddMapping(diag::kind Diag, + const DiagnosticIDs &IDs); const_iterator begin() const { return DiagMap.begin(); } const_iterator end() const { return DiagMap.end(); } Index: include/clang/Basic/DiagnosticCommonKinds.td =================================================================== --- include/clang/Basic/DiagnosticCommonKinds.td +++ include/clang/Basic/DiagnosticCommonKinds.td @@ -182,6 +182,8 @@ // Sema && AST def note_invalid_subexpr_in_const_expr : Note< "subexpression not valid in a constant expression">; +def err_unavailable : Error<"%0 is unavailable">; +def err_unavailable_message : Error<"%0 is unavailable: %1">; // Targets Index: include/clang/Basic/DiagnosticIDs.h =================================================================== --- include/clang/Basic/DiagnosticIDs.h +++ include/clang/Basic/DiagnosticIDs.h @@ -16,6 +16,7 @@ #define LLVM_CLANG_BASIC_DIAGNOSTICIDS_H #include "clang/Basic/LLVM.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" #include @@ -168,12 +169,81 @@ Ignored, Note, Remark, Warning, Error, Fatal }; + // Diagnostic classes. + enum { + CLASS_NOTE = 0x01, + CLASS_REMARK = 0x02, + CLASS_WARNING = 0x03, + CLASS_EXTENSION = 0x04, + CLASS_ERROR = 0x05 + }; + + struct DiagInfoRec { + uint16_t DiagID; + unsigned DefaultSeverity : 3; + unsigned Class : 3; + unsigned SFINAE : 2; + unsigned WarnNoWerror : 1; + unsigned WarnShowInSystemHeader : 1; + unsigned Category : 6; + + uint16_t OptionGroupIndex; + + uint16_t DescriptionLen; + const char *DescriptionStr; + + unsigned getOptionGroupIndex() const { return OptionGroupIndex; } + + StringRef getDescription() const { + return StringRef(DescriptionStr, DescriptionLen); + } + + diag::Flavor getFlavor() const { + return Class == CLASS_REMARK ? diag::Flavor::Remark + : diag::Flavor::WarningOrError; + } + + bool operator<(const DiagInfoRec &RHS) const { return DiagID < RHS.DiagID; } + }; + + struct WarningOption { + uint16_t NameOffset; + uint16_t Members; + uint16_t SubGroups; + + // String is stored with a pascal-style length byte. + StringRef getName(const char *DiagGroupNames) const { + return StringRef(DiagGroupNames + NameOffset + 1, + DiagGroupNames[NameOffset]); + } + }; + + struct CategoryRec { + const char *NameStr; + uint8_t NameLen; + + StringRef getName() const { return StringRef(NameStr, NameLen); } + }; + private: /// \brief Information for uniquing and looking up custom diags. - diag::CustomDiagInfo *CustomDiagInfo; + diag::CustomDiagInfo *CustomDiagInfo = nullptr; + ArrayRef DiagInfo; + const char *DiagGroupNames; + ArrayRef CategoryNameTable; + + ArrayRef OptionTable; + const int16_t *XDiagArrays; + const int16_t *XDiagSubGroups; + + std::function GetDiagInfo; public: - DiagnosticIDs(); + DiagnosticIDs(ArrayRef DiagInfo, const char *DiagGroupNames, + ArrayRef CategoryNameTable, + ArrayRef OptionTable, const int16_t *XDiagArrays, + const int16_t *XDiagSubGroups, + std::function GetDiagInfo); ~DiagnosticIDs(); /// \brief Return an ID for a diagnostic with the specified format string and @@ -199,18 +269,18 @@ /// /// This only works on builtin diagnostics, not custom ones, and is not /// legal to call on NOTEs. - static bool isBuiltinWarningOrExtension(unsigned DiagID); + bool isBuiltinWarningOrExtension(unsigned DiagID) const; /// \brief Return true if the specified diagnostic is mapped to errors by /// default. - static bool isDefaultMappingAsError(unsigned DiagID); + bool isDefaultMappingAsError(unsigned DiagID) const; /// \brief Determine whether the given built-in diagnostic ID is a Note. - static bool isBuiltinNote(unsigned DiagID); + bool isBuiltinNote(unsigned DiagID) const; /// \brief Determine whether the given built-in diagnostic ID is for an /// extension of some sort. - static bool isBuiltinExtensionDiag(unsigned DiagID) { + bool isBuiltinExtensionDiag(unsigned DiagID) const { bool ignored; return isBuiltinExtensionDiag(DiagID, ignored); } @@ -222,28 +292,27 @@ /// diagnostic is ignored by default (in which case -pedantic enables it) or /// treated as a warning/error by default. /// - static bool isBuiltinExtensionDiag(unsigned DiagID, bool &EnabledByDefault); - + bool isBuiltinExtensionDiag(unsigned DiagID, bool &EnabledByDefault) const; /// \brief Return the lowest-level warning option that enables the specified /// diagnostic. /// /// If there is no -Wfoo flag that controls the diagnostic, this returns null. - static StringRef getWarningOptionForDiag(unsigned DiagID); - + StringRef getWarningOptionForDiag(unsigned DiagID) const; + /// \brief Return the category number that a specified \p DiagID belongs to, /// or 0 if no category. - static unsigned getCategoryNumberForDiag(unsigned DiagID); + unsigned getCategoryNumberForDiag(unsigned DiagID) const; /// \brief Return the number of diagnostic categories. - static unsigned getNumberOfCategories(); + unsigned getNumberOfCategories() const; /// \brief Given a category ID, return the name of the category. - static StringRef getCategoryNameFromID(unsigned CategoryID); - + StringRef getCategoryNameFromID(unsigned CategoryID) const; + /// \brief Return true if a given diagnostic falls into an ARC diagnostic /// category. - static bool isARCDiagnostic(unsigned DiagID); + bool isARCDiagnostic(unsigned DiagID) const; /// \brief Enumeration describing how the emission of a diagnostic should /// be treated when it occurs during C++ template argument deduction. @@ -279,14 +348,14 @@ /// deduction fails but no diagnostic is emitted. Certain classes of /// errors, such as those errors that involve C++ access control, /// are not SFINAE errors. - static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID); + SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID) const; /// \brief Get the string of all diagnostic flags. /// /// \returns A list of all diagnostics flags as they would be written in a /// command line invocation including their `no-` variants. For example: /// `{"-Wempty-body", "-Wno-empty-body", ...}` - static std::vector getDiagnosticFlags(); + std::vector getDiagnosticFlags() const; /// \brief Get the set of all diagnostic IDs in the group with the given name. /// @@ -296,12 +365,11 @@ SmallVectorImpl &Diags) const; /// \brief Get the set of all diagnostic IDs. - static void getAllDiagnostics(diag::Flavor Flavor, - std::vector &Diags); + void getAllDiagnostics(diag::Flavor Flavor, std::vector &Diags); /// \brief Get the diagnostic option with the closest edit distance to the /// given group name. - static StringRef getNearestOption(diag::Flavor Flavor, StringRef Group); + StringRef getNearestOption(diag::Flavor Flavor, StringRef Group) const; private: /// \brief Classify the specified diagnostic ID into a Level, consumable by @@ -334,6 +402,9 @@ /// invariants can break. bool isUnrecoverable(unsigned DiagID) const; + DiagnosticMapping GetDefaultDiagMapping(unsigned DiagID) const; + unsigned getBuiltinDiagClass(unsigned DiagID) const; + friend class DiagnosticsEngine; }; Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -4605,10 +4605,8 @@ def warn_unavailable_def : Warning< "implementing unavailable method">, InGroup, DefaultIgnore; -def err_unavailable : Error<"%0 is unavailable">; def err_property_method_unavailable : Error<"property access is using %0 method which is unavailable">; -def err_unavailable_message : Error<"%0 is unavailable: %1">; def warn_unavailable_fwdclass_message : Warning< "%0 may be unavailable because the receiver type is unknown">, InGroup; Index: include/clang/CrossTU/CrossTranslationUnit.h =================================================================== --- include/clang/CrossTU/CrossTranslationUnit.h +++ include/clang/CrossTU/CrossTranslationUnit.h @@ -16,6 +16,7 @@ #define LLVM_CLANG_CROSSTU_CROSSTRANSLATIONUNIT_H #include "clang/Basic/LLVM.h" +#include "clang/Frontend/CompilerInstance.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" @@ -27,6 +28,7 @@ class ASTImporter; class ASTUnit; class DeclContext; +class DiagnosticIDs; class FunctionDecl; class NamedDecl; class TranslationUnitDecl; @@ -108,7 +110,8 @@ /// Note that the AST files should also be in the \p CrossTUDir. llvm::Expected getCrossTUDefinition(const FunctionDecl *FD, StringRef CrossTUDir, - StringRef IndexName); + StringRef IndexName, + const IntrusiveRefCntPtr &DiagIDs); /// \brief This function loads a function definition from an external AST /// file. @@ -122,9 +125,10 @@ /// function. /// /// Note that the AST files should also be in the \p CrossTUDir. - llvm::Expected loadExternalAST(StringRef LookupName, - StringRef CrossTUDir, - StringRef IndexName); + llvm::Expected + loadExternalAST(StringRef LookupName, StringRef CrossTUDir, + StringRef IndexName, + const IntrusiveRefCntPtr &DiagIDs); /// \brief This function merges a definition from a separate AST Unit into /// the current one which was created by the compiler instance that @@ -139,6 +143,8 @@ /// \brief Emit diagnostics for the user for potential configuration errors. void emitCrossTUDiagnostics(const IndexError &IE); + CompilerInstance &getCompilerInstance() { return CI; } + private: ASTImporter &getOrCreateASTImporter(ASTContext &From); const FunctionDecl *findFunctionInDeclContext(const DeclContext *DC, Index: include/clang/Frontend/CompilerInstance.h =================================================================== --- include/clang/Frontend/CompilerInstance.h +++ include/clang/Frontend/CompilerInstance.h @@ -615,7 +615,8 @@ /// /// \param ShouldOwnClient If Client is non-NULL, specifies whether /// the diagnostic object should take ownership of the client. - void createDiagnostics(DiagnosticConsumer *Client = nullptr, + void createDiagnostics(IntrusiveRefCntPtr DiagIDs, + DiagnosticConsumer *Client = nullptr, bool ShouldOwnClient = true); /// Create a DiagnosticsEngine object with a the TextDiagnosticPrinter. @@ -636,11 +637,10 @@ /// used by some diagnostics printers (for logging purposes only). /// /// \return The new object on success, or null on failure. - static IntrusiveRefCntPtr - createDiagnostics(DiagnosticOptions *Opts, - DiagnosticConsumer *Client = nullptr, - bool ShouldOwnClient = true, - const CodeGenOptions *CodeGenOpts = nullptr); + static IntrusiveRefCntPtr createDiagnostics( + IntrusiveRefCntPtr DiagIDs, DiagnosticOptions *Optns, + DiagnosticConsumer *Client = nullptr, bool ShouldOwnClient = true, + const CodeGenOptions *CodeGenOpts = nullptr); /// Create the file manager and replace any existing one with it. /// Index: include/clang/Frontend/LogDiagnosticPrinter.h =================================================================== --- include/clang/Frontend/LogDiagnosticPrinter.h +++ include/clang/Frontend/LogDiagnosticPrinter.h @@ -52,6 +52,7 @@ raw_ostream &OS; std::unique_ptr StreamOwner; const LangOptions *LangOpts; + IntrusiveRefCntPtr DiagIDs; IntrusiveRefCntPtr DiagOpts; SourceLocation LastWarningLoc; @@ -63,7 +64,9 @@ std::string DwarfDebugFlags; public: - LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags, + LogDiagnosticPrinter(raw_ostream &OS, + IntrusiveRefCntPtr DiagIDs, + DiagnosticOptions *Diags, std::unique_ptr StreamOwner); void setDwarfDebugFlags(StringRef Value) { Index: include/clang/Frontend/SerializedDiagnosticPrinter.h =================================================================== --- include/clang/Frontend/SerializedDiagnosticPrinter.h +++ include/clang/Frontend/SerializedDiagnosticPrinter.h @@ -21,6 +21,7 @@ namespace clang { class DiagnosticConsumer; class DiagnosticsEngine; +class DiagnosticIDs; class DiagnosticOptions; namespace serialized_diags { @@ -33,9 +34,10 @@ /// This allows wrapper tools for Clang to get diagnostics from Clang /// (via libclang) without needing to parse Clang's command line output. /// -std::unique_ptr create(StringRef OutputFile, - DiagnosticOptions *Diags, - bool MergeChildRecords = false); +std::unique_ptr +create(StringRef OutputFile, DiagnosticOptions *Diags, + IntrusiveRefCntPtr DiagIDs, + bool MergeChildRecords = false); } // end serialized_diags namespace } // end clang namespace Index: include/clang/Frontend/TextDiagnosticPrinter.h =================================================================== --- include/clang/Frontend/TextDiagnosticPrinter.h +++ include/clang/Frontend/TextDiagnosticPrinter.h @@ -27,6 +27,7 @@ class TextDiagnosticPrinter : public DiagnosticConsumer { raw_ostream &OS; + IntrusiveRefCntPtr DiagIDs; IntrusiveRefCntPtr DiagOpts; /// \brief Handle to the currently active text diagnostic emitter. @@ -38,7 +39,9 @@ unsigned OwnsOutputStream : 1; public: - TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags, + TextDiagnosticPrinter(raw_ostream &os, + IntrusiveRefCntPtr DiagIDs, + DiagnosticOptions *diags, bool OwnsOutputStream = false); ~TextDiagnosticPrinter() override; @@ -46,8 +49,10 @@ /// printed at the start of any diagnostics. If empty, no prefix string is /// used. void setPrefix(std::string Value) { Prefix = std::move(Value); } + const IntrusiveRefCntPtr &getDiagIDs() { return DiagIDs; } - void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override; + void BeginSourceFile(const LangOptions &LO, + const Preprocessor *PP = nullptr) override; void EndSourceFile() override; void HandleDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info) override; Index: include/clang/Frontend/Utils.h =================================================================== --- include/clang/Frontend/Utils.h +++ include/clang/Frontend/Utils.h @@ -198,9 +198,7 @@ /// \return A CompilerInvocation, or 0 if none was built for the given /// argument vector. std::unique_ptr createInvocationFromCommandLine( - ArrayRef Args, - IntrusiveRefCntPtr Diags = - IntrusiveRefCntPtr(), + ArrayRef Args, IntrusiveRefCntPtr Diags, IntrusiveRefCntPtr VFS = nullptr); /// Return the value of the last argument as an integer, or a default. If Diags Index: include/clang/FrontendTool/AllDiagnostics.h =================================================================== --- include/clang/FrontendTool/AllDiagnostics.h +++ include/clang/FrontendTool/AllDiagnostics.h @@ -12,8 +12,8 @@ /// //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_BASIC_ALLDIAGNOSTICS_H -#define LLVM_CLANG_BASIC_ALLDIAGNOSTICS_H +#ifndef LLVM_CLANG_FRONTENDTOOL_ALLDIAGNOSTICS_H +#define LLVM_CLANG_FRONTENDTOOL_ALLDIAGNOSTICS_H #include "clang/AST/ASTDiagnostic.h" #include "clang/AST/CommentDiagnostic.h" @@ -34,9 +34,9 @@ public: enum { Size = SizeOfStr }; }; -} // end namespace clang +} // end namespace clang -#define STR_SIZE(str, fieldTy) clang::StringSizerHelper::Size +#define STR_SIZE(str, fieldTy) \ + clang::StringSizerHelper::Size #endif Index: include/clang/FrontendTool/DiagnosticTable.h =================================================================== --- /dev/null +++ include/clang/FrontendTool/DiagnosticTable.h @@ -0,0 +1,7 @@ +#include "clang/Basic/DiagnosticIDs.h" + +namespace clang { +DiagnosticIDs *AllDiagnostics(); +// const DiagnosticIDs::DiagInfoRec *GetDiagInfo(unsigned DiagID); +// ArrayRef GetDiagInfoTable(); +} Index: include/clang/module.modulemap =================================================================== --- include/clang/module.modulemap +++ include/clang/module.modulemap @@ -62,7 +62,7 @@ module Clang_Diagnostics { requires cplusplus - module All { header "Basic/AllDiagnostics.h" export * } + module All { header "FrontendTool/AllDiagnostics.h" export * } module Analysis { header "Analysis/AnalysisDiagnostic.h" export * } module AST { header "AST/ASTDiagnostic.h" export * } module Comment { header "AST/CommentDiagnostic.h" export * } Index: lib/ARCMigrate/ARCMT.cpp =================================================================== --- lib/ARCMigrate/ARCMT.cpp +++ lib/ARCMigrate/ARCMT.cpp @@ -132,7 +132,7 @@ void HandleDiagnostic(DiagnosticsEngine::Level level, const Diagnostic &Info) override { - if (DiagnosticIDs::isARCDiagnostic(Info.getID()) || + if (Diags.getDiagnosticIDs()->isARCDiagnostic(Info.getID()) || level >= DiagnosticsEngine::Error || level == DiagnosticsEngine::Note) { if (Info.getLocation().isValid()) CapturedDiags.push_back(StoredDiagnostic(level, Info)); @@ -171,7 +171,8 @@ } static CompilerInvocation * -createInvocationForMigration(CompilerInvocation &origCI, +createInvocationForMigration(const IntrusiveRefCntPtr &DiagID, + CompilerInvocation &origCI, const PCHContainerReader &PCHContainerRdr) { std::unique_ptr CInvok; CInvok.reset(new CompilerInvocation(origCI)); @@ -180,10 +181,8 @@ // We can't use a PCH because it was likely built in non-ARC mode and we // want to parse in ARC. Include the original header. FileManager FileMgr(origCI.getFileSystemOpts()); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr Diags( - new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(), - new IgnoringDiagConsumer())); + IntrusiveRefCntPtr Diags(new DiagnosticsEngine( + DiagID, &origCI.getDiagnosticOpts(), new IgnoringDiagConsumer())); std::string OriginalFile = ASTReader::getOriginalSourceFile( PPOpts.ImplicitPCHInclude, FileMgr, PCHContainerRdr, *Diags); if (!OriginalFile.empty()) @@ -220,11 +219,11 @@ static void emitPremigrationErrors(const CapturedDiagList &arcDiags, DiagnosticOptions *diagOpts, Preprocessor &PP) { - TextDiagnosticPrinter printer(llvm::errs(), diagOpts); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr Diags( - new DiagnosticsEngine(DiagID, diagOpts, &printer, - /*ShouldOwnClient=*/false)); + TextDiagnosticPrinter printer( + llvm::errs(), PP.getDiagnostics().getDiagnosticIDs(), diagOpts); + IntrusiveRefCntPtr Diags(new DiagnosticsEngine( + PP.getDiagnostics().getDiagnosticIDs(), diagOpts, &printer, + /*ShouldOwnClient=*/false)); Diags->setSourceManager(&PP.getSourceManager()); printer.BeginSourceFile(PP.getLangOpts(), &PP); @@ -239,7 +238,7 @@ bool arcmt::checkForManualIssues( CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr PCHContainerOps, - DiagnosticConsumer *DiagClient, bool emitPremigrationARCErrors, + DiagnosticsEngine &OriginalDiags, bool emitPremigrationARCErrors, StringRef plistOut) { if (!origCI.getLangOpts()->ObjC1) return false; @@ -253,18 +252,19 @@ assert(!transforms.empty()); std::unique_ptr CInvok; - CInvok.reset( - createInvocationForMigration(origCI, PCHContainerOps->getRawReader())); + CInvok.reset(createInvocationForMigration(OriginalDiags.getDiagnosticIDs(), + origCI, + PCHContainerOps->getRawReader())); CInvok->getFrontendOpts().Inputs.clear(); CInvok->getFrontendOpts().Inputs.push_back(Input); CapturedDiagList capturedDiags; + auto *DiagClient = OriginalDiags.getClient(); assert(DiagClient); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr Diags( - new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(), - DiagClient, /*ShouldOwnClient=*/false)); + IntrusiveRefCntPtr Diags(new DiagnosticsEngine( + OriginalDiags.getDiagnosticIDs(), &origCI.getDiagnosticOpts(), DiagClient, + /*ShouldOwnClient=*/false)); // Filter of all diagnostics. CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags); @@ -299,8 +299,8 @@ for (CapturedDiagList::iterator I = capturedDiags.begin(), E = capturedDiags.end(); I != E; ++I) arcDiags.push_back(*I); - writeARCDiagsToPlist(plistOut, arcDiags, - Ctx.getSourceManager(), Ctx.getLangOpts()); + writeARCDiagsToPlist(plistOut, arcDiags, Ctx.getSourceManager(), + Ctx.getLangOpts(), *OriginalDiags.getDiagnosticIDs()); } // After parsing of source files ended, we want to reuse the @@ -340,7 +340,7 @@ static bool applyTransforms(CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr PCHContainerOps, - DiagnosticConsumer *DiagClient, StringRef outputDir, + DiagnosticsEngine &Diags, StringRef outputDir, bool emitPremigrationARCErrors, StringRef plistOut) { if (!origCI.getLangOpts()->ObjC1) return false; @@ -349,16 +349,15 @@ // Make sure checking is successful first. CompilerInvocation CInvokForCheck(origCI); - if (arcmt::checkForManualIssues(CInvokForCheck, Input, PCHContainerOps, - DiagClient, emitPremigrationARCErrors, - plistOut)) + if (arcmt::checkForManualIssues(CInvokForCheck, Input, PCHContainerOps, Diags, + emitPremigrationARCErrors, plistOut)) return true; CompilerInvocation CInvok(origCI); CInvok.getFrontendOpts().Inputs.clear(); CInvok.getFrontendOpts().Inputs.push_back(Input); - MigrationProcess migration(CInvok, PCHContainerOps, DiagClient, outputDir); + MigrationProcess migration(CInvok, PCHContainerOps, Diags, outputDir); bool NoFinalizeRemoval = origCI.getMigratorOpts().NoFinalizeRemoval; std::vector transforms = arcmt::getAllTransformations(OrigGCMode, @@ -370,46 +369,40 @@ if (err) return true; } - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr Diags( - new DiagnosticsEngine(DiagID, &origCI.getDiagnosticOpts(), - DiagClient, /*ShouldOwnClient=*/false)); - if (outputDir.empty()) { origCI.getLangOpts()->ObjCAutoRefCount = true; - return migration.getRemapper().overwriteOriginal(*Diags); + return migration.getRemapper().overwriteOriginal(Diags); } else { - return migration.getRemapper().flushToDisk(outputDir, *Diags); + return migration.getRemapper().flushToDisk(outputDir, Diags); } } bool arcmt::applyTransformations( CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr PCHContainerOps, - DiagnosticConsumer *DiagClient) { - return applyTransforms(origCI, Input, PCHContainerOps, DiagClient, - StringRef(), false, StringRef()); + DiagnosticsEngine &Diags) { + return applyTransforms(origCI, Input, PCHContainerOps, Diags, StringRef(), + false, StringRef()); } bool arcmt::migrateWithTemporaryFiles( CompilerInvocation &origCI, const FrontendInputFile &Input, std::shared_ptr PCHContainerOps, - DiagnosticConsumer *DiagClient, StringRef outputDir, + DiagnosticsEngine &Diags, StringRef outputDir, bool emitPremigrationARCErrors, StringRef plistOut) { assert(!outputDir.empty() && "Expected output directory path"); - return applyTransforms(origCI, Input, PCHContainerOps, DiagClient, outputDir, + return applyTransforms(origCI, Input, PCHContainerOps, Diags, outputDir, emitPremigrationARCErrors, plistOut); } -bool arcmt::getFileRemappings(std::vector > & - remap, - StringRef outputDir, - DiagnosticConsumer *DiagClient) { +bool arcmt::getFileRemappings( + std::vector> &remap, + StringRef outputDir, DiagnosticConsumer *DiagClient, + IntrusiveRefCntPtr DiagIDs) { assert(!outputDir.empty()); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); IntrusiveRefCntPtr Diags( - new DiagnosticsEngine(DiagID, new DiagnosticOptions, + new DiagnosticsEngine(std::move(DiagIDs), new DiagnosticOptions, DiagClient, /*ShouldOwnClient=*/false)); FileRemapper remapper; @@ -509,14 +502,13 @@ MigrationProcess::MigrationProcess( const CompilerInvocation &CI, std::shared_ptr PCHContainerOps, - DiagnosticConsumer *diagClient, StringRef outputDir) + DiagnosticsEngine &OriginalDiags, StringRef outputDir) : OrigCI(CI), PCHContainerOps(std::move(PCHContainerOps)), - DiagClient(diagClient), HadARCErrors(false) { + OriginalDiags(OriginalDiags), HadARCErrors(false) { if (!outputDir.empty()) { - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr Diags( - new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(), - DiagClient, /*ShouldOwnClient=*/false)); + IntrusiveRefCntPtr Diags(new DiagnosticsEngine( + OriginalDiags.getDiagnosticIDs(), &CI.getDiagnosticOpts(), + OriginalDiags.getClient(), /*ShouldOwnClient=*/false)); Remapper.initFromDisk(outputDir, *Diags, /*ignoreIfFilesChanges=*/true); } } @@ -524,8 +516,9 @@ bool MigrationProcess::applyTransform(TransformFn trans, RewriteListener *listener) { std::unique_ptr CInvok; - CInvok.reset( - createInvocationForMigration(OrigCI, PCHContainerOps->getRawReader())); + CInvok.reset(createInvocationForMigration(OriginalDiags.getDiagnosticIDs(), + OrigCI, + PCHContainerOps->getRawReader())); CInvok->getDiagnosticOpts().IgnoreWarnings = true; Remapper.applyMappings(CInvok->getPreprocessorOpts()); @@ -533,11 +526,11 @@ CapturedDiagList capturedDiags; std::vector ARCMTMacroLocs; - assert(DiagClient); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr Diags( - new DiagnosticsEngine(DiagID, new DiagnosticOptions, - DiagClient, /*ShouldOwnClient=*/false)); + auto *DiagClient = OriginalDiags.getClient(); + assert(OriginalDiags.getClient()); + IntrusiveRefCntPtr Diags(new DiagnosticsEngine( + OriginalDiags.getDiagnosticIDs(), new DiagnosticOptions, DiagClient, + /*ShouldOwnClient=*/false)); // Filter of all diagnostics. CaptureDiagnosticConsumer errRec(*Diags, *DiagClient, capturedDiags); Index: lib/ARCMigrate/ARCMTActions.cpp =================================================================== --- lib/ARCMigrate/ARCMTActions.cpp +++ lib/ARCMigrate/ARCMTActions.cpp @@ -17,7 +17,7 @@ bool CheckAction::BeginInvocation(CompilerInstance &CI) { if (arcmt::checkForManualIssues(CI.getInvocation(), getCurrentInput(), CI.getPCHContainerOperations(), - CI.getDiagnostics().getClient())) + CI.getDiagnostics())) return false; // errors, stop the action. // We only want to see warnings reported from arcmt::checkForManualIssues. @@ -31,7 +31,7 @@ bool ModifyAction::BeginInvocation(CompilerInstance &CI) { return !arcmt::applyTransformations(CI.getInvocation(), getCurrentInput(), CI.getPCHContainerOperations(), - CI.getDiagnostics().getClient()); + CI.getDiagnostics()); } ModifyAction::ModifyAction(std::unique_ptr WrappedAction) @@ -40,8 +40,7 @@ bool MigrateAction::BeginInvocation(CompilerInstance &CI) { if (arcmt::migrateWithTemporaryFiles( CI.getInvocation(), getCurrentInput(), CI.getPCHContainerOperations(), - CI.getDiagnostics().getClient(), MigrateDir, EmitPremigrationARCErros, - PlistOut)) + CI.getDiagnostics(), MigrateDir, EmitPremigrationARCErros, PlistOut)) return false; // errors, stop the action. // We only want to see diagnostics emitted by migrateWithTemporaryFiles. Index: lib/ARCMigrate/Internals.h =================================================================== --- lib/ARCMigrate/Internals.h +++ lib/ARCMigrate/Internals.h @@ -42,8 +42,9 @@ }; void writeARCDiagsToPlist(const std::string &outPath, - ArrayRef diags, - SourceManager &SM, const LangOptions &LangOpts); + ArrayRef diags, SourceManager &SM, + const LangOptions &LangOpts, + const DiagnosticIDs &DiagIDs); class TransformActions { DiagnosticsEngine &Diags; Index: lib/ARCMigrate/ObjCMT.cpp =================================================================== --- lib/ARCMigrate/ObjCMT.cpp +++ lib/ARCMigrate/ObjCMT.cpp @@ -24,6 +24,7 @@ #include "clang/Edit/Rewriters.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/MultiplexConsumer.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/PPConditionalDirectiveRecord.h" #include "clang/Lex/Preprocessor.h" #include "clang/Rewrite/Core/Rewriter.h" @@ -2222,7 +2223,7 @@ FileManager FileMgr(FSOpts); RemapFileParser Parser(FileMgr); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagID = AllDiagnostics(); IntrusiveRefCntPtr Diags( new DiagnosticsEngine(DiagID, new DiagnosticOptions, DiagClient, /*ShouldOwnClient=*/false)); Index: lib/ARCMigrate/PlistReporter.cpp =================================================================== --- lib/ARCMigrate/PlistReporter.cpp +++ lib/ARCMigrate/PlistReporter.cpp @@ -34,9 +34,8 @@ void arcmt::writeARCDiagsToPlist(const std::string &outPath, ArrayRef diags, - SourceManager &SM, - const LangOptions &LangOpts) { - DiagnosticIDs DiagIDs; + SourceManager &SM, const LangOptions &LangOpts, + const DiagnosticIDs &DiagIDs) { // Build up a set of FIDs that we use by scanning the locations and // ranges of the diagnostics. Index: lib/Basic/Diagnostic.cpp =================================================================== --- lib/Basic/Diagnostic.cpp +++ lib/Basic/Diagnostic.cpp @@ -290,7 +290,8 @@ for (auto &Mapping : *Transition.State) { StringRef Option = - DiagnosticIDs::getWarningOptionForDiag(Mapping.first); + SrcMgr.getDiagnostics().getDiagnosticIDs()->getWarningOptionForDiag( + Mapping.first); if (!DiagName.empty() && DiagName != Option) continue; @@ -344,7 +345,7 @@ // Don't allow a mapping to a warning override an error/fatal mapping. bool WasUpgradedFromWarning = false; if (Map == diag::Severity::Warning) { - DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); + DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag, *Diags); if (Info.getSeverity() == diag::Severity::Error || Info.getSeverity() == diag::Severity::Fatal) { Map = Info.getSeverity(); @@ -407,7 +408,7 @@ // Perform the mapping change. for (diag::kind Diag : GroupDiags) { - DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); + DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag, *Diags); if (Info.getSeverity() == diag::Severity::Error || Info.getSeverity() == diag::Severity::Fatal) @@ -438,7 +439,7 @@ // Perform the mapping change. for (diag::kind Diag : GroupDiags) { - DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag); + DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag, *Diags); if (Info.getSeverity() == diag::Severity::Fatal) Info.setSeverity(diag::Severity::Error); @@ -454,7 +455,7 @@ SourceLocation Loc) { // Get all the diagnostics. std::vector AllDiags; - DiagnosticIDs::getAllDiagnostics(Flavor, AllDiags); + Diags->getAllDiagnostics(Flavor, AllDiags); // Set the mapping. for (diag::kind Diag : AllDiags) Index: lib/Basic/DiagnosticIDs.cpp =================================================================== --- lib/Basic/DiagnosticIDs.cpp +++ lib/Basic/DiagnosticIDs.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/DiagnosticIDs.h" -#include "clang/Basic/AllDiagnostics.h" +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticCategories.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/STLExtras.h" @@ -25,156 +25,22 @@ // Builtin Diagnostic information //===----------------------------------------------------------------------===// -namespace { - -// Diagnostic classes. -enum { - CLASS_NOTE = 0x01, - CLASS_REMARK = 0x02, - CLASS_WARNING = 0x03, - CLASS_EXTENSION = 0x04, - CLASS_ERROR = 0x05 -}; - -struct StaticDiagInfoRec { - uint16_t DiagID; - unsigned DefaultSeverity : 3; - unsigned Class : 3; - unsigned SFINAE : 2; - unsigned WarnNoWerror : 1; - unsigned WarnShowInSystemHeader : 1; - unsigned Category : 6; - - uint16_t OptionGroupIndex; - - uint16_t DescriptionLen; - const char *DescriptionStr; - - unsigned getOptionGroupIndex() const { - return OptionGroupIndex; - } - - StringRef getDescription() const { - return StringRef(DescriptionStr, DescriptionLen); - } - - diag::Flavor getFlavor() const { - return Class == CLASS_REMARK ? diag::Flavor::Remark - : diag::Flavor::WarningOrError; - } - - bool operator<(const StaticDiagInfoRec &RHS) const { - return DiagID < RHS.DiagID; - } -}; - -#define STRINGIFY_NAME(NAME) #NAME -#define VALIDATE_DIAG_SIZE(NAME) \ - static_assert( \ - static_cast(diag::NUM_BUILTIN_##NAME##_DIAGNOSTICS) < \ - static_cast(diag::DIAG_START_##NAME) + \ - static_cast(diag::DIAG_SIZE_##NAME), \ - STRINGIFY_NAME( \ - DIAG_SIZE_##NAME) " is insufficient to contain all " \ - "diagnostics, it may need to be made larger in " \ - "DiagnosticIDs.h."); -VALIDATE_DIAG_SIZE(COMMON) -VALIDATE_DIAG_SIZE(DRIVER) -VALIDATE_DIAG_SIZE(FRONTEND) -VALIDATE_DIAG_SIZE(SERIALIZATION) -VALIDATE_DIAG_SIZE(LEX) -VALIDATE_DIAG_SIZE(PARSE) -VALIDATE_DIAG_SIZE(AST) -VALIDATE_DIAG_SIZE(COMMENT) -VALIDATE_DIAG_SIZE(SEMA) -VALIDATE_DIAG_SIZE(ANALYSIS) -VALIDATE_DIAG_SIZE(REFACTORING) -#undef VALIDATE_DIAG_SIZE -#undef STRINGIFY_NAME - -} // namespace anonymous - -static const StaticDiagInfoRec StaticDiagInfo[] = { -#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \ - SHOWINSYSHEADER, CATEGORY) \ - { \ - diag::ENUM, DEFAULT_SEVERITY, CLASS, DiagnosticIDs::SFINAE, NOWERROR, \ - SHOWINSYSHEADER, CATEGORY, GROUP, STR_SIZE(DESC, uint16_t), DESC \ - } \ - , -#include "clang/Basic/DiagnosticCommonKinds.inc" -#include "clang/Basic/DiagnosticDriverKinds.inc" -#include "clang/Basic/DiagnosticFrontendKinds.inc" -#include "clang/Basic/DiagnosticSerializationKinds.inc" -#include "clang/Basic/DiagnosticLexKinds.inc" -#include "clang/Basic/DiagnosticParseKinds.inc" -#include "clang/Basic/DiagnosticASTKinds.inc" -#include "clang/Basic/DiagnosticCommentKinds.inc" -#include "clang/Basic/DiagnosticCrossTUKinds.inc" -#include "clang/Basic/DiagnosticSemaKinds.inc" -#include "clang/Basic/DiagnosticAnalysisKinds.inc" -#include "clang/Basic/DiagnosticRefactoringKinds.inc" -#undef DIAG -}; - -static const unsigned StaticDiagInfoSize = llvm::array_lengthof(StaticDiagInfo); - -/// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID, -/// or null if the ID is invalid. -static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { - // Out of bounds diag. Can't be in the table. - using namespace diag; - if (DiagID >= DIAG_UPPER_LIMIT || DiagID <= DIAG_START_COMMON) - return nullptr; - - // Compute the index of the requested diagnostic in the static table. - // 1. Add the number of diagnostics in each category preceding the - // diagnostic and of the category the diagnostic is in. This gives us - // the offset of the category in the table. - // 2. Subtract the number of IDs in each category from our ID. This gives us - // the offset of the diagnostic in the category. - // This is cheaper than a binary search on the table as it doesn't touch - // memory at all. - unsigned Offset = 0; - unsigned ID = DiagID - DIAG_START_COMMON - 1; -#define CATEGORY(NAME, PREV) \ - if (DiagID > DIAG_START_##NAME) { \ - Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV - 1; \ - ID -= DIAG_START_##NAME - DIAG_START_##PREV; \ - } -CATEGORY(DRIVER, COMMON) -CATEGORY(FRONTEND, DRIVER) -CATEGORY(SERIALIZATION, FRONTEND) -CATEGORY(LEX, SERIALIZATION) -CATEGORY(PARSE, LEX) -CATEGORY(AST, PARSE) -CATEGORY(COMMENT, AST) -CATEGORY(CROSSTU, COMMENT) -CATEGORY(SEMA, CROSSTU) -CATEGORY(ANALYSIS, SEMA) -CATEGORY(REFACTORING, ANALYSIS) -#undef CATEGORY - - // Avoid out of bounds reads. - if (ID + Offset >= StaticDiagInfoSize) - return nullptr; - - assert(ID < StaticDiagInfoSize && Offset < StaticDiagInfoSize); - - const StaticDiagInfoRec *Found = &StaticDiagInfo[ID + Offset]; - // If the diag id doesn't match we found a different diag, abort. This can - // happen when this function is called with an ID that points into a hole in - // the diagID space. - if (Found->DiagID != DiagID) - return nullptr; - return Found; -} - -static DiagnosticMapping GetDefaultDiagMapping(unsigned DiagID) { +DiagnosticIDs::DiagnosticIDs( + ArrayRef DiagInfo, const char *DiagGroupNames, + ArrayRef CategoryNameTable, + ArrayRef OptionTable, const int16_t *XDiagArrays, + const int16_t *XDiagSubGroups, + std::function GetDiagInfo) + : DiagInfo(DiagInfo), DiagGroupNames(DiagGroupNames), + CategoryNameTable(CategoryNameTable), OptionTable(OptionTable), + XDiagArrays(XDiagArrays), XDiagSubGroups(XDiagSubGroups), + GetDiagInfo(std::move(GetDiagInfo)) {} + +DiagnosticMapping DiagnosticIDs::GetDefaultDiagMapping(unsigned DiagID) const { DiagnosticMapping Info = DiagnosticMapping::Make( diag::Severity::Fatal, /*IsUser=*/false, /*IsPragma=*/false); - if (const StaticDiagInfoRec *StaticInfo = GetDiagInfo(DiagID)) { + if (const auto *StaticInfo = GetDiagInfo(DiagID)) { Info.setSeverity((diag::Severity)StaticInfo->DefaultSeverity); if (StaticInfo->WarnNoWerror) { @@ -189,8 +55,8 @@ /// getCategoryNumberForDiag - Return the category number that a specified /// DiagID belongs to, or 0 if no category. -unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) +unsigned DiagnosticIDs::getCategoryNumberForDiag(unsigned DiagID) const { + if (const auto *Info = GetDiagInfo(DiagID)) return Info->Category; return 0; } @@ -211,52 +77,43 @@ // particularly clean, but for now we just implement this method here so we can // access GetDefaultDiagMapping. DiagnosticMapping & -DiagnosticsEngine::DiagState::getOrAddMapping(diag::kind Diag) { +DiagnosticsEngine::DiagState::getOrAddMapping(diag::kind Diag, + const DiagnosticIDs &IDs) { std::pair Result = DiagMap.insert(std::make_pair(Diag, DiagnosticMapping())); // Initialize the entry if we added it. if (Result.second) - Result.first->second = GetDefaultDiagMapping(Diag); + Result.first->second = IDs.GetDefaultDiagMapping(Diag); return Result.first->second; } -static const StaticDiagCategoryRec CategoryNameTable[] = { -#define GET_CATEGORY_TABLE -#define CATEGORY(X, ENUM) { X, STR_SIZE(X, uint8_t) }, -#include "clang/Basic/DiagnosticGroups.inc" -#undef GET_CATEGORY_TABLE - { nullptr, 0 } -}; - /// getNumberOfCategories - Return the number of categories -unsigned DiagnosticIDs::getNumberOfCategories() { - return llvm::array_lengthof(CategoryNameTable) - 1; +unsigned DiagnosticIDs::getNumberOfCategories() const { + return CategoryNameTable.size(); } /// getCategoryNameFromID - Given a category ID, return the name of the /// category, an empty string if CategoryID is zero, or null if CategoryID is /// invalid. -StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) { +StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) const { if (CategoryID >= getNumberOfCategories()) return StringRef(); return CategoryNameTable[CategoryID].getName(); } - - DiagnosticIDs::SFINAEResponse -DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) +DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) const { + if (const auto *Info = GetDiagInfo(DiagID)) return static_cast(Info->SFINAE); return SFINAE_Report; } /// getBuiltinDiagClass - Return the class field of the diagnostic. /// -static unsigned getBuiltinDiagClass(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) +unsigned DiagnosticIDs::getBuiltinDiagClass(unsigned DiagID) const { + if (const auto *Info = GetDiagInfo(DiagID)) return Info->Class; return ~0U; } @@ -312,8 +169,6 @@ // Common Diagnostic implementation //===----------------------------------------------------------------------===// -DiagnosticIDs::DiagnosticIDs() { CustomDiagInfo = nullptr; } - DiagnosticIDs::~DiagnosticIDs() { delete CustomDiagInfo; } @@ -335,14 +190,14 @@ /// level of the specified diagnostic ID is a Warning or Extension. /// This only works on builtin diagnostics, not custom ones, and is not legal to /// call on NOTEs. -bool DiagnosticIDs::isBuiltinWarningOrExtension(unsigned DiagID) { +bool DiagnosticIDs::isBuiltinWarningOrExtension(unsigned DiagID) const { return DiagID < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) != CLASS_ERROR; } /// \brief Determine whether the given built-in diagnostic ID is a /// Note. -bool DiagnosticIDs::isBuiltinNote(unsigned DiagID) { +bool DiagnosticIDs::isBuiltinNote(unsigned DiagID) const { return DiagID < diag::DIAG_UPPER_LIMIT && getBuiltinDiagClass(DiagID) == CLASS_NOTE; } @@ -353,7 +208,7 @@ /// which case -pedantic enables it) or treated as a warning/error by default. /// bool DiagnosticIDs::isBuiltinExtensionDiag(unsigned DiagID, - bool &EnabledByDefault) { + bool &EnabledByDefault) const { if (DiagID >= diag::DIAG_UPPER_LIMIT || getBuiltinDiagClass(DiagID) != CLASS_EXTENSION) return false; @@ -363,7 +218,7 @@ return true; } -bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) { +bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) const { if (DiagID >= diag::DIAG_UPPER_LIMIT) return false; @@ -373,7 +228,7 @@ /// getDescription - Given a diagnostic ID, return a description of the /// issue. StringRef DiagnosticIDs::getDescription(unsigned DiagID) const { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) + if (const DiagInfoRec *Info = GetDiagInfo(DiagID)) return Info->getDescription(); assert(CustomDiagInfo && "Invalid CustomDiagInfo"); return CustomDiagInfo->getDescription(DiagID); @@ -429,7 +284,8 @@ // Get the mapping information, or compute it lazily. DiagnosticsEngine::DiagState *State = Diag.GetDiagStateForLoc(Loc); - DiagnosticMapping &Mapping = State->getOrAddMapping((diag::kind)DiagID); + DiagnosticMapping &Mapping = + State->getOrAddMapping((diag::kind)DiagID, *this); // TODO: Can a null severity really get here? if (Mapping.getSeverity() != diag::Severity()) @@ -492,41 +348,16 @@ return Result; } -#define GET_DIAG_ARRAYS -#include "clang/Basic/DiagnosticGroups.inc" -#undef GET_DIAG_ARRAYS - -namespace { - struct WarningOption { - uint16_t NameOffset; - uint16_t Members; - uint16_t SubGroups; - - // String is stored with a pascal-style length byte. - StringRef getName() const { - return StringRef(DiagGroupNames + NameOffset + 1, - DiagGroupNames[NameOffset]); - } - }; -} - -// Second the table of options, sorted by name for fast binary lookup. -static const WarningOption OptionTable[] = { -#define GET_DIAG_TABLE -#include "clang/Basic/DiagnosticGroups.inc" -#undef GET_DIAG_TABLE -}; - /// getWarningOptionForDiag - Return the lowest-level warning option that /// enables the specified diagnostic. If there is no -Wfoo flag that controls /// the diagnostic, this returns null. -StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) - return OptionTable[Info->getOptionGroupIndex()].getName(); +StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) const { + if (const DiagInfoRec *Info = GetDiagInfo(DiagID)) + return OptionTable[Info->getOptionGroupIndex()].getName(DiagGroupNames); return StringRef(); } -std::vector DiagnosticIDs::getDiagnosticFlags() { +std::vector DiagnosticIDs::getDiagnosticFlags() const { std::vector Res; for (size_t I = 1; DiagGroupNames[I] != '\0';) { std::string Diag(DiagGroupNames + I + 1, DiagGroupNames[I]); @@ -540,9 +371,13 @@ /// Return \c true if any diagnostics were found in this group, even if they /// were filtered out due to having the wrong flavor. -static bool getDiagnosticsInGroup(diag::Flavor Flavor, - const WarningOption *Group, - SmallVectorImpl &Diags) { +static bool getDiagnosticsInGroup( + diag::Flavor Flavor, const DiagnosticIDs::WarningOption *Group, + SmallVectorImpl &Diags, + llvm::function_ref + GetDiagInfo, + ArrayRef OptionTable, + const int16_t *XDiagArrays, const int16_t *XDiagSubGroups) { // An empty group is considered to be a warning group: we have empty groups // for GCC compatibility, and GCC does not have remarks. if (!Group->Members && !Group->SubGroups) @@ -551,7 +386,7 @@ bool NotFound = true; // Add the members of the option diagnostic set. - const int16_t *Member = DiagArrays + Group->Members; + const int16_t *Member = XDiagArrays + Group->Members; for (; *Member != -1; ++Member) { if (GetDiagInfo(*Member)->getFlavor() == Flavor) { NotFound = false; @@ -560,10 +395,11 @@ } // Add the members of the subgroups. - const int16_t *SubGroups = DiagSubGroups + Group->SubGroups; + const int16_t *SubGroups = XDiagSubGroups + Group->SubGroups; for (; *SubGroups != (int16_t)-1; ++SubGroups) NotFound &= getDiagnosticsInGroup(Flavor, &OptionTable[(short)*SubGroups], - Diags); + Diags, GetDiagInfo, OptionTable, + XDiagArrays, XDiagSubGroups); return NotFound; } @@ -571,26 +407,27 @@ bool DiagnosticIDs::getDiagnosticsInGroup(diag::Flavor Flavor, StringRef Group, SmallVectorImpl &Diags) const { - auto Found = std::lower_bound(std::begin(OptionTable), std::end(OptionTable), - Group, - [](const WarningOption &LHS, StringRef RHS) { - return LHS.getName() < RHS; - }); - if (Found == std::end(OptionTable) || Found->getName() != Group) + auto Found = + std::lower_bound(std::begin(OptionTable), std::end(OptionTable), Group, + [&](const WarningOption &LHS, StringRef RHS) { + return LHS.getName(DiagGroupNames) < RHS; + }); + if (Found == std::end(OptionTable) || Found->getName(DiagGroupNames) != Group) return true; // Option not found. - return ::getDiagnosticsInGroup(Flavor, Found, Diags); + return ::getDiagnosticsInGroup(Flavor, Found, Diags, GetDiagInfo, OptionTable, + XDiagArrays, XDiagSubGroups); } void DiagnosticIDs::getAllDiagnostics(diag::Flavor Flavor, std::vector &Diags) { - for (unsigned i = 0; i != StaticDiagInfoSize; ++i) - if (StaticDiagInfo[i].getFlavor() == Flavor) - Diags.push_back(StaticDiagInfo[i].DiagID); + for (const auto &Diag : DiagInfo) + if (Diag.getFlavor() == Flavor) + Diags.push_back(Diag.DiagID); } StringRef DiagnosticIDs::getNearestOption(diag::Flavor Flavor, - StringRef Group) { + StringRef Group) const { StringRef Best; unsigned BestDistance = Group.size() + 1; // Sanity threshold. for (const WarningOption &O : OptionTable) { @@ -598,13 +435,16 @@ if (!O.Members && !O.SubGroups) continue; - unsigned Distance = O.getName().edit_distance(Group, true, BestDistance); + unsigned Distance = + O.getName(DiagGroupNames).edit_distance(Group, true, BestDistance); if (Distance > BestDistance) continue; // Don't suggest groups that are not of this kind. llvm::SmallVector Diags; - if (::getDiagnosticsInGroup(Flavor, &O, Diags) || Diags.empty()) + if (::getDiagnosticsInGroup(Flavor, &O, Diags, GetDiagInfo, OptionTable, + XDiagArrays, XDiagSubGroups) || + Diags.empty()) continue; if (Distance == BestDistance) { @@ -612,7 +452,7 @@ Best = ""; } else if (Distance < BestDistance) { // This is a better match. - Best = O.getName(); + Best = O.getName(DiagGroupNames); BestDistance = Distance; } } @@ -738,7 +578,7 @@ return true; } -bool DiagnosticIDs::isARCDiagnostic(unsigned DiagID) { +bool DiagnosticIDs::isARCDiagnostic(unsigned DiagID) const { unsigned cat = getCategoryNumberForDiag(DiagID); return DiagnosticIDs::getCategoryNameFromID(cat).startswith("ARC "); } Index: lib/Basic/Warnings.cpp =================================================================== --- lib/Basic/Warnings.cpp +++ lib/Basic/Warnings.cpp @@ -22,9 +22,9 @@ // // Remark options are also handled here, analogously, except that they are much // simpler because a remark can't be promoted to an error. -#include "clang/Basic/AllDiagnostics.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" +#include "clang/Frontend/FrontendDiagnostic.h" #include #include #include @@ -35,7 +35,8 @@ static void EmitUnknownDiagWarning(DiagnosticsEngine &Diags, diag::Flavor Flavor, StringRef Prefix, StringRef Opt) { - StringRef Suggestion = DiagnosticIDs::getNearestOption(Flavor, Opt); + StringRef Suggestion = + Diags.getDiagnosticIDs()->getNearestOption(Flavor, Opt); Diags.Report(diag::warn_unknown_diag_option) << (Flavor == diag::Flavor::WarningOrError ? 0 : 1) << (Prefix.str() += Opt) << !Suggestion.empty() << (Prefix.str() += Suggestion); Index: lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- lib/CrossTU/CrossTranslationUnit.cpp +++ lib/CrossTU/CrossTranslationUnit.cpp @@ -147,16 +147,16 @@ } llvm::Expected -CrossTranslationUnitContext::getCrossTUDefinition(const FunctionDecl *FD, - StringRef CrossTUDir, - StringRef IndexName) { +CrossTranslationUnitContext::getCrossTUDefinition( + const FunctionDecl *FD, StringRef CrossTUDir, StringRef IndexName, + const IntrusiveRefCntPtr &DiagIDs) { assert(!FD->hasBody() && "FD has a definition in current translation unit!"); const std::string LookupFnName = getLookupName(FD); if (LookupFnName.empty()) return llvm::make_error( index_error_code::failed_to_generate_usr); llvm::Expected ASTUnitOrError = - loadExternalAST(LookupFnName, CrossTUDir, IndexName); + loadExternalAST(LookupFnName, CrossTUDir, IndexName, DiagIDs); if (!ASTUnitOrError) return ASTUnitOrError.takeError(); ASTUnit *Unit = *ASTUnitOrError; @@ -193,7 +193,8 @@ } llvm::Expected CrossTranslationUnitContext::loadExternalAST( - StringRef LookupName, StringRef CrossTUDir, StringRef IndexName) { + StringRef LookupName, StringRef CrossTUDir, StringRef IndexName, + const IntrusiveRefCntPtr &DiagIDs) { // FIXME: The current implementation only supports loading functions with // a lookup name from a single translation unit. If multiple // translation units contains functions with the same lookup name an @@ -223,10 +224,9 @@ if (ASTCacheEntry == FileASTUnitMap.end()) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); TextDiagnosticPrinter *DiagClient = - new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + new TextDiagnosticPrinter(llvm::errs(), DiagIDs, &*DiagOpts); IntrusiveRefCntPtr Diags( - new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient)); + new DiagnosticsEngine(DiagIDs, &*DiagOpts, DiagClient)); std::unique_ptr LoadedUnit(ASTUnit::LoadFromASTFile( ASTFileName, CI.getPCHContainerOperations()->getRawReader(), Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -1420,11 +1420,11 @@ /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories /// option. -static void PrintDiagnosticCategories(raw_ostream &OS) { +static void PrintDiagnosticCategories(const DiagnosticIDs &IDs, + raw_ostream &OS) { // Skip the empty category. - for (unsigned i = 1, max = DiagnosticIDs::getNumberOfCategories(); i != max; - ++i) - OS << i << ',' << DiagnosticIDs::getCategoryNameFromID(i) << '\n'; + for (unsigned i = 1, max = IDs.getNumberOfCategories(); i != max; ++i) + OS << i << ',' << IDs.getCategoryNameFromID(i) << '\n'; } void Driver::HandleAutocompletions(StringRef PassedFlags) const { @@ -1473,7 +1473,7 @@ // We have to query the -W flags manually as they're not in the OptTable. // TODO: Find a good way to add them to OptTable instead and them remove // this code. - for (StringRef S : DiagnosticIDs::getDiagnosticFlags()) + for (StringRef S : Diags.getDiagnosticIDs()->getDiagnosticFlags()) if (S.startswith(Cur)) SuggestedCompletions.push_back(S); } @@ -1513,7 +1513,7 @@ } if (C.getArgs().hasArg(options::OPT__print_diagnostic_categories)) { - PrintDiagnosticCategories(llvm::outs()); + PrintDiagnosticCategories(*Diags.getDiagnosticIDs(), llvm::outs()); return false; } Index: lib/Format/CMakeLists.txt =================================================================== --- lib/Format/CMakeLists.txt +++ lib/Format/CMakeLists.txt @@ -19,5 +19,6 @@ LINK_LIBS clangBasic clangLex + clangFrontendTool clangToolingCore ) Index: lib/Format/TokenAnalyzer.cpp =================================================================== --- lib/Format/TokenAnalyzer.cpp +++ lib/Format/TokenAnalyzer.cpp @@ -26,6 +26,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Format/Format.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Debug.h" @@ -52,9 +53,8 @@ new FileManager(FileSystemOptions(), InMemoryFileSystem)); // This is passed to `SM` as reference, so the pointer has to be referenced // by `Environment` due to the same reason above. - std::unique_ptr Diagnostics(new DiagnosticsEngine( - IntrusiveRefCntPtr(new DiagnosticIDs), - new DiagnosticOptions)); + std::unique_ptr Diagnostics( + new DiagnosticsEngine(AllDiagnostics(), new DiagnosticOptions)); // This will be stored as reference, so the pointer has to be stored in // due to the same reason above. std::unique_ptr VirtualSM( Index: lib/Frontend/ChainedIncludesSource.cpp =================================================================== --- lib/Frontend/ChainedIncludesSource.cpp +++ lib/Frontend/ChainedIncludesSource.cpp @@ -139,9 +139,10 @@ FrontendInputFile InputFile(includes[i], IK); CInvok->getFrontendOpts().Inputs.push_back(InputFile); - TextDiagnosticPrinter *DiagClient = - new TextDiagnosticPrinter(llvm::errs(), new DiagnosticOptions()); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagID = + CI.getDiagnostics().getDiagnosticIDs(); + TextDiagnosticPrinter *DiagClient = new TextDiagnosticPrinter( + llvm::errs(), DiagID, new DiagnosticOptions()); IntrusiveRefCntPtr Diags( new DiagnosticsEngine(DiagID, &CI.getDiagnosticOpts(), DiagClient)); Index: lib/Frontend/CompilerInstance.cpp =================================================================== --- lib/Frontend/CompilerInstance.cpp +++ lib/Frontend/CompilerInstance.cpp @@ -234,8 +234,8 @@ } // Chain in the diagnostic client which will log the diagnostics. - auto Logger = llvm::make_unique(*OS, DiagOpts, - std::move(StreamOwner)); + auto Logger = llvm::make_unique( + *OS, Diags.getDiagnosticIDs(), DiagOpts, std::move(StreamOwner)); if (CodeGenOpts) Logger->setDwarfDebugFlags(CodeGenOpts->DwarfDebugFlags); assert(Diags.ownsClient()); @@ -246,8 +246,8 @@ static void SetupSerializedDiagnostics(DiagnosticOptions *DiagOpts, DiagnosticsEngine &Diags, StringRef OutputFile) { - auto SerializedConsumer = - clang::serialized_diags::create(OutputFile, DiagOpts); + auto SerializedConsumer = clang::serialized_diags::create( + OutputFile, DiagOpts, Diags.getDiagnosticIDs()); if (Diags.ownsClient()) { Diags.setClient(new ChainedDiagnosticConsumer( @@ -258,27 +258,27 @@ } } -void CompilerInstance::createDiagnostics(DiagnosticConsumer *Client, - bool ShouldOwnClient) { - Diagnostics = createDiagnostics(&getDiagnosticOpts(), Client, - ShouldOwnClient, &getCodeGenOpts()); +void CompilerInstance::createDiagnostics( + IntrusiveRefCntPtr DiagIDs, DiagnosticConsumer *Client, + bool ShouldOwnClient) { + Diagnostics = createDiagnostics(std::move(DiagIDs), &getDiagnosticOpts(), + Client, ShouldOwnClient, &getCodeGenOpts()); } -IntrusiveRefCntPtr -CompilerInstance::createDiagnostics(DiagnosticOptions *Opts, - DiagnosticConsumer *Client, - bool ShouldOwnClient, - const CodeGenOptions *CodeGenOpts) { - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); - IntrusiveRefCntPtr - Diags(new DiagnosticsEngine(DiagID, Opts)); +IntrusiveRefCntPtr CompilerInstance::createDiagnostics( + IntrusiveRefCntPtr DiagIDs, DiagnosticOptions *Opts, + DiagnosticConsumer *Client, bool ShouldOwnClient, + const CodeGenOptions *CodeGenOpts) { + IntrusiveRefCntPtr Diags( + new DiagnosticsEngine(DiagIDs, Opts)); // Create the diagnostic client for reporting errors or for // implementing -verify. if (Client) { Diags->setClient(Client, ShouldOwnClient); } else - Diags->setClient(new TextDiagnosticPrinter(llvm::errs(), Opts)); + Diags->setClient( + new TextDiagnosticPrinter(llvm::errs(), std::move(DiagIDs), Opts)); // Chain in -verify checker, if requested. if (Opts->VerifyDiagnostics) @@ -1061,6 +1061,7 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, StringRef ModuleName, FrontendInputFile Input, StringRef OriginalModuleMapFile, StringRef ModuleFileName, + IntrusiveRefCntPtr DiagIDs, llvm::function_ref PreBuildStep = [](CompilerInstance &) {}, llvm::function_ref PostBuildStep = @@ -1134,9 +1135,10 @@ auto &Inv = *Invocation; Instance.setInvocation(std::move(Invocation)); - Instance.createDiagnostics(new ForwardingDiagnosticConsumer( - ImportingInstance.getDiagnosticClient()), - /*ShouldOwnClient=*/true); + Instance.createDiagnostics( + std::move(DiagIDs), + new ForwardingDiagnosticConsumer(ImportingInstance.getDiagnosticClient()), + /*ShouldOwnClient=*/true); Instance.setVirtualFileSystem(&ImportingInstance.getVirtualFileSystem()); @@ -1192,9 +1194,9 @@ /// provided by the importing compiler instance. Returns true if the module /// was built without errors. static bool compileModuleImpl(CompilerInstance &ImportingInstance, - SourceLocation ImportLoc, - Module *Module, - StringRef ModuleFileName) { + SourceLocation ImportLoc, Module *Module, + StringRef ModuleFileName, + IntrusiveRefCntPtr Diags) { InputKind IK(getLanguageFromOptions(ImportingInstance.getLangOpts()), InputKind::ModuleMap); @@ -1208,8 +1210,8 @@ Result = compileModuleImpl( ImportingInstance, ImportLoc, Module->getTopLevelModuleName(), FrontendInputFile(ModuleMapFile->getName(), IK, +Module->IsSystem), - ModMap.getModuleMapFileForUniquing(Module)->getName(), - ModuleFileName); + ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName, + std::move(Diags)); } else { // FIXME: We only need to fake up an input file here as a way of // transporting the module's directory to the module map parser. We should @@ -1226,16 +1228,15 @@ Result = compileModuleImpl( ImportingInstance, ImportLoc, Module->getTopLevelModuleName(), FrontendInputFile(FakeModuleMapFile, IK, +Module->IsSystem), - ModMap.getModuleMapFileForUniquing(Module)->getName(), - ModuleFileName, - [&](CompilerInstance &Instance) { - std::unique_ptr ModuleMapBuffer = - llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent); - ModuleMapFile = Instance.getFileManager().getVirtualFile( - FakeModuleMapFile, InferredModuleMapContent.size(), 0); - Instance.getSourceManager().overrideFileContents( - ModuleMapFile, std::move(ModuleMapBuffer)); - }); + ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName, + std::move(Diags), [&](CompilerInstance &Instance) { + std::unique_ptr ModuleMapBuffer = + llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent); + ModuleMapFile = Instance.getFileManager().getVirtualFile( + FakeModuleMapFile, InferredModuleMapContent.size(), 0); + Instance.getSourceManager().overrideFileContents( + ModuleMapFile, std::move(ModuleMapBuffer)); + }); } // We've rebuilt a module. If we're allowed to generate or update the global @@ -1279,7 +1280,7 @@ case llvm::LockFileManager::LFS_Owned: // We're responsible for building the module ourselves. if (!compileModuleImpl(ImportingInstance, ModuleNameLoc, Module, - ModuleFileName)) { + ModuleFileName, Diags.getDiagnosticIDs())) { diagnoseBuildFailure(); return false; } @@ -2031,7 +2032,8 @@ // Build the module, inheriting any modules that we've built locally. if (compileModuleImpl(*this, ImportLoc, ModuleName, Input, StringRef(), - ModuleFileName, PreBuildStep, PostBuildStep)) { + ModuleFileName, Diagnostics->getDiagnosticIDs(), + PreBuildStep, PostBuildStep)) { BuiltModules[ModuleName] = ModuleFileName.str(); llvm::sys::RemoveFileOnSignal(ModuleFileName); } Index: lib/Frontend/CreateInvocationFromCommandLine.cpp =================================================================== --- lib/Frontend/CreateInvocationFromCommandLine.cpp +++ lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -33,12 +33,6 @@ std::unique_ptr clang::createInvocationFromCommandLine( ArrayRef ArgList, IntrusiveRefCntPtr Diags, IntrusiveRefCntPtr VFS) { - if (!Diags.get()) { - // No diagnostics engine was provided, so create our own diagnostics object - // with the default options. - Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions); - } - SmallVector Args(ArgList.begin(), ArgList.end()); // FIXME: Find a cleaner way to force the driver into restricted modes. Index: lib/Frontend/LogDiagnosticPrinter.cpp =================================================================== --- lib/Frontend/LogDiagnosticPrinter.cpp +++ lib/Frontend/LogDiagnosticPrinter.cpp @@ -19,10 +19,10 @@ using namespace markup; LogDiagnosticPrinter::LogDiagnosticPrinter( - raw_ostream &os, DiagnosticOptions *diags, - std::unique_ptr StreamOwner) + raw_ostream &os, IntrusiveRefCntPtr DiagIDs, + DiagnosticOptions *diags, std::unique_ptr StreamOwner) : OS(os), StreamOwner(std::move(StreamOwner)), LangOpts(nullptr), - DiagOpts(diags) {} + DiagIDs(std::move(DiagIDs)), DiagOpts(diags) {} static StringRef getLevelName(DiagnosticsEngine::Level Level) { switch (Level) { @@ -130,7 +130,7 @@ DE.DiagnosticID = Info.getID(); DE.DiagnosticLevel = Level; - DE.WarningOption = DiagnosticIDs::getWarningOptionForDiag(DE.DiagnosticID); + DE.WarningOption = DiagIDs->getWarningOptionForDiag(DE.DiagnosticID); // Format the message. SmallString<100> MessageStr; Index: lib/Frontend/Rewrite/FrontendActions.cpp =================================================================== --- lib/Frontend/Rewrite/FrontendActions.cpp +++ lib/Frontend/Rewrite/FrontendActions.cpp @@ -242,6 +242,7 @@ Instance.setInvocation( std::make_shared(CI.getInvocation())); Instance.createDiagnostics( + CI.getDiagnostics().getDiagnosticIDs(), new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()), /*ShouldOwnClient=*/true); Instance.getFrontendOpts().DisableFree = false; Index: lib/Frontend/SerializedDiagnosticPrinter.cpp =================================================================== --- lib/Frontend/SerializedDiagnosticPrinter.cpp +++ lib/Frontend/SerializedDiagnosticPrinter.cpp @@ -141,10 +141,12 @@ State(std::move(State)) {} public: - SDiagsWriter(StringRef File, DiagnosticOptions *Diags, bool MergeChildRecords) + SDiagsWriter(StringRef File, DiagnosticOptions *Diags, + IntrusiveRefCntPtr DiagIDs, + bool MergeChildRecords) : LangOpts(nullptr), OriginalInstance(true), MergeChildRecords(MergeChildRecords), - State(std::make_shared(File, Diags)) { + State(std::make_shared(File, Diags, std::move(DiagIDs))) { if (MergeChildRecords) RemoveOldDiagnostics(); EmitPreamble(); @@ -240,12 +242,14 @@ /// \brief State that is shared among the various clones of this diagnostic /// consumer. struct SharedState { - SharedState(StringRef File, DiagnosticOptions *Diags) - : DiagOpts(Diags), Stream(Buffer), OutputFile(File.str()), - EmittedAnyDiagBlocks(false) {} + SharedState(StringRef File, DiagnosticOptions *Diags, + IntrusiveRefCntPtr DiagIDs) + : DiagOpts(Diags), DiagIDs(std::move(DiagIDs)), Stream(Buffer), + OutputFile(File.str()), EmittedAnyDiagBlocks(false) {} /// \brief Diagnostic options. IntrusiveRefCntPtr DiagOpts; + IntrusiveRefCntPtr DiagIDs; /// \brief The byte buffer for the serialized content. SmallString<1024> Buffer; @@ -294,8 +298,10 @@ namespace clang { namespace serialized_diags { std::unique_ptr -create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords) { - return llvm::make_unique(OutputFile, Diags, MergeChildRecords); +create(StringRef OutputFile, DiagnosticOptions *Diags, + IntrusiveRefCntPtr DiagIDs, bool MergeChildRecords) { + return llvm::make_unique(OutputFile, Diags, std::move(DiagIDs), + MergeChildRecords); } } // end namespace serialized_diags @@ -525,7 +531,7 @@ // We use a local version of 'Record' so that we can be generating // another record when we lazily generate one for the category entry. - StringRef catName = DiagnosticIDs::getCategoryNameFromID(category); + StringRef catName = State->DiagIDs->getCategoryNameFromID(category); RecordData::value_type Record[] = {RECORD_CATEGORY, category, catName.size()}; State->Stream.EmitRecordWithBlob(State->Abbrevs.get(RECORD_CATEGORY), Record, catName); @@ -537,8 +543,8 @@ unsigned DiagID) { if (DiagLevel == DiagnosticsEngine::Note) return 0; // No flag for notes. - - StringRef FlagName = DiagnosticIDs::getWarningOptionForDiag(DiagID); + + StringRef FlagName = State->DiagIDs->getWarningOptionForDiag(DiagID); return getEmitDiagnosticFlag(FlagName); } @@ -639,7 +645,7 @@ if (const Diagnostic *Info = D.dyn_cast()) { // Emit the category string lazily and get the category ID. - unsigned DiagID = DiagnosticIDs::getCategoryNumberForDiag(Info->getID()); + unsigned DiagID = State->DiagIDs->getCategoryNumberForDiag(Info->getID()); Record.push_back(getEmitCategory(DiagID)); // Emit the diagnostic flag string lazily and get the mapped ID. Record.push_back(getEmitDiagnosticFlag(Level, Info->getID())); @@ -739,11 +745,10 @@ // to be distinct from the engine the writer was being added to and would // normally not be used. if (!State->MetaDiagnostics) { - IntrusiveRefCntPtr IDs(new DiagnosticIDs()); - auto Client = - new TextDiagnosticPrinter(llvm::errs(), State->DiagOpts.get()); + auto Client = new TextDiagnosticPrinter(llvm::errs(), State->DiagIDs, + State->DiagOpts.get()); State->MetaDiagnostics = llvm::make_unique( - IDs, State->DiagOpts.get(), Client); + State->DiagIDs, State->DiagOpts.get(), Client); } return State->MetaDiagnostics.get(); } Index: lib/Frontend/TextDiagnosticPrinter.cpp =================================================================== --- lib/Frontend/TextDiagnosticPrinter.cpp +++ lib/Frontend/TextDiagnosticPrinter.cpp @@ -22,12 +22,11 @@ #include using namespace clang; -TextDiagnosticPrinter::TextDiagnosticPrinter(raw_ostream &os, - DiagnosticOptions *diags, - bool _OwnsOutputStream) - : OS(os), DiagOpts(diags), - OwnsOutputStream(_OwnsOutputStream) { -} +TextDiagnosticPrinter::TextDiagnosticPrinter( + raw_ostream &os, IntrusiveRefCntPtr DiagIDs, + DiagnosticOptions *diags, bool _OwnsOutputStream) + : OS(os), DiagIDs(std::move(DiagIDs)), DiagOpts(diags), + OwnsOutputStream(_OwnsOutputStream) {} TextDiagnosticPrinter::~TextDiagnosticPrinter() { if (OwnsOutputStream) @@ -52,7 +51,8 @@ static void printDiagnosticOptions(raw_ostream &OS, DiagnosticsEngine::Level Level, const Diagnostic &Info, - const DiagnosticOptions &DiagOpts) { + const DiagnosticOptions &DiagOpts, + const DiagnosticIDs &DiagIDs) { bool Started = false; if (DiagOpts.ShowOptionNames) { // Handle special cases for non-warnings early. @@ -71,13 +71,13 @@ // flag it as such. Note that diagnostics could also have been mapped by a // pragma, but we don't currently have a way to distinguish this. if (Level == DiagnosticsEngine::Error && - DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID()) && - !DiagnosticIDs::isDefaultMappingAsError(Info.getID())) { + DiagIDs.isBuiltinWarningOrExtension(Info.getID()) && + !DiagIDs.isDefaultMappingAsError(Info.getID())) { OS << " [-Werror"; Started = true; } - StringRef Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID()); + StringRef Opt = DiagIDs.getWarningOptionForDiag(Info.getID()); if (!Opt.empty()) { OS << (Started ? "," : " [") << (Level == DiagnosticsEngine::Remark ? "-R" : "-W") << Opt; @@ -90,8 +90,7 @@ // If the user wants to see category information, include it too. if (DiagOpts.ShowCategories) { - unsigned DiagCategory = - DiagnosticIDs::getCategoryNumberForDiag(Info.getID()); + unsigned DiagCategory = DiagIDs.getCategoryNumberForDiag(Info.getID()); if (DiagCategory) { OS << (Started ? "," : " ["); Started = true; @@ -99,7 +98,7 @@ OS << DiagCategory; else { assert(DiagOpts.ShowCategories == 2 && "Invalid ShowCategories value"); - OS << DiagnosticIDs::getCategoryNameFromID(DiagCategory); + OS << DiagIDs.getCategoryNameFromID(DiagCategory); } } } @@ -118,7 +117,7 @@ Info.FormatDiagnostic(OutStr); llvm::raw_svector_ostream DiagMessageStream(OutStr); - printDiagnosticOptions(DiagMessageStream, Level, Info, *DiagOpts); + printDiagnosticOptions(DiagMessageStream, Level, Info, *DiagOpts, *DiagIDs); // Keeps track of the starting position of the location // information (e.g., "foo.c:10:4:") that precedes the error Index: lib/FrontendTool/CMakeLists.txt =================================================================== --- lib/FrontendTool/CMakeLists.txt +++ lib/FrontendTool/CMakeLists.txt @@ -25,6 +25,7 @@ add_clang_library(clangFrontendTool ExecuteCompilerInvocation.cpp + DiagnosticTable.cpp DEPENDS ClangDriverOptions Index: lib/FrontendTool/DiagnosticTable.cpp =================================================================== --- /dev/null +++ lib/FrontendTool/DiagnosticTable.cpp @@ -0,0 +1,138 @@ +#include "clang/FrontendTool/DiagnosticTable.h" +#include "clang/FrontendTool/AllDiagnostics.h" +#include + +using namespace clang; + +#define STRINGIFY_NAME(NAME) #NAME +#define VALIDATE_DIAG_SIZE(NAME) \ + static_assert( \ + static_cast(diag::NUM_BUILTIN_##NAME##_DIAGNOSTICS) < \ + static_cast(diag::DIAG_START_##NAME) + \ + static_cast(diag::DIAG_SIZE_##NAME), \ + STRINGIFY_NAME( \ + DIAG_SIZE_##NAME) " is insufficient to contain all " \ + "diagnostics, it may need to be made larger in " \ + "DiagnosticIDs.h."); +VALIDATE_DIAG_SIZE(COMMON) +VALIDATE_DIAG_SIZE(DRIVER) +VALIDATE_DIAG_SIZE(FRONTEND) +VALIDATE_DIAG_SIZE(SERIALIZATION) +VALIDATE_DIAG_SIZE(LEX) +VALIDATE_DIAG_SIZE(PARSE) +VALIDATE_DIAG_SIZE(AST) +VALIDATE_DIAG_SIZE(COMMENT) +VALIDATE_DIAG_SIZE(SEMA) +VALIDATE_DIAG_SIZE(ANALYSIS) +VALIDATE_DIAG_SIZE(REFACTORING) +#undef VALIDATE_DIAG_SIZE +#undef STRINGIFY_NAME + +static const DiagnosticIDs::DiagInfoRec StaticDiagInfo[] = { +#define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \ + SHOWINSYSHEADER, CATEGORY) \ + {diag::ENUM, \ + DEFAULT_SEVERITY, \ + DiagnosticIDs::CLASS, \ + DiagnosticIDs::SFINAE, \ + NOWERROR, \ + SHOWINSYSHEADER, \ + CATEGORY, \ + GROUP, \ + STR_SIZE(DESC, uint16_t), \ + DESC}, +#include "clang/Basic/DiagnosticCommonKinds.inc" +#include "clang/Basic/DiagnosticDriverKinds.inc" +#include "clang/Basic/DiagnosticFrontendKinds.inc" +#include "clang/Basic/DiagnosticSerializationKinds.inc" +#include "clang/Basic/DiagnosticLexKinds.inc" +#include "clang/Basic/DiagnosticParseKinds.inc" +#include "clang/Basic/DiagnosticASTKinds.inc" +#include "clang/Basic/DiagnosticCommentKinds.inc" +#include "clang/Basic/DiagnosticCrossTUKinds.inc" +#include "clang/Basic/DiagnosticSemaKinds.inc" +#include "clang/Basic/DiagnosticAnalysisKinds.inc" +#include "clang/Basic/DiagnosticRefactoringKinds.inc" +#undef DIAG +}; + +static ArrayRef GetDiagInfoTable() { + return StaticDiagInfo; +} + +/// GetDiagInfo - Return the DiagInfoRec entry for the specified DiagID, +/// or null if the ID is invalid. +static const DiagnosticIDs::DiagInfoRec *GetDiagInfo(unsigned DiagID) { + // Out of bounds diag. Can't be in the table. + using namespace diag; + if (DiagID >= DIAG_UPPER_LIMIT || DiagID <= DIAG_START_COMMON) + return nullptr; + + // Compute the index of the requested diagnostic in the static table. + // 1. Add the number of diagnostics in each category preceding the + // diagnostic and of the category the diagnostic is in. This gives us + // the offset of the category in the table. + // 2. Subtract the number of IDs in each category from our ID. This gives us + // the offset of the diagnostic in the category. + // This is cheaper than a binary search on the table as it doesn't touch + // memory at all. + unsigned Offset = 0; + unsigned ID = DiagID - DIAG_START_COMMON - 1; +#define CATEGORY(NAME, PREV) \ + if (DiagID > DIAG_START_##NAME) { \ + Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV - 1; \ + ID -= DIAG_START_##NAME - DIAG_START_##PREV; \ + } + CATEGORY(DRIVER, COMMON) + CATEGORY(FRONTEND, DRIVER) + CATEGORY(SERIALIZATION, FRONTEND) + CATEGORY(LEX, SERIALIZATION) + CATEGORY(PARSE, LEX) + CATEGORY(AST, PARSE) + CATEGORY(COMMENT, AST) + CATEGORY(CROSSTU, COMMENT) + CATEGORY(SEMA, CROSSTU) + CATEGORY(ANALYSIS, SEMA) + CATEGORY(REFACTORING, ANALYSIS) +#undef CATEGORY + + auto DiagInfoArr = GetDiagInfoTable(); + + // Avoid out of bounds reads. + if (ID + Offset >= DiagInfoArr.size()) + return nullptr; + + assert(ID < DiagInfoArr.size() && Offset < DiagInfoArr.size()); + + const auto *Found = &DiagInfoArr[ID + Offset]; + // If the diag id doesn't match we found a different diag, abort. This can + // happen when this function is called with an ID that points into a hole in + // the diagID space. + if (Found->DiagID != DiagID) + return nullptr; + return Found; +} + +static const DiagnosticIDs::CategoryRec CategoryNameTable[] = { +#define GET_CATEGORY_TABLE +#define CATEGORY(X, ENUM) {X, STR_SIZE(X, uint8_t)}, +#include "clang/Basic/DiagnosticGroups.inc" +#undef GET_CATEGORY_TABLE +}; + +#define GET_DIAG_ARRAYS +#include "clang/Basic/DiagnosticGroups.inc" +#undef GET_DIAG_ARRAYS + +// Second the table of options, sorted by name for fast binary lookup. +static const clang::DiagnosticIDs::WarningOption OptionTable[] = { +#define GET_DIAG_TABLE +#include "clang/Basic/DiagnosticGroups.inc" +#undef GET_DIAG_TABLE +}; + +DiagnosticIDs *clang::AllDiagnostics() { + return new DiagnosticIDs(GetDiagInfoTable(), DiagGroupNames, + CategoryNameTable, OptionTable, DiagArrays, + DiagSubGroups, GetDiagInfo); +} Index: lib/Sema/Sema.cpp =================================================================== --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -1211,8 +1211,8 @@ // issue I am not seeing yet), then there should at least be a clarifying // comment somewhere. if (Optional Info = isSFINAEContext()) { - switch (DiagnosticIDs::getDiagnosticSFINAEResponse( - Diags.getCurrentDiagID())) { + switch (Diags.getDiagnosticIDs()->getDiagnosticSFINAEResponse( + Diags.getCurrentDiagID())) { case DiagnosticIDs::SFINAE_Report: // We'll report the diagnostic below. break; @@ -1295,7 +1295,7 @@ // that is different from the last template instantiation where // we emitted an error, print a template instantiation // backtrace. - if (!DiagnosticIDs::isBuiltinNote(DiagID)) + if (!Diags.getDiagnosticIDs()->isBuiltinNote(DiagID)) PrintContextStack(); } Index: lib/Serialization/ASTReader.cpp =================================================================== --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -5718,7 +5718,8 @@ if (!NewMapping.isPragma() && !IncludeNonPragmaStates) continue; - DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID); + DiagnosticMapping &Mapping = + NewState->getOrAddMapping(DiagID, *Diag.getDiagnosticIDs()); // If this mapping was specified as a warning but the severity was // upgraded due to diagnostic settings, simulate the current diagnostic Index: lib/StaticAnalyzer/Core/CallEvent.cpp =================================================================== --- lib/StaticAnalyzer/Core/CallEvent.cpp +++ lib/StaticAnalyzer/Core/CallEvent.cpp @@ -418,7 +418,9 @@ cross_tu::CrossTranslationUnitContext &CTUCtx = *Engine->getCrossTranslationUnitContext(); llvm::Expected CTUDeclOrError = - CTUCtx.getCrossTUDefinition(FD, Opts.getCTUDir(), Opts.getCTUIndexName()); + CTUCtx.getCrossTUDefinition( + FD, Opts.getCTUDir(), Opts.getCTUIndexName(), + Engine->getAnalysisManager().getDiagnostic().getDiagnosticIDs()); if (!CTUDeclOrError) { handleAllErrors(CTUDeclOrError.takeError(), Index: lib/StaticAnalyzer/Frontend/ModelInjector.cpp =================================================================== --- lib/StaticAnalyzer/Frontend/ModelInjector.cpp +++ lib/StaticAnalyzer/Frontend/ModelInjector.cpp @@ -77,6 +77,7 @@ CompilerInstance Instance(CI.getPCHContainerOperations()); Instance.setInvocation(std::move(Invocation)); Instance.createDiagnostics( + CI.getDiagnostics().getDiagnosticIDs(), new ForwardingDiagnosticConsumer(CI.getDiagnosticClient()), /*ShouldOwnClient=*/true); Index: lib/Tooling/CMakeLists.txt =================================================================== --- lib/Tooling/CMakeLists.txt +++ lib/Tooling/CMakeLists.txt @@ -32,6 +32,7 @@ clangDriver clangFormat clangFrontend + clangFrontendTool clangLex clangRewrite clangToolingCore Index: lib/Tooling/CompilationDatabase.cpp =================================================================== --- lib/Tooling/CompilationDatabase.cpp +++ lib/Tooling/CompilationDatabase.cpp @@ -26,6 +26,7 @@ #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Job.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Tooling/CompilationDatabasePluginRegistry.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/ArrayRef.h" @@ -244,11 +245,12 @@ std::string &ErrorMsg) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); llvm::raw_string_ostream Output(ErrorMsg); - TextDiagnosticPrinter DiagnosticPrinter(Output, &*DiagOpts); + IntrusiveRefCntPtr DiagIDs( + AllDiagnostics()); + TextDiagnosticPrinter DiagnosticPrinter(Output, DiagIDs, &*DiagOpts); UnusedInputDiagConsumer DiagClient(DiagnosticPrinter); - DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs()), - &*DiagOpts, &DiagClient, false); + DiagnosticsEngine Diagnostics(std::move(DiagIDs), &*DiagOpts, &DiagClient, + false); // The clang executable path isn't required since the jobs the driver builds // will not be executed. Index: lib/Tooling/Core/CMakeLists.txt =================================================================== --- lib/Tooling/Core/CMakeLists.txt +++ lib/Tooling/Core/CMakeLists.txt @@ -10,4 +10,5 @@ clangBasic clangLex clangRewrite + clangFrontendTool ) Index: lib/Tooling/Core/Replacement.cpp =================================================================== --- lib/Tooling/Core/Replacement.cpp +++ lib/Tooling/Core/Replacement.cpp @@ -20,6 +20,7 @@ #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/VirtualFileSystem.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/Lexer.h" #include "clang/Rewrite/Core/RewriteBuffer.h" #include "clang/Rewrite/Core/Rewriter.h" @@ -587,9 +588,7 @@ IntrusiveRefCntPtr InMemoryFileSystem( new vfs::InMemoryFileSystem); FileManager Files(FileSystemOptions(), InMemoryFileSystem); - DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs), - new DiagnosticOptions); + DiagnosticsEngine Diagnostics(AllDiagnostics(), new DiagnosticOptions); SourceManager SourceMgr(Diagnostics, Files); Rewriter Rewrite(SourceMgr, LangOptions()); InMemoryFileSystem->addFile( Index: lib/Tooling/Refactoring.cpp =================================================================== --- lib/Tooling/Refactoring.cpp +++ lib/Tooling/Refactoring.cpp @@ -17,6 +17,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Format/Format.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/Lexer.h" #include "clang/Rewrite/Core/Rewriter.h" #include "llvm/Support/Path.h" @@ -41,10 +42,11 @@ LangOptions DefaultLangOptions; IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts); - DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs()), - &*DiagOpts, &DiagnosticPrinter, false); + IntrusiveRefCntPtr DiagIDs( + AllDiagnostics()); + TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), DiagIDs, &*DiagOpts); + DiagnosticsEngine Diagnostics(std::move(DiagIDs), &*DiagOpts, + &DiagnosticPrinter, false); SourceManager Sources(Diagnostics, getFiles()); Rewriter Rewrite(Sources, DefaultLangOptions); Index: lib/Tooling/Tooling.cpp =================================================================== --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -32,6 +32,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendOptions.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Tooling/ArgumentsAdjusters.h" @@ -281,10 +282,11 @@ llvm::opt::InputArgList ParsedArgs = Opts->ParseArgs( ArrayRef(Argv).slice(1), MissingArgIndex, MissingArgCount); ParseDiagnosticArgs(*DiagOpts, ParsedArgs); - TextDiagnosticPrinter DiagnosticPrinter( - llvm::errs(), &*DiagOpts); + IntrusiveRefCntPtr DiagIDs = + AllDiagnostics(); + TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), DiagIDs, &*DiagOpts); DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs()), &*DiagOpts, + std::move(DiagIDs), &*DiagOpts, DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); const std::unique_ptr Driver( @@ -343,7 +345,9 @@ std::unique_ptr ScopedToolAction(create()); // Create the compiler's actual diagnostics engine. - Compiler.createDiagnostics(DiagConsumer, /*ShouldOwnClient=*/false); + Compiler.createDiagnostics( + AllDiagnostics(), DiagConsumer, + /*ShouldOwnClient=*/false); if (!Compiler.hasDiagnostics()) return false; @@ -506,11 +510,13 @@ FileManager *Files, std::shared_ptr PCHContainerOps, DiagnosticConsumer *DiagConsumer) override { + std::unique_ptr AST = ASTUnit::LoadFromCompilerInvocation( Invocation, std::move(PCHContainerOps), - CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts(), - DiagConsumer, - /*ShouldOwnClient=*/false), + CompilerInstance::createDiagnostics( + AllDiagnostics(), + &Invocation->getDiagnosticOpts(), DiagConsumer, + /*ShouldOwnClient=*/false), Files); if (!AST) return false; Index: tools/arcmt-test/CMakeLists.txt =================================================================== --- tools/arcmt-test/CMakeLists.txt +++ tools/arcmt-test/CMakeLists.txt @@ -11,5 +11,6 @@ clangARCMigrate clangBasic clangFrontend + clangFrontendTool clangLex ) Index: tools/arcmt-test/arcmt-test.cpp =================================================================== --- tools/arcmt-test/arcmt-test.cpp +++ tools/arcmt-test/arcmt-test.cpp @@ -13,6 +13,7 @@ #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" #include "clang/Frontend/VerifyDiagnosticConsumer.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "llvm/Support/FileSystem.h" @@ -109,9 +110,9 @@ static bool checkForMigration(StringRef resourcesPath, ArrayRef Args) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); + IntrusiveRefCntPtr DiagID = AllDiagnostics(); DiagnosticConsumer *DiagClient = - new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + new TextDiagnosticPrinter(llvm::errs(), DiagID, &*DiagOpts); IntrusiveRefCntPtr Diags( new DiagnosticsEngine(DiagID, &*DiagOpts, DiagClient)); // Chain in -verify checker, if requested. @@ -135,7 +136,7 @@ arcmt::checkForManualIssues(CI, CI.getFrontendOpts().Inputs[0], std::make_shared(), - Diags->getClient()); + *Diags); return Diags->getClient()->getNumErrors() > 0; } @@ -154,9 +155,9 @@ return true; IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); + IntrusiveRefCntPtr DiagID = AllDiagnostics(); DiagnosticConsumer *DiagClient = - new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + new TextDiagnosticPrinter(llvm::errs(), DiagID, &*DiagOpts); IntrusiveRefCntPtr TopDiags( new DiagnosticsEngine(DiagID, &*DiagOpts, &*DiagClient)); @@ -174,7 +175,7 @@ return false; MigrationProcess migration(origCI, std::make_shared(), - DiagClient); + *TopDiags); std::vector transforms = arcmt::getAllTransformations(origCI.getLangOpts()->getGC(), Index: tools/c-index-test/CMakeLists.txt =================================================================== --- tools/c-index-test/CMakeLists.txt +++ tools/c-index-test/CMakeLists.txt @@ -29,6 +29,7 @@ clangBasic clangCodeGen clangFrontend + clangFrontendTool clangIndex clangSerialization ) Index: tools/c-index-test/core_main.cpp =================================================================== --- tools/c-index-test/core_main.cpp +++ tools/c-index-test/core_main.cpp @@ -12,15 +12,16 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendAction.h" -#include "clang/Index/IndexingAction.h" +#include "clang/FrontendTool/DiagnosticTable.h" +#include "clang/Index/CodegenNameGenerator.h" #include "clang/Index/IndexDataConsumer.h" +#include "clang/Index/IndexingAction.h" #include "clang/Index/USRGeneration.h" -#include "clang/Index/CodegenNameGenerator.h" #include "clang/Serialization/ASTReader.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/PrettyStackTrace.h" using namespace clang; using namespace clang::index; @@ -170,8 +171,9 @@ SmallVector ArgsWithProgName; ArgsWithProgName.push_back("clang"); ArgsWithProgName.append(Args.begin(), Args.end()); - IntrusiveRefCntPtr - Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)); + IntrusiveRefCntPtr Diags = + CompilerInstance::createDiagnostics(AllDiagnostics(), + new DiagnosticOptions); auto CInvok = createInvocationFromCommandLine(ArgsWithProgName, Diags); if (!CInvok) return true; @@ -218,7 +220,8 @@ } IntrusiveRefCntPtr Diags = - CompilerInstance::createDiagnostics(new DiagnosticOptions()); + CompilerInstance::createDiagnostics(AllDiagnostics(), + new DiagnosticOptions()); std::unique_ptr AU = ASTUnit::LoadFromASTFile( modulePath, *pchRdr, ASTUnit::LoadASTOnly, Diags, FileSystemOpts, /*UseDebugInfo=*/false, Index: tools/clang-check/CMakeLists.txt =================================================================== --- tools/clang-check/CMakeLists.txt +++ tools/clang-check/CMakeLists.txt @@ -14,6 +14,7 @@ clangBasic clangDriver clangFrontend + clangFrontendTool clangRewriteFrontend clangStaticAnalyzerFrontend clangTooling Index: tools/clang-format/CMakeLists.txt =================================================================== --- tools/clang-format/CMakeLists.txt +++ tools/clang-format/CMakeLists.txt @@ -9,6 +9,7 @@ clangFormat clangRewrite clangToolingCore + clangFrontendTool ) target_link_libraries(clang-format Index: tools/clang-format/ClangFormat.cpp =================================================================== --- tools/clang-format/ClangFormat.cpp +++ tools/clang-format/ClangFormat.cpp @@ -19,6 +19,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/Version.h" #include "clang/Format/Format.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Rewrite/Core/Rewriter.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" @@ -135,9 +136,7 @@ IntrusiveRefCntPtr InMemoryFileSystem( new vfs::InMemoryFileSystem); FileManager Files(FileSystemOptions(), InMemoryFileSystem); - DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs), - new DiagnosticOptions); + DiagnosticsEngine Diagnostics(AllDiagnostics(), new DiagnosticOptions); SourceManager Sources(Diagnostics, Files); FileID ID = createInMemoryFile("", Code, Sources, Files, InMemoryFileSystem.get()); @@ -303,9 +302,7 @@ IntrusiveRefCntPtr InMemoryFileSystem( new vfs::InMemoryFileSystem); FileManager Files(FileSystemOptions(), InMemoryFileSystem); - DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs), - new DiagnosticOptions); + DiagnosticsEngine Diagnostics(AllDiagnostics(), new DiagnosticOptions); SourceManager Sources(Diagnostics, Files); FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources, Files, InMemoryFileSystem.get()); Index: tools/clang-fuzzer/handle-cxx/CMakeLists.txt =================================================================== --- tools/clang-fuzzer/handle-cxx/CMakeLists.txt +++ tools/clang-fuzzer/handle-cxx/CMakeLists.txt @@ -7,6 +7,7 @@ clangBasic clangCodeGen clangFrontend + clangFrontendTool clangLex clangTooling ) Index: tools/clang-fuzzer/handle-cxx/handle_cxx.cpp =================================================================== --- tools/clang-fuzzer/handle-cxx/handle_cxx.cpp +++ tools/clang-fuzzer/handle-cxx/handle_cxx.cpp @@ -15,6 +15,7 @@ #include "clang/CodeGen/CodeGenAction.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Tooling/Tooling.h" #include "llvm/Option/Option.h" @@ -39,9 +40,7 @@ new FileManager(FileSystemOptions())); IgnoringDiagConsumer Diags; IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs()), &*DiagOpts, - &Diags, false); + DiagnosticsEngine Diagnostics(AllDiagnostics(), &*DiagOpts, &Diags, false); std::unique_ptr Invocation( tooling::newInvocation(&Diagnostics, CC1Args)); std::unique_ptr Input = Index: tools/clang-import-test/CMakeLists.txt =================================================================== --- tools/clang-import-test/CMakeLists.txt +++ tools/clang-import-test/CMakeLists.txt @@ -19,6 +19,7 @@ clangCodeGen clangDriver clangFrontend + clangFrontendTool clangLex clangParse ) Index: tools/clang-import-test/clang-import-test.cpp =================================================================== --- tools/clang-import-test/clang-import-test.cpp +++ tools/clang-import-test/clang-import-test.cpp @@ -22,6 +22,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/MultiplexConsumer.h" #include "clang/Frontend/TextDiagnosticBuffer.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/Lexer.h" #include "clang/Lex/Preprocessor.h" #include "clang/Parse/ParseAST.h" @@ -161,7 +162,7 @@ auto Ins = llvm::make_unique(); auto DC = llvm::make_unique(); const bool ShouldOwnClient = true; - Ins->createDiagnostics(DC.release(), ShouldOwnClient); + Ins->createDiagnostics(AllDiagnostics(), DC.release(), ShouldOwnClient); auto Inv = llvm::make_unique(); Index: tools/clang-rename/ClangRename.cpp =================================================================== --- tools/clang-rename/ClangRename.cpp +++ tools/clang-rename/ClangRename.cpp @@ -21,6 +21,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TokenKinds.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Rewrite/Core/Rewriter.h" #include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Refactoring.h" @@ -213,10 +214,10 @@ // in the same order we see them. LangOptions DefaultLangOptions; IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - TextDiagnosticPrinter DiagnosticPrinter(errs(), &*DiagOpts); - DiagnosticsEngine Diagnostics( - IntrusiveRefCntPtr(new DiagnosticIDs()), &*DiagOpts, - &DiagnosticPrinter, false); + IntrusiveRefCntPtr DiagIDs = AllDiagnostics(); + TextDiagnosticPrinter DiagnosticPrinter(errs(), DiagIDs, &*DiagOpts); + DiagnosticsEngine Diagnostics(std::move(DiagIDs), &*DiagOpts, + &DiagnosticPrinter, false); auto &FileMgr = Tool.getFiles(); SourceManager Sources(Diagnostics, FileMgr); Rewriter Rewrite(Sources, DefaultLangOptions); Index: tools/diagtool/CMakeLists.txt =================================================================== --- tools/diagtool/CMakeLists.txt +++ tools/diagtool/CMakeLists.txt @@ -16,6 +16,7 @@ PRIVATE clangBasic clangFrontend + clangFrontendTool ) if(UNIX) Index: tools/diagtool/DiagnosticNames.cpp =================================================================== --- tools/diagtool/DiagnosticNames.cpp +++ tools/diagtool/DiagnosticNames.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// #include "DiagnosticNames.h" -#include "clang/Basic/AllDiagnostics.h" +#include "clang/FrontendTool/AllDiagnostics.h" #include "llvm/ADT/STLExtras.h" using namespace clang; Index: tools/diagtool/FindDiagnosticID.cpp =================================================================== --- tools/diagtool/FindDiagnosticID.cpp +++ tools/diagtool/FindDiagnosticID.cpp @@ -9,7 +9,7 @@ #include "DiagTool.h" #include "DiagnosticNames.h" -#include "clang/Basic/AllDiagnostics.h" +#include "clang/FrontendTool/AllDiagnostics.h" #include "llvm/Support/CommandLine.h" DEF_DIAGTOOL("find-diagnostic-id", "Print the id of the given diagnostic", Index: tools/diagtool/ListWarnings.cpp =================================================================== --- tools/diagtool/ListWarnings.cpp +++ tools/diagtool/ListWarnings.cpp @@ -15,8 +15,9 @@ #include "DiagTool.h" #include "DiagnosticNames.h" #include "clang/AST/ASTDiagnostic.h" -#include "clang/Basic/AllDiagnostics.h" +#include "clang/FrontendTool/AllDiagnostics.h" #include "clang/Basic/Diagnostic.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/Format.h" @@ -52,16 +53,18 @@ std::vector Flagged, Unflagged; llvm::StringMap > flagHistogram; + std::unique_ptr IDs(AllDiagnostics()); + for (const DiagnosticRecord &DR : getBuiltinDiagnosticsByName()) { const unsigned diagID = DR.DiagID; - if (DiagnosticIDs::isBuiltinNote(diagID)) + if (IDs->isBuiltinNote(diagID)) continue; - if (!DiagnosticIDs::isBuiltinWarningOrExtension(diagID)) + if (!IDs->isBuiltinWarningOrExtension(diagID)) continue; - Entry entry(DR.getName(), DiagnosticIDs::getWarningOptionForDiag(diagID)); + Entry entry(DR.getName(), IDs->getWarningOptionForDiag(diagID)); if (entry.Flag.empty()) Unflagged.push_back(entry); Index: tools/diagtool/ShowEnabledWarnings.cpp =================================================================== --- tools/diagtool/ShowEnabledWarnings.cpp +++ tools/diagtool/ShowEnabledWarnings.cpp @@ -14,6 +14,7 @@ #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/Support/TargetSelect.h" DEF_DIAGTOOL("show-enabled", @@ -54,9 +55,8 @@ } static IntrusiveRefCntPtr -createDiagnostics(unsigned int argc, char **argv) { - IntrusiveRefCntPtr DiagIDs(new DiagnosticIDs()); - +createDiagnostics(unsigned int argc, char **argv, + IntrusiveRefCntPtr DiagIDs) { // Buffer diagnostics from argument parsing so that we can output them using a // well formed diagnostic object. TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer; @@ -74,7 +74,8 @@ // Build the diagnostics parser IntrusiveRefCntPtr FinalDiags = - CompilerInstance::createDiagnostics(&Invocation->getDiagnosticOpts()); + CompilerInstance::createDiagnostics(DiagIDs, + &Invocation->getDiagnosticOpts()); if (!FinalDiags) return nullptr; @@ -101,8 +102,11 @@ } } + IntrusiveRefCntPtr DiagIDs = AllDiagnostics(); + // Create the diagnostic engine. - IntrusiveRefCntPtr Diags = createDiagnostics(argc, argv); + IntrusiveRefCntPtr Diags = + createDiagnostics(argc, argv, DiagIDs); if (!Diags) { printUsage(); return EXIT_FAILURE; @@ -117,10 +121,10 @@ for (const DiagnosticRecord &DR : getBuiltinDiagnosticsByName()) { unsigned DiagID = DR.DiagID; - if (DiagnosticIDs::isBuiltinNote(DiagID)) + if (DiagIDs->isBuiltinNote(DiagID)) continue; - if (!DiagnosticIDs::isBuiltinWarningOrExtension(DiagID)) + if (!DiagIDs->isBuiltinWarningOrExtension(DiagID)) continue; DiagnosticsEngine::Level DiagLevel = @@ -128,7 +132,7 @@ if (DiagLevel == DiagnosticsEngine::Ignored) continue; - StringRef WarningOpt = DiagnosticIDs::getWarningOptionForDiag(DiagID); + StringRef WarningOpt = DiagIDs->getWarningOptionForDiag(DiagID); Active.push_back(PrettyDiag(DR.getName(), WarningOpt, DiagLevel)); } Index: tools/diagtool/TreeView.cpp =================================================================== --- tools/diagtool/TreeView.cpp +++ tools/diagtool/TreeView.cpp @@ -10,9 +10,10 @@ #include "DiagTool.h" #include "DiagnosticNames.h" #include "clang/AST/ASTDiagnostic.h" -#include "clang/Basic/AllDiagnostics.h" +#include "clang/FrontendTool/AllDiagnostics.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/DenseSet.h" #include "llvm/Support/Format.h" #include "llvm/Support/Process.h" @@ -49,7 +50,7 @@ static bool isIgnored(unsigned DiagID) { // FIXME: This feels like a hack. - static clang::DiagnosticsEngine Diags(new DiagnosticIDs, + static clang::DiagnosticsEngine Diags(AllDiagnostics(), new DiagnosticOptions); return Diags.isIgnored(DiagID, SourceLocation()); } Index: tools/driver/cc1_main.cpp =================================================================== --- tools/driver/cc1_main.cpp +++ tools/driver/cc1_main.cpp @@ -13,7 +13,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Option/Arg.h" +#include "clang/FrontendTool/AllDiagnostics.h" #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" #include "clang/Config/config.h" #include "clang/Driver/DriverDiagnostic.h" @@ -24,9 +24,11 @@ #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/FrontendTool/Utils.h" #include "llvm/ADT/Statistic.h" #include "llvm/LinkAllPasses.h" +#include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" #include "llvm/Support/Compiler.h" @@ -171,7 +173,8 @@ ensureSufficientStack(); std::unique_ptr Clang(new CompilerInstance()); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagID = + AllDiagnostics(); // Register the support for object-file-wrapped Clang modules. auto PCHOps = Clang->getPCHContainerOperations(); @@ -204,7 +207,7 @@ CompilerInvocation::GetResourcesPath(Argv0, MainAddr); // Create the actual diagnostics engine. - Clang->createDiagnostics(); + Clang->createDiagnostics(DiagID); if (!Clang->hasDiagnostics()) return 1; Index: tools/driver/cc1as_main.cpp =================================================================== --- tools/driver/cc1as_main.cpp +++ tools/driver/cc1as_main.cpp @@ -19,6 +19,7 @@ #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" @@ -490,10 +491,11 @@ // Construct our diagnostic client. IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - TextDiagnosticPrinter *DiagClient - = new TextDiagnosticPrinter(errs(), &*DiagOpts); + IntrusiveRefCntPtr DiagID = + AllDiagnostics(); + TextDiagnosticPrinter *DiagClient = + new TextDiagnosticPrinter(errs(), DiagID, &*DiagOpts); DiagClient->setPrefix("clang -cc1as"); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); // Set an error handler, so that any LLVM backend diagnostics go through our Index: tools/driver/cc1gen_reproducer_main.cpp =================================================================== --- tools/driver/cc1gen_reproducer_main.cpp +++ tools/driver/cc1gen_reproducer_main.cpp @@ -17,6 +17,7 @@ #include "clang/Basic/VirtualFileSystem.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/FileSystem.h" @@ -116,7 +117,7 @@ IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions; - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagID = AllDiagnostics(); DiagnosticsEngine Diags(DiagID, &*DiagOpts, new IgnoringDiagConsumer()); ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false); Driver TheDriver(Argv[0], llvm::sys::getDefaultTargetTriple(), Diags); Index: tools/driver/driver.cpp =================================================================== --- tools/driver/driver.cpp +++ tools/driver/driver.cpp @@ -12,9 +12,9 @@ // //===----------------------------------------------------------------------===// +#include "clang/Driver/Driver.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Driver/Compilation.h" -#include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "clang/Driver/ToolChain.h" @@ -23,6 +23,7 @@ #include "clang/Frontend/SerializedDiagnosticPrinter.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/Utils.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -441,18 +442,19 @@ IntrusiveRefCntPtr DiagOpts = CreateAndPopulateDiagOpts(argv); - TextDiagnosticPrinter *DiagClient - = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); - FixupDiagPrefixExeName(DiagClient, Path); + IntrusiveRefCntPtr DiagID = + AllDiagnostics(); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + TextDiagnosticPrinter *DiagClient = + new TextDiagnosticPrinter(llvm::errs(), DiagID, &*DiagOpts); + FixupDiagPrefixExeName(DiagClient, Path); DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); if (!DiagOpts->DiagnosticSerializationFile.empty()) { - auto SerializedConsumer = - clang::serialized_diags::create(DiagOpts->DiagnosticSerializationFile, - &*DiagOpts, /*MergeChildRecords=*/true); + auto SerializedConsumer = clang::serialized_diags::create( + DiagOpts->DiagnosticSerializationFile, &*DiagOpts, DiagID, + /*MergeChildRecords=*/true); Diags.setClient(new ChainedDiagnosticConsumer( Diags.takeClient(), std::move(SerializedConsumer))); } Index: tools/libclang/ARCMigrate.cpp =================================================================== --- tools/libclang/ARCMigrate.cpp +++ tools/libclang/ARCMigrate.cpp @@ -11,11 +11,12 @@ // //===----------------------------------------------------------------------===// -#include "clang-c/Index.h" #include "CXString.h" +#include "clang-c/Index.h" #include "clang/ARCMigrate/ARCMT.h" #include "clang/Config/config.h" #include "clang/Frontend/TextDiagnosticBuffer.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/Support/FileSystem.h" using namespace clang; @@ -56,9 +57,11 @@ } TextDiagnosticBuffer diagBuffer; + IntrusiveRefCntPtr DiagIDs = AllDiagnostics(); std::unique_ptr remap(new Remap()); - bool err = arcmt::getFileRemappings(remap->Vec, migrate_dir_path,&diagBuffer); + bool err = arcmt::getFileRemappings(remap->Vec, migrate_dir_path, &diagBuffer, + DiagIDs); if (err) { if (Logging) { Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -31,6 +31,7 @@ #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Index/CodegenNameGenerator.h" #include "clang/Index/CommentToXML.h" #include "clang/Lex/HeaderSearch.h" @@ -91,8 +92,8 @@ DEnd = AU->stored_diag_end(); D != DEnd; ++D) { if (D->getLevel() >= DiagnosticsEngine::Error && - DiagnosticIDs::getCategoryNumberForDiag(D->getID()) == - diag::DiagCat_AST_Deserialization_Issue) + AU->getDiagnostics().getDiagnosticIDs()->getCategoryNumberForDiag( + D->getID()) == diag::DiagCat_AST_Deserialization_Issue) return true; } return false; @@ -3314,7 +3315,8 @@ FileSystemOptions FileSystemOpts; IntrusiveRefCntPtr Diags = - CompilerInstance::createDiagnostics(new DiagnosticOptions()); + CompilerInstance::createDiagnostics(AllDiagnostics(), + new DiagnosticOptions()); std::unique_ptr AU = ASTUnit::LoadFromASTFile( ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything, Diags, @@ -3381,8 +3383,9 @@ bool ForSerialization = options & CXTranslationUnit_ForSerialization; // Configure the diagnostics. - IntrusiveRefCntPtr - Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)); + IntrusiveRefCntPtr Diags( + CompilerInstance::createDiagnostics(AllDiagnostics(), + new DiagnosticOptions)); if (options & CXTranslationUnit_KeepGoing) Diags->setSuppressAfterFatalError(false); Index: tools/libclang/CIndexCodeCompletion.cpp =================================================================== --- tools/libclang/CIndexCodeCompletion.cpp +++ tools/libclang/CIndexCodeCompletion.cpp @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#include "CIndexer.h" #include "CIndexDiagnostic.h" +#include "CIndexer.h" #include "CLog.h" #include "CXCursor.h" #include "CXString.h" @@ -26,6 +26,7 @@ #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Sema/CodeCompleteConsumer.h" #include "clang/Sema/Sema.h" #include "llvm/ADT/SmallString.h" @@ -42,7 +43,6 @@ #include #include - #ifdef UDP_CODE_COMPLETION_LOGGER #include "clang/Basic/Version.h" #include @@ -315,8 +315,7 @@ AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults( IntrusiveRefCntPtr FileMgr) : CXCodeCompleteResults(), DiagOpts(new DiagnosticOptions), - Diag(new DiagnosticsEngine( - IntrusiveRefCntPtr(new DiagnosticIDs), &*DiagOpts)), + Diag(new DiagnosticsEngine(AllDiagnostics(), &*DiagOpts)), FileMgr(std::move(FileMgr)), SourceMgr(new SourceManager(*Diag, *this->FileMgr)), CodeCompletionAllocator( Index: tools/libclang/CIndexDiagnostic.cpp =================================================================== --- tools/libclang/CIndexDiagnostic.cpp +++ tools/libclang/CIndexDiagnostic.cpp @@ -20,6 +20,7 @@ #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/DiagnosticRenderer.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/raw_ostream.h" @@ -402,7 +403,8 @@ CXString clang_getDiagnosticCategoryName(unsigned Category) { // Kept for backward compatibility. - return cxstring::createRef(DiagnosticIDs::getCategoryNameFromID(Category)); + std::unique_ptr Diags(AllDiagnostics()); + return cxstring::createRef(Diags->getCategoryNameFromID(Category)); } CXString clang_getDiagnosticCategoryText(CXDiagnostic Diag) { Index: tools/libclang/CMakeLists.txt =================================================================== --- tools/libclang/CMakeLists.txt +++ tools/libclang/CMakeLists.txt @@ -37,6 +37,7 @@ clangAST clangBasic clangFrontend + clangFrontendTool clangIndex clangLex clangSema Index: tools/libclang/CXStoredDiagnostic.cpp =================================================================== --- tools/libclang/CXStoredDiagnostic.cpp +++ tools/libclang/CXStoredDiagnostic.cpp @@ -19,6 +19,7 @@ #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/Twine.h" using namespace clang; @@ -52,7 +53,8 @@ CXString CXStoredDiagnostic::getDiagnosticOption(CXString *Disable) const { unsigned ID = Diag.getID(); - StringRef Option = DiagnosticIDs::getWarningOptionForDiag(ID); + std::unique_ptr IDs(AllDiagnostics()); + StringRef Option = IDs->getWarningOptionForDiag(ID); if (!Option.empty()) { if (Disable) *Disable = cxstring::createDup((Twine("-Wno-") + Option).str()); @@ -69,12 +71,14 @@ } unsigned CXStoredDiagnostic::getCategory() const { - return DiagnosticIDs::getCategoryNumberForDiag(Diag.getID()); + std::unique_ptr IDs(AllDiagnostics()); + return IDs->getCategoryNumberForDiag(Diag.getID()); } CXString CXStoredDiagnostic::getCategoryText() const { - unsigned catID = DiagnosticIDs::getCategoryNumberForDiag(Diag.getID()); - return cxstring::createRef(DiagnosticIDs::getCategoryNameFromID(catID)); + std::unique_ptr IDs(AllDiagnostics()); + unsigned catID = IDs->getCategoryNumberForDiag(Diag.getID()); + return cxstring::createRef(IDs->getCategoryNameFromID(catID)); } unsigned CXStoredDiagnostic::getNumRanges() const { Index: tools/libclang/Indexing.cpp =================================================================== --- tools/libclang/Indexing.cpp +++ tools/libclang/Indexing.cpp @@ -21,6 +21,7 @@ #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/Utils.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Index/IndexingAction.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/PPCallbacks.h" @@ -451,10 +452,10 @@ CaptureDiag = new CaptureDiagnosticConsumer(); // Configure the diagnostics. - IntrusiveRefCntPtr - Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions, - CaptureDiag, - /*ShouldOwnClient=*/true)); + IntrusiveRefCntPtr Diags = + CompilerInstance::createDiagnostics(AllDiagnostics(), + new DiagnosticOptions, CaptureDiag, + /*ShouldOwnClient=*/true); // Recover resources if we crash before exiting this function. llvm::CrashRecoveryContextCleanupRegistrar @@ -29,7 +30,7 @@ protected: CommentLexerTest() : FileMgr(FileMgrOpts), - DiagID(new DiagnosticIDs()), + DiagID(AllDiagnostics()), Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()), SourceMgr(Diags, FileMgr), Traits(Allocator, CommentOptions()) { Index: unittests/AST/CommentParser.cpp =================================================================== --- unittests/AST/CommentParser.cpp +++ unittests/AST/CommentParser.cpp @@ -17,6 +17,7 @@ #include "clang/Basic/DiagnosticOptions.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Allocator.h" #include "gtest/gtest.h" @@ -35,7 +36,7 @@ protected: CommentParserTest() : FileMgr(FileMgrOpts), - DiagID(new DiagnosticIDs()), + DiagID(AllDiagnostics()), Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()), SourceMgr(Diags, FileMgr), Traits(Allocator, CommentOptions()) { Index: unittests/AST/ExternalASTSourceTest.cpp =================================================================== --- unittests/AST/ExternalASTSourceTest.cpp +++ unittests/AST/ExternalASTSourceTest.cpp @@ -11,12 +11,13 @@ // //===----------------------------------------------------------------------===// +#include "clang/AST/ExternalASTSource.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/ExternalASTSource.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendActions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/PreprocessorOptions.h" #include "gtest/gtest.h" @@ -47,7 +48,7 @@ bool testExternalASTSource(ExternalASTSource *Source, StringRef FileContents) { CompilerInstance Compiler; - Compiler.createDiagnostics(); + Compiler.createDiagnostics(AllDiagnostics()); auto Invocation = std::make_shared(); Invocation->getPreprocessorOpts().addRemappedFile( Index: unittests/Basic/CMakeLists.txt =================================================================== --- unittests/Basic/CMakeLists.txt +++ unittests/Basic/CMakeLists.txt @@ -14,5 +14,6 @@ target_link_libraries(BasicTests PRIVATE clangBasic + clangFrontendTool clangLex ) Index: unittests/Basic/DiagnosticTest.cpp =================================================================== --- unittests/Basic/DiagnosticTest.cpp +++ unittests/Basic/DiagnosticTest.cpp @@ -10,6 +10,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticError.h" #include "clang/Basic/DiagnosticIDs.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "gtest/gtest.h" using namespace llvm; @@ -19,7 +20,7 @@ // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics. TEST(DiagnosticTest, suppressAndTrap) { - DiagnosticsEngine Diags(new DiagnosticIDs(), + DiagnosticsEngine Diags(AllDiagnostics(), new DiagnosticOptions, new IgnoringDiagConsumer()); Diags.setSuppressAllDiagnostics(true); @@ -50,7 +51,7 @@ // Check that SuppressAfterFatalError works as intended TEST(DiagnosticTest, suppressAfterFatalError) { for (unsigned Suppress = 0; Suppress != 2; ++Suppress) { - DiagnosticsEngine Diags(new DiagnosticIDs(), + DiagnosticsEngine Diags(AllDiagnostics(), new DiagnosticOptions, new IgnoringDiagConsumer()); Diags.setSuppressAfterFatalError(Suppress); @@ -74,7 +75,7 @@ } TEST(DiagnosticTest, diagnosticError) { - DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions, + DiagnosticsEngine Diags(AllDiagnostics(), new DiagnosticOptions, new IgnoringDiagConsumer()); PartialDiagnostic::StorageAllocator Alloc; llvm::Expected> Value = DiagnosticError::create( Index: unittests/Basic/SourceManagerTest.cpp =================================================================== --- unittests/Basic/SourceManagerTest.cpp +++ unittests/Basic/SourceManagerTest.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/MemoryBufferCache.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleLoader.h" @@ -33,7 +34,7 @@ protected: SourceManagerTest() : FileMgr(FileMgrOpts), - DiagID(new DiagnosticIDs()), + DiagID(AllDiagnostics()), Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()), SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) { Index: unittests/CodeGen/BufferSourceTest.cpp =================================================================== --- unittests/CodeGen/BufferSourceTest.cpp +++ unittests/CodeGen/BufferSourceTest.cpp @@ -13,6 +13,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/Preprocessor.h" #include "clang/Parse/ParseAST.h" #include "clang/Sema/Sema.h" @@ -42,7 +43,7 @@ LLVMContext Context; CompilerInstance compiler; - compiler.createDiagnostics(); + compiler.createDiagnostics(AllDiagnostics()); compiler.getLangOpts().CPlusPlus = 1; compiler.getLangOpts().CPlusPlus11 = 1; Index: unittests/CodeGen/CMakeLists.txt =================================================================== --- unittests/CodeGen/CMakeLists.txt +++ unittests/CodeGen/CMakeLists.txt @@ -16,6 +16,7 @@ clangBasic clangCodeGen clangFrontend + clangFrontendTool clangLex clangParse ) Index: unittests/CodeGen/CodeGenExternalTest.cpp =================================================================== --- unittests/CodeGen/CodeGenExternalTest.cpp +++ unittests/CodeGen/CodeGenExternalTest.cpp @@ -15,6 +15,7 @@ #include "clang/CodeGen/CodeGenABITypes.h" #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/Preprocessor.h" #include "clang/Parse/ParseAST.h" #include "clang/Sema/Sema.h" @@ -261,7 +262,7 @@ LLVMContext Context; CompilerInstance compiler; - compiler.createDiagnostics(); + compiler.createDiagnostics(AllDiagnostics()); compiler.getLangOpts().CPlusPlus = 1; compiler.getLangOpts().CPlusPlus11 = 1; Index: unittests/CodeGen/IncrementalProcessingTest.cpp =================================================================== --- unittests/CodeGen/IncrementalProcessingTest.cpp +++ unittests/CodeGen/IncrementalProcessingTest.cpp @@ -13,6 +13,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/Preprocessor.h" #include "clang/Parse/Parser.h" #include "clang/Sema/Sema.h" @@ -112,7 +113,7 @@ LLVMContext Context; CompilerInstance compiler; - compiler.createDiagnostics(); + compiler.createDiagnostics(AllDiagnostics()); compiler.getLangOpts().CPlusPlus = 1; compiler.getLangOpts().CPlusPlus11 = 1; Index: unittests/CodeGen/TBAAMetadataTest.cpp =================================================================== --- unittests/CodeGen/TBAAMetadataTest.cpp +++ unittests/CodeGen/TBAAMetadataTest.cpp @@ -12,10 +12,11 @@ #include "clang/AST/ASTContext.h" #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Parse/ParseAST.h" #include "llvm/ADT/Triple.h" -#include "llvm/IR/LLVMContext.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Support/MemoryBuffer.h" #include "gtest/gtest.h" @@ -33,7 +34,7 @@ unsigned PtrSize = 0; void init(const char *TestProgram) { - compiler.createDiagnostics(); + compiler.createDiagnostics(clang::AllDiagnostics()); compiler.getCodeGenOpts().StructPathTBAA = 1; compiler.getCodeGenOpts().OptimizationLevel = 1; Index: unittests/CrossTU/CrossTranslationUnitTest.cpp =================================================================== --- unittests/CrossTU/CrossTranslationUnitTest.cpp +++ unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -73,7 +73,9 @@ // Load the definition from the AST file. llvm::Expected NewFDorError = - CTU.getCrossTUDefinition(FD, "", IndexFileName); + CTU.getCrossTUDefinition( + FD, "", IndexFileName, + CTU.getCompilerInstance().getDiagnostics().getDiagnosticIDs()); EXPECT_TRUE((bool)NewFDorError); const FunctionDecl *NewFD = *NewFDorError; Index: unittests/Driver/CMakeLists.txt =================================================================== --- unittests/Driver/CMakeLists.txt +++ unittests/Driver/CMakeLists.txt @@ -15,4 +15,5 @@ PRIVATE clangDriver clangBasic + clangFrontendTool ) Index: unittests/Driver/ToolChainTest.cpp =================================================================== --- unittests/Driver/ToolChainTest.cpp +++ unittests/Driver/ToolChainTest.cpp @@ -18,6 +18,7 @@ #include "clang/Basic/VirtualFileSystem.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" @@ -30,7 +31,7 @@ TEST(ToolChainTest, VFSGCCInstallation) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagID = AllDiagnostics(); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); IntrusiveRefCntPtr InMemoryFileSystem( @@ -84,7 +85,7 @@ TEST(ToolChainTest, VFSGCCInstallationRelativeDir) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagID = AllDiagnostics(); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); IntrusiveRefCntPtr InMemoryFileSystem( @@ -124,7 +125,7 @@ TEST(ToolChainTest, DefaultDriverMode) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagID = AllDiagnostics(); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); IntrusiveRefCntPtr InMemoryFileSystem( @@ -155,7 +156,7 @@ EXPECT_TRUE(CLDriver.IsCLMode()); } TEST(ToolChainTest, InvalidArgument) { - IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); + IntrusiveRefCntPtr DiagID = AllDiagnostics(); struct TestDiagnosticConsumer : public DiagnosticConsumer {}; IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); Index: unittests/Format/CMakeLists.txt =================================================================== --- unittests/Format/CMakeLists.txt +++ unittests/Format/CMakeLists.txt @@ -24,6 +24,7 @@ clangBasic clangFormat clangFrontend + clangFrontendTool clangRewrite clangToolingCore ) Index: unittests/Frontend/ASTUnitTest.cpp =================================================================== --- unittests/Frontend/ASTUnitTest.cpp +++ unittests/Frontend/ASTUnitTest.cpp @@ -13,6 +13,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/PCHContainerOperations.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/ToolOutputFile.h" @@ -47,7 +48,8 @@ const char* Args[] = {"clang", "-xc++", InputFileName.c_str()}; IntrusiveRefCntPtr Diags = - CompilerInstance::createDiagnostics(new DiagnosticOptions()); + CompilerInstance::createDiagnostics(AllDiagnostics(), + new DiagnosticOptions()); std::shared_ptr CInvok = createInvocationFromCommandLine(Args, Diags); Index: unittests/Frontend/CodeGenActionTest.cpp =================================================================== --- unittests/Frontend/CodeGenActionTest.cpp +++ unittests/Frontend/CodeGenActionTest.cpp @@ -11,9 +11,10 @@ // //===----------------------------------------------------------------------===// -#include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/CodeGenAction.h" +#include "clang/CodeGen/BackendUtil.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/PreprocessorOptions.h" #include "gtest/gtest.h" @@ -51,7 +52,7 @@ Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler; Compiler.setInvocation(std::move(Invocation)); - Compiler.createDiagnostics(); + Compiler.createDiagnostics(AllDiagnostics()); EXPECT_TRUE(Compiler.hasDiagnostics()); std::unique_ptr Act(new NullCodeGenAction); Index: unittests/Frontend/CompilerInstanceTest.cpp =================================================================== --- unittests/Frontend/CompilerInstanceTest.cpp +++ unittests/Frontend/CompilerInstanceTest.cpp @@ -9,6 +9,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Format.h" #include "llvm/Support/ToolOutputFile.h" @@ -52,7 +53,8 @@ const char *Args[] = {"clang", VFSArg.c_str(), "-xc++", "-"}; IntrusiveRefCntPtr Diags = - CompilerInstance::createDiagnostics(new DiagnosticOptions()); + CompilerInstance::createDiagnostics(AllDiagnostics(), + new DiagnosticOptions()); std::shared_ptr CInvok = createInvocationFromCommandLine(Args, Diags); Index: unittests/Frontend/FrontendActionTest.cpp =================================================================== --- unittests/Frontend/FrontendActionTest.cpp +++ unittests/Frontend/FrontendActionTest.cpp @@ -7,13 +7,14 @@ // //===----------------------------------------------------------------------===// +#include "clang/Frontend/FrontendAction.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" -#include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Sema/Sema.h" @@ -88,7 +89,7 @@ invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler; compiler.setInvocation(std::move(invocation)); - compiler.createDiagnostics(); + compiler.createDiagnostics(AllDiagnostics()); TestASTFrontendAction test_action; ASSERT_TRUE(compiler.ExecuteAction(test_action)); @@ -108,7 +109,7 @@ invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler; compiler.setInvocation(std::move(invocation)); - compiler.createDiagnostics(); + compiler.createDiagnostics(AllDiagnostics()); TestASTFrontendAction test_action(/*enableIncrementalProcessing=*/true); ASSERT_TRUE(compiler.ExecuteAction(test_action)); @@ -135,7 +136,7 @@ invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance compiler; compiler.setInvocation(std::move(invocation)); - compiler.createDiagnostics(); + compiler.createDiagnostics(AllDiagnostics()); TestASTFrontendAction test_action(/*enableIncrementalProcessing=*/true, /*actOnEndOfTranslationUnit=*/true); @@ -181,7 +182,7 @@ Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu"; CompilerInstance Compiler; Compiler.setInvocation(std::move(Invocation)); - Compiler.createDiagnostics(); + Compiler.createDiagnostics(AllDiagnostics()); TestPPCallbacks *Callbacks = new TestPPCallbacks; TestPPCallbacksFrontendAction TestAction(Callbacks); @@ -243,7 +244,9 @@ CompilerInstance Compiler; Compiler.setInvocation(std::move(Invocation)); auto *TDC = new TypoDiagnosticConsumer; - Compiler.createDiagnostics(TDC, /*ShouldOwnClient=*/true); + Compiler.createDiagnostics( + AllDiagnostics(), TDC, + /*ShouldOwnClient=*/true); Compiler.setExternalSemaSource(new TypoExternalSemaSource(Compiler)); SyntaxOnlyAction TestAction; Index: unittests/Frontend/OutputStreamTest.cpp =================================================================== --- unittests/Frontend/OutputStreamTest.cpp +++ unittests/Frontend/OutputStreamTest.cpp @@ -10,6 +10,7 @@ #include "clang/CodeGen/BackendUtil.h" #include "clang/CodeGen/CodeGenAction.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/FrontendTool/Utils.h" #include "clang/Lex/PreprocessorOptions.h" #include "gtest/gtest.h" @@ -36,7 +37,7 @@ Compiler.setOutputStream(std::move(IRStream)); Compiler.setInvocation(std::move(Invocation)); - Compiler.createDiagnostics(); + Compiler.createDiagnostics(AllDiagnostics()); bool Success = ExecuteCompilerInvocation(&Compiler); EXPECT_TRUE(Success); Index: unittests/Frontend/PCHPreambleTest.cpp =================================================================== --- unittests/Frontend/PCHPreambleTest.cpp +++ unittests/Frontend/PCHPreambleTest.cpp @@ -7,14 +7,15 @@ // //===----------------------------------------------------------------------===// +#include "clang/Basic/Diagnostic.h" +#include "clang/Basic/FileManager.h" #include "clang/Frontend/ASTUnit.h" -#include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/FrontendOptions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/PreprocessorOptions.h" -#include "clang/Basic/Diagnostic.h" -#include "clang/Basic/FileManager.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" @@ -91,8 +92,9 @@ PreprocessorOptions &PPOpts = CI->getPreprocessorOpts(); PPOpts.RemappedFilesKeepOriginalName = true; - IntrusiveRefCntPtr - Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions, new DiagnosticConsumer)); + IntrusiveRefCntPtr Diags( + CompilerInstance::createDiagnostics( + AllDiagnostics(), new DiagnosticOptions, new DiagnosticConsumer)); FileManager *FileMgr = new FileManager(FSOpts, VFS); Index: unittests/Lex/CMakeLists.txt =================================================================== --- unittests/Lex/CMakeLists.txt +++ unittests/Lex/CMakeLists.txt @@ -14,6 +14,7 @@ PRIVATE clangAST clangBasic + clangFrontendTool clangLex clangParse clangSema Index: unittests/Lex/HeaderSearchTest.cpp =================================================================== --- unittests/Lex/HeaderSearchTest.cpp +++ unittests/Lex/HeaderSearchTest.cpp @@ -16,6 +16,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "gtest/gtest.h" @@ -28,7 +29,7 @@ protected: HeaderSearchTest() : VFS(new vfs::InMemoryFileSystem), FileMgr(FileMgrOpts, VFS), - DiagID(new DiagnosticIDs()), + DiagID(AllDiagnostics()), Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()), SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions), Search(std::make_shared(), SourceMgr, Diags, Index: unittests/Lex/LexerTest.cpp =================================================================== --- unittests/Lex/LexerTest.cpp +++ unittests/Lex/LexerTest.cpp @@ -16,6 +16,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/MacroArgs.h" @@ -34,7 +35,7 @@ protected: LexerTest() : FileMgr(FileMgrOpts), - DiagID(new DiagnosticIDs()), + DiagID(AllDiagnostics()), Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()), SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) Index: unittests/Lex/PPCallbacksTest.cpp =================================================================== --- unittests/Lex/PPCallbacksTest.cpp +++ unittests/Lex/PPCallbacksTest.cpp @@ -7,7 +7,6 @@ // //===--------------------------------------------------------------===// -#include "clang/Lex/Preprocessor.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/Diagnostic.h" @@ -18,9 +17,11 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleLoader.h" +#include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Parse/Parser.h" #include "clang/Sema/Sema.h" @@ -94,7 +95,7 @@ PPCallbacksTest() : InMemoryFileSystem(new vfs::InMemoryFileSystem), FileMgr(FileSystemOptions(), InMemoryFileSystem), - DiagID(new DiagnosticIDs()), DiagOpts(new DiagnosticOptions()), + DiagID(AllDiagnostics()), DiagOpts(new DiagnosticOptions()), Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()), SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions()) { TargetOpts->Triple = "x86_64-apple-darwin11.1.0"; Index: unittests/Lex/PPConditionalDirectiveRecordTest.cpp =================================================================== --- unittests/Lex/PPConditionalDirectiveRecordTest.cpp +++ unittests/Lex/PPConditionalDirectiveRecordTest.cpp @@ -16,6 +16,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/TargetOptions.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleLoader.h" @@ -32,7 +33,7 @@ protected: PPConditionalDirectiveRecordTest() : FileMgr(FileMgrOpts), - DiagID(new DiagnosticIDs()), + DiagID(AllDiagnostics()), Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()), SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) Index: unittests/Rename/CMakeLists.txt =================================================================== --- unittests/Rename/CMakeLists.txt +++ unittests/Rename/CMakeLists.txt @@ -20,6 +20,7 @@ clangBasic clangFormat clangFrontend + clangFrontendTool clangRewrite clangTooling clangToolingCore Index: unittests/Tooling/CMakeLists.txt =================================================================== --- unittests/Tooling/CMakeLists.txt +++ unittests/Tooling/CMakeLists.txt @@ -42,6 +42,7 @@ clangBasic clangFormat clangFrontend + clangFrontendTool clangLex clangRewrite clangTooling Index: unittests/Tooling/RewriterTestContext.h =================================================================== --- unittests/Tooling/RewriterTestContext.h +++ unittests/Tooling/RewriterTestContext.h @@ -20,6 +20,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/FrontendTool/DiagnosticTable.h" #include "clang/Rewrite/Core/Rewriter.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" @@ -36,18 +37,18 @@ public: RewriterTestContext() : DiagOpts(new DiagnosticOptions()), - Diagnostics(IntrusiveRefCntPtr(new DiagnosticIDs), - &*DiagOpts), - DiagnosticPrinter(llvm::outs(), &*DiagOpts), + Diagnostics(AllDiagnostics(), &*DiagOpts), + DiagnosticPrinter(llvm::outs(), Diagnostics.getDiagnosticIDs(), + &*DiagOpts), InMemoryFileSystem(new vfs::InMemoryFileSystem), OverlayFileSystem( new vfs::OverlayFileSystem(vfs::getRealFileSystem())), Files(FileSystemOptions(), OverlayFileSystem), Sources(Diagnostics, Files), Rewrite(Sources, Options) { - Diagnostics.setClient(&DiagnosticPrinter, false); - // FIXME: To make these tests truly in-memory, we need to overlay the - // builtin headers. - OverlayFileSystem->pushOverlay(InMemoryFileSystem); + Diagnostics.setClient(&DiagnosticPrinter, false); + // FIXME: To make these tests truly in-memory, we need to overlay the + // builtin headers. + OverlayFileSystem->pushOverlay(InMemoryFileSystem); } ~RewriterTestContext() {}