15#ifndef LLVM_CLANG_INTERPRETER_ERROR_RECOVERY_H
16#define LLVM_CLANG_INTERPRETER_ERROR_RECOVERY_H
26#include "llvm/ADT/BitVector.h"
39#define FIELD(Name, Width, Merge) unsigned Name : Width;
40#include "clang/AST/CXXRecordDeclDefinitionBits.def"
43#define FIELD(Name, Width, Merge) \
46#include "clang/AST/CXXRecordDeclDefinitionBits.def"
108 return !(*
this == O);
141 return !(*
this == O);
174 return !(*
this == O);
177 template <
typename OwnerT>
void update(
const OwnerT &Live) {
183 template <
typename OwnerT>
void restore(OwnerT &Live)
const {
191class PTUMutationActions;
198 llvm::BitVector Dead;
205 assert(ID == CheckpointBeforePTU.size() &&
206 "PTUs must be recorded in order");
207 CheckpointBeforePTU.push_back(Ctx.getAllocator().identifyKnownObject(
208 Ctx.getAllocator().Allocate(
sizeof(
int),
alignof(
int))));
209 Dead.push_back(
false);
214 assert(ID < CheckpointBeforePTU.size());
216 "querying provenance against a PTU that no longer exists");
217 return Ctx.getAllocator().identifyKnownObject(Ptr) >=
218 CheckpointBeforePTU[ID];
224 assert(ID < Dead.size());
283 llvm::DenseMap<std::pair<const Decl *, MutationKind>,
289 template <
typename T>
291 auto &History = Store[{Owner, K}];
292 if (!History.empty() && std::get<T>(History.back().Data) == Fresh)
299 template <
typename T>
301 auto It = Store.find({Owner, K});
302 if (It == Store.end() || It->second.empty())
304 return std::get_if<T>(&It->second.back().Data);
310 auto It = Store.find({Owner, K});
311 if (It == Store.end())
313 auto &History = It->second;
314 while (!History.empty() && History.back().ID >= ID)
325 llvm::MapVector<const Decl *, MutationRecord>
Mutations;
338 template <
typename KindT>
342 auto [It, Inserted] =
Mutations.try_emplace(D);
347 assert(It->second.S == S &&
"same decl noted under two different shapes");
377 llvm::DenseMap<const Decl *, uint32_t> Active;
382 Active[D] |= HiddenBits;
386 auto It = Active.find(D);
387 return It != Active.end() && (It->second & Flag);
391 auto It = Active.find(D);
392 if (It == Active.end())
400 template <
typename PredicateFn>
void untrackIf(PredicateFn Predicate) {
402 for (
auto &Entry : Active)
403 if (Predicate(Entry.getFirst()))
404 Stale.push_back(Entry.getFirst());
405 for (
const Decl *D : Stale)
412 template <
typename OnConfirmedFn>
433 mutable std::vector<PTUStateInfo> PTUStack;
446 : Ctx(Ctx), PTUSlabCheckpoints(Ctx) {}
451 template <
typename T>
454 Footprints.commit(Owner, K, ID, Fresh);
461 assert(!PTUStack.empty() &&
"no PTU has been started");
462 return PTUStack.back();
470 PTUSlabCheckpoints.recordCheckpoint(ID);
471 PTUStack.emplace_back(ID);
475 return PTUSlabCheckpoints.isFromThisPTU(Ptr, ID);
488 void popCurrentPTU() {
502 : SemaRef(S), Tracker(Tracker) {}
524 PTUID CurrentID()
const {
return Tracker.currentID(); }
526 assert(Rec &&
"Invalid MutationRecord");
534 HiddenMutationTracker(Tracker.getHiddenMutationTracker()), SemaRef(S),
535 CodeGen(CodeGen), SemaCache(S, Tracker) {}
578 template <
typename TemplateT,
typename SpecT>
579 void noteTemplateDeclMutation(
const TemplateT *TD,
const SpecT *Spec);
581 void noteDefinitionInstantiated(
const Decl *D);
624 Expr *ThisArg)
override {}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
llvm::MachO::Record Record
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Attr - This represents one attribute.
Represents a C++ destructor within a class.
Represents a C++ struct/union/class.
Declaration of a class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
void setPointOfInstantiation(SourceLocation Loc)
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setSpecializationKind(TemplateSpecializationKind TSK)
The primary public interface to the Clang code generator.
A simple visitor class that helps create declaration visitors.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
SourceLocation getLocation() const
void setLocation(SourceLocation L)
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
void setLexicalDeclContext(DeclContext *DC)
This represents one expression.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
ConstexprSpecKind getConstexprKind() const
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
void setConstexprKind(ConstexprSpecKind CSK)
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Declaration of a template function.
bool isFromCurrentPTU(const void *Ptr) const
FootprintStore & getFootprints()
friend class PTUMutationActions
PTUCheckpointLedger & getPTUSlabCheckpoints()
ASTContext & getASTContext() const
SweepTracker & getHiddenMutationTracker()
IncrementalStateTracker(ASTContext &Ctx)
PTUStateInfo & current() const
void commitFootprint(const Decl *Owner, MutationKind K, PTUID ID, const T &Fresh)
bool isFromThisPTU(const void *Ptr, PTUID ID) const
Provides information a specialization of a member of a class template, which may be a member function...
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the template specialization kind.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Describes a module or submodule.
This represents a decl that may have a name.
Represent a C++ namespace.
ObjCCategoryDecl - Represents a category declaration.
Represents an ObjC class declaration.
Maps addresses to the PTU that allocated them, by keeping the slab checkpoint taken before each PTU b...
void recordCheckpoint(PTUID ID)
Called once, right before parsing PTU ID begins.
void markDead(PTUID ID)
FIXME: Pop back CheckpointBeforePTU once memory restoration is supported.
PTUCheckpointLedger(const ASTContext &Ctx)
bool isFromThisPTU(const void *Ptr, PTUID ID) const
Was Ptr allocated during PTU ID or later?
void VisitVarDecl(const VarDecl *VD)
uint32_t confirmMutation(const Decl *D, DeclShape S, uint32_t FlaggedKinds)
The single place to check whether a kind has actually changed.
bool shouldRecurseInto(const Decl *D)
These are the places where the incremental state of a declaration is registered based on its DeclKind...
void CommitDecl(const Decl *D, MutationRecord *Rec)
void CommitPTU(TranslationUnitDecl *MostRecentTU)
void VisitFunctionDecl(const FunctionDecl *FD)
uint32_t DeclNeedingTracking(DeclShape S, const Decl *D)
This is called when a decl is created or seen for the first time.
void VisitDeclContext(const DeclContext *DC)
void VisitRedeclarableTemplateDecl(const RedeclarableTemplateDecl *RT)
void untrackIfClosed(const Decl *D, DeclShape S, uint32_t Confirmed)
Stop tracking Decl D when it no longer needs verification.
void VisitCXXRecordDecl(const CXXRecordDecl *RD)
void syncSweepTracking(const Decl *D, DeclShape S, uint32_t Kinds, bool IsNew)
void RestorePTU(TranslationUnitDecl *MostRecentTU)
void VisitEnumDecl(const EnumDecl *ED)
CodeGenerator * getCodeGen() const
PTUMutationActions(IncrementalStateTracker &Tracker, Sema &S, CodeGenerator *CodeGen=nullptr)
void trackForSweep(const Decl *D, uint32_t Kinds)
Start tracking D for mutation kinds that need verification.
void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override
A new declaration with name has been added to a DeclContext.
void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override
A declaration is marked as OpenMP threadprivate which was not previously marked as threadprivate.
void ResolvedOperatorDelete(const CXXDestructorDecl *DD, const FunctionDecl *Delete, Expr *ThisArg) override
A virtual destructor's operator delete has been resolved.
void CompletedImplicitDefinition(const FunctionDecl *D) override
An implicit member got a definition.
void DefaultMemberInitializerInstantiated(const FieldDecl *D) override
A default member initializer was instantiated.
void DeclarationMarkedUsed(const Decl *D) override
A declaration is marked used which was not previously marked used.
void AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, const FunctionDecl *D) override
A template specialization (or partial one) was added to the template declaration.
void DeclarationMarkedOpenMPGroupPrivate(const Decl *D) override
A declaration is marked as OpenMP groupprivate which was not previously marked as groupprivate.
void AddedAnonymousNamespace(const TranslationUnitDecl *TU, NamespaceDecl *AnonNamespace) override
An anonymous namespace was added the translation unit decl.
void FunctionDefinitionInstantiated(const FunctionDecl *D) override
A function template's definition was instantiated.
void DeclarationMarkedOpenMPDeclareTarget(const Decl *D, const Attr *Attr) override
A declaration is marked as OpenMP declaretarget which was not previously marked as declaretarget.
void AddedAttributeToRecord(const Attr *Attr, const RecordDecl *Record) override
An attribute was added to a RecordDecl.
void ResolvedOperatorArrayDelete(const CXXDestructorDecl *DD, const FunctionDecl *ArrayDelete) override
A virtual destructor's operator array delete has been resolved.
void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override
A definition has been made visible by being redefined locally.
void AddedManglingNumber(const Decl *D, unsigned Number) override
An mangling number was added to a Decl.
void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override
An implicit member was added after the definition was completed.
void DefaultArgumentInstantiated(const ParmVarDecl *D) override
A default argument was instantiated.
void CompletedTagDefinition(const TagDecl *D) override
A new TagDecl definition was completed.
void AddedCXXTemplateSpecialization(const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) override
A template specialization (or partial one) was added to the template declaration.
void AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, const ObjCInterfaceDecl *IFD) override
A new objc category class was added for an interface.
void VariableDefinitionInstantiated(const VarDecl *D) override
A templated variable's definition was implicitly instantiated.
void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override
A declaration is marked as a variable with OpenMP allocator.
void AddedStaticLocalNumbers(const Decl *D, unsigned Number) override
An static local number was added to a Decl.
void ResolvedOperatorGlobArrayDelete(const CXXDestructorDecl *DD, const FunctionDecl *GlobArrayDelete) override
A virtual destructor's operator global array delete has been resolved.
void InstantiationRequested(const ValueDecl *D) override
The instantiation of a templated function or variable was requested.
void AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) override
A template specialization (or partial one) was added to the template declaration.
void ResolvedOperatorGlobDelete(const CXXDestructorDecl *DD, const FunctionDecl *GlobDelete) override
A virtual destructor's operator global delete has been resolved.
void ResolvedExceptionSpec(const FunctionDecl *FD) override
A function's exception specification has been evaluated or instantiated.
void DeclarationMarkedOpenMPIndirectCall(const Decl *D) override
A declaration is marked as an OpenMP indirect call target.
void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override
A function's return type has been deduced.
PTUMutationRecorder(IncrementalStateTracker &Tracker)
Represents a parameter to a function.
A (possibly-)qualified type.
Represents a struct/union/class.
Declaration of a redeclarable template.
void restoreSpecialMemberCache(PTUID ID)
SemaCacheReverter(Sema &S, IncrementalStateTracker &Tracker)
void restoreVTableUsed(CXXRecordDecl *RD)
Sema - This implements semantic analysis and AST building for C.
Encodes a location in the source.
void untrackIf(PredicateFn Predicate)
bool isTrackedFor(const Decl *D, uint32_t Flag) const
void sweep(PTUMutationActions &Act, OnConfirmedFn OnConfirmed)
A single function called during commit and restore (when the PTU is uncommitted).
void track(const Decl *D, uint32_t HiddenBits)
void untrack(const Decl *D, uint32_t Flag)
Represents the declaration of a struct/union/class/enum.
The top declaration context.
The base class of the type hierarchy.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
SourceLocation getPointOfInstantiation() const
Get the point of instantiation (if any), or null if none.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setPointOfInstantiation(SourceLocation Loc)
TemplateSpecializationKind getSpecializationKind() const
Determine the kind of specialization that this declaration represents.
Top level wrappers for InstallAPI frontend operations.
std::variant< DefinitionDataFootprint, ClassSpecializationFootprint, VarSpecializationFootprint, FunctionSpecializationFootprint, MemberSpecializationFootprint, QualType, const Type * > FootprintValue
unsigned PTUID
Index of a per PTU State.
ConstexprSpecKind
Define the kind of constexpr specifier.
MutationRecord::MutationKind MutationKind
@ Delete
'delete' clause, allowed on the 'exit data' construct.
MutationRecord::DeclShape DeclShape
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
int32_t uint32_t uint32_t __builtin_riscv_mhracc_i32 __builtin_riscv_mhraccu_u32 __builtin_riscv_mhraccsu_i32 __builtin_riscv_mhacc_h1_i32 __builtin_riscv_mhaccsu_h1_i32 __builtin_riscv_mulqr_i32 __builtin_riscv_mqrwacc_i64 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 uint16_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 unsigned
void clear(MutationKind K)
bool has(MutationKind K) const
const TranslationUnitDecl * ThisPTU
llvm::MapVector< const Decl *, MutationRecord > Mutations
void verifyMutations(PTUMutationActions &Actions)
Verify recorded mutations and remove any false mutation ones.
bool HadImplicitCXXMember
Set exactly when AddedCXXImplicitMember fires this PTU.
void noteMutated(const Decl *D, DeclShape S, KindT K)
llvm::SmallVector< std::pair< const Decl *, MutationKind >, 8 > TouchedFootprints
Every (Owner, Kind) key this PTU's own commit() wrote a FootprintStore entry for.
llvm::SmallPtrSet< const Decl *, 4 > ImplicitlyGeneratedDecls