From 2a88047295ff7c24cf81b3e551577d3e64c8e47a Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Thu, 27 Nov 2025 13:09:14 +0100 Subject: [PATCH 01/18] Revert all downstream commits --- .../clang/include/clang/AST/ASTContext.h | 15 +- .../clang/include/clang/AST/Decl.h | 2 - .../clang/include/clang/AST/DeclCXX.h | 1 - .../clang/include/clang/AST/DeclTemplate.h | 42 ----- .../include/clang/AST/ExternalASTSource.h | 14 +- .../clang/include/clang/Basic/FileManager.h | 9 - .../clang/include/clang/Basic/Module.h | 3 - .../clang/include/clang/Basic/SourceManager.h | 4 +- .../include/clang/CodeGen/ModuleBuilder.h | 11 -- .../clang/include/clang/Lex/ModuleMap.h | 5 +- .../clang/include/clang/Lex/Preprocessor.h | 82 --------- .../clang/include/clang/Parse/Parser.h | 33 ---- .../clang/include/clang/Sema/Sema.h | 80 +-------- .../include/clang/Serialization/ASTReader.h | 9 - .../clang/Serialization/GlobalModuleIndex.h | 28 +-- .../clang/lib/AST/ASTImporter.cpp | 2 +- .../clang/lib/AST/DeclTemplate.cpp | 6 + .../clang/lib/AST/ExternalASTSource.cpp | 20 ++- .../clang/lib/AST/TemplateBase.cpp | 8 +- .../clang/lib/Basic/Diagnostic.cpp | 24 +-- .../clang/lib/Basic/FileManager.cpp | 45 +---- .../llvm-project/clang/lib/Basic/Module.cpp | 3 +- .../clang/lib/Basic/SourceManager.cpp | 29 ---- .../clang/lib/CodeGen/CodeGenModule.cpp | 9 +- .../clang/lib/CodeGen/CodeGenModule.h | 2 - .../clang/lib/CodeGen/ModuleBuilder.cpp | 162 +----------------- .../lib/Frontend/VerifyDiagnosticConsumer.cpp | 5 - .../clang/lib/Lex/HeaderSearch.cpp | 25 +-- .../llvm-project/clang/lib/Lex/Lexer.cpp | 4 - .../llvm-project/clang/lib/Lex/ModuleMap.cpp | 15 +- .../clang/lib/Lex/PPDirectives.cpp | 2 +- .../clang/lib/Lex/PPMacroExpansion.cpp | 14 -- .../clang/lib/Lex/Preprocessor.cpp | 37 ---- .../llvm-project/clang/lib/Sema/Sema.cpp | 3 +- .../clang/lib/Sema/SemaCXXScopeSpec.cpp | 20 +-- .../llvm-project/clang/lib/Sema/SemaDecl.cpp | 33 +--- .../clang/lib/Sema/SemaDeclCXX.cpp | 5 +- .../llvm-project/clang/lib/Sema/SemaExpr.cpp | 41 ----- .../clang/lib/Sema/SemaExprCXX.cpp | 3 +- .../clang/lib/Sema/SemaLookup.cpp | 8 +- .../clang/lib/Sema/SemaModule.cpp | 2 +- .../clang/lib/Sema/SemaTemplate.cpp | 52 +----- .../lib/Sema/SemaTemplateInstantiate.cpp | 10 -- .../llvm-project/clang/lib/Sema/SemaType.cpp | 4 +- .../clang/lib/Serialization/ASTReader.cpp | 118 ++++--------- .../lib/Serialization/ASTReaderInternals.h | 2 +- .../clang/lib/Serialization/ASTWriter.cpp | 3 - .../lib/Serialization/GlobalModuleIndex.cpp | 114 ++++-------- .../Serialization/TemplateArgumentHasher.cpp | 51 ++++-- .../clang/utils/TableGen/ClangAttrEmitter.cpp | 7 +- 50 files changed, 180 insertions(+), 1046 deletions(-) diff --git a/interpreter/llvm-project/clang/include/clang/AST/ASTContext.h b/interpreter/llvm-project/clang/include/clang/AST/ASTContext.h index 2d6bea73c9709..65be782c1ba43 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/ASTContext.h +++ b/interpreter/llvm-project/clang/include/clang/AST/ASTContext.h @@ -276,10 +276,6 @@ class ASTContext : public RefCountedBase { mutable llvm::ContextualFoldingSet ArrayParameterTypes; - /// Generation number for this external AST source. Must be increased - /// whenever we might have added new redeclarations for existing decls. - uint32_t CurrentGeneration = 0; - /// The set of nested name specifiers. /// /// This set is managed by the NestedNameSpecifier class. @@ -734,15 +730,6 @@ class ASTContext : public RefCountedBase { /// use ParentMapContext::getParents() directly. template DynTypedNodeList getParents(const NodeT &Node); - uint32_t getGeneration() const { return CurrentGeneration; } - uint32_t incrementGeneration() { - uint32_t OldGeneration = CurrentGeneration; - CurrentGeneration++; - assert(CurrentGeneration > OldGeneration && - "Overflowed generation counter"); - return OldGeneration; - } - const clang::PrintingPolicy &getPrintingPolicy() const { return PrintingPolicy; } @@ -3725,7 +3712,7 @@ typename clang::LazyGenerationalUpdatePtr::ValueType // include ASTContext.h. We explicitly instantiate it for all relevant types // in ASTContext.cpp. if (auto *Source = Ctx.getExternalSource()) - return new (Ctx) LazyData(&Ctx, Source, Value); + return new (Ctx) LazyData(Source, Value); return Value; } diff --git a/interpreter/llvm-project/clang/include/clang/AST/Decl.h b/interpreter/llvm-project/clang/include/clang/AST/Decl.h index 4942d7af2acc6..362a2741a0cdd 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/Decl.h +++ b/interpreter/llvm-project/clang/include/clang/AST/Decl.h @@ -50,8 +50,6 @@ #include #include -namespace cling { class DeclUnloader; } - namespace clang { class ASTContext; diff --git a/interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h b/interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h index 94f236b0d9a2f..79fd403c2718c 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h +++ b/interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h @@ -266,7 +266,6 @@ class CXXRecordDecl : public RecordDecl { friend class DeclContext; friend class LambdaExpr; friend class ODRDiagsEmitter; - friend class ::cling::DeclUnloader; friend void FunctionDecl::setIsPureVirtual(bool); friend void TagDecl::startDefinition(); diff --git a/interpreter/llvm-project/clang/include/clang/AST/DeclTemplate.h b/interpreter/llvm-project/clang/include/clang/AST/DeclTemplate.h index 8cbc48efbb52c..472b079c8f728 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/DeclTemplate.h +++ b/interpreter/llvm-project/clang/include/clang/AST/DeclTemplate.h @@ -1085,20 +1085,6 @@ class FunctionTemplateDecl : public RedeclarableTemplateDecl { return makeSpecIterator(getSpecializations(), true); } - /// All specializations that that have already been loaded, ie avoiding - /// deserialization of lazily registered specializations. - spec_range loaded_specializations() const { - return spec_range(loaded_spec_begin(), loaded_spec_end()); - } - - spec_iterator loaded_spec_begin() const { - return makeSpecIterator(getCommonPtr()->Specializations, false); - } - - spec_iterator loaded_spec_end() const { - return makeSpecIterator(getCommonPtr()->Specializations, true); - } - /// Return whether this function template is an abbreviated function template, /// e.g. `void foo(auto x)` or `template void foo(auto x)` bool isAbbreviated() const { @@ -2468,20 +2454,6 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl { return makeSpecIterator(getSpecializations(), true); } - /// All specializations that that have already been loaded, ie avoiding - /// deserialization of lazily registered specializations. - spec_range loaded_specializations() const { - return spec_range(loaded_spec_begin(), loaded_spec_end()); - } - - spec_iterator loaded_spec_begin() const { - return makeSpecIterator(getCommonPtr()->Specializations, false); - } - - spec_iterator loaded_spec_end() const { - return makeSpecIterator(getCommonPtr()->Specializations, true); - } - // Implement isa/cast/dyncast support static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == ClassTemplate; } @@ -3210,20 +3182,6 @@ class VarTemplateDecl : public RedeclarableTemplateDecl { return makeSpecIterator(getSpecializations(), true); } - /// All specializations that that have already been loaded, ie avoiding - /// deserialization of lazily registered specializations. - spec_range loaded_specializations() const { - return spec_range(loaded_spec_begin(), loaded_spec_end()); - } - - spec_iterator loaded_spec_begin() const { - return makeSpecIterator(getCommonPtr()->Specializations, false); - } - - spec_iterator loaded_spec_end() const { - return makeSpecIterator(getCommonPtr()->Specializations, true); - } - // Implement isa/cast/dyncast support static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == VarTemplate; } diff --git a/interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h b/interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h index b8b0b88438a78..42aed56d42e07 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h +++ b/interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h @@ -92,7 +92,7 @@ class ExternalASTSource : public RefCountedBase { /// Get the current generation of this AST source. This number /// is incremented each time the AST source lazily extends an existing /// entity. - uint32_t getGeneration(const ASTContext &C) const; + uint32_t getGeneration() const { return CurrentGeneration; } /// Resolve a declaration ID into a declaration, potentially /// building a new declaration. @@ -442,14 +442,12 @@ struct LazyGenerationalUpdatePtr { /// A cache of the value of this pointer, in the most recent generation in /// which we queried it. struct LazyData { - const ASTContext *Context; ExternalASTSource *ExternalSource; uint32_t LastGeneration = 0; T LastValue; - LazyData(const ASTContext *Context, ExternalASTSource *Source, T Value) - : Context(Context), ExternalSource(Source), LastGeneration(0), - LastValue(Value) {} + LazyData(ExternalASTSource *Source, T Value) + : ExternalSource(Source), LastValue(Value) {} }; // Our value is represented as simply T if there is no external AST source. @@ -489,10 +487,8 @@ struct LazyGenerationalUpdatePtr { /// Get the value of this pointer, updating its owner if necessary. T get(Owner O) { if (auto *LazyVal = Value.template dyn_cast()) { - if (LazyVal->LastGeneration != - LazyVal->ExternalSource->getGeneration(*LazyVal->Context)) { - LazyVal->LastGeneration = - LazyVal->ExternalSource->getGeneration(*LazyVal->Context); + if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) { + LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); (LazyVal->ExternalSource->*Update)(O); } return LazyVal->LastValue; diff --git a/interpreter/llvm-project/clang/include/clang/Basic/FileManager.h b/interpreter/llvm-project/clang/include/clang/Basic/FileManager.h index e213dab0fbd66..6cc6c2bfd2b6b 100644 --- a/interpreter/llvm-project/clang/include/clang/Basic/FileManager.h +++ b/interpreter/llvm-project/clang/include/clang/Basic/FileManager.h @@ -32,7 +32,6 @@ #include #include #include -#include namespace llvm { @@ -108,11 +107,6 @@ class FileManager : public RefCountedBase { /// The canonical names of files and directories . llvm::DenseMap CanonicalNames; - std::set FileEntriesToReread; - - /// The canonical names of directories. - llvm::DenseMap CanonicalDirNames; - /// Storage for canonical names that we have computed. llvm::BumpPtrAllocator CanonicalNameStorage; @@ -332,9 +326,6 @@ class FileManager : public RefCountedBase { std::error_code getNoncachedStatValue(StringRef Path, llvm::vfs::Status &Result); - /// Remove the real file \p Entry from the cache. - void invalidateCache(FileEntryRef Entry); - /// If path is not absolute and FileSystemOptions set the working /// directory, the path is modified to be relative to the given /// working directory. diff --git a/interpreter/llvm-project/clang/include/clang/Basic/Module.h b/interpreter/llvm-project/clang/include/clang/Basic/Module.h index 262b0c79751a6..dd384c1d76c5f 100644 --- a/interpreter/llvm-project/clang/include/clang/Basic/Module.h +++ b/interpreter/llvm-project/clang/include/clang/Basic/Module.h @@ -399,9 +399,6 @@ class alignas(8) Module { LLVM_PREFERRED_TYPE(bool) unsigned NoUndeclaredIncludes : 1; - /// Whether the submodule is allowed to have missing headers. - unsigned IsOptional: 1; - /// Whether this module came from a "private" module map, found next /// to a regular (public) module map. LLVM_PREFERRED_TYPE(bool) diff --git a/interpreter/llvm-project/clang/include/clang/Basic/SourceManager.h b/interpreter/llvm-project/clang/include/clang/Basic/SourceManager.h index 4195cf31a1380..e0f1ea435d54e 100644 --- a/interpreter/llvm-project/clang/include/clang/Basic/SourceManager.h +++ b/interpreter/llvm-project/clang/include/clang/Basic/SourceManager.h @@ -256,7 +256,7 @@ class alignas(8) ContentCache { /// Set the buffer. void setBuffer(std::unique_ptr B) { - IsBufferInvalid = !B; + IsBufferInvalid = false; Buffer = std::move(B); } @@ -845,8 +845,6 @@ class SourceManager : public RefCountedBase { void clearIDTables(); - void invalidateCache(FileID FID); - /// Initialize this source manager suitably to replay the compilation /// described by \p Old. Requires that \p Old outlive \p *this. void initializeForReplay(const SourceManager &Old); diff --git a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h index 8f3168a975513..59b9840d02e08 100644 --- a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h +++ b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h @@ -19,11 +19,9 @@ namespace llvm { class Constant; - class GlobalValue; class LLVMContext; class Module; class StringRef; - class raw_ostream; namespace vfs { class FileSystem; @@ -99,18 +97,9 @@ class CodeGenerator : public ASTConsumer { /// definition has been registered with this code generator. llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition); - void print(llvm::raw_ostream& out); - /// Create a new \c llvm::Module after calling HandleTranslationUnit. This /// enable codegen in interactive processing environments. llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C); - - llvm::Module* StartModule(llvm::StringRef ModuleName, - llvm::LLVMContext& C, - const CodeGenOptions& CGO); - - void forgetGlobal(llvm::GlobalValue* GV); - void forgetDecl(llvm::StringRef MangledName); }; /// CreateLLVMCodeGen - Create a CodeGenerator instance. diff --git a/interpreter/llvm-project/clang/include/clang/Lex/ModuleMap.h b/interpreter/llvm-project/clang/include/clang/Lex/ModuleMap.h index 026f8849edbf5..53e9e0ec83ddb 100644 --- a/interpreter/llvm-project/clang/include/clang/Lex/ModuleMap.h +++ b/interpreter/llvm-project/clang/include/clang/Lex/ModuleMap.h @@ -251,12 +251,9 @@ class ModuleMap { LLVM_PREFERRED_TYPE(bool) unsigned NoUndeclaredIncludes : 1; - /// Whether we can have a submodule with missing header files. - unsigned IsOptional : 1; - Attributes() : IsSystem(false), IsExternC(false), IsExhaustive(false), - NoUndeclaredIncludes(false), IsOptional(false) {} + NoUndeclaredIncludes(false) {} }; /// A directory for which framework modules can be inferred. diff --git a/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h b/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h index e0e6010e744a1..416f403c29841 100644 --- a/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h +++ b/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h @@ -1427,11 +1427,6 @@ class Preprocessor { return appendDefMacroDirective(II, MI, MI->getDefinitionLoc()); } - /// Remove a IdentifierInfo and MacroDirective from the history. - /// Given an IdentifierInfo and a MacroDirective we can remove them from - /// the macros vector. - void removeMacro(IdentifierInfo *II, MacroDirective *MD); - /// Set a MacroDirective that was loaded from a PCH file. void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD); @@ -1698,77 +1693,6 @@ class Preprocessor { IsReinject); } - /// A RAII object to temporarily reset PP's state and restore it. - class CleanupAndRestoreCacheRAII { - private: - Preprocessor &PP; - CachedTokensTy SavedCachedTokens; - CachedTokensTy::size_type SavedCachedLexPos; - std::vector SavedBacktrackPositions; - std::vector SavedStack; - Lexer *SavedCurLexer; - PreprocessorLexer *SavedCurPPLexer; - TokenLexer* SavedCurTokenLexer; - ConstSearchDirIterator SavedCurDirLookup; - LexerCallback SavedCurLexerCallback; - unsigned SavedLexLevel; - - public: - CleanupAndRestoreCacheRAII(Preprocessor &PP) - : PP(PP), SavedCachedTokens(std::move(PP.CachedTokens)), - SavedCachedLexPos(PP.CachedLexPos), - SavedBacktrackPositions(std::move(PP.BacktrackPositions)), - SavedStack(std::move(PP.IncludeMacroStack)), - SavedCurLexer(PP.CurLexer.release()), SavedCurPPLexer(PP.CurPPLexer), - SavedCurTokenLexer(PP.CurTokenLexer.release()), - SavedCurDirLookup(PP.CurDirLookup), - SavedCurLexerCallback(PP.CurLexerCallback), - SavedLexLevel(PP.LexLevel) { - PP.CachedTokens.clear(); - PP.CachedLexPos = 0; - PP.BacktrackPositions.clear(); - PP.IncludeMacroStack.clear(); - PP.CurLexer.reset(0); - PP.CurPPLexer = 0; - PP.CurTokenLexer.reset(0); - PP.CurDirLookup = 0; - PP.CurLexerCallback = CLK_CachingLexer; - PP.LexLevel = 0; - } - - void pop() { - if (SavedCurLexerCallback == nullptr) - return; - - // ExitCachingLexMode(); - PP.CachedTokens = std::move(SavedCachedTokens); - PP.CachedLexPos = SavedCachedLexPos; - PP.BacktrackPositions = std::move(SavedBacktrackPositions); - PP.IncludeMacroStack = std::move(SavedStack); - PP.CurLexer.reset(SavedCurLexer); - PP.CurPPLexer = SavedCurPPLexer; - PP.CurTokenLexer.reset(SavedCurTokenLexer); - PP.CurDirLookup = SavedCurDirLookup; - PP.CurLexerCallback = SavedCurLexerCallback; - PP.LexLevel = SavedLexLevel; - - SavedCachedTokens.clear(); - SavedCachedLexPos = 0; - SavedBacktrackPositions.clear(); - SavedStack.clear(); - SavedCurLexer = 0; - SavedCurPPLexer = 0; - SavedCurTokenLexer = 0; - SavedCurDirLookup = 0; - SavedCurLexerCallback = nullptr; - SavedLexLevel = ~0U; - } - - ~CleanupAndRestoreCacheRAII() { - pop(); - } - }; - /// Pop the current lexer/macro exp off the top of the lexer stack. /// /// This should only be used in situations where the current state of the @@ -2290,12 +2214,6 @@ class Preprocessor { void DumpMacro(const MacroInfo &MI) const; void dumpMacroInfo(const IdentifierInfo *II); - /// Print a Macro to an ostream used for ClangInternalState - /// Same as dump, but without orinting source location. - void printMacros(raw_ostream &OS) const; - void printMacro(const IdentifierInfo* II, const MacroDirective *MD, - llvm::raw_ostream &OS) const; - /// Given a location that specifies the start of a /// token, return a new location that specifies a character within the token. SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, diff --git a/interpreter/llvm-project/clang/include/clang/Parse/Parser.h b/interpreter/llvm-project/clang/include/clang/Parse/Parser.h index 5df3bb7ed0f14..e99d2cf2eaa40 100644 --- a/interpreter/llvm-project/clang/include/clang/Parse/Parser.h +++ b/interpreter/llvm-project/clang/include/clang/Parse/Parser.h @@ -27,8 +27,6 @@ #include #include -namespace cling { class ParserStateRAII; } - namespace clang { class PragmaHandler; class Scope; @@ -52,7 +50,6 @@ namespace clang { struct OMPTraitSelector; struct OMPTraitSet; class OMPTraitInfo; - class DestroyTemplateIdAnnotationsRAIIObj; /// Parser - This implements a parser for the C family of languages. After /// parsing units of the grammar, productions are invoked to handle whatever has @@ -68,8 +65,6 @@ class Parser : public CodeCompletionHandler { friend class ObjCDeclContextSwitch; friend class ParenBraceBracketBalancer; friend class BalancedDelimiterTracker; - friend class DestroyTemplateIdAnnotationsRAIIObj; - friend class ::cling::ParserStateRAII; Preprocessor &PP; @@ -504,34 +499,6 @@ class Parser : public CodeCompletionHandler { AttributeFactory &getAttrFactory() { return AttrFactory; } const Token &getCurToken() const { return Tok; } - - /// A RAII object to temporarily reset PP's state and restore it. - class ParserCurTokRestoreRAII { - private: - Parser &P; - Token SavedTok; - - public: - ParserCurTokRestoreRAII(Parser &P) - : P(P), SavedTok(P.Tok) - { - } - - void pop() { - if (SavedTok.is(tok::unknown)) - return; - - P.Tok = SavedTok; - - SavedTok.startToken(); - } - - ~ParserCurTokRestoreRAII() { - pop(); - } - }; - - Scope *getCurScope() const { return Actions.getCurScope(); } void incrementMSManglingNumber() const { return Actions.incrementMSManglingNumber(); diff --git a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h index f53e08ac0cf13..d8cc0171c22c6 100644 --- a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h +++ b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h @@ -1183,7 +1183,6 @@ class Sema final : public SemaBase { friend class ASTReader; friend class ASTDeclReader; friend class ASTWriter; - friend class ::cling::DeclUnloader; private: std::optional> CachedDarwinSDKInfo; @@ -2732,7 +2731,7 @@ class Sema final : public SemaBase { public: // Marks SS invalid if it represents an incomplete type. - bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *&DC); + bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); // Complete an enum decl, maybe without a scope spec. bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, CXXScopeSpec *SS = nullptr); @@ -3060,27 +3059,6 @@ class Sema final : public SemaBase { /// attribute. mutable llvm::DenseMap FlagBitsCache; - class DelayedInfoRAII { - Sema &S; - SmallVector, 2> - DelayedOverridingExceptionSpecChecks; - SmallVector, 2> - DelayedEquivalentExceptionSpecChecks; - public: - DelayedInfoRAII(Sema& S): S(S) { - std::swap(S.DelayedOverridingExceptionSpecChecks, - DelayedOverridingExceptionSpecChecks); - std::swap(S.DelayedEquivalentExceptionSpecChecks, - DelayedEquivalentExceptionSpecChecks); - } - ~DelayedInfoRAII() { - std::swap(S.DelayedOverridingExceptionSpecChecks, - DelayedOverridingExceptionSpecChecks); - std::swap(S.DelayedEquivalentExceptionSpecChecks, - DelayedEquivalentExceptionSpecChecks); - } - }; - /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before /// declared. Rare. May alias another identifier, declared or undeclared. /// @@ -11344,8 +11322,8 @@ class Sema final : public SemaBase { bool CheckTemplateParameterList(TemplateParameterList *NewParams, TemplateParameterList *OldParams, TemplateParamListContext TPC, - SkipBodyInfo *SkipBody = nullptr, - bool Complain = true); + SkipBodyInfo *SkipBody = nullptr); + /// Match the given template parameter lists to the given scope /// specifier, returning the template parameter list that applies to the /// name. @@ -13135,39 +13113,6 @@ class Sema final : public SemaBase { bool SkipForSpecialization = false, bool ForDefaultArgumentSubstitution = false); - /// A RAII object to temporarily push a decl context and scope. - class ContextAndScopeRAII { - private: - Sema &S; - DeclContext *SavedContext; - Scope *SavedScope; - ProcessingContextState SavedContextState; - QualType SavedCXXThisTypeOverride; - - public: - ContextAndScopeRAII(Sema &S, DeclContext *ContextToPush, Scope *ScopeToPush) - : S(S), SavedContext(S.CurContext), SavedScope(S.CurScope), - SavedContextState(S.DelayedDiagnostics.pushUndelayed()), - SavedCXXThisTypeOverride(S.CXXThisTypeOverride) { - assert(ContextToPush && "pushing null context"); - S.CurContext = ContextToPush; - S.CurScope = ScopeToPush; - } - - void pop() { - if (!SavedContext) - return; - S.CurContext = SavedContext; - S.CurScope = SavedScope; - S.DelayedDiagnostics.popUndelayed(SavedContextState); - S.CXXThisTypeOverride = SavedCXXThisTypeOverride; - SavedContext = 0; - SavedScope = 0; - } - - ~ContextAndScopeRAII() { pop(); } - }; - /// RAII object to handle the state changes required to synthesize /// a function body. class SynthesizedFunctionScope { @@ -13662,25 +13607,6 @@ class Sema final : public SemaBase { SavedPendingLocalImplicitInstantiations; }; - class SavePendingInstantiationsRAII { - public: - SavePendingInstantiationsRAII(Sema &S) - : SavedPendingLocalImplicitInstantiations(S), S(S) { - SavedPendingInstantiations.swap(S.PendingInstantiations); - } - - ~SavePendingInstantiationsRAII() { - assert(S.PendingInstantiations.empty() && - "there shouldn't be any pending instantiations"); - SavedPendingInstantiations.swap(S.PendingInstantiations); - } - - private: - LocalEagerInstantiationScope SavedPendingLocalImplicitInstantiations; - Sema &S; - std::deque SavedPendingInstantiations; - }; - /// Records and restores the CurFPFeatures state on entry/exit of compound /// statements. class FPFeaturesStateRAII { diff --git a/interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h b/interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h index bea453546157e..47301419c76c6 100644 --- a/interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h +++ b/interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h @@ -757,9 +757,6 @@ class ASTReader /// files. llvm::DenseSet LoadedUndefs; - /// \Token literal data loaded and owned by us. - std::vector TokenLiteralDataLoaded; - using GlobalMacroMapType = ContinuousRangeMap; @@ -1511,12 +1508,6 @@ class ASTReader : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {} }; - uint32_t getGenerationOrNull() const { - if (ContextObj) - return getGeneration(*ContextObj); - return 0u; - } - ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, ModuleFile *ImportedBy, SmallVectorImpl &Loaded, diff --git a/interpreter/llvm-project/clang/include/clang/Serialization/GlobalModuleIndex.h b/interpreter/llvm-project/clang/include/clang/Serialization/GlobalModuleIndex.h index 2ff0f5845c1c6..93d674e440034 100644 --- a/interpreter/llvm-project/clang/include/clang/Serialization/GlobalModuleIndex.h +++ b/interpreter/llvm-project/clang/include/clang/Serialization/GlobalModuleIndex.h @@ -15,16 +15,12 @@ #ifndef LLVM_CLANG_SERIALIZATION_GLOBALMODULEINDEX_H #define LLVM_CLANG_SERIALIZATION_GLOBALMODULEINDEX_H -#include "clang/Basic/FileEntry.h" - #include "llvm/ADT/DenseMap.h" -#include #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" -#include "llvm/ADT/StringSet.h" #include #include @@ -44,12 +40,6 @@ namespace serialization { class ModuleFile; } -using llvm::SmallVector; -using llvm::SmallVectorImpl; -using llvm::StringRef; -using llvm::StringSet; -using serialization::ModuleFile; - /// A global index for a set of module files, providing information about /// the identifiers within those module files. /// @@ -62,6 +52,8 @@ using serialization::ModuleFile; /// imported, and can be queried to determine which modules the current /// translation could or should load to fix a problem. class GlobalModuleIndex { + using ModuleFile = serialization::ModuleFile; + /// Buffer containing the index file, which is lazily accessed so long /// as the global module index is live. std::unique_ptr Buffer; @@ -127,9 +119,6 @@ class GlobalModuleIndex { GlobalModuleIndex &operator=(const GlobalModuleIndex &) = delete; public: - using UserDefinedInterestingIDs = - llvm::StringMap>; - ~GlobalModuleIndex(); /// Read a global index file for the given directory. @@ -147,12 +136,6 @@ class GlobalModuleIndex { /// The caller accepts ownership of the returned object. IdentifierIterator *createIdentifierIterator() const; - /// Retrieve the set of modules that have up-to-date indexes. - /// - /// \param ModuleFiles Will be populated with the set of module file namess - /// that have been indexed. - void getKnownModuleFileNames(StringSet<> &ModuleFiles); - /// Retrieve the set of module files on which the given module file /// directly depends. void getModuleDependencies(ModuleFile *File, @@ -172,9 +155,6 @@ class GlobalModuleIndex { /// \returns true if the identifier is known to the index, false otherwise. bool lookupIdentifier(llvm::StringRef Name, HitSet &Hits); - typedef llvm::SmallDenseSet FileNameHitSet; - bool lookupIdentifier(StringRef Name, FileNameHitSet &Hits); - /// Note that the given module file has been loaded. /// /// \returns false if the global module index has information about this @@ -194,11 +174,9 @@ class GlobalModuleIndex { /// creating modules. /// \param Path The path to the directory containing module files, into /// which the global index will be written. - /// \param Optionally pass already precomputed interesting identifiers. static llvm::Error writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, - StringRef Path, - UserDefinedInterestingIDs *ExternalIDs = nullptr); + llvm::StringRef Path); }; } diff --git a/interpreter/llvm-project/clang/lib/AST/ASTImporter.cpp b/interpreter/llvm-project/clang/lib/AST/ASTImporter.cpp index 686f0068aeb48..13e7f93233a7f 100644 --- a/interpreter/llvm-project/clang/lib/AST/ASTImporter.cpp +++ b/interpreter/llvm-project/clang/lib/AST/ASTImporter.cpp @@ -10080,7 +10080,7 @@ Expected ASTImporter::Import(FileID FromID, bool IsBuiltin) { // FIXME: We want to re-use the existing MemoryBuffer! std::optional FromBuf = Cache->getBufferOrNone(FromContext.getDiagnostics(), - FromFileManager, SourceLocation{}); + FromSM.getFileManager(), SourceLocation{}); if (!FromBuf) return llvm::make_error(ASTImportError::Unknown); diff --git a/interpreter/llvm-project/clang/lib/AST/DeclTemplate.cpp b/interpreter/llvm-project/clang/lib/AST/DeclTemplate.cpp index 37412abcfbc75..fe8734d262a96 100644 --- a/interpreter/llvm-project/clang/lib/AST/DeclTemplate.cpp +++ b/interpreter/llvm-project/clang/lib/AST/DeclTemplate.cpp @@ -367,6 +367,12 @@ bool RedeclarableTemplateDecl::loadLazySpecializationsImpl( if (!ExternalSource) return false; + // If TPL is not null, it implies that we're loading specializations for + // partial templates. We need to load all specializations in such cases. + if (TPL) + return ExternalSource->LoadExternalSpecializations(this->getCanonicalDecl(), + /*OnlyPartial=*/false); + return ExternalSource->LoadExternalSpecializations(this->getCanonicalDecl(), Args); } diff --git a/interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp b/interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp index 7ae7188b7ef8f..e2451f294741d 100644 --- a/interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp +++ b/interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp @@ -28,10 +28,6 @@ char ExternalASTSource::ID; ExternalASTSource::~ExternalASTSource() = default; -uint32_t ExternalASTSource::getGeneration(const ASTContext &C) const { - return C.getGeneration(); -} - std::optional ExternalASTSource::getSourceDescriptor(unsigned ID) { return std::nullopt; @@ -118,5 +114,19 @@ void ExternalASTSource::FindExternalLexicalDecls( void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {} uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) { - return C.incrementGeneration(); + uint32_t OldGeneration = CurrentGeneration; + + // Make sure the generation of the topmost external source for the context is + // incremented. That might not be us. + auto *P = C.getExternalSource(); + if (P && P != this) + CurrentGeneration = P->incrementGeneration(C); + else { + // FIXME: Only bump the generation counter if the current generation number + // has been observed? + if (!++CurrentGeneration) + llvm::report_fatal_error("generation counter overflowed", false); + } + + return OldGeneration; } diff --git a/interpreter/llvm-project/clang/lib/AST/TemplateBase.cpp b/interpreter/llvm-project/clang/lib/AST/TemplateBase.cpp index 1ad0661c146ef..0eef8f305fcb3 100644 --- a/interpreter/llvm-project/clang/lib/AST/TemplateBase.cpp +++ b/interpreter/llvm-project/clang/lib/AST/TemplateBase.cpp @@ -130,14 +130,8 @@ static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out, } else Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")" << Val; - } else { + } else Out << Val; - // Handle cases where the value is too large to fit into the underlying type - // i.e. where the unsignedness matters. - if (T->isBuiltinType()) - if (Val.isUnsigned() && Val.getBitWidth() == 64 && Val.countLeadingOnes()) - Out << "ull"; - } } static unsigned getArrayDepth(QualType type) { diff --git a/interpreter/llvm-project/clang/lib/Basic/Diagnostic.cpp b/interpreter/llvm-project/clang/lib/Basic/Diagnostic.cpp index dec6f04a29143..9e2f134135647 100644 --- a/interpreter/llvm-project/clang/lib/Basic/Diagnostic.cpp +++ b/interpreter/llvm-project/clang/lib/Basic/Diagnostic.cpp @@ -183,29 +183,7 @@ void DiagnosticsEngine::DiagStateMap::append(SourceManager &SrcMgr, Offset = F->ParentOffset, F = F->Parent) { F->HasLocalTransitions = true; auto &Last = F->StateTransitions.back(); - if (Last.Offset > Offset) { - // Deal with a state change induce by recursive parsing. The first parsing is - // suspended and a (recursive) parsing is started between associated (in the upper/outer - // file) with a newer line (hence greater offset). After the end of the recursive - // parsing, we go back to the first parsing and any state change will done 'earlier' - // and trigger: - // assert(Last.Offset <= Offset && "state transitions added out of order"); - auto OnePastIt = std::upper_bound( - F->StateTransitions.begin(), F->StateTransitions.end(), Offset, - [](unsigned Offset, const DiagStatePoint &P) { - return Offset < P.Offset; - }); - if (OnePastIt == F->StateTransitions.begin() || (OnePastIt[-1].Offset != Offset)) { - F->StateTransitions.insert( OnePastIt, {State, Offset}); - } else { - auto &Prev = OnePastIt[-1]; - if (Prev.State == State) - break; - Prev.State = State; - continue; - } - continue; - } + assert(Last.Offset <= Offset && "state transitions added out of order"); if (Last.Offset == Offset) { if (Last.State == State) diff --git a/interpreter/llvm-project/clang/lib/Basic/FileManager.cpp b/interpreter/llvm-project/clang/lib/Basic/FileManager.cpp index c19ef63194ecf..f0b6f7be6c84f 100644 --- a/interpreter/llvm-project/clang/lib/Basic/FileManager.cpp +++ b/interpreter/llvm-project/clang/lib/Basic/FileManager.cpp @@ -221,25 +221,7 @@ llvm::Expected FileManager::getFileRef(StringRef Filename, // See if there is already an entry in the map. auto SeenFileInsertResult = SeenFileEntries.insert({Filename, std::errc::no_such_file_or_directory}); - - auto *NamedFileEnt = &*SeenFileInsertResult.first; - - const FileEntry *StaleFileEntry = 0; - bool needsRereading = false; - if (NamedFileEnt && NamedFileEnt->getValue()) { - FileEntryRef::MapValue Value = *NamedFileEnt->getValue(); - if (isa(Value.V)) { - auto found = FileEntriesToReread.find(cast(Value.V)); - if (found != FileEntriesToReread.end()) { - needsRereading = true; - StaleFileEntry = *found; - FileEntriesToReread.erase(found); - } - } - } - - // See if there is already an entry in the map. - if (!SeenFileInsertResult.second && !needsRereading) { + if (!SeenFileInsertResult.second) { if (!SeenFileInsertResult.first->second) return llvm::errorCodeToError( SeenFileInsertResult.first->second.getError()); @@ -248,6 +230,8 @@ llvm::Expected FileManager::getFileRef(StringRef Filename, // We've not seen this before. Fill it in. ++NumFileCacheMisses; + auto *NamedFileEnt = &*SeenFileInsertResult.first; + assert(!NamedFileEnt->second && "should be newly-created"); // Get the null-terminated file name as stored as the key of the // SeenFileEntries map. @@ -351,9 +335,7 @@ llvm::Expected FileManager::getFileRef(StringRef Filename, } FileEntryRef ReturnedRef(*NamedFileEnt); - if (ReusingEntry && - llvm::sys::toTimeT(Status.getLastModificationTime()) == UFE->ModTime) { - // Already have an entry with this inode, return it. + if (ReusingEntry) { // Already have an entry with this inode, return it. return ReturnedRef; } @@ -373,20 +355,6 @@ llvm::Expected FileManager::getFileRef(StringRef Filename, // We should still fill the path even if we aren't opening the file. fillRealPathName(UFE, InterndFileName); } - - if (StaleFileEntry) { - // Find occurrences of old FileEntry; update with new one: - for (auto& fe: SeenFileEntries) { - if (fe.getValue()) { - FileEntryRef::MapValue Value = *fe.getValue(); - if (isa(Value.V) && - cast(Value.V) == StaleFileEntry) { - fe.setValue(FileEntryRef::MapValue(*UFE, DirInfo)); - } - } - } - } - return ReturnedRef; } @@ -645,11 +613,6 @@ FileManager::getNoncachedStatValue(StringRef Path, return std::error_code(); } -void FileManager::invalidateCache(FileEntryRef Entry) { - assert(Entry && "Cannot invalidate a NULL FileEntry"); - FileEntriesToReread.insert(Entry); -} - void FileManager::GetUniqueIDMapping( SmallVectorImpl &UIDToFiles) const { UIDToFiles.clear(); diff --git a/interpreter/llvm-project/clang/lib/Basic/Module.cpp b/interpreter/llvm-project/clang/lib/Basic/Module.cpp index 2307aacf5194f..330108d5b3e47 100644 --- a/interpreter/llvm-project/clang/lib/Basic/Module.cpp +++ b/interpreter/llvm-project/clang/lib/Basic/Module.cpp @@ -44,7 +44,7 @@ Module::Module(ModuleConstructorTag, StringRef Name, IsSystem(false), IsExternC(false), IsInferred(false), InferSubmodules(false), InferExplicitSubmodules(false), InferExportWildcard(false), ConfigMacrosExhaustive(false), - NoUndeclaredIncludes(false), IsOptional(false), ModuleMapIsPrivate(false), + NoUndeclaredIncludes(false), ModuleMapIsPrivate(false), NamedModuleHasInit(true), NameVisibility(Hidden) { if (Parent) { IsAvailable = Parent->isAvailable(); @@ -52,7 +52,6 @@ Module::Module(ModuleConstructorTag, StringRef Name, IsSystem = Parent->IsSystem; IsExternC = Parent->IsExternC; NoUndeclaredIncludes = Parent->NoUndeclaredIncludes; - IsOptional = Parent->IsOptional; ModuleMapIsPrivate = Parent->ModuleMapIsPrivate; Parent->SubModules.push_back(this); diff --git a/interpreter/llvm-project/clang/lib/Basic/SourceManager.cpp b/interpreter/llvm-project/clang/lib/Basic/SourceManager.cpp index 9343b3a3ecced..b1f2180c1d462 100644 --- a/interpreter/llvm-project/clang/lib/Basic/SourceManager.cpp +++ b/interpreter/llvm-project/clang/lib/Basic/SourceManager.cpp @@ -356,25 +356,6 @@ bool SourceManager::isMainFile(const FileEntry &SourceFile) { return false; } -void SourceManager::invalidateCache(FileID FID) { - OptionalFileEntryRef Entry = getFileEntryRefForID(FID); - if (!Entry) - return; - if (ContentCache *&E = FileInfos[*Entry]) { - E->setBuffer(nullptr); - E = 0; - } - if (!FID.isInvalid()) { - const SrcMgr::SLocEntry& SLocE = getSLocEntry(FID); - if (SLocE.isFile()) { - SrcMgr::ContentCache& CC = - const_cast(SLocE.getFile().getContentCache()); - CC.setBuffer(nullptr); - } - } - getFileManager().invalidateCache(*Entry); -} - void SourceManager::initializeForReplay(const SourceManager &Old) { assert(MainFileID.isInvalid() && "expected uninitialized SourceManager"); @@ -1492,16 +1473,6 @@ StringRef SourceManager::getBufferName(SourceLocation Loc, auto B = getBufferOrNone(getFileID(Loc)); if (Invalid) *Invalid = !B; - - // Try to get the name without reading the buffer. - FileID FID = getFileID(Loc); - const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, Invalid); - if (!Invalid && Entry.isFile()) { - if (OptionalFileEntryRef FE = - Entry.getFile().getContentCache().ContentsEntry) - return FE->getName(); - } - return B ? B->getBufferIdentifier() : ""; } diff --git a/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp b/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp index 609e18a05b870..eb8d3ceeeba4c 100644 --- a/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp +++ b/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp @@ -3392,21 +3392,18 @@ llvm::Constant *CodeGenModule::EmitAnnotationString(StringRef Str) { llvm::Constant *CodeGenModule::EmitAnnotationUnit(SourceLocation Loc) { SourceManager &SM = getContext().getSourceManager(); - //PresumedLoc PLoc = SM.getPresumedLoc(Loc); - //if (PLoc.isValid()) - // return EmitAnnotationString(PLoc.getFilename()); + PresumedLoc PLoc = SM.getPresumedLoc(Loc); + if (PLoc.isValid()) + return EmitAnnotationString(PLoc.getFilename()); return EmitAnnotationString(SM.getBufferName(Loc)); } llvm::Constant *CodeGenModule::EmitAnnotationLineNo(SourceLocation L) { - return llvm::ConstantInt::get(Int32Ty, 1); -#if 0 SourceManager &SM = getContext().getSourceManager(); PresumedLoc PLoc = SM.getPresumedLoc(L); unsigned LineNo = PLoc.isValid() ? PLoc.getLine() : SM.getExpansionLineNumber(L); return llvm::ConstantInt::get(Int32Ty, LineNo); -#endif } llvm::Constant *CodeGenModule::EmitAnnotationArgs(const AnnotateAttr *Attr) { diff --git a/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.h b/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.h index 85bdb868e65a2..0956296e2d5d8 100644 --- a/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.h +++ b/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.h @@ -59,7 +59,6 @@ class FileSystem; namespace clang { class ASTContext; class AtomicType; -class CodeGeneratorImpl; // hack needed by cling class FunctionDecl; class IdentifierInfo; class ObjCImplementationDecl; @@ -1988,7 +1987,6 @@ class CodeGenModule : public CodeGenTypeCache { llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map, StringRef Suffix); - friend class clang::CodeGeneratorImpl; // hack needed by cling }; } // end namespace CodeGen diff --git a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp index 19e3bdd6e7758..d4e0ab0339a8b 100644 --- a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp @@ -29,14 +29,14 @@ using namespace clang; using namespace CodeGen; -namespace clang { +namespace { class CodeGeneratorImpl : public CodeGenerator { DiagnosticsEngine &Diags; ASTContext *Ctx; IntrusiveRefCntPtr FS; // Only used for debug info. const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info. const PreprocessorOptions &PreprocessorOpts; // Only used for debug info. - CodeGenOptions CodeGenOpts; // Intentionally copied in. + const CodeGenOptions &CodeGenOpts; unsigned HandlingTopLevelDecls; @@ -107,11 +107,6 @@ namespace clang { } llvm::Module *ReleaseModule() { - // Remove pending etc decls in case of error; the asserts in StartModule() - // will rightfully be confused otherwise, as none of the decls were - // emitted. - if (Diags.hasErrorOccurred()) - Builder->clear(); return M.release(); } @@ -138,119 +133,6 @@ namespace clang { return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition)); } - void print(llvm::raw_ostream& out) { - out << "\n\nCodeGen:\n"; - //llvm::SmallPtrSet WeakRefReferences; - out << " WeakRefReferences (llvm::SmallPtrSet)\n"; - for(auto I = Builder->WeakRefReferences.begin(), - E = Builder->WeakRefReferences.end(); I != E; ++I) { - (*I)->print(out); - out << "\n"; - } - - //llvm::StringMap DeferredDecls; - out << " DeferredDecls (llvm::StringMap)\n"; - for(auto I = Builder->DeferredDecls.begin(), - E = Builder->DeferredDecls.end(); I != E; ++I) { - out << I->first.str().c_str(); - I->second.getDecl()->print(out); - out << "\n"; - } - - //std::vector DeferredDeclsToEmit; - out << " DeferredDeclsToEmit (std::vector)\n"; - for(auto I = Builder->DeferredDeclsToEmit.begin(), - E = Builder->DeferredDeclsToEmit.end(); I != E; ++I) { - I->getDecl()->print(out); - out << "\n"; - } - - //std::vector Aliases; - out << " Aliases (std::vector)\n"; - for(auto I = Builder->Aliases.begin(), - E = Builder->Aliases.end(); I != E; ++I) { - I->getDecl()->print(out); - out << "\n"; - } - //typedef llvm::StringMap > - // ReplacementsTy; - //ReplacementsTy Replacements; - out - << " Replacements (llvm::StringMap>\n"; - for(auto I = Builder->Replacements.begin(), - E = Builder->Replacements.end(); I != E; ++I) { - out << I->first.str().c_str(); - (*I->second).print(out); - out << "\n"; - } - - //std::vector DeferredVTables; - out << " DeferredVTables (std::vector\n"; - for(auto I = Builder->DeferredVTables.begin(), - E = Builder->DeferredVTables.end(); I != E; ++I) { - (*I)->print(out); - out << "\n"; - } - - //std::vector LLVMUsed; - out << " LLVMUsed (std::vector >\n"; - for(auto I = Builder->LLVMUsed.begin(), - E = Builder->LLVMUsed.end(); I != E; ++I) { - (*I)->print(out); - out << "\n"; - } - - // typedef std::vector > CtorList; - //CtorList GlobalCtors; - out << " GlobalCtors (std::vector >\n"; - for(auto I = Builder->GlobalCtors.begin(), - E = Builder->GlobalCtors.end(); I != E; ++I) { - out << I->Initializer << " : " << I->AssociatedData; - out << "\n"; - } - - //CtorList GlobalDtors; - out << " GlobalDtors (std::vector >\n"; - for(auto I = Builder->GlobalDtors.begin(), - E = Builder->GlobalDtors.end(); I != E; ++I) { - out << I->Initializer << " : " << I->AssociatedData; - out << "\n"; - } - - //llvm::DenseMap MangledDeclNames; - //std::vector Annotations; - //llvm::StringMap AnnotationStrings; - //llvm::StringMap CFConstantStringMap; - //llvm::StringMap ConstantStringMap; - out << " ConstantStringMap (llvm::DenseMap)\n"; - for(auto I = Builder->ConstantStringMap.begin(), - E = Builder->ConstantStringMap.end(); I != E; ++I) { - I->first->print(out); - I->second->print(out); - out << "\n"; - } - - //llvm::DenseMap StaticLocalDeclMap; - //llvm::DenseMap StaticLocalDeclGuardMap; - //llvm::DenseMap MaterializedGlobalTemporaryMap; - //llvm::DenseMap AtomicSetterHelperFnMap; - //llvm::DenseMap AtomicGetterHelperFnMap; - //llvm::DenseMap TypeDescriptorMap; - //StaticExternCMap StaticExternCValues; - //std::vector > - // CXXThreadLocals; - //std::vector CXXThreadLocalInits; - //std::vector CXXGlobalInits; - //llvm::DenseMap DelayedCXXInitPosition; - //SmallVector PrioritizedCXXGlobalInits; - //std::vector > CXXGlobalDtors; - //llvm::SetVector ImportedModules; - //SmallVector LinkerOptionsMetadata; - // - out.flush(); - } - llvm::Module *StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C) { assert(!M && "Replacing existing Module?"); @@ -266,28 +148,6 @@ namespace clang { return M.get(); } - llvm::Module *StartModule(llvm::StringRef ModuleName, - llvm::LLVMContext& C, - const CodeGenOptions& CGO) { - CodeGenOpts = CGO; - return StartModule(ModuleName, C); - } - - void forgetGlobal(llvm::GlobalValue* GV) { - for (auto I = Builder->ConstantStringMap.begin(), - E = Builder->ConstantStringMap.end(); I != E; ++I) { - if (I->second == GV) { - Builder->ConstantStringMap.erase(I); - break; - } - } - } - - void forgetDecl(llvm::StringRef MangledName) { - Builder->DeferredDecls.erase(MangledName); - Builder->Manglings.erase(MangledName); - } - void Initialize(ASTContext &Context) override { Ctx = &Context; @@ -495,29 +355,11 @@ llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global, ->GetAddrOfGlobal(global, isForDefinition); } -void CodeGenerator::print(llvm::raw_ostream& out) { - static_cast(this)->print(out); -} - llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C) { return static_cast(this)->StartModule(ModuleName, C); } -llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName, - llvm::LLVMContext& C, - const CodeGenOptions& CGO) { - return static_cast(this)->StartModule(ModuleName, C, CGO); -} - -void CodeGenerator::forgetGlobal(llvm::GlobalValue* GV) { - static_cast(this)->forgetGlobal(GV); -} - -void CodeGenerator::forgetDecl(llvm::StringRef MangledName) { - static_cast(this)->forgetDecl(MangledName); -} - CodeGenerator * clang::CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName, IntrusiveRefCntPtr FS, diff --git a/interpreter/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/interpreter/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index 57460d91d83c4..48330e9361718 100644 --- a/interpreter/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/interpreter/llvm-project/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -548,11 +548,6 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, OptionalFileEntryRef File = PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); - - // Check if the file was virtual - if (!File) - File = SM.getFileManager().getOptionalFileRef(Filename); - if (!File) { Diags.Report(Pos.getLocWithOffset(PH.C - PH.Begin), diag::err_verify_missing_file) diff --git a/interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp b/interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp index 74d4cd86adc76..bf8fe44e4ca9c 100644 --- a/interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp @@ -212,9 +212,6 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName, if (FileMapOnly || HSOpts->PrebuiltModulePaths.empty()) return {}; - llvm::StringRef ModuleCachePath = getModuleCachePath(); - bool CacheFailure = true; - // Then go through each prebuilt module directory and try to find the pcm // file. for (const std::string &Dir : HSOpts->PrebuiltModulePaths) { @@ -229,13 +226,7 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName, ".pcm"); else llvm::sys::path::append(Result, ModuleName + ".pcm"); - // If we have the same ModuleCachePath and PrebuiltModulePath pointing - // to the same folder we should not cache the file lookup failure as it - // may be currently building an implicit module. - if (!ModuleCachePath.empty() && ModuleCachePath == Dir) - CacheFailure = false; - - if (getFileMgr().getOptionalFileRef(Result.str(), /*Open=*/false, CacheFailure)) + if (getFileMgr().getOptionalFileRef(Result)) return std::string(Result); } @@ -459,9 +450,7 @@ OptionalFileEntryRef HeaderSearch::getFileAndSuggestModule( std::error_code EC = llvm::errorToErrorCode(File.takeError()); if (EC != llvm::errc::no_such_file_or_directory && EC != llvm::errc::invalid_argument && - EC != llvm::errc::is_a_directory && - EC != llvm::errc::not_a_directory && - EC != llvm::errc::permission_denied) { + EC != llvm::errc::is_a_directory && EC != llvm::errc::not_a_directory) { Diags.Report(IncludeLoc, diag::err_cannot_open_file) << FileName << EC.message(); } @@ -960,9 +949,13 @@ OptionalFileEntryRef HeaderSearch::LookupFile( // If we have no includer, that means we're processing a #include // from a module build. We should treat this as a system header if we're // building a [system] module. - bool IncluderIsSystemHeader = - Includer ? getFileInfo(*Includer).DirInfo != SrcMgr::C_User : - BuildSystemModule; + bool IncluderIsSystemHeader = [&]() { + if (!Includer) + return BuildSystemModule; + const HeaderFileInfo *HFI = getExistingFileInfo(*Includer); + assert(HFI && "includer without file info"); + return HFI->DirInfo != SrcMgr::C_User; + }(); if (OptionalFileEntryRef FE = getFileAndSuggestModule( TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader, RequestingModule, SuggestedModule)) { diff --git a/interpreter/llvm-project/clang/lib/Lex/Lexer.cpp b/interpreter/llvm-project/clang/lib/Lex/Lexer.cpp index 75dcea2e1d5bc..087c6f13aea66 100644 --- a/interpreter/llvm-project/clang/lib/Lex/Lexer.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/Lexer.cpp @@ -857,10 +857,6 @@ SourceLocation Lexer::getLocForEndOfToken(SourceLocation Loc, unsigned Offset, return {}; // Points inside the macro expansion. } - // Don't hit the file system for ASTReader tokens. - if (SM.isLoadedSourceLocation(Loc)) - return Loc; - unsigned Len = Lexer::MeasureTokenLength(Loc, SM, LangOpts); if (Len > Offset) Len = Len - Offset; diff --git a/interpreter/llvm-project/clang/lib/Lex/ModuleMap.cpp b/interpreter/llvm-project/clang/lib/Lex/ModuleMap.cpp index d24aaa5e17b77..ccf94f6345ff2 100644 --- a/interpreter/llvm-project/clang/lib/Lex/ModuleMap.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/ModuleMap.cpp @@ -315,8 +315,6 @@ void ModuleMap::resolveHeader(Module *Mod, // this was supposed to modularize the builtin header alone. } else if (Header.Kind == Module::HK_Excluded) { // Ignore missing excluded header files. They're optional anyway. - } else if (Mod->IsOptional) { - // Optional submodules can have missing headers. } else { // If we find a module that has a missing header, we mark this module as // unavailable and store the header directive for displaying diagnostics. @@ -1116,7 +1114,6 @@ Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir, Result->IsExternC |= Attrs.IsExternC; Result->ConfigMacrosExhaustive |= Attrs.IsExhaustive; Result->NoUndeclaredIncludes |= Attrs.NoUndeclaredIncludes; - Result->IsOptional |= Attrs.IsOptional; Result->Directory = FrameworkDir; // Chop off the first framework bit, as that is implied. @@ -1866,10 +1863,7 @@ namespace { AT_exhaustive, /// The 'no_undeclared_includes' attribute. - AT_no_undeclared_includes, - - /// The 'optional' attribute. - AT_optional + AT_no_undeclared_includes }; } // namespace @@ -2147,8 +2141,6 @@ void ModuleMapParser::parseModuleDecl() { ActiveModule->IsExternC = true; if (Attrs.NoUndeclaredIncludes) ActiveModule->NoUndeclaredIncludes = true; - if (Attrs.IsOptional) - ActiveModule->IsOptional = true; ActiveModule->Directory = Directory; StringRef MapFileName( @@ -3052,7 +3044,6 @@ bool ModuleMapParser::parseOptionalAttributes(Attributes &Attrs) { .Case("exhaustive", AT_exhaustive) .Case("extern_c", AT_extern_c) .Case("no_undeclared_includes", AT_no_undeclared_includes) - .Case("optional", AT_optional) .Case("system", AT_system) .Default(AT_unknown); switch (Attribute) { @@ -3076,10 +3067,6 @@ bool ModuleMapParser::parseOptionalAttributes(Attributes &Attrs) { case AT_no_undeclared_includes: Attrs.NoUndeclaredIncludes = true; break; - - case AT_optional: - Attrs.IsOptional = true; - break; } consumeToken(); diff --git a/interpreter/llvm-project/clang/lib/Lex/PPDirectives.cpp b/interpreter/llvm-project/clang/lib/Lex/PPDirectives.cpp index 19e49fc628c92..a29b73f97ab7e 100644 --- a/interpreter/llvm-project/clang/lib/Lex/PPDirectives.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/PPDirectives.cpp @@ -988,7 +988,7 @@ OptionalFileEntryRef Preprocessor::LookupFile( // stack, record the parent #includes. SmallVector, 16> Includers; bool BuildSystemModule = false; - if (!FromDir && !FromFile && getCurrentFileLexer()) { + if (!FromDir && !FromFile) { FileID FID = getCurrentFileLexer()->getFileID(); OptionalFileEntryRef FileEnt = SourceMgr.getFileEntryRefForID(FID); diff --git a/interpreter/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp b/interpreter/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp index 68961144b4b0d..347c13da0ad21 100644 --- a/interpreter/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp @@ -91,20 +91,6 @@ void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){ II->setChangedSinceDeserialization(); } -void Preprocessor::removeMacro(IdentifierInfo *II, MacroDirective *MD) { - assert(II && MD); - II->setHasMacroDefinition(false); - CurSubmoduleState->Macros.erase(II); - if (MacroDirective* prevMD = MD->getPrevious()) { - // Avoid assertion in appendMacroDirective. - MacroDirective* prevPrevMD = prevMD->getPrevious(); - prevMD->setPrevious(0); - appendMacroDirective(II, prevMD); - prevMD->setPrevious(prevPrevMD); - } -} - - void Preprocessor::setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD) { diff --git a/interpreter/llvm-project/clang/lib/Lex/Preprocessor.cpp b/interpreter/llvm-project/clang/lib/Lex/Preprocessor.cpp index 19dd29090df5f..5ac5e6feae144 100644 --- a/interpreter/llvm-project/clang/lib/Lex/Preprocessor.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/Preprocessor.cpp @@ -271,43 +271,6 @@ void Preprocessor::DumpMacro(const MacroInfo &MI) const { llvm::errs() << "\n"; } -void Preprocessor::printMacros(raw_ostream &OS) const { - for (macro_iterator I = macro_begin(), E = macro_end(); I != E; ++I) { - Preprocessor::printMacro(I->first, I->second.getLatest(), OS); - } -} - -void Preprocessor::printMacro(const IdentifierInfo* II,const MacroDirective *MD, - llvm::raw_ostream &OS) const { - OS << ""; - OS << II->getName() << " "; - OS << "(Tokens:)"; - const MacroInfo* MI = MD->getMacroInfo(); - for (unsigned i = 0, e = MI->getNumTokens(); i != e; ++i) { - const Token &Tok = MI->getReplacementToken(i); - OS << tok::getTokenName(Tok.getKind()) << " '" - << getSpelling(Tok) << "'"; - OS << "\t"; - if (Tok.isAtStartOfLine()) - OS << " [StartOfLine]"; - if (Tok.hasLeadingSpace()) - OS << " [LeadingSpace]"; - if (Tok.isExpandDisabled()) - OS << " [ExpandDisabled]"; - if (Tok.needsCleaning()) { - const char *Start = SourceMgr.getCharacterData(Tok.getLocation()); - OS << " [UnClean='" << StringRef(Start, Tok.getLength()) - << "']"; - } - //Do not print location it uses the SourceManager dump to llvm::errs. - OS << "\tLoc=<"; - Tok.getLocation().print(OS, SourceMgr); - OS << ">"; - OS << " "; - } - OS << "\n"; -} - void Preprocessor::PrintStats() { llvm::errs() << "\n*** Preprocessor Stats:\n"; llvm::errs() << NumDirectives << " directives found:\n"; diff --git a/interpreter/llvm-project/clang/lib/Sema/Sema.cpp b/interpreter/llvm-project/clang/lib/Sema/Sema.cpp index 1fa2e17c3a67e..e0eac690e6e65 100644 --- a/interpreter/llvm-project/clang/lib/Sema/Sema.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/Sema.cpp @@ -1517,7 +1517,7 @@ void Sema::ActOnEndOfTranslationUnit() { } if (!Diags.isIgnored(diag::warn_mismatched_delete_new, SourceLocation())) { - if (ExternalSource && !PP.isIncrementalProcessingEnabled()) + if (ExternalSource) ExternalSource->ReadMismatchingDeleteExpressions(DeleteExprs); for (const auto &DeletedFieldInfo : DeleteExprs) { for (const auto &DeleteExprLoc : DeletedFieldInfo.second) { @@ -1525,7 +1525,6 @@ void Sema::ActOnEndOfTranslationUnit() { DeleteExprLoc.second); } } - DeleteExprs.clear(); } AnalysisWarnings.IssueWarnings(Context.getTranslationUnitDecl()); diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaCXXScopeSpec.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaCXXScopeSpec.cpp index f72516003ad86..f04f7f9929442 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -190,7 +190,7 @@ CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) { /// a class template specialization that is not a complete type, we /// will attempt to instantiate that class template. bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS, - DeclContext *&DC) { + DeclContext *DC) { assert(DC && "given null context"); TagDecl *tag = dyn_cast(DC); @@ -216,12 +216,6 @@ bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS, // The type must be complete. if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec, SS.getRange())) { - // The actual information about the decl may have been loaded via an - // external source that created a new AST node/decl for the definition - // rather than reusing the one we had (DC) like the ASTReader does. - // To avoid the caller to continue using the still incomplete decl, let's - // set it to the definition. - DC = tag->getDefinition(); SS.SetInvalid(SS.getRange()); return true; } @@ -450,15 +444,9 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, // nested-name-specifier. // The declaration context must be complete. - if (!LookupCtx->isDependentContext()) { - if (RequireCompleteDeclContext(SS, LookupCtx)) { - return true; - } else if (TagDecl* TD = dyn_cast(LookupCtx)) { - // Update the DeclContext to point to the Tag definition. - LookupCtx = TD->getDefinition(); - } - } - + if (!LookupCtx->isDependentContext() && + RequireCompleteDeclContext(SS, LookupCtx)) + return true; LookupQualifiedName(Found, LookupCtx); diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaDecl.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaDecl.cpp index 6054f97055acc..320ffba55c4bf 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaDecl.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaDecl.cpp @@ -352,14 +352,9 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, return nullptr; } - if (!LookupCtx->isDependentContext()) { - if (RequireCompleteDeclContext(*SS, LookupCtx)) { - return nullptr; - } else if (TagDecl* TD = dyn_cast(LookupCtx)) { - // Update the DeclContext to point to the Tag definition. - LookupCtx = TD->getDefinition(); - } - } + if (!LookupCtx->isDependentContext() && + RequireCompleteDeclContext(*SS, LookupCtx)) + return nullptr; } // In the case where we know that the identifier is a class name, we know that @@ -16924,28 +16919,6 @@ bool Sema::CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, return true; } } else if (IsFixed != Prev->isFixed()) { - // Determine whether this is a cling fwd decl. - auto hasFwdDeclAnnotation = [](const Decl *Prev) -> bool { - for(auto attr = Prev->specific_attr_begin(), - end = Prev->specific_attr_end (); - attr != end; - ++attr) - { - if (!attr->isInherited()) { - llvm::StringRef annotation = attr->getAnnotation(); - assert(!annotation.empty() && "Empty annotation!"); - if (annotation.starts_with("$clingAutoload$")) { - // autoload annotation. - return true; - } - } - } - return false; - }; - - if (hasFwdDeclAnnotation(Prev)) - return false; - Diag(EnumLoc, diag::err_enum_redeclare_fixed_mismatch) << Prev->isFixed(); Diag(Prev->getLocation(), diag::note_previous_declaration); diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp index 3a3e0738257aa..85de46c9adab4 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp @@ -542,8 +542,6 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, } } - (void)DiagDefaultParamID; -#if 0 // Disable until Diag is rewired // FIXME: If we knew where the '=' was, we could easily provide a fix-it // hint here. Alternatively, we could walk the type-source information // for NewParam to find the last source location in the type... but it @@ -565,7 +563,6 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Diag(OldParam->getLocation(), diag::note_previous_definition) << OldParam->getDefaultArgRange(); -#endif } else if (OldParamHasDfl) { // Merge the old default argument into the new parameter unless the new // function is a friend declaration in a template class. In the latter @@ -13243,7 +13240,7 @@ bool Sema::CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, if (Cxx20Enumerator) return false; // OK - DeclContext *RD = NamedContext + auto *RD = NamedContext ? cast(NamedContext->getRedeclContext()) : nullptr; if (RD && !RequireCompleteDeclContext(const_cast(SS), RD)) { diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaExpr.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaExpr.cpp index 40f4d895327e6..23d0f9532d4f8 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaExpr.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaExpr.cpp @@ -14840,47 +14840,6 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc, switch (Opc) { case BO_Assign: - // ROOT hack: we want to support constructs like n = new TNamed() and if n - // wasn't declared we should declare it. - if (DeclRefExpr* DRE = dyn_cast(LHSExpr)) { - if (VarDecl* VD = dyn_cast(DRE->getDecl())) { - if (const AutoType* aTy = dyn_cast(VD->getType().getTypePtr())) { - if (const AnnotateAttr* A = VD->getAttr()) { - // If the deduction didn't take place and it is our special - // annotation - if (!aTy->isDeduced() && A->getAnnotation() == "__Auto") { - QualType ResTy; - ASTContext& C = getASTContext(); - TypeSourceInfo* TrivialTSI - = C.getTrivialTypeSourceInfo(VD->getType()); - TemplateDeductionInfo Info(RHSExpr->getExprLoc()); - TemplateDeductionResult Result = - DeduceAutoType(TrivialTSI->getTypeLoc(), RHSExpr, ResTy, Info); - if (Result != TemplateDeductionResult::Success && - Result != TemplateDeductionResult::AlreadyDiagnosed) { - Diag(VD->getLocation(), diag::err_auto_var_requires_init) - << VD->getDeclName() << VD->getType(); - VD->setInvalidDecl(); - - return ExprError(); - } - if (!ResTy.isNull()) { - VD->setTypeSourceInfo(C.getTrivialTypeSourceInfo(ResTy)); - VD->setType(ResTy); - } - VD->setInit(DefaultLvalueConversion(RHSExpr).get()); - PushOnScopeChains(VD, getCurScope(), /*Add to ctx*/true); - - // Here we need to return 'something' to make the parser happy. - // A reference to the decl is semantically closest to what we want. - return BuildDeclRefExpr(VD, VD->getType(), VK_LValue, - SourceLocation()); - } - } - } - } - } - ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, QualType(), Opc); if (getLangOpts().CPlusPlus && LHS.get()->getObjectKind() != OK_ObjCProperty) { diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaExprCXX.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaExprCXX.cpp index 47c9fd3f6134a..c6621402adfc9 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaExprCXX.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaExprCXX.cpp @@ -106,8 +106,7 @@ ParsedType Sema::getConstructorName(const IdentifierInfo &II, return ParsedType::make(T); } - DeclContext *DC = CurClass; - if (SS.isNotEmpty() && RequireCompleteDeclContext(SS, DC)) + if (SS.isNotEmpty() && RequireCompleteDeclContext(SS, CurClass)) return ParsedType(); // Find the injected-class-name declaration. Note that we make no attempt to diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaLookup.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaLookup.cpp index 1d2053050e6a6..0f5b7426e743e 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaLookup.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaLookup.cpp @@ -2277,14 +2277,8 @@ bool Sema::LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation, } } else { // Perform C++ unqualified name lookup. - if (CppLookupName(R, S)) { - if (R.isSingleResult()) - if (const TagDecl *TD = dyn_cast(R.getFoundDecl())) { - if (!TD->getDefinition() && ExternalSource) - ExternalSource->LookupUnqualified(R, S); - } + if (CppLookupName(R, S)) return true; - } } // If we didn't find a use of this identifier, and if the identifier diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaModule.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaModule.cpp index 663994a7af0a7..76589bff40be9 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaModule.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaModule.cpp @@ -657,7 +657,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, diag::warn_import_implementation_partition_unit_in_interface_unit) << Mod->Name; - //checkModuleImportContext(*this, Mod, ImportLoc, CurContext); + checkModuleImportContext(*this, Mod, ImportLoc, CurContext); // FIXME: we should support importing a submodule within a different submodule // of the same top-level module. Until we do, make it an error rather than diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaTemplate.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaTemplate.cpp index 0eb3fa3df743f..1c555b38277b0 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaTemplate.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaTemplate.cpp @@ -428,11 +428,6 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS, // The declaration context must be complete. if (LookupCtx && RequireCompleteDeclContext(SS, LookupCtx)) return true; - - if (TagDecl* TD = dyn_cast_or_null(LookupCtx)) { - // Update the DeclContext to point to the Tag definition. - LookupCtx = TD->getDefinition(); - } } bool ObjectTypeSearchedInScope = false; @@ -1783,12 +1778,6 @@ static void SetNestedNameSpecifier(Sema &S, TagDecl *T, if (SS.isSet()) T->setQualifierInfo(SS.getWithLocInContext(S.Context)); } -static bool IsRootAutoloadDeclTemplate(ClassTemplateDecl *D) { - for (TagDecl *TD = D->getTemplatedDecl(); TD; TD = TD->getPreviousDecl()) - if (auto AnnotAttr = TD->getAttr()) - return AnnotAttr->getAnnotation().starts_with("$clingAutoload$"); - return false; -} // Returns the template parameter list with all default template argument // information. @@ -2075,20 +2064,6 @@ DeclResult Sema::CheckClassTemplate( return true; } - // AXEL - do not check for redecls of template arg defaults when parsing - // dictionary forward decls. - bool fwdDeclFromROOT = false; - for (const auto &A : Attr) { - if (A.getKind() != ParsedAttr::AT_Annotate) - continue; - if (A.getNumArgs() > 0 && A.isArgExpr(0)) - if (auto AnnotVal = dyn_cast(A.getArgAsExpr(0))) - if (AnnotVal->getString().starts_with("$clingAutoload$")) - fwdDeclFromROOT = true; - } - if (!fwdDeclFromROOT && PrevClassTemplate) - fwdDeclFromROOT = IsRootAutoloadDeclTemplate(PrevClassTemplate); - // Check the template parameter list of this declaration, possibly // merging in the template parameter list from the previous class // template declaration. Skip this check for a friend in a dependent @@ -2103,7 +2078,7 @@ DeclResult Sema::CheckClassTemplate( ? TPC_ClassTemplateMember : TUK == TagUseKind::Friend ? TPC_FriendClassTemplate : TPC_Other, - SkipBody, /*Complain*/!fwdDeclFromROOT)) + SkipBody)) Invalid = true; if (SS.isSet()) { @@ -2335,8 +2310,7 @@ static bool DiagnoseUnexpandedParameterPacks(Sema &S, bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, TemplateParameterList *OldParams, TemplateParamListContext TPC, - SkipBodyInfo *SkipBody, - bool Complain /*true*/) { + SkipBodyInfo *SkipBody) { bool Invalid = false; // C++ [temp.param]p10: @@ -2378,7 +2352,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, if (TemplateTypeParmDecl *NewTypeParm = dyn_cast(*NewParam)) { // Check the presence of a default argument here. - if (Complain && NewTypeParm->hasDefaultArgument() && + if (NewTypeParm->hasDefaultArgument() && DiagnoseDefaultTemplateArgument( *this, TPC, NewTypeParm->getLocation(), NewTypeParm->getDefaultArgument().getSourceRange())) @@ -2432,7 +2406,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, } // Check the presence of a default argument here. - if (Complain && NewNonTypeParm->hasDefaultArgument() && + if (NewNonTypeParm->hasDefaultArgument() && DiagnoseDefaultTemplateArgument( *this, TPC, NewNonTypeParm->getLocation(), NewNonTypeParm->getDefaultArgument().getSourceRange())) { @@ -2483,7 +2457,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, } // Check the presence of a default argument here. - if (Complain && NewTemplateParm->hasDefaultArgument() && + if (NewTemplateParm->hasDefaultArgument() && DiagnoseDefaultTemplateArgument(*this, TPC, NewTemplateParm->getLocation(), NewTemplateParm->getDefaultArgument().getSourceRange())) @@ -2537,14 +2511,6 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, Invalid = true; } - if (RedundantDefaultArg && - (((*OldParam)->hasAttr() && - (*OldParam)->getAttr()->getAnnotation() == "rootmap") || - ((*NewParam)->hasAttr() && - (*NewParam)->getAttr()->getAnnotation() == "rootmap"))) { - RedundantDefaultArg = false; - } - // [basic.def.odr]/13: // There can be more than one definition of a // ... @@ -2558,13 +2524,11 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, // argument to be repeated across translation unit. Note that the ODR is // checked elsewhere. But it is still not allowed to repeat template default // argument in the same translation unit. - if (Complain && RedundantDefaultArg) { -#if 0 // Disable until Diag is rewired + if (RedundantDefaultArg) { Diag(NewDefaultLoc, diag::err_template_param_default_arg_redefinition); Diag(OldDefaultLoc, diag::note_template_param_prev_default_arg); -#endif Invalid = true; - } else if (Complain && InconsistentDefaultArg) { + } else if (InconsistentDefaultArg) { // We could only diagnose about the case that the OldParam is imported. // The case NewParam is imported should be handled in ASTReader. Diag(NewDefaultLoc, @@ -2573,7 +2537,7 @@ bool Sema::CheckTemplateParameterList(TemplateParameterList *NewParams, diag::note_template_param_prev_default_arg_in_other_module) << PrevModuleName; Invalid = true; - } else if (Complain && MissingDefaultArg && + } else if (MissingDefaultArg && (TPC == TPC_Other || TPC == TPC_TemplateTemplateParameterPack || TPC == TPC_FriendClassTemplate)) { // C++ 23[temp.param]p14: diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp index 2745ca0e718c9..73567f3be814d 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -4198,16 +4198,6 @@ static ActionResult getPatternForClassTemplateSpecialization( } Pattern = PartialSpec; } else { - // -- If no matches are found, the instantiation is generated - // from the primary template. - - // Try first to get it externally: - if(S.getExternalSource()) { - S.getExternalSource()->CompleteType(ClassTemplateSpec); - if (ClassTemplateSpec->getDefinition()) - return ClassTemplateSpec; - } - ClassTemplateDecl *Template = ClassTemplateSpec->getSpecializedTemplate(); while (Template->getInstantiatedFromMemberTemplate()) { // If we've found an explicit specialization of this class template, diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaType.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaType.cpp index fd3b936c195a1..77b52b832d771 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaType.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaType.cpp @@ -9372,9 +9372,7 @@ bool Sema::RequireCompleteTypeImpl(SourceLocation Loc, QualType T, // Give the external AST source a chance to complete the type. if (auto *Source = Context.getExternalSource()) { - // AXEL: allows ROOT to autoload/-parse template specializations before - // trying to instantiate through the template definition. See ROOT-7462. - if (Tag /*&& Tag->hasExternalLexicalStorage()*/) + if (Tag && Tag->hasExternalLexicalStorage()) Source->CompleteType(Tag); if (IFace && IFace->hasExternalLexicalStorage()) Source->CompleteType(IFace); diff --git a/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp b/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp index ac32f8bb8cad8..427b3c82c4737 100644 --- a/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp +++ b/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp @@ -2049,14 +2049,6 @@ Token ASTReader::ReadToken(ModuleFile &M, const RecordDataImpl &Record, if (IdentifierInfo *II = getLocalIdentifier(M, Record[Idx++])) Tok.setIdentifierInfo(II); } - - if (Tok.isLiteral()) { - const RecordData& RD = reinterpret_cast(Record); - std::string* Lit = new std::string(ReadString(RD, Idx)); - TokenLiteralDataLoaded.push_back(Lit); - Tok.setLiteralData(Lit->c_str()); - } - return Tok; } @@ -2471,7 +2463,7 @@ void ASTReader::markIdentifierUpToDate(const IdentifierInfo *II) { // Update the generation for this identifier. if (getContext().getLangOpts().Modules) - IdentifierGeneration[II] = getGenerationOrNull(); + IdentifierGeneration[II] = getGeneration(); } void ASTReader::resolvePendingMacro(IdentifierInfo *II, @@ -2741,12 +2733,8 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { // For an overridden file, create a virtual file with the stored // size/timestamp. - bool DisableValidation = bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & - DisableValidationForModuleKind::All); - if ((Overridden || Transient || SkipChecks) && (!File || DisableValidation)) { + if ((Overridden || Transient || SkipChecks) && !File) File = FileMgr.getVirtualFileRef(*Filename, StoredSize, StoredTime); - Overridden = true; - } if (!File) { if (Complain) { @@ -3090,10 +3078,9 @@ ASTReader::ReadControlBlock(ModuleFile &F, // All user input files reside at the index range [0, NumUserInputs), and // system input files reside at [NumUserInputs, NumInputs). For explicitly // loaded module files, ignore missing inputs. - bool Validate = !DisableValidation && F.Kind != MK_ExplicitModule && - F.Kind != MK_PrebuiltModule; + if (!DisableValidation && F.Kind != MK_ExplicitModule && + F.Kind != MK_PrebuiltModule) { bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; - Complain &= Validate; // If we are reading a module, we will create a verification timestamp, // so we verify all input files. Otherwise, verify only user input @@ -3105,13 +3092,12 @@ ASTReader::ReadControlBlock(ModuleFile &F, F.Kind == MK_ImplicitModule) N = NumUserInputs; - for (unsigned I = 0; I < NumInputs; ++I) { - if (I == N) - Complain = false; + for (unsigned I = 0; I < N; ++I) { InputFile IF = getInputFile(F, I+1, Complain); - if (Validate && (!IF.getFile() || IF.isOutOfDate())) + if (!IF.getFile() || IF.isOutOfDate()) return OutOfDate; } + } if (Listener) Listener->visitModuleFile(F.FileName, F.Kind); @@ -3159,7 +3145,7 @@ ASTReader::ReadControlBlock(ModuleFile &F, // // FIXME: Allow this for files explicitly specified with -include-pch. bool AllowCompatibleConfigurationMismatch = - F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; + F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; ASTReadResult Result = ReadOptionsBlock(Stream, F.FileName, ClientLoadCapabilities, @@ -3318,28 +3304,6 @@ ASTReader::ReadControlBlock(ModuleFile &F, } } - // Check if ImportedFile exists on disk - if (!llvm::sys::fs::is_directory(ImportedFile)) { - StringRef ModuleName = llvm::sys::path::filename(ImportedFile.c_str()); - ModuleName.consume_back(".pcm"); - // Get clang::Module pointer by looking up the module name - HeaderSearch &HS = PP.getHeaderSearchInfo(); - Module *M = HS.lookupModule(ModuleName, SourceLocation(), - /*AllowSearch*/ true, - /*AllowExtraModuleMapSearch*/ true); - if (M) { - std::string Path = HS.getPrebuiltModuleFileName(M->Name); - if (Path.empty()) - Path = HS.getCachedModuleFileName( - M->Name, - HS.getModuleMap().getModuleMapFileForUniquing(M)->getName()); - // FIXME: Add a hash comparison to check if ImportedFile's hash and - // the new Modules Path's hash matches or not. - if (!Path.empty()) - ImportedFile = Path; - } - } - // If our client can't cope with us being out of date, we can't cope with // our dependency being missing. unsigned Capabilities = ClientLoadCapabilities; @@ -4385,32 +4349,10 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { ? ModuleMgr.lookupByModuleName(Name) : ModuleMgr.lookupByFileName(Name)); if (!OM) { - StringRef ModuleName = llvm::sys::path::filename(Name); - ModuleName.consume_back(".pcm"); - HeaderSearch &HS = PP.getHeaderSearchInfo(); - Module *M = HS.lookupModule(ModuleName, SourceLocation(), - /*AllowSearch*/ true, - /*AllowExtraModuleMapSearch*/ true); - std::string Path; - // If module definition exists in modulemap, search the modulepath in - // HeaderSearchInfo - if (M) { - Path = HS.getPrebuiltModuleFileName(M->Name); - if (Path.empty()) - Path = HS.getCachedModuleFileName( - M->Name, - HS.getModuleMap().getModuleMapFileForUniquing(M)->getName()); - } - - StringRef NewName = StringRef(Path); - OM = ModuleMgr.lookupByFileName(NewName); - if (!OM) { - std::string Msg = - "SourceLocation remap refers to unknown module, cannot find "; - Msg.append(std::string(NewName)); - Error(Msg); - return; - } + std::string Msg = "refers to unknown module, cannot find "; + Msg.append(std::string(Name)); + Error(Msg); + return; } ImportedModuleVector.push_back(OM); @@ -4490,15 +4432,9 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, assert(M && M->Name == F.ModuleName && "found module with different name"); - // Check any additional module map files (e.g. module.private.modulemap) - // that are not in the pcm. - bool DisableValidation = - PP.getPreprocessorOpts().DisablePCHOrModuleValidation != - DisableValidationForModuleKind::None; - // Check the primary module map file. auto StoredModMap = FileMgr.getOptionalFileRef(F.ModuleMapPath); - if (!DisableValidation && (!StoredModMap || *StoredModMap != ModMap)) { + if (!StoredModMap || *StoredModMap != ModMap) { assert(ModMap && "found module is missing module map file"); assert((ImportedBy || F.Kind == MK_ImplicitModule) && "top-level import should be verified"); @@ -4523,7 +4459,8 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, AdditionalStoredMaps.insert(*SF); } - if (!DisableValidation) { + // Check any additional module map files (e.g. module.private.modulemap) + // that are not in the pcm. if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) { for (FileEntryRef ModMap : *AdditionalModuleMaps) { // Remove files that match @@ -4546,7 +4483,6 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, return OutOfDate; } } - } if (Listener) Listener->ReadModuleMapFile(F.ModuleMapPath); @@ -5022,10 +4958,11 @@ ASTReader::ReadASTCore(StringRef FileName, unsigned ClientLoadCapabilities) { ModuleFile *M; std::string ErrorStr; - ModuleManager::AddModuleResult AddResult = - ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, - getGenerationOrNull(), ExpectedSize, ExpectedModTime, - ExpectedSignature, readASTFileSignature, M, ErrorStr); + ModuleManager::AddModuleResult AddResult + = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, + getGeneration(), ExpectedSize, ExpectedModTime, + ExpectedSignature, readASTFileSignature, + M, ErrorStr); switch (AddResult) { case ModuleManager::AlreadyLoaded: @@ -7947,8 +7884,14 @@ void ASTReader::CompleteRedeclChain(const Decl *D) { } } - if (Template) - Template->loadLazySpecializationsImpl(Args); + if (Template) { + // For partitial specialization, load all the specializations for safety. + if (isa(D)) + Template->loadLazySpecializationsImpl(); + else + Template->loadLazySpecializationsImpl(Args); + } } CXXCtorInitializer ** @@ -9200,7 +9143,7 @@ void ASTReader::ReadMethodPool(Selector Sel) { // Get the selector generation and update it to the current generation. unsigned &Generation = SelectorGeneration[Sel]; unsigned PriorGeneration = Generation; - Generation = getGenerationOrNull(); + Generation = getGeneration(); SelectorOutOfDate[Sel] = false; // Search for methods defined with this selector. @@ -10972,9 +10915,6 @@ ASTReader::ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache, ASTReader::~ASTReader() { if (OwnsDeserializationListener) delete DeserializationListener; - for (auto PStr: TokenLiteralDataLoaded) { - delete PStr; - } } IdentifierResolver &ASTReader::getIdResolver() { diff --git a/interpreter/llvm-project/clang/lib/Serialization/ASTReaderInternals.h b/interpreter/llvm-project/clang/lib/Serialization/ASTReaderInternals.h index cacef385acc45..4be2b2323ec40 100644 --- a/interpreter/llvm-project/clang/lib/Serialization/ASTReaderInternals.h +++ b/interpreter/llvm-project/clang/lib/Serialization/ASTReaderInternals.h @@ -46,7 +46,7 @@ class ASTDeclContextNameLookupTraitBase { public: // Maximum number of lookup tables we allow before condensing the tables. - static const int MaxTables = 256; + static const int MaxTables = 4; /// The lookup result is a list of global declaration IDs. using data_type = SmallVector; diff --git a/interpreter/llvm-project/clang/lib/Serialization/ASTWriter.cpp b/interpreter/llvm-project/clang/lib/Serialization/ASTWriter.cpp index 4333f0b95b853..2d0fae8b64d07 100644 --- a/interpreter/llvm-project/clang/lib/Serialization/ASTWriter.cpp +++ b/interpreter/llvm-project/clang/lib/Serialization/ASTWriter.cpp @@ -5227,9 +5227,6 @@ void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { // is needed. AddIdentifierRef(Tok.getIdentifierInfo(), Record); } - - if (Tok.isLiteral()) - AddString(StringRef(Tok.getLiteralData(), Tok.getLength()), Record); } void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { diff --git a/interpreter/llvm-project/clang/lib/Serialization/GlobalModuleIndex.cpp b/interpreter/llvm-project/clang/lib/Serialization/GlobalModuleIndex.cpp index 27c104a048746..4b920fccecac3 100644 --- a/interpreter/llvm-project/clang/lib/Serialization/GlobalModuleIndex.cpp +++ b/interpreter/llvm-project/clang/lib/Serialization/GlobalModuleIndex.cpp @@ -280,13 +280,6 @@ GlobalModuleIndex::readIndex(StringRef Path) { llvm::Error::success()); } -void GlobalModuleIndex::getKnownModuleFileNames(StringSet<> &ModuleFiles) { - ModuleFiles.clear(); - for (unsigned I = 0, N = Modules.size(); I != N; ++I) { - ModuleFiles.insert(Modules[I].FileName); - } -} - void GlobalModuleIndex::getModuleDependencies( ModuleFile *File, SmallVectorImpl &Dependencies) { @@ -331,32 +324,6 @@ bool GlobalModuleIndex::lookupIdentifier(StringRef Name, HitSet &Hits) { return true; } -bool GlobalModuleIndex::lookupIdentifier(StringRef Name, FileNameHitSet &Hits) { - Hits.clear(); - - // If there's no identifier index, there is nothing we can do. - if (!IdentifierIndex) - return false; - - // Look into the identifier index. - ++NumIdentifierLookups; - IdentifierIndexTable &Table = - *static_cast(IdentifierIndex); - IdentifierIndexTable::iterator Known = Table.find(Name); - if (Known == Table.end()) { - return false; - } - - SmallVector ModuleIDs = *Known; - for (unsigned I = 0, N = ModuleIDs.size(); I != N; ++I) { - assert(!Modules[ModuleIDs[I]].FileName.empty()); - Hits.insert(Modules[ModuleIDs[I]].FileName); - } - - ++NumIdentifierLookupHits; - return true; -} - bool GlobalModuleIndex::loadedModuleFile(ModuleFile *File) { // Look for the module in the global module index based on the module name. StringRef Name = File->ModuleName; @@ -433,6 +400,9 @@ namespace { /// Builder that generates the global module index file. class GlobalModuleIndexBuilder { + FileManager &FileMgr; + const PCHContainerReader &PCHContainerRdr; + /// Mapping from files to module file information. using ModuleFilesMap = llvm::MapVector; @@ -470,21 +440,12 @@ namespace { } public: - explicit GlobalModuleIndexBuilder(GlobalModuleIndex::UserDefinedInterestingIDs* ExternalIDs) { - if (!ExternalIDs) - return; - - for (const auto & I : *ExternalIDs) - for (auto J : I.getValue()) - if (J) - InterestingIdentifiers[I.getKey()].push_back( - getModuleFileInfo(*J).ID); - } + explicit GlobalModuleIndexBuilder( + FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr) + : FileMgr(FileMgr), PCHContainerRdr(PCHContainerRdr) {} /// Load the contents of the given module file into the builder. - /// - llvm::Error loadModuleFile(FileEntryRef File, FileManager &FileMgr, - const PCHContainerReader &PCHContainerRdr); + llvm::Error loadModuleFile(FileEntryRef File); /// Write the index to the given bitstream. /// \returns true if an error occurred, false otherwise. @@ -556,9 +517,7 @@ namespace { }; } -llvm::Error GlobalModuleIndexBuilder::loadModuleFile( - FileEntryRef File, FileManager &FileMgr, - const PCHContainerReader &PCHContainerRdr) { +llvm::Error GlobalModuleIndexBuilder::loadModuleFile(FileEntryRef File) { // Open the module file. auto Buffer = FileMgr.getBufferForFile(File, /*isVolatile=*/true); @@ -796,8 +755,7 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) { // Verify Signature. return true; } else if (Info.StoredSize != File.getSize() || - (Info.StoredModTime && - Info.StoredModTime != File.getModificationTime())) + Info.StoredModTime != File.getModificationTime()) // Verify Size and ModTime. return true; } @@ -884,9 +842,7 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) { llvm::Error GlobalModuleIndex::writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, - StringRef Path, - UserDefinedInterestingIDs *ExternalIDs /* = nullptr */) { - + StringRef Path) { llvm::SmallString<128> IndexPath; IndexPath += Path; llvm::sys::path::append(IndexPath, IndexFileName); @@ -910,35 +866,33 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr, } // The module index builder. - GlobalModuleIndexBuilder Builder(ExternalIDs); - - if (!ExternalIDs) { - // Load each of the module files. - std::error_code EC; - for (llvm::sys::fs::directory_iterator D(Path, EC), DEnd; - D != DEnd && !EC; - D.increment(EC)) { - // If this isn't a module file, we don't care. - if (llvm::sys::path::extension(D->path()) != ".pcm") { - // ... unless it's a .pcm.lock file, which indicates that someone is - // in the process of rebuilding a module. They'll rebuild the index - // at the end of that translation unit, so we don't have to. - if (llvm::sys::path::extension(D->path()) == ".pcm.lock") - return llvm::createStringError(std::errc::device_or_resource_busy, - "someone else is building the index"); + GlobalModuleIndexBuilder Builder(FileMgr, PCHContainerRdr); + + // Load each of the module files. + std::error_code EC; + for (llvm::sys::fs::directory_iterator D(Path, EC), DEnd; + D != DEnd && !EC; + D.increment(EC)) { + // If this isn't a module file, we don't care. + if (llvm::sys::path::extension(D->path()) != ".pcm") { + // ... unless it's a .pcm.lock file, which indicates that someone is + // in the process of rebuilding a module. They'll rebuild the index + // at the end of that translation unit, so we don't have to. + if (llvm::sys::path::extension(D->path()) == ".pcm.lock") + return llvm::createStringError(std::errc::device_or_resource_busy, + "someone else is building the index"); - continue; - } + continue; + } - // If we can't find the module file, skip it. - auto ModuleFile = FileMgr.getOptionalFileRef(D->path()); - if (!ModuleFile) - continue; + // If we can't find the module file, skip it. + auto ModuleFile = FileMgr.getOptionalFileRef(D->path()); + if (!ModuleFile) + continue; - // Load this module file. - if (auto Err = Builder.loadModuleFile(*ModuleFile, FileMgr, PCHContainerRdr)) - return Err; - } + // Load this module file. + if (llvm::Error Err = Builder.loadModuleFile(*ModuleFile)) + return Err; } // The output buffer, into which the global index will be written. diff --git a/interpreter/llvm-project/clang/lib/Serialization/TemplateArgumentHasher.cpp b/interpreter/llvm-project/clang/lib/Serialization/TemplateArgumentHasher.cpp index b08d6c25de6f9..5fd6941256fe2 100644 --- a/interpreter/llvm-project/clang/lib/Serialization/TemplateArgumentHasher.cpp +++ b/interpreter/llvm-project/clang/lib/Serialization/TemplateArgumentHasher.cpp @@ -21,6 +21,17 @@ using namespace clang; namespace { class TemplateArgumentHasher { + // If we bail out during the process of calculating hash values for + // template arguments for any reason. We're allowed to do it since + // TemplateArgumentHasher are only required to give the same hash value + // for the same template arguments, but not required to give different + // hash value for different template arguments. + // + // So in the worst case, it is still a valid implementation to give all + // inputs the same BailedOutValue as output. + bool BailedOut = false; + static constexpr unsigned BailedOutValue = 0x12345678; + llvm::FoldingSetNodeID ID; public: @@ -30,7 +41,14 @@ class TemplateArgumentHasher { void AddInteger(unsigned V) { ID.AddInteger(V); } - unsigned getValue() { return ID.computeStableHash(); } + unsigned getValue() { + if (BailedOut) + return BailedOutValue; + + return ID.computeStableHash(); + } + + void setBailedOut() { BailedOut = true; } void AddType(const Type *T); void AddQualType(QualType T); @@ -76,7 +94,8 @@ void TemplateArgumentHasher::AddTemplateArgument(TemplateArgument TA) { case TemplateArgument::Expression: // If we meet expression in template argument, it implies // that the template is still dependent. It is meaningless - // to get a stable hash for the template. + // to get a stable hash for the template. Bail out simply. + BailedOut = true; break; case TemplateArgument::Pack: AddInteger(TA.pack_size()); @@ -93,9 +112,10 @@ void TemplateArgumentHasher::AddStructuralValue(const APValue &Value) { // 'APValue::Profile' uses pointer values to make hash for LValue and // MemberPointer, but they differ from one compiler invocation to another. - // It may be difficult to handle such cases. + // It may be difficult to handle such cases. Bail out simply. if (Kind == APValue::LValue || Kind == APValue::MemberPointer) { + BailedOut = true; return; } @@ -117,11 +137,14 @@ void TemplateArgumentHasher::AddTemplateName(TemplateName Name) { case TemplateName::DependentTemplate: case TemplateName::SubstTemplateTemplateParm: case TemplateName::SubstTemplateTemplateParmPack: + BailedOut = true; break; case TemplateName::UsingTemplate: { UsingShadowDecl *USD = Name.getAsUsingShadowDecl(); if (USD) AddDecl(USD->getTargetDecl()); + else + BailedOut = true; break; } case TemplateName::DeducedTemplate: @@ -146,6 +169,7 @@ void TemplateArgumentHasher::AddDeclarationName(DeclarationName Name) { case DeclarationName::ObjCZeroArgSelector: case DeclarationName::ObjCOneArgSelector: case DeclarationName::ObjCMultiArgSelector: + BailedOut = true; break; case DeclarationName::CXXConstructorName: case DeclarationName::CXXDestructorName: @@ -172,29 +196,16 @@ void TemplateArgumentHasher::AddDeclarationName(DeclarationName Name) { void TemplateArgumentHasher::AddDecl(const Decl *D) { const NamedDecl *ND = dyn_cast(D); if (!ND) { + BailedOut = true; return; } AddDeclarationName(ND->getDeclName()); - - // If this was a specialization we should take into account its template - // arguments. This helps to reduce collisions coming when visiting template - // specialization types (eg. when processing type template arguments). - ArrayRef Args; - if (auto *CTSD = dyn_cast(D)) - Args = CTSD->getTemplateArgs().asArray(); - else if (auto *VTSD = dyn_cast(D)) - Args = VTSD->getTemplateArgs().asArray(); - else if (auto *FD = dyn_cast(D)) - if (FD->getTemplateSpecializationArgs()) - Args = FD->getTemplateSpecializationArgs()->asArray(); - - for (auto &TA : Args) - AddTemplateArgument(TA); } void TemplateArgumentHasher::AddQualType(QualType T) { if (T.isNull()) { + BailedOut = true; return; } SplitQualType split = T.split(); @@ -204,6 +215,7 @@ void TemplateArgumentHasher::AddQualType(QualType T) { // Process a Type pointer. Add* methods call back into TemplateArgumentHasher // while Visit* methods process the relevant parts of the Type. +// Any unhandled type will make the hash computation bail out. class TypeVisitorHelper : public TypeVisitor { typedef TypeVisitor Inherited; llvm::FoldingSetNodeID &ID; @@ -235,6 +247,9 @@ class TypeVisitorHelper : public TypeVisitor { void Visit(const Type *T) { Inherited::Visit(T); } + // Unhandled types. Bail out simply. + void VisitType(const Type *T) { Hash.setBailedOut(); } + void VisitAdjustedType(const AdjustedType *T) { AddQualType(T->getOriginalType()); } diff --git a/interpreter/llvm-project/clang/utils/TableGen/ClangAttrEmitter.cpp b/interpreter/llvm-project/clang/utils/TableGen/ClangAttrEmitter.cpp index b1d9c2250b483..de12c7062666a 100644 --- a/interpreter/llvm-project/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/interpreter/llvm-project/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -488,13 +488,12 @@ namespace { } void writeValue(raw_ostream &OS) const override { - OS << "R\\\"ATTRDUMP(\" << get" << getUpperName() - << "() << \")ATTRDUMP\\\""; + OS << "\\\"\" << get" << getUpperName() << "() << \"\\\""; } void writeDump(raw_ostream &OS) const override { - OS << " OS << \" R\\\"ATTRDUMP(\" << SA->get" << getUpperName() - << "() << \")ATTRDUMP\\\"\";\n"; + OS << " OS << \" \\\"\" << SA->get" << getUpperName() + << "() << \"\\\"\";\n"; } }; From a7b5594432ffee3afdd10feb7dabcb65b26a4255 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Tue, 18 Mar 2014 14:55:01 +0100 Subject: [PATCH 02/18] Revert "Implement FileManager uncaching." Comment out invalidating cache --- interpreter/cling/lib/Interpreter/DeclUnloader.cpp | 12 ++++++------ .../cling/lib/Interpreter/TransactionUnloader.cpp | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/interpreter/cling/lib/Interpreter/DeclUnloader.cpp b/interpreter/cling/lib/Interpreter/DeclUnloader.cpp index 37a60a0aef66d..24dee1896550c 100644 --- a/interpreter/cling/lib/Interpreter/DeclUnloader.cpp +++ b/interpreter/cling/lib/Interpreter/DeclUnloader.cpp @@ -493,12 +493,12 @@ namespace cling { } DeclUnloader::~DeclUnloader() { - SourceManager& SM = m_Sema->getSourceManager(); - for (FileIDs::iterator I = m_FilesToUncache.begin(), - E = m_FilesToUncache.end(); I != E; ++I) { - // We need to reset the cache - SM.invalidateCache(*I); - } + // SourceManager& SM = m_Sema->getSourceManager(); + // for (FileIDs::iterator I = m_FilesToUncache.begin(), + // E = m_FilesToUncache.end(); I != E; ++I) { + // // We need to reset the cache + // SM.invalidateCache(*I); + // } } void DeclUnloader::CollectFilesToUncache(SourceLocation Loc) { diff --git a/interpreter/cling/lib/Interpreter/TransactionUnloader.cpp b/interpreter/cling/lib/Interpreter/TransactionUnloader.cpp index 78f3c47130920..1c50d8586d0cb 100644 --- a/interpreter/cling/lib/Interpreter/TransactionUnloader.cpp +++ b/interpreter/cling/lib/Interpreter/TransactionUnloader.cpp @@ -161,9 +161,9 @@ namespace cling { else T->setState(Transaction::kRolledBackWithErrors); - // Release the input_line_X file unless verifying diagnostics. - if (!m_Interp->getCI()->getDiagnosticOpts().VerifyDiagnostics) - m_Sema->getSourceManager().invalidateCache(T->getBufferFID()); + // // Release the input_line_X file unless verifying diagnostics. + // if (!m_Interp->getCI()->getDiagnosticOpts().VerifyDiagnostics) + // m_Sema->getSourceManager().invalidateCache(T->getBufferFID()); return Successful; } From 2caa7a8218a97b9d4669e2eba7ad7820be98e0f3 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Mon, 3 Jul 2023 10:42:23 +0200 Subject: [PATCH 03/18] Revert "[clang] Add API to iterate already loaded specializations" This reverts commit 1324b32fd16e0616afa2f100d9cfe2cfc2e3f15f. --- interpreter/cling/lib/Interpreter/DeclUnloader.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/interpreter/cling/lib/Interpreter/DeclUnloader.cpp b/interpreter/cling/lib/Interpreter/DeclUnloader.cpp index 24dee1896550c..d9a8616a36cd8 100644 --- a/interpreter/cling/lib/Interpreter/DeclUnloader.cpp +++ b/interpreter/cling/lib/Interpreter/DeclUnloader.cpp @@ -1024,8 +1024,8 @@ namespace cling { bool Successful = true; // Remove specializations, but do not invalidate the iterator! - for (FunctionTemplateDecl::spec_iterator I = FTD->loaded_spec_begin(), - E = FTD->loaded_spec_end(); I != E; ++I) + for (FunctionTemplateDecl::spec_iterator I = FTD->spec_begin(), + E = FTD->spec_end(); I != E; ++I) Successful &= VisitFunctionDecl(*I, /*RemoveSpec=*/false); Successful &= VisitRedeclarableTemplateDecl(FTD); @@ -1036,9 +1036,9 @@ namespace cling { bool DeclUnloader::VisitClassTemplateDecl(ClassTemplateDecl* CTD) { // ClassTemplateDecl: TemplateDecl, Redeclarable bool Successful = true; - // Remove specializations, but do not invalidate the iterator! - for (ClassTemplateDecl::spec_iterator I = CTD->loaded_spec_begin(), - E = CTD->loaded_spec_end(); I != E; ++I) + // Remove specializations: + for (ClassTemplateDecl::spec_iterator I = CTD->spec_begin(), + E = CTD->spec_end(); I != E; ++I) Successful &= VisitClassTemplateSpecializationDecl(*I, /*RemoveSpec=*/false); @@ -1082,8 +1082,8 @@ namespace cling { // VarTemplateDecl: TemplateDecl, Redeclarable bool Successful = true; // Remove specializations, but do not invalidate the iterator! - for (VarTemplateDecl::spec_iterator I = VTD->loaded_spec_begin(), - E = VTD->loaded_spec_end(); + for (VarTemplateDecl::spec_iterator I = VTD->spec_begin(), + E = VTD->spec_end(); I != E; ++I) Successful &= VisitVarTemplateSpecializationDecl(*I, /*RemoveSpec=*/false); From 0c3d95b8ec0e40c2574d92e348fadaf7502ed474 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 28 Mar 2014 10:48:12 +0100 Subject: [PATCH 04/18] Access sema internals and revert the list of unused decls. --- interpreter/llvm-project/clang/include/clang/AST/Decl.h | 2 ++ interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h | 1 + interpreter/llvm-project/clang/include/clang/Sema/Sema.h | 1 + 3 files changed, 4 insertions(+) diff --git a/interpreter/llvm-project/clang/include/clang/AST/Decl.h b/interpreter/llvm-project/clang/include/clang/AST/Decl.h index 362a2741a0cdd..4942d7af2acc6 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/Decl.h +++ b/interpreter/llvm-project/clang/include/clang/AST/Decl.h @@ -50,6 +50,8 @@ #include #include +namespace cling { class DeclUnloader; } + namespace clang { class ASTContext; diff --git a/interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h b/interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h index 79fd403c2718c..94f236b0d9a2f 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h +++ b/interpreter/llvm-project/clang/include/clang/AST/DeclCXX.h @@ -266,6 +266,7 @@ class CXXRecordDecl : public RecordDecl { friend class DeclContext; friend class LambdaExpr; friend class ODRDiagsEmitter; + friend class ::cling::DeclUnloader; friend void FunctionDecl::setIsPureVirtual(bool); friend void TagDecl::startDefinition(); diff --git a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h index d8cc0171c22c6..57f1e5674614c 100644 --- a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h +++ b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h @@ -1183,6 +1183,7 @@ class Sema final : public SemaBase { friend class ASTReader; friend class ASTDeclReader; friend class ASTWriter; + friend class ::cling::DeclUnloader; private: std::optional> CachedDarwinSDKInfo; From f52b00eaad53ca667754ebe8a9c5ff4a748d0410 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Mon, 26 Aug 2013 15:08:12 +0200 Subject: [PATCH 05/18] More RAIIs for autoloading. Co-authored-by: Jonas Hahnfeld --- .../clang/include/clang/Lex/Preprocessor.h | 71 +++++++++++++++++++ .../clang/include/clang/Sema/Sema.h | 33 +++++++++ 2 files changed, 104 insertions(+) diff --git a/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h b/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h index 416f403c29841..a30553b44d2db 100644 --- a/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h +++ b/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h @@ -1693,6 +1693,77 @@ class Preprocessor { IsReinject); } + /// A RAII object to temporarily reset PP's state and restore it. + class CleanupAndRestoreCacheRAII { + private: + Preprocessor &PP; + CachedTokensTy SavedCachedTokens; + CachedTokensTy::size_type SavedCachedLexPos; + std::vector SavedBacktrackPositions; + std::vector SavedStack; + Lexer *SavedCurLexer; + PreprocessorLexer *SavedCurPPLexer; + TokenLexer* SavedCurTokenLexer; + ConstSearchDirIterator SavedCurDirLookup; + LexerCallback SavedCurLexerCallback; + unsigned SavedLexLevel; + + public: + CleanupAndRestoreCacheRAII(Preprocessor &PP) + : PP(PP), SavedCachedTokens(std::move(PP.CachedTokens)), + SavedCachedLexPos(PP.CachedLexPos), + SavedBacktrackPositions(std::move(PP.BacktrackPositions)), + SavedStack(std::move(PP.IncludeMacroStack)), + SavedCurLexer(PP.CurLexer.release()), SavedCurPPLexer(PP.CurPPLexer), + SavedCurTokenLexer(PP.CurTokenLexer.release()), + SavedCurDirLookup(PP.CurDirLookup), + SavedCurLexerCallback(PP.CurLexerCallback), + SavedLexLevel(PP.LexLevel) { + PP.CachedTokens.clear(); + PP.CachedLexPos = 0; + PP.BacktrackPositions.clear(); + PP.IncludeMacroStack.clear(); + PP.CurLexer.reset(0); + PP.CurPPLexer = 0; + PP.CurTokenLexer.reset(0); + PP.CurDirLookup = 0; + PP.CurLexerCallback = CLK_CachingLexer; + PP.LexLevel = 0; + } + + void pop() { + if (SavedCurLexerCallback == nullptr) + return; + + // ExitCachingLexMode(); + PP.CachedTokens = std::move(SavedCachedTokens); + PP.CachedLexPos = SavedCachedLexPos; + PP.BacktrackPositions = std::move(SavedBacktrackPositions); + PP.IncludeMacroStack = std::move(SavedStack); + PP.CurLexer.reset(SavedCurLexer); + PP.CurPPLexer = SavedCurPPLexer; + PP.CurTokenLexer.reset(SavedCurTokenLexer); + PP.CurDirLookup = SavedCurDirLookup; + PP.CurLexerCallback = SavedCurLexerCallback; + PP.LexLevel = SavedLexLevel; + + SavedCachedTokens.clear(); + SavedCachedLexPos = 0; + SavedBacktrackPositions.clear(); + SavedStack.clear(); + SavedCurLexer = 0; + SavedCurPPLexer = 0; + SavedCurTokenLexer = 0; + SavedCurDirLookup = 0; + SavedCurLexerCallback = nullptr; + SavedLexLevel = ~0U; + } + + ~CleanupAndRestoreCacheRAII() { + pop(); + } + }; + /// Pop the current lexer/macro exp off the top of the lexer stack. /// /// This should only be used in situations where the current state of the diff --git a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h index 57f1e5674614c..6a0723fa4a9f7 100644 --- a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h +++ b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h @@ -13114,6 +13114,39 @@ class Sema final : public SemaBase { bool SkipForSpecialization = false, bool ForDefaultArgumentSubstitution = false); + /// A RAII object to temporarily push a decl context and scope. + class ContextAndScopeRAII { + private: + Sema &S; + DeclContext *SavedContext; + Scope *SavedScope; + ProcessingContextState SavedContextState; + QualType SavedCXXThisTypeOverride; + + public: + ContextAndScopeRAII(Sema &S, DeclContext *ContextToPush, Scope *ScopeToPush) + : S(S), SavedContext(S.CurContext), SavedScope(S.CurScope), + SavedContextState(S.DelayedDiagnostics.pushUndelayed()), + SavedCXXThisTypeOverride(S.CXXThisTypeOverride) { + assert(ContextToPush && "pushing null context"); + S.CurContext = ContextToPush; + S.CurScope = ScopeToPush; + } + + void pop() { + if (!SavedContext) + return; + S.CurContext = SavedContext; + S.CurScope = SavedScope; + S.DelayedDiagnostics.popUndelayed(SavedContextState); + S.CXXThisTypeOverride = SavedCXXThisTypeOverride; + SavedContext = 0; + SavedScope = 0; + } + + ~ContextAndScopeRAII() { pop(); } + }; + /// RAII object to handle the state changes required to synthesize /// a function body. class SynthesizedFunctionScope { From a9ded8347792fb2544bf740754ac45b609f79d17 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Thu, 8 Jan 2015 18:29:58 +0100 Subject: [PATCH 06/18] Also store Parser paren numbers; likely fixes ROOT-6976: The parser (or rather the BalancedDelimiterTracker) was doing a Parser::cutOffParsing() because of an overflow of open ( - because we never reset the count. --- interpreter/llvm-project/clang/include/clang/Parse/Parser.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interpreter/llvm-project/clang/include/clang/Parse/Parser.h b/interpreter/llvm-project/clang/include/clang/Parse/Parser.h index e99d2cf2eaa40..b1b064bfea738 100644 --- a/interpreter/llvm-project/clang/include/clang/Parse/Parser.h +++ b/interpreter/llvm-project/clang/include/clang/Parse/Parser.h @@ -27,6 +27,8 @@ #include #include +namespace cling { class ParserStateRAII; } + namespace clang { class PragmaHandler; class Scope; @@ -65,6 +67,7 @@ class Parser : public CodeCompletionHandler { friend class ObjCDeclContextSwitch; friend class ParenBraceBracketBalancer; friend class BalancedDelimiterTracker; + friend class ::cling::ParserStateRAII; Preprocessor &PP; From b28d5cd572e83c390fad9a0538291a92931cd438 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Wed, 7 Jan 2015 10:28:02 +0100 Subject: [PATCH 07/18] Provide (possibly updated) CodegenOpts to StartModule. --- .../clang/include/clang/CodeGen/ModuleBuilder.h | 4 ++++ .../clang/lib/CodeGen/ModuleBuilder.cpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h index 59b9840d02e08..8ef8c471dca7f 100644 --- a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h +++ b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h @@ -100,6 +100,10 @@ class CodeGenerator : public ASTConsumer { /// Create a new \c llvm::Module after calling HandleTranslationUnit. This /// enable codegen in interactive processing environments. llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C); + + llvm::Module* StartModule(llvm::StringRef ModuleName, + llvm::LLVMContext& C, + const CodeGenOptions& CGO); }; /// CreateLLVMCodeGen - Create a CodeGenerator instance. diff --git a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp index d4e0ab0339a8b..d1cb068bd00ee 100644 --- a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp @@ -36,7 +36,7 @@ namespace { IntrusiveRefCntPtr FS; // Only used for debug info. const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info. const PreprocessorOptions &PreprocessorOpts; // Only used for debug info. - const CodeGenOptions &CodeGenOpts; + CodeGenOptions CodeGenOpts; // Intentionally copied in. unsigned HandlingTopLevelDecls; @@ -148,6 +148,13 @@ namespace { return M.get(); } + llvm::Module *StartModule(llvm::StringRef ModuleName, + llvm::LLVMContext& C, + const CodeGenOptions& CGO) { + CodeGenOpts = CGO; + return StartModule(ModuleName, C); + } + void Initialize(ASTContext &Context) override { Ctx = &Context; @@ -360,6 +367,12 @@ llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName, return static_cast(this)->StartModule(ModuleName, C); } +llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName, + llvm::LLVMContext& C, + const CodeGenOptions& CGO) { + return static_cast(this)->StartModule(ModuleName, C, CGO); +} + CodeGenerator * clang::CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName, IntrusiveRefCntPtr FS, From 344d4737f1372696698d280f568624de417dd4af Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Fri, 19 Sep 2025 15:35:52 +0200 Subject: [PATCH 08/18] Restore pre-LLVM20 behaviour in HeaderSearch::LookupFile Reverts part of upstream LLVM commit https://github.com/llvm/llvm-project/commit/84df7a09f8da5809b85fd097015e5ac6cc8a3f88 The newer logic triggers an assertion when building ROOT. --- .../llvm-project/clang/lib/Lex/HeaderSearch.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp b/interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp index bf8fe44e4ca9c..483259c6d1953 100644 --- a/interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/HeaderSearch.cpp @@ -949,13 +949,9 @@ OptionalFileEntryRef HeaderSearch::LookupFile( // If we have no includer, that means we're processing a #include // from a module build. We should treat this as a system header if we're // building a [system] module. - bool IncluderIsSystemHeader = [&]() { - if (!Includer) - return BuildSystemModule; - const HeaderFileInfo *HFI = getExistingFileInfo(*Includer); - assert(HFI && "includer without file info"); - return HFI->DirInfo != SrcMgr::C_User; - }(); + bool IncluderIsSystemHeader = + Includer ? getFileInfo(*Includer).DirInfo != SrcMgr::C_User : + BuildSystemModule; if (OptionalFileEntryRef FE = getFileAndSuggestModule( TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader, RequestingModule, SuggestedModule)) { From 6e156ebc348bc8a2b0a2a044edb9c81e80333060 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Mon, 27 Mar 2023 19:43:33 +0000 Subject: [PATCH 09/18] Implement a module attribute 'optional' to allow missing headers. This deals with the fact that our modulemaps include headers which can vary across library versions and that attribute is a way to express this. --- .../clang/include/clang/Basic/Module.h | 3 +++ .../clang/include/clang/Lex/ModuleMap.h | 5 ++++- .../llvm-project/clang/lib/Basic/Module.cpp | 3 ++- .../llvm-project/clang/lib/Lex/ModuleMap.cpp | 15 ++++++++++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/interpreter/llvm-project/clang/include/clang/Basic/Module.h b/interpreter/llvm-project/clang/include/clang/Basic/Module.h index dd384c1d76c5f..262b0c79751a6 100644 --- a/interpreter/llvm-project/clang/include/clang/Basic/Module.h +++ b/interpreter/llvm-project/clang/include/clang/Basic/Module.h @@ -399,6 +399,9 @@ class alignas(8) Module { LLVM_PREFERRED_TYPE(bool) unsigned NoUndeclaredIncludes : 1; + /// Whether the submodule is allowed to have missing headers. + unsigned IsOptional: 1; + /// Whether this module came from a "private" module map, found next /// to a regular (public) module map. LLVM_PREFERRED_TYPE(bool) diff --git a/interpreter/llvm-project/clang/include/clang/Lex/ModuleMap.h b/interpreter/llvm-project/clang/include/clang/Lex/ModuleMap.h index 53e9e0ec83ddb..026f8849edbf5 100644 --- a/interpreter/llvm-project/clang/include/clang/Lex/ModuleMap.h +++ b/interpreter/llvm-project/clang/include/clang/Lex/ModuleMap.h @@ -251,9 +251,12 @@ class ModuleMap { LLVM_PREFERRED_TYPE(bool) unsigned NoUndeclaredIncludes : 1; + /// Whether we can have a submodule with missing header files. + unsigned IsOptional : 1; + Attributes() : IsSystem(false), IsExternC(false), IsExhaustive(false), - NoUndeclaredIncludes(false) {} + NoUndeclaredIncludes(false), IsOptional(false) {} }; /// A directory for which framework modules can be inferred. diff --git a/interpreter/llvm-project/clang/lib/Basic/Module.cpp b/interpreter/llvm-project/clang/lib/Basic/Module.cpp index 330108d5b3e47..2307aacf5194f 100644 --- a/interpreter/llvm-project/clang/lib/Basic/Module.cpp +++ b/interpreter/llvm-project/clang/lib/Basic/Module.cpp @@ -44,7 +44,7 @@ Module::Module(ModuleConstructorTag, StringRef Name, IsSystem(false), IsExternC(false), IsInferred(false), InferSubmodules(false), InferExplicitSubmodules(false), InferExportWildcard(false), ConfigMacrosExhaustive(false), - NoUndeclaredIncludes(false), ModuleMapIsPrivate(false), + NoUndeclaredIncludes(false), IsOptional(false), ModuleMapIsPrivate(false), NamedModuleHasInit(true), NameVisibility(Hidden) { if (Parent) { IsAvailable = Parent->isAvailable(); @@ -52,6 +52,7 @@ Module::Module(ModuleConstructorTag, StringRef Name, IsSystem = Parent->IsSystem; IsExternC = Parent->IsExternC; NoUndeclaredIncludes = Parent->NoUndeclaredIncludes; + IsOptional = Parent->IsOptional; ModuleMapIsPrivate = Parent->ModuleMapIsPrivate; Parent->SubModules.push_back(this); diff --git a/interpreter/llvm-project/clang/lib/Lex/ModuleMap.cpp b/interpreter/llvm-project/clang/lib/Lex/ModuleMap.cpp index ccf94f6345ff2..d24aaa5e17b77 100644 --- a/interpreter/llvm-project/clang/lib/Lex/ModuleMap.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/ModuleMap.cpp @@ -315,6 +315,8 @@ void ModuleMap::resolveHeader(Module *Mod, // this was supposed to modularize the builtin header alone. } else if (Header.Kind == Module::HK_Excluded) { // Ignore missing excluded header files. They're optional anyway. + } else if (Mod->IsOptional) { + // Optional submodules can have missing headers. } else { // If we find a module that has a missing header, we mark this module as // unavailable and store the header directive for displaying diagnostics. @@ -1114,6 +1116,7 @@ Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir, Result->IsExternC |= Attrs.IsExternC; Result->ConfigMacrosExhaustive |= Attrs.IsExhaustive; Result->NoUndeclaredIncludes |= Attrs.NoUndeclaredIncludes; + Result->IsOptional |= Attrs.IsOptional; Result->Directory = FrameworkDir; // Chop off the first framework bit, as that is implied. @@ -1863,7 +1866,10 @@ namespace { AT_exhaustive, /// The 'no_undeclared_includes' attribute. - AT_no_undeclared_includes + AT_no_undeclared_includes, + + /// The 'optional' attribute. + AT_optional }; } // namespace @@ -2141,6 +2147,8 @@ void ModuleMapParser::parseModuleDecl() { ActiveModule->IsExternC = true; if (Attrs.NoUndeclaredIncludes) ActiveModule->NoUndeclaredIncludes = true; + if (Attrs.IsOptional) + ActiveModule->IsOptional = true; ActiveModule->Directory = Directory; StringRef MapFileName( @@ -3044,6 +3052,7 @@ bool ModuleMapParser::parseOptionalAttributes(Attributes &Attrs) { .Case("exhaustive", AT_exhaustive) .Case("extern_c", AT_extern_c) .Case("no_undeclared_includes", AT_no_undeclared_includes) + .Case("optional", AT_optional) .Case("system", AT_system) .Default(AT_unknown); switch (Attribute) { @@ -3067,6 +3076,10 @@ bool ModuleMapParser::parseOptionalAttributes(Attributes &Attrs) { case AT_no_undeclared_includes: Attrs.NoUndeclaredIncludes = true; break; + + case AT_optional: + Attrs.IsOptional = true; + break; } consumeToken(); From e50bda886ceb66f2038ac26c595a8faf49bd771f Mon Sep 17 00:00:00 2001 From: CristinaCristescu Date: Tue, 29 Oct 2013 09:57:54 +0100 Subject: [PATCH 10/18] Remove macro and print macro. --- .../clang/include/clang/Lex/Preprocessor.h | 11 ++++++ .../clang/lib/Lex/PPMacroExpansion.cpp | 14 +++++++ .../clang/lib/Lex/Preprocessor.cpp | 37 +++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h b/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h index a30553b44d2db..e0e6010e744a1 100644 --- a/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h +++ b/interpreter/llvm-project/clang/include/clang/Lex/Preprocessor.h @@ -1427,6 +1427,11 @@ class Preprocessor { return appendDefMacroDirective(II, MI, MI->getDefinitionLoc()); } + /// Remove a IdentifierInfo and MacroDirective from the history. + /// Given an IdentifierInfo and a MacroDirective we can remove them from + /// the macros vector. + void removeMacro(IdentifierInfo *II, MacroDirective *MD); + /// Set a MacroDirective that was loaded from a PCH file. void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD); @@ -2285,6 +2290,12 @@ class Preprocessor { void DumpMacro(const MacroInfo &MI) const; void dumpMacroInfo(const IdentifierInfo *II); + /// Print a Macro to an ostream used for ClangInternalState + /// Same as dump, but without orinting source location. + void printMacros(raw_ostream &OS) const; + void printMacro(const IdentifierInfo* II, const MacroDirective *MD, + llvm::raw_ostream &OS) const; + /// Given a location that specifies the start of a /// token, return a new location that specifies a character within the token. SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, diff --git a/interpreter/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp b/interpreter/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp index 347c13da0ad21..68961144b4b0d 100644 --- a/interpreter/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp @@ -91,6 +91,20 @@ void Preprocessor::appendMacroDirective(IdentifierInfo *II, MacroDirective *MD){ II->setChangedSinceDeserialization(); } +void Preprocessor::removeMacro(IdentifierInfo *II, MacroDirective *MD) { + assert(II && MD); + II->setHasMacroDefinition(false); + CurSubmoduleState->Macros.erase(II); + if (MacroDirective* prevMD = MD->getPrevious()) { + // Avoid assertion in appendMacroDirective. + MacroDirective* prevPrevMD = prevMD->getPrevious(); + prevMD->setPrevious(0); + appendMacroDirective(II, prevMD); + prevMD->setPrevious(prevPrevMD); + } +} + + void Preprocessor::setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD) { diff --git a/interpreter/llvm-project/clang/lib/Lex/Preprocessor.cpp b/interpreter/llvm-project/clang/lib/Lex/Preprocessor.cpp index 5ac5e6feae144..19dd29090df5f 100644 --- a/interpreter/llvm-project/clang/lib/Lex/Preprocessor.cpp +++ b/interpreter/llvm-project/clang/lib/Lex/Preprocessor.cpp @@ -271,6 +271,43 @@ void Preprocessor::DumpMacro(const MacroInfo &MI) const { llvm::errs() << "\n"; } +void Preprocessor::printMacros(raw_ostream &OS) const { + for (macro_iterator I = macro_begin(), E = macro_end(); I != E; ++I) { + Preprocessor::printMacro(I->first, I->second.getLatest(), OS); + } +} + +void Preprocessor::printMacro(const IdentifierInfo* II,const MacroDirective *MD, + llvm::raw_ostream &OS) const { + OS << ""; + OS << II->getName() << " "; + OS << "(Tokens:)"; + const MacroInfo* MI = MD->getMacroInfo(); + for (unsigned i = 0, e = MI->getNumTokens(); i != e; ++i) { + const Token &Tok = MI->getReplacementToken(i); + OS << tok::getTokenName(Tok.getKind()) << " '" + << getSpelling(Tok) << "'"; + OS << "\t"; + if (Tok.isAtStartOfLine()) + OS << " [StartOfLine]"; + if (Tok.hasLeadingSpace()) + OS << " [LeadingSpace]"; + if (Tok.isExpandDisabled()) + OS << " [ExpandDisabled]"; + if (Tok.needsCleaning()) { + const char *Start = SourceMgr.getCharacterData(Tok.getLocation()); + OS << " [UnClean='" << StringRef(Start, Tok.getLength()) + << "']"; + } + //Do not print location it uses the SourceManager dump to llvm::errs. + OS << "\tLoc=<"; + Tok.getLocation().print(OS, SourceMgr); + OS << ">"; + OS << " "; + } + OS << "\n"; +} + void Preprocessor::PrintStats() { llvm::errs() << "\n*** Preprocessor Stats:\n"; llvm::errs() << NumDirectives << " directives found:\n"; From fb1b37e00d82e049ad5c3588cec4f779381c3d84 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Wed, 6 Apr 2016 14:31:51 +0200 Subject: [PATCH 11/18] Cleanup cached constant (.str) from codegen. --- .../clang/include/clang/CodeGen/ModuleBuilder.h | 3 +++ .../clang/lib/CodeGen/ModuleBuilder.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h index 8ef8c471dca7f..4a0f84ec980b1 100644 --- a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h +++ b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h @@ -19,6 +19,7 @@ namespace llvm { class Constant; + class GlobalValue; class LLVMContext; class Module; class StringRef; @@ -104,6 +105,8 @@ class CodeGenerator : public ASTConsumer { llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext& C, const CodeGenOptions& CGO); + + void forgetGlobal(llvm::GlobalValue* GV); }; /// CreateLLVMCodeGen - Create a CodeGenerator instance. diff --git a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp index d1cb068bd00ee..b6b24cda9fec4 100644 --- a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp @@ -155,6 +155,16 @@ namespace { return StartModule(ModuleName, C); } + void forgetGlobal(llvm::GlobalValue* GV) { + for (auto I = Builder->ConstantStringMap.begin(), + E = Builder->ConstantStringMap.end(); I != E; ++I) { + if (I->second == GV) { + Builder->ConstantStringMap.erase(I); + break; + } + } + } + void Initialize(ASTContext &Context) override { Ctx = &Context; @@ -373,6 +383,10 @@ llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName, return static_cast(this)->StartModule(ModuleName, C, CGO); } +void CodeGenerator::forgetGlobal(llvm::GlobalValue* GV) { + static_cast(this)->forgetGlobal(GV); +} + CodeGenerator * clang::CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName, IntrusiveRefCntPtr FS, From 2290dbf3ba3d264f0912535b9265ca0695290597 Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Tue, 2 Dec 2014 17:43:18 +0100 Subject: [PATCH 12/18] Buffer the pending instantiations in case or recursive parsing. --- .../clang/include/clang/Sema/Sema.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h index 6a0723fa4a9f7..3f0f77f21aad9 100644 --- a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h +++ b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h @@ -13641,6 +13641,25 @@ class Sema final : public SemaBase { SavedPendingLocalImplicitInstantiations; }; + class SavePendingInstantiationsRAII { + public: + SavePendingInstantiationsRAII(Sema &S) + : SavedPendingLocalImplicitInstantiations(S), S(S) { + SavedPendingInstantiations.swap(S.PendingInstantiations); + } + + ~SavePendingInstantiationsRAII() { + assert(S.PendingInstantiations.empty() && + "there shouldn't be any pending instantiations"); + SavedPendingInstantiations.swap(S.PendingInstantiations); + } + + private: + LocalEagerInstantiationScope SavedPendingLocalImplicitInstantiations; + Sema &S; + std::deque SavedPendingInstantiations; + }; + /// Records and restores the CurFPFeatures state on entry/exit of compound /// statements. class FPFeaturesStateRAII { From 02000e5c9c40b0b781f8fc50d497921a9c1fc290 Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Tue, 11 Jul 2023 16:52:29 +0200 Subject: [PATCH 13/18] Add method to forget generated declarations --- .../clang/include/clang/CodeGen/ModuleBuilder.h | 1 + .../llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h index 4a0f84ec980b1..b712130f30b9f 100644 --- a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h +++ b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h @@ -107,6 +107,7 @@ class CodeGenerator : public ASTConsumer { const CodeGenOptions& CGO); void forgetGlobal(llvm::GlobalValue* GV); + void forgetDecl(llvm::StringRef MangledName); }; /// CreateLLVMCodeGen - Create a CodeGenerator instance. diff --git a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp index b6b24cda9fec4..b41aaa499115a 100644 --- a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp @@ -165,6 +165,11 @@ namespace { } } + void forgetDecl(llvm::StringRef MangledName) { + Builder->DeferredDecls.erase(MangledName); + Builder->Manglings.erase(MangledName); + } + void Initialize(ASTContext &Context) override { Ctx = &Context; @@ -387,6 +392,10 @@ void CodeGenerator::forgetGlobal(llvm::GlobalValue* GV) { static_cast(this)->forgetGlobal(GV); } +void CodeGenerator::forgetDecl(llvm::StringRef MangledName) { + static_cast(this)->forgetDecl(MangledName); +} + CodeGenerator * clang::CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName, IntrusiveRefCntPtr FS, From 2aa83561c1a81beb8205c9182ba27d9820cf100c Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Thu, 27 Feb 2014 15:50:37 +0100 Subject: [PATCH 14/18] Add (debug) printout of ModuleBuilder data structures --- .../include/clang/CodeGen/ModuleBuilder.h | 3 + .../clang/lib/CodeGen/CodeGenModule.h | 2 + .../clang/lib/CodeGen/ModuleBuilder.cpp | 119 +++++++++++++++++- 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h index b712130f30b9f..8f3168a975513 100644 --- a/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h +++ b/interpreter/llvm-project/clang/include/clang/CodeGen/ModuleBuilder.h @@ -23,6 +23,7 @@ namespace llvm { class LLVMContext; class Module; class StringRef; + class raw_ostream; namespace vfs { class FileSystem; @@ -98,6 +99,8 @@ class CodeGenerator : public ASTConsumer { /// definition has been registered with this code generator. llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition); + void print(llvm::raw_ostream& out); + /// Create a new \c llvm::Module after calling HandleTranslationUnit. This /// enable codegen in interactive processing environments. llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C); diff --git a/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.h b/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.h index 0956296e2d5d8..85bdb868e65a2 100644 --- a/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.h +++ b/interpreter/llvm-project/clang/lib/CodeGen/CodeGenModule.h @@ -59,6 +59,7 @@ class FileSystem; namespace clang { class ASTContext; class AtomicType; +class CodeGeneratorImpl; // hack needed by cling class FunctionDecl; class IdentifierInfo; class ObjCImplementationDecl; @@ -1987,6 +1988,7 @@ class CodeGenModule : public CodeGenTypeCache { llvm::Metadata *CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map, StringRef Suffix); + friend class clang::CodeGeneratorImpl; // hack needed by cling }; } // end namespace CodeGen diff --git a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp index b41aaa499115a..46e524a023e06 100644 --- a/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/interpreter/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp @@ -29,7 +29,7 @@ using namespace clang; using namespace CodeGen; -namespace { +namespace clang { class CodeGeneratorImpl : public CodeGenerator { DiagnosticsEngine &Diags; ASTContext *Ctx; @@ -133,6 +133,119 @@ namespace { return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition)); } + void print(llvm::raw_ostream& out) { + out << "\n\nCodeGen:\n"; + //llvm::SmallPtrSet WeakRefReferences; + out << " WeakRefReferences (llvm::SmallPtrSet)\n"; + for(auto I = Builder->WeakRefReferences.begin(), + E = Builder->WeakRefReferences.end(); I != E; ++I) { + (*I)->print(out); + out << "\n"; + } + + //llvm::StringMap DeferredDecls; + out << " DeferredDecls (llvm::StringMap)\n"; + for(auto I = Builder->DeferredDecls.begin(), + E = Builder->DeferredDecls.end(); I != E; ++I) { + out << I->first.str().c_str(); + I->second.getDecl()->print(out); + out << "\n"; + } + + //std::vector DeferredDeclsToEmit; + out << " DeferredDeclsToEmit (std::vector)\n"; + for(auto I = Builder->DeferredDeclsToEmit.begin(), + E = Builder->DeferredDeclsToEmit.end(); I != E; ++I) { + I->getDecl()->print(out); + out << "\n"; + } + + //std::vector Aliases; + out << " Aliases (std::vector)\n"; + for(auto I = Builder->Aliases.begin(), + E = Builder->Aliases.end(); I != E; ++I) { + I->getDecl()->print(out); + out << "\n"; + } + //typedef llvm::StringMap > + // ReplacementsTy; + //ReplacementsTy Replacements; + out + << " Replacements (llvm::StringMap>\n"; + for(auto I = Builder->Replacements.begin(), + E = Builder->Replacements.end(); I != E; ++I) { + out << I->first.str().c_str(); + (*I->second).print(out); + out << "\n"; + } + + //std::vector DeferredVTables; + out << " DeferredVTables (std::vector\n"; + for(auto I = Builder->DeferredVTables.begin(), + E = Builder->DeferredVTables.end(); I != E; ++I) { + (*I)->print(out); + out << "\n"; + } + + //std::vector LLVMUsed; + out << " LLVMUsed (std::vector >\n"; + for(auto I = Builder->LLVMUsed.begin(), + E = Builder->LLVMUsed.end(); I != E; ++I) { + (*I)->print(out); + out << "\n"; + } + + // typedef std::vector > CtorList; + //CtorList GlobalCtors; + out << " GlobalCtors (std::vector >\n"; + for(auto I = Builder->GlobalCtors.begin(), + E = Builder->GlobalCtors.end(); I != E; ++I) { + out << I->Initializer << " : " << I->AssociatedData; + out << "\n"; + } + + //CtorList GlobalDtors; + out << " GlobalDtors (std::vector >\n"; + for(auto I = Builder->GlobalDtors.begin(), + E = Builder->GlobalDtors.end(); I != E; ++I) { + out << I->Initializer << " : " << I->AssociatedData; + out << "\n"; + } + + //llvm::DenseMap MangledDeclNames; + //std::vector Annotations; + //llvm::StringMap AnnotationStrings; + //llvm::StringMap CFConstantStringMap; + //llvm::StringMap ConstantStringMap; + out << " ConstantStringMap (llvm::DenseMap)\n"; + for(auto I = Builder->ConstantStringMap.begin(), + E = Builder->ConstantStringMap.end(); I != E; ++I) { + I->first->print(out); + I->second->print(out); + out << "\n"; + } + + //llvm::DenseMap StaticLocalDeclMap; + //llvm::DenseMap StaticLocalDeclGuardMap; + //llvm::DenseMap MaterializedGlobalTemporaryMap; + //llvm::DenseMap AtomicSetterHelperFnMap; + //llvm::DenseMap AtomicGetterHelperFnMap; + //llvm::DenseMap TypeDescriptorMap; + //StaticExternCMap StaticExternCValues; + //std::vector > + // CXXThreadLocals; + //std::vector CXXThreadLocalInits; + //std::vector CXXGlobalInits; + //llvm::DenseMap DelayedCXXInitPosition; + //SmallVector PrioritizedCXXGlobalInits; + //std::vector > CXXGlobalDtors; + //llvm::SetVector ImportedModules; + //SmallVector LinkerOptionsMetadata; + // + out.flush(); + } + llvm::Module *StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C) { assert(!M && "Replacing existing Module?"); @@ -377,6 +490,10 @@ llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global, ->GetAddrOfGlobal(global, isForDefinition); } +void CodeGenerator::print(llvm::raw_ostream& out) { + static_cast(this)->print(out); +} + llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C) { return static_cast(this)->StartModule(ModuleName, C); From 26cf3db49dc62bdc5c00d4c443ce6c3db612610a Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Fri, 22 Jul 2016 18:04:04 +0200 Subject: [PATCH 15/18] Add RAII to buffer delayed infos, for recursive parsing. --- .../clang/include/clang/Sema/Sema.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h index 3f0f77f21aad9..a58ec59794e85 100644 --- a/interpreter/llvm-project/clang/include/clang/Sema/Sema.h +++ b/interpreter/llvm-project/clang/include/clang/Sema/Sema.h @@ -3060,6 +3060,27 @@ class Sema final : public SemaBase { /// attribute. mutable llvm::DenseMap FlagBitsCache; + class DelayedInfoRAII { + Sema &S; + SmallVector, 2> + DelayedOverridingExceptionSpecChecks; + SmallVector, 2> + DelayedEquivalentExceptionSpecChecks; + public: + DelayedInfoRAII(Sema& S): S(S) { + std::swap(S.DelayedOverridingExceptionSpecChecks, + DelayedOverridingExceptionSpecChecks); + std::swap(S.DelayedEquivalentExceptionSpecChecks, + DelayedEquivalentExceptionSpecChecks); + } + ~DelayedInfoRAII() { + std::swap(S.DelayedOverridingExceptionSpecChecks, + DelayedOverridingExceptionSpecChecks); + std::swap(S.DelayedEquivalentExceptionSpecChecks, + DelayedEquivalentExceptionSpecChecks); + } + }; + /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before /// declared. Rare. May alias another identifier, declared or undeclared. /// From 0d4923f361f9a1f1c4f4d08fb2ffe2380de78bdc Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Wed, 28 Mar 2018 12:40:52 +0200 Subject: [PATCH 16/18] Refactor generation counter in LLVM Right now the ExternalASTSources in LLVM have an awkward way of implementing their generation counters, which provide an incrementing UID for versioning the AST when it is changed lazily by the ExternalASTSource (for example when more decls are). The current implementation is based on having an counter in each ExternalASTSource, but each ExternalASTSource actually only refers to the top most ExternalASTSource of the current ASTContext, which means that the counter suddenly resets when we add any kind of new ExternalASTSource (and we have no way to work around this). Also, some ExternalASTSources like the ASTReader make assumptions that they are the top most ExternalASTSource which means that as soon as we overwrite the ASTReader, we suddenly have two counters running providing conflicting information to anyone querying the counters. This patch merges all these counters into one counter which is in the ASTContext. This should get rid of any more counter desyncronization problems when we attach our own external sources or when parts of the code make invalid assumptions about which external source is currently the top most one in the ASTContext. Patch is upstreamed via LLVM phabricator review D39714. --- .../clang/include/clang/AST/ASTContext.h | 15 +++++++++++++- .../include/clang/AST/ExternalASTSource.h | 14 ++++++++----- .../include/clang/Serialization/ASTReader.h | 6 ++++++ .../clang/lib/AST/ExternalASTSource.cpp | 20 +++++-------------- .../clang/lib/Serialization/ASTReader.cpp | 13 ++++++------ 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/interpreter/llvm-project/clang/include/clang/AST/ASTContext.h b/interpreter/llvm-project/clang/include/clang/AST/ASTContext.h index 65be782c1ba43..2d6bea73c9709 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/ASTContext.h +++ b/interpreter/llvm-project/clang/include/clang/AST/ASTContext.h @@ -276,6 +276,10 @@ class ASTContext : public RefCountedBase { mutable llvm::ContextualFoldingSet ArrayParameterTypes; + /// Generation number for this external AST source. Must be increased + /// whenever we might have added new redeclarations for existing decls. + uint32_t CurrentGeneration = 0; + /// The set of nested name specifiers. /// /// This set is managed by the NestedNameSpecifier class. @@ -730,6 +734,15 @@ class ASTContext : public RefCountedBase { /// use ParentMapContext::getParents() directly. template DynTypedNodeList getParents(const NodeT &Node); + uint32_t getGeneration() const { return CurrentGeneration; } + uint32_t incrementGeneration() { + uint32_t OldGeneration = CurrentGeneration; + CurrentGeneration++; + assert(CurrentGeneration > OldGeneration && + "Overflowed generation counter"); + return OldGeneration; + } + const clang::PrintingPolicy &getPrintingPolicy() const { return PrintingPolicy; } @@ -3712,7 +3725,7 @@ typename clang::LazyGenerationalUpdatePtr::ValueType // include ASTContext.h. We explicitly instantiate it for all relevant types // in ASTContext.cpp. if (auto *Source = Ctx.getExternalSource()) - return new (Ctx) LazyData(Source, Value); + return new (Ctx) LazyData(&Ctx, Source, Value); return Value; } diff --git a/interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h b/interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h index 42aed56d42e07..b8b0b88438a78 100644 --- a/interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h +++ b/interpreter/llvm-project/clang/include/clang/AST/ExternalASTSource.h @@ -92,7 +92,7 @@ class ExternalASTSource : public RefCountedBase { /// Get the current generation of this AST source. This number /// is incremented each time the AST source lazily extends an existing /// entity. - uint32_t getGeneration() const { return CurrentGeneration; } + uint32_t getGeneration(const ASTContext &C) const; /// Resolve a declaration ID into a declaration, potentially /// building a new declaration. @@ -442,12 +442,14 @@ struct LazyGenerationalUpdatePtr { /// A cache of the value of this pointer, in the most recent generation in /// which we queried it. struct LazyData { + const ASTContext *Context; ExternalASTSource *ExternalSource; uint32_t LastGeneration = 0; T LastValue; - LazyData(ExternalASTSource *Source, T Value) - : ExternalSource(Source), LastValue(Value) {} + LazyData(const ASTContext *Context, ExternalASTSource *Source, T Value) + : Context(Context), ExternalSource(Source), LastGeneration(0), + LastValue(Value) {} }; // Our value is represented as simply T if there is no external AST source. @@ -487,8 +489,10 @@ struct LazyGenerationalUpdatePtr { /// Get the value of this pointer, updating its owner if necessary. T get(Owner O) { if (auto *LazyVal = Value.template dyn_cast()) { - if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) { - LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); + if (LazyVal->LastGeneration != + LazyVal->ExternalSource->getGeneration(*LazyVal->Context)) { + LazyVal->LastGeneration = + LazyVal->ExternalSource->getGeneration(*LazyVal->Context); (LazyVal->ExternalSource->*Update)(O); } return LazyVal->LastValue; diff --git a/interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h b/interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h index 47301419c76c6..2bf1f698b5cb1 100644 --- a/interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h +++ b/interpreter/llvm-project/clang/include/clang/Serialization/ASTReader.h @@ -1508,6 +1508,12 @@ class ASTReader : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {} }; + uint32_t getGenerationOrNull() const { + if (ContextObj) + return getGeneration(*ContextObj); + return 0u; + } + ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, ModuleFile *ImportedBy, SmallVectorImpl &Loaded, diff --git a/interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp b/interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp index e2451f294741d..7ae7188b7ef8f 100644 --- a/interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp +++ b/interpreter/llvm-project/clang/lib/AST/ExternalASTSource.cpp @@ -28,6 +28,10 @@ char ExternalASTSource::ID; ExternalASTSource::~ExternalASTSource() = default; +uint32_t ExternalASTSource::getGeneration(const ASTContext &C) const { + return C.getGeneration(); +} + std::optional ExternalASTSource::getSourceDescriptor(unsigned ID) { return std::nullopt; @@ -114,19 +118,5 @@ void ExternalASTSource::FindExternalLexicalDecls( void ExternalASTSource::getMemoryBufferSizes(MemoryBufferSizes &sizes) const {} uint32_t ExternalASTSource::incrementGeneration(ASTContext &C) { - uint32_t OldGeneration = CurrentGeneration; - - // Make sure the generation of the topmost external source for the context is - // incremented. That might not be us. - auto *P = C.getExternalSource(); - if (P && P != this) - CurrentGeneration = P->incrementGeneration(C); - else { - // FIXME: Only bump the generation counter if the current generation number - // has been observed? - if (!++CurrentGeneration) - llvm::report_fatal_error("generation counter overflowed", false); - } - - return OldGeneration; + return C.incrementGeneration(); } diff --git a/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp b/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp index 427b3c82c4737..812f5173832d3 100644 --- a/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp +++ b/interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp @@ -2463,7 +2463,7 @@ void ASTReader::markIdentifierUpToDate(const IdentifierInfo *II) { // Update the generation for this identifier. if (getContext().getLangOpts().Modules) - IdentifierGeneration[II] = getGeneration(); + IdentifierGeneration[II] = getGenerationOrNull(); } void ASTReader::resolvePendingMacro(IdentifierInfo *II, @@ -4958,11 +4958,10 @@ ASTReader::ReadASTCore(StringRef FileName, unsigned ClientLoadCapabilities) { ModuleFile *M; std::string ErrorStr; - ModuleManager::AddModuleResult AddResult - = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, - getGeneration(), ExpectedSize, ExpectedModTime, - ExpectedSignature, readASTFileSignature, - M, ErrorStr); + ModuleManager::AddModuleResult AddResult = + ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, + getGenerationOrNull(), ExpectedSize, ExpectedModTime, + ExpectedSignature, readASTFileSignature, M, ErrorStr); switch (AddResult) { case ModuleManager::AlreadyLoaded: @@ -9143,7 +9142,7 @@ void ASTReader::ReadMethodPool(Selector Sel) { // Get the selector generation and update it to the current generation. unsigned &Generation = SelectorGeneration[Sel]; unsigned PriorGeneration = Generation; - Generation = getGeneration(); + Generation = getGenerationOrNull(); SelectorOutOfDate[Sel] = false; // Search for methods defined with this selector. From 37c9bc54ef6ab53dc6bfcfc0841cb0be5dbd278e Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sat, 15 Aug 2020 06:39:01 +0000 Subject: [PATCH 17/18] Import various changes to the global module index. Adds root-project/root@2eada9379d, root-project/root@e874b29424, root-project/root@e67108aba6, root-project/root@e9060b6356, root-project/root@9368f052c1 --- .../clang/Serialization/GlobalModuleIndex.h | 28 ++++- .../clang/lib/Sema/SemaModule.cpp | 2 +- .../lib/Serialization/GlobalModuleIndex.cpp | 114 ++++++++++++------ 3 files changed, 106 insertions(+), 38 deletions(-) diff --git a/interpreter/llvm-project/clang/include/clang/Serialization/GlobalModuleIndex.h b/interpreter/llvm-project/clang/include/clang/Serialization/GlobalModuleIndex.h index 93d674e440034..2ff0f5845c1c6 100644 --- a/interpreter/llvm-project/clang/include/clang/Serialization/GlobalModuleIndex.h +++ b/interpreter/llvm-project/clang/include/clang/Serialization/GlobalModuleIndex.h @@ -15,12 +15,16 @@ #ifndef LLVM_CLANG_SERIALIZATION_GLOBALMODULEINDEX_H #define LLVM_CLANG_SERIALIZATION_GLOBALMODULEINDEX_H +#include "clang/Basic/FileEntry.h" + #include "llvm/ADT/DenseMap.h" +#include #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" +#include "llvm/ADT/StringSet.h" #include #include @@ -40,6 +44,12 @@ namespace serialization { class ModuleFile; } +using llvm::SmallVector; +using llvm::SmallVectorImpl; +using llvm::StringRef; +using llvm::StringSet; +using serialization::ModuleFile; + /// A global index for a set of module files, providing information about /// the identifiers within those module files. /// @@ -52,8 +62,6 @@ namespace serialization { /// imported, and can be queried to determine which modules the current /// translation could or should load to fix a problem. class GlobalModuleIndex { - using ModuleFile = serialization::ModuleFile; - /// Buffer containing the index file, which is lazily accessed so long /// as the global module index is live. std::unique_ptr Buffer; @@ -119,6 +127,9 @@ class GlobalModuleIndex { GlobalModuleIndex &operator=(const GlobalModuleIndex &) = delete; public: + using UserDefinedInterestingIDs = + llvm::StringMap>; + ~GlobalModuleIndex(); /// Read a global index file for the given directory. @@ -136,6 +147,12 @@ class GlobalModuleIndex { /// The caller accepts ownership of the returned object. IdentifierIterator *createIdentifierIterator() const; + /// Retrieve the set of modules that have up-to-date indexes. + /// + /// \param ModuleFiles Will be populated with the set of module file namess + /// that have been indexed. + void getKnownModuleFileNames(StringSet<> &ModuleFiles); + /// Retrieve the set of module files on which the given module file /// directly depends. void getModuleDependencies(ModuleFile *File, @@ -155,6 +172,9 @@ class GlobalModuleIndex { /// \returns true if the identifier is known to the index, false otherwise. bool lookupIdentifier(llvm::StringRef Name, HitSet &Hits); + typedef llvm::SmallDenseSet FileNameHitSet; + bool lookupIdentifier(StringRef Name, FileNameHitSet &Hits); + /// Note that the given module file has been loaded. /// /// \returns false if the global module index has information about this @@ -174,9 +194,11 @@ class GlobalModuleIndex { /// creating modules. /// \param Path The path to the directory containing module files, into /// which the global index will be written. + /// \param Optionally pass already precomputed interesting identifiers. static llvm::Error writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, - llvm::StringRef Path); + StringRef Path, + UserDefinedInterestingIDs *ExternalIDs = nullptr); }; } diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaModule.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaModule.cpp index 76589bff40be9..663994a7af0a7 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaModule.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaModule.cpp @@ -657,7 +657,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, diag::warn_import_implementation_partition_unit_in_interface_unit) << Mod->Name; - checkModuleImportContext(*this, Mod, ImportLoc, CurContext); + //checkModuleImportContext(*this, Mod, ImportLoc, CurContext); // FIXME: we should support importing a submodule within a different submodule // of the same top-level module. Until we do, make it an error rather than diff --git a/interpreter/llvm-project/clang/lib/Serialization/GlobalModuleIndex.cpp b/interpreter/llvm-project/clang/lib/Serialization/GlobalModuleIndex.cpp index 4b920fccecac3..27c104a048746 100644 --- a/interpreter/llvm-project/clang/lib/Serialization/GlobalModuleIndex.cpp +++ b/interpreter/llvm-project/clang/lib/Serialization/GlobalModuleIndex.cpp @@ -280,6 +280,13 @@ GlobalModuleIndex::readIndex(StringRef Path) { llvm::Error::success()); } +void GlobalModuleIndex::getKnownModuleFileNames(StringSet<> &ModuleFiles) { + ModuleFiles.clear(); + for (unsigned I = 0, N = Modules.size(); I != N; ++I) { + ModuleFiles.insert(Modules[I].FileName); + } +} + void GlobalModuleIndex::getModuleDependencies( ModuleFile *File, SmallVectorImpl &Dependencies) { @@ -324,6 +331,32 @@ bool GlobalModuleIndex::lookupIdentifier(StringRef Name, HitSet &Hits) { return true; } +bool GlobalModuleIndex::lookupIdentifier(StringRef Name, FileNameHitSet &Hits) { + Hits.clear(); + + // If there's no identifier index, there is nothing we can do. + if (!IdentifierIndex) + return false; + + // Look into the identifier index. + ++NumIdentifierLookups; + IdentifierIndexTable &Table = + *static_cast(IdentifierIndex); + IdentifierIndexTable::iterator Known = Table.find(Name); + if (Known == Table.end()) { + return false; + } + + SmallVector ModuleIDs = *Known; + for (unsigned I = 0, N = ModuleIDs.size(); I != N; ++I) { + assert(!Modules[ModuleIDs[I]].FileName.empty()); + Hits.insert(Modules[ModuleIDs[I]].FileName); + } + + ++NumIdentifierLookupHits; + return true; +} + bool GlobalModuleIndex::loadedModuleFile(ModuleFile *File) { // Look for the module in the global module index based on the module name. StringRef Name = File->ModuleName; @@ -400,9 +433,6 @@ namespace { /// Builder that generates the global module index file. class GlobalModuleIndexBuilder { - FileManager &FileMgr; - const PCHContainerReader &PCHContainerRdr; - /// Mapping from files to module file information. using ModuleFilesMap = llvm::MapVector; @@ -440,12 +470,21 @@ namespace { } public: - explicit GlobalModuleIndexBuilder( - FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr) - : FileMgr(FileMgr), PCHContainerRdr(PCHContainerRdr) {} + explicit GlobalModuleIndexBuilder(GlobalModuleIndex::UserDefinedInterestingIDs* ExternalIDs) { + if (!ExternalIDs) + return; + + for (const auto & I : *ExternalIDs) + for (auto J : I.getValue()) + if (J) + InterestingIdentifiers[I.getKey()].push_back( + getModuleFileInfo(*J).ID); + } /// Load the contents of the given module file into the builder. - llvm::Error loadModuleFile(FileEntryRef File); + /// + llvm::Error loadModuleFile(FileEntryRef File, FileManager &FileMgr, + const PCHContainerReader &PCHContainerRdr); /// Write the index to the given bitstream. /// \returns true if an error occurred, false otherwise. @@ -517,7 +556,9 @@ namespace { }; } -llvm::Error GlobalModuleIndexBuilder::loadModuleFile(FileEntryRef File) { +llvm::Error GlobalModuleIndexBuilder::loadModuleFile( + FileEntryRef File, FileManager &FileMgr, + const PCHContainerReader &PCHContainerRdr) { // Open the module file. auto Buffer = FileMgr.getBufferForFile(File, /*isVolatile=*/true); @@ -755,7 +796,8 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) { // Verify Signature. return true; } else if (Info.StoredSize != File.getSize() || - Info.StoredModTime != File.getModificationTime()) + (Info.StoredModTime && + Info.StoredModTime != File.getModificationTime())) // Verify Size and ModTime. return true; } @@ -842,7 +884,9 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) { llvm::Error GlobalModuleIndex::writeIndex(FileManager &FileMgr, const PCHContainerReader &PCHContainerRdr, - StringRef Path) { + StringRef Path, + UserDefinedInterestingIDs *ExternalIDs /* = nullptr */) { + llvm::SmallString<128> IndexPath; IndexPath += Path; llvm::sys::path::append(IndexPath, IndexFileName); @@ -866,33 +910,35 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr, } // The module index builder. - GlobalModuleIndexBuilder Builder(FileMgr, PCHContainerRdr); - - // Load each of the module files. - std::error_code EC; - for (llvm::sys::fs::directory_iterator D(Path, EC), DEnd; - D != DEnd && !EC; - D.increment(EC)) { - // If this isn't a module file, we don't care. - if (llvm::sys::path::extension(D->path()) != ".pcm") { - // ... unless it's a .pcm.lock file, which indicates that someone is - // in the process of rebuilding a module. They'll rebuild the index - // at the end of that translation unit, so we don't have to. - if (llvm::sys::path::extension(D->path()) == ".pcm.lock") - return llvm::createStringError(std::errc::device_or_resource_busy, - "someone else is building the index"); + GlobalModuleIndexBuilder Builder(ExternalIDs); + + if (!ExternalIDs) { + // Load each of the module files. + std::error_code EC; + for (llvm::sys::fs::directory_iterator D(Path, EC), DEnd; + D != DEnd && !EC; + D.increment(EC)) { + // If this isn't a module file, we don't care. + if (llvm::sys::path::extension(D->path()) != ".pcm") { + // ... unless it's a .pcm.lock file, which indicates that someone is + // in the process of rebuilding a module. They'll rebuild the index + // at the end of that translation unit, so we don't have to. + if (llvm::sys::path::extension(D->path()) == ".pcm.lock") + return llvm::createStringError(std::errc::device_or_resource_busy, + "someone else is building the index"); - continue; - } + continue; + } - // If we can't find the module file, skip it. - auto ModuleFile = FileMgr.getOptionalFileRef(D->path()); - if (!ModuleFile) - continue; + // If we can't find the module file, skip it. + auto ModuleFile = FileMgr.getOptionalFileRef(D->path()); + if (!ModuleFile) + continue; - // Load this module file. - if (llvm::Error Err = Builder.loadModuleFile(*ModuleFile)) - return Err; + // Load this module file. + if (auto Err = Builder.loadModuleFile(*ModuleFile, FileMgr, PCHContainerRdr)) + return Err; + } } // The output buffer, into which the global index will be written. From 127c34368b7d81efda66e709b5eb0e4cc273eee1 Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy Date: Thu, 22 Jan 2026 15:12:42 +0100 Subject: [PATCH 18/18] Move ParserCurTokRestoreRAII to cling --- core/metacling/src/ClingRAII.h | 2 +- core/metacling/src/TCling.cxx | 2 +- core/metacling/src/TClingCallbacks.cxx | 3 ++- .../include/cling/Utils/ParserStateRAII.h | 24 +++++++++++++++++++ .../cling/lib/Interpreter/ClingPragmas.cpp | 3 ++- .../cling/lib/Interpreter/LookupHelper.cpp | 2 +- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/core/metacling/src/ClingRAII.h b/core/metacling/src/ClingRAII.h index cce753ced1266..d17b5630f28b6 100644 --- a/core/metacling/src/ClingRAII.h +++ b/core/metacling/src/ClingRAII.h @@ -58,7 +58,7 @@ namespace ROOT { }; clang::Preprocessor::CleanupAndRestoreCacheRAII fCleanupRAII; - clang::Parser::ParserCurTokRestoreRAII fSavedCurToken; + cling::ParserCurTokRestoreRAII fSavedCurToken; cling::ParserStateRAII fParserRAII; // Buffer the delayed infos when doing recursive parsing. diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx index 79b6f4ab2e4dd..0d6493c447dc2 100644 --- a/core/metacling/src/TCling.cxx +++ b/core/metacling/src/TCling.cxx @@ -7828,7 +7828,7 @@ TObject* TCling::GetObjectAddress(const char *Name, void *&LookupCtx) Preprocessor &PP = SemaR.getPreprocessor(); Parser& P = const_cast(fInterpreter->getParser()); Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP); - Parser::ParserCurTokRestoreRAII savedCurToken(P); + cling::ParserCurTokRestoreRAII savedCurToken(P); // After we have saved the token reset the current one to something which // is safe (semi colon usually means empty decl) Token& Tok = const_cast(P.getCurToken()); diff --git a/core/metacling/src/TClingCallbacks.cxx b/core/metacling/src/TClingCallbacks.cxx index bfe0f0607973e..a5e064fe050f5 100644 --- a/core/metacling/src/TClingCallbacks.cxx +++ b/core/metacling/src/TClingCallbacks.cxx @@ -19,6 +19,7 @@ #include "cling/Interpreter/InterpreterCallbacks.h" #include "cling/Interpreter/Transaction.h" #include "cling/Utils/AST.h" +#include "cling/Utils/ParserStateRAII.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" @@ -252,7 +253,7 @@ bool TClingCallbacks::FileNotFound(llvm::StringRef FileName) { Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP); Parser& P = const_cast(m_Interpreter->getParser()); // We parsed 'include' token. Store it. - clang::Parser::ParserCurTokRestoreRAII fSavedCurToken(P); + cling::ParserCurTokRestoreRAII fSavedCurToken(P); // We provide our own way of handling the entire #include "file.c+" // After we have saved the token reset the current one to // something which is safe (semi colon usually means empty decl) diff --git a/interpreter/cling/include/cling/Utils/ParserStateRAII.h b/interpreter/cling/include/cling/Utils/ParserStateRAII.h index 211ebb362e391..f26d0c12bcf03 100644 --- a/interpreter/cling/include/cling/Utils/ParserStateRAII.h +++ b/interpreter/cling/include/cling/Utils/ParserStateRAII.h @@ -19,6 +19,30 @@ namespace clang { } namespace cling { + /// A RAII object to temporarily reset PP's state and restore it. + class ParserCurTokRestoreRAII { + private: + clang::Parser& P; + clang::Token SavedTok; + + public: + ParserCurTokRestoreRAII(clang::Parser& P) + : P(P), SavedTok(P.getCurToken()) {} + + void pop() { + if (SavedTok.is(clang::tok::unknown)) + return; + + // Restore the token by getting a non-const reference + // Not ideal, but the only way to avoid the patch. + const_cast(P.getCurToken()) = SavedTok; + + SavedTok.startToken(); + } + + ~ParserCurTokRestoreRAII() { pop(); } + }; + ///\brief Cleanup Parser state after a failed lookup. /// /// After a failed lookup we need to discard the remaining unparsed input, diff --git a/interpreter/cling/lib/Interpreter/ClingPragmas.cpp b/interpreter/cling/lib/Interpreter/ClingPragmas.cpp index b5c309652f8eb..62e6373b33530 100644 --- a/interpreter/cling/lib/Interpreter/ClingPragmas.cpp +++ b/interpreter/cling/lib/Interpreter/ClingPragmas.cpp @@ -13,6 +13,7 @@ #include "cling/Interpreter/Interpreter.h" #include "cling/Interpreter/Transaction.h" #include "cling/Utils/Output.h" +#include "cling/Utils/ParserStateRAII.h" #include "cling/Utils/Paths.h" #include "clang/AST/ASTContext.h" @@ -140,7 +141,7 @@ namespace { FileInfos.push_back({std::move(Literal), Tok.getLocation()}); clang::Parser& P = m_Interp.getParser(); - Parser::ParserCurTokRestoreRAII savedCurToken(P); + cling::ParserCurTokRestoreRAII savedCurToken(P); // After we have saved the token reset the current one to something // which is safe (semi colon usually means empty decl) Token& CurTok = const_cast(P.getCurToken()); diff --git a/interpreter/cling/lib/Interpreter/LookupHelper.cpp b/interpreter/cling/lib/Interpreter/LookupHelper.cpp index 66fed6c29fa10..bcc6ab208f2ac 100644 --- a/interpreter/cling/lib/Interpreter/LookupHelper.cpp +++ b/interpreter/cling/lib/Interpreter/LookupHelper.cpp @@ -47,7 +47,7 @@ namespace cling { // whether we need to do so here too or whether we need to also see the // "on-going" semantic information ... For now, we leave Sema untouched. clang::Preprocessor::CleanupAndRestoreCacheRAII fCleanupRAII; - clang::Parser::ParserCurTokRestoreRAII fSavedCurToken; + cling::ParserCurTokRestoreRAII fSavedCurToken; ParserStateRAII ResetParserState; clang::Sema::SFINAETrap fSFINAETrap; void prepareForParsing(llvm::StringRef code, llvm::StringRef bufferName,