Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/metacling/src/ClingRAII.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7828,7 +7828,7 @@ TObject* TCling::GetObjectAddress(const char *Name, void *&LookupCtx)
Preprocessor &PP = SemaR.getPreprocessor();
Parser& P = const_cast<Parser&>(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<Token&>(P.getCurToken());
Expand Down
3 changes: 2 additions & 1 deletion core/metacling/src/TClingCallbacks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -252,7 +253,7 @@ bool TClingCallbacks::FileNotFound(llvm::StringRef FileName) {
Preprocessor::CleanupAndRestoreCacheRAII cleanupRAII(PP);
Parser& P = const_cast<Parser&>(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)
Expand Down
24 changes: 24 additions & 0 deletions interpreter/cling/include/cling/Utils/ParserStateRAII.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::Token&>(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,
Expand Down
3 changes: 2 additions & 1 deletion interpreter/cling/lib/Interpreter/ClingPragmas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<Token&>(P.getCurToken());
Expand Down
26 changes: 13 additions & 13 deletions interpreter/cling/lib/Interpreter/DeclUnloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion interpreter/cling/lib/Interpreter/LookupHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions interpreter/cling/lib/Interpreter/TransactionUnloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
42 changes: 0 additions & 42 deletions interpreter/llvm-project/clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T> void foo(auto x)`
bool isAbbreviated() const {
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <map>
#include <memory>
#include <string>
#include <set>

namespace llvm {

Expand Down Expand Up @@ -108,11 +107,6 @@ class FileManager : public RefCountedBase<FileManager> {
/// The canonical names of files and directories .
llvm::DenseMap<const void *, llvm::StringRef> CanonicalNames;

std::set<const FileEntry*> FileEntriesToReread;

/// The canonical names of directories.
llvm::DenseMap<const DirectoryEntry *, llvm::StringRef> CanonicalDirNames;

/// Storage for canonical names that we have computed.
llvm::BumpPtrAllocator CanonicalNameStorage;

Expand Down Expand Up @@ -332,9 +326,6 @@ class FileManager : public RefCountedBase<FileManager> {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class alignas(8) ContentCache {

/// Set the buffer.
void setBuffer(std::unique_ptr<llvm::MemoryBuffer> B) {
IsBufferInvalid = !B;
IsBufferInvalid = false;
Buffer = std::move(B);
}

Expand Down Expand Up @@ -845,8 +845,6 @@ class SourceManager : public RefCountedBase<SourceManager> {

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);
Expand Down
30 changes: 0 additions & 30 deletions interpreter/llvm-project/clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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
Expand All @@ -68,7 +67,6 @@ class Parser : public CodeCompletionHandler {
friend class ObjCDeclContextSwitch;
friend class ParenBraceBracketBalancer;
friend class BalancedDelimiterTracker;
friend class DestroyTemplateIdAnnotationsRAIIObj;
friend class ::cling::ParserStateRAII;

Preprocessor &PP;
Expand Down Expand Up @@ -504,34 +502,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();
Expand Down
6 changes: 3 additions & 3 deletions interpreter/llvm-project/clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,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);
Expand Down Expand Up @@ -11344,8 +11344,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,6 @@ class ASTReader
/// files.
llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;

/// \Token literal data loaded and owned by us.
std::vector<std::string *> TokenLiteralDataLoaded;

using GlobalMacroMapType =
ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>;

Expand Down
2 changes: 1 addition & 1 deletion interpreter/llvm-project/clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10080,7 +10080,7 @@ Expected<FileID> ASTImporter::Import(FileID FromID, bool IsBuiltin) {
// FIXME: We want to re-use the existing MemoryBuffer!
std::optional<llvm::MemoryBufferRef> FromBuf =
Cache->getBufferOrNone(FromContext.getDiagnostics(),
FromFileManager, SourceLocation{});
FromSM.getFileManager(), SourceLocation{});
if (!FromBuf)
return llvm::make_error<ASTImportError>(ASTImportError::Unknown);

Expand Down
6 changes: 6 additions & 0 deletions interpreter/llvm-project/clang/lib/AST/DeclTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 1 addition & 7 deletions interpreter/llvm-project/clang/lib/AST/TemplateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading
Loading