clang 24.0.0git
ErrorRecovery.h
Go to the documentation of this file.
1//===--- ErrorRecovery.h - Errory Recovery Impl --------------*- C++
2//-*-===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9//
10// This header provides the main error-recovery component for supporting
11// error recovery in clang-repl.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_INTERPRETER_ERROR_RECOVERY_H
16#define LLVM_CLANG_INTERPRETER_ERROR_RECOVERY_H
17
20#include "clang/AST/Decl.h"
21#include "clang/AST/DeclBase.h"
22#include "clang/AST/DeclCXX.h"
26#include "llvm/ADT/BitVector.h"
27#include <variant>
28
29namespace clang {
30class ASTContext;
31class Sema;
32
33/// Index of a per PTU State.
35
36/// A snapshot of the DefinitionData bits and bitfields that can change
37/// after a class gets a special implicit member added.
39#define FIELD(Name, Width, Merge) unsigned Name : Width;
40#include "clang/AST/CXXRecordDeclDefinitionBits.def"
41
42 bool operator==(const DefinitionDataFootprint &O) const {
43#define FIELD(Name, Width, Merge) \
44 if (Name != O.Name) \
45 return false;
46#include "clang/AST/CXXRecordDeclDefinitionBits.def"
47 return true;
48 }
49 bool operator!=(const DefinitionDataFootprint &O) const {
50 return !(*this == O);
51 }
52
53 // void update(const CXXRecordDecl &Live) {
54 // DeclStateReverter::createDefinitionDataFootprint(*this, Live);
55 // }
56
57 // void restore(CXXRecordDecl &Live) const {
58 // DeclStateReverter::restoreDefinitionDataFootprint(*this, Live);
59 // }
60};
61
62// Stores the state of a class template specialization. Tracks its
63// specialization kind, point of instantiation, source location, and lexical
64// declaration context so the state can be compared and restored.
95
96// Stores the state of a variable template specialization. Tracks its
97// specialization kind and point of instantiation so the state can be
98// compared and restored.
122
123// Stores the state of a function template specialization. Tracks its
124// specialization kind, point of instantiation, source location, lexical
125// declaration context, and constexpr state so the state can be compared
126// and restored.
161
162// Stores the state of an ordinary class member created from a class template
163// instantiation. Tracks its specialization kind and point of instantiation
164// so the state can be compared and restored.
166 unsigned SpecializationKind : 3;
168
174 return !(*this == O);
175 }
176
177 template <typename OwnerT> void update(const OwnerT &Live) {
178 const MemberSpecializationInfo *MSI = Live.getMemberSpecializationInfo();
181 }
182
183 template <typename OwnerT> void restore(OwnerT &Live) const {
184 MemberSpecializationInfo *MSI = Live.getMemberSpecializationInfo();
188 }
189};
190
191class PTUMutationActions;
192
193/// Maps addresses to the PTU that allocated them, by keeping the slab
194/// checkpoint taken before each PTU began.
196 const ASTContext &Ctx;
197 llvm::SmallVector<int64_t, 16> CheckpointBeforePTU;
198 llvm::BitVector Dead;
199
200public:
201 explicit PTUCheckpointLedger(const ASTContext &Ctx) : Ctx(Ctx) {}
202
203 /// Called once, right before parsing PTU \p ID begins.
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);
210 }
211
212 /// Was \p Ptr allocated during PTU \p ID or later?
213 bool isFromThisPTU(const void *Ptr, PTUID ID) const {
214 assert(ID < CheckpointBeforePTU.size());
215 assert(!Dead[ID] &&
216 "querying provenance against a PTU that no longer exists");
217 return Ctx.getAllocator().identifyKnownObject(Ptr) >=
218 CheckpointBeforePTU[ID];
219 }
220
221 /// FIXME: Pop back CheckpointBeforePTU once memory restoration is supported.
222 /// For now, there is no memory restoration, so mark it dead.
223 void markDead(PTUID ID) {
224 assert(ID < Dead.size());
225 Dead[ID] = true;
226 }
227};
228
230 enum class DeclShape : uint16_t {
231 None = 0,
232 // Base shapes -- what the decl fundamentally is. Exactly one is set.
233 Class = 1 << 0, // CXXRecordDecl/TagDecl: DefinitionData, TypeForDecl
234 Function = 1 << 1, // FunctionDecl: exception spec, deduced return, body
235 Var = 1 << 2, // VarDecl: cached constant-eval result
236 Enum = 1 << 3, // EnumDecl: TypeForDecl
237 Template = 1 << 4, // RedeclarableTemplateDecl: spec list grows
238 Typedef = 1 << 5, // TypedefDecl/TypeAliasDecl: TypeForDecl.
239 };
240
241 enum class MutationKind : uint32_t {
242 None = 0,
243 // ---- Common ----
244 DefinitionInstantiate = 1 << 0, // Class, Function, Var
245 SpecInfo = 1 << 1, // Class, Function, Var (Spec)
246 MemberSpecInfo = 1 << 2, // Class, Function, Var, Enum (Member)
247 TypeForDecl = 1 << 3, // Class, Enum
248
249 // ---- Shape-specific ----
250 DefinitionData = 1 << 8, // Class only
251 ExceptionSpec = 1 << 9, // Function only
252 DeducedReturnType = 1 << 10, // Function only
253 EvaluatedValue = 1 << 11, // Var only
254 SpecializationAdded = 1 << 12, // Template only
255
256 TemplateCommon = 1 << 4, // Template CommonBase
257 CanonInjectedTST = 1 << 5, // Template CommonBase Type
258 };
259
260 DeclShape S = DeclShape::None;
261 uint32_t MutationFlags = 0; // what this decl can ever have
262
265 bool has(MutationKind K) const { return MutationFlags & uint32_t(K); }
267};
268
271
276
281
283 llvm::DenseMap<std::pair<const Decl *, MutationKind>,
285 Store;
286
287public:
288 // commit decl state owner+mutation_kind -> Footprint.
289 template <typename T>
290 void commit(const Decl *Owner, MutationKind K, PTUID ID, const T &Fresh) {
291 auto &History = Store[{Owner, K}];
292 if (!History.empty() && std::get<T>(History.back().Data) == Fresh)
293 return;
294 History.push_back(FootprintSnapshot{ID, FootprintValue(Fresh)});
295 }
296
297 // nullptr means either "no history at all" or "history exists but the
298 // most recent entry isn't a T".
299 template <typename T>
300 const T *mostRecent(const Decl *Owner, MutationKind K) const {
301 auto It = Store.find({Owner, K});
302 if (It == Store.end() || It->second.empty())
303 return nullptr;
304 return std::get_if<T>(&It->second.back().Data);
305 }
306
307 /// Remove all entries with IDs greater than or equal to \p ID for this
308 /// (Owner, K). If no entries remain, remove the key entirely.
309 void removeFrom(const Decl *Owner, MutationKind K, PTUID ID) {
310 auto It = Store.find({Owner, K});
311 if (It == Store.end())
312 return;
313 auto &History = It->second;
314 while (!History.empty() && History.back().ID >= ID)
315 History.pop_back();
316 if (History.empty())
317 Store.erase(It);
318 }
319};
320
323 const TranslationUnitDecl *ThisPTU; // current info
324
325 llvm::MapVector<const Decl *, MutationRecord> Mutations;
326
328
329 /// Set exactly when AddedCXXImplicitMember fires this PTU.
331
332 /// Every (Owner, Kind) key this PTU's own commit() wrote a FootprintStore
333 /// entry for.
335
336 explicit PTUStateInfo(PTUID ID) : ID(ID) {}
337
338 template <typename KindT>
339 void noteMutated(const Decl *D, DeclShape S, KindT K) {
341 return;
342 auto [It, Inserted] = Mutations.try_emplace(D);
343 if (Inserted) {
344 It->second.S = S;
345 }
346
347 assert(It->second.S == S && "same decl noted under two different shapes");
348
349 It->second.add(K);
350 }
351
352 void verifyMutations(PTUMutationActions &Actions);
353
354 // False until this PTU is actually committed.
355 // PTUMutationActions uses this to decide what "undo" should do:
356 // - If this PTU was never committed, nothing was added to the chain,
357 // so we just restore the last PTU that was committed.
358 // - If this PTU was already committed (for example, by using %undo),
359 // first remove the entries created by this PTU, then restore the
360 // state from before this PTU was added.
361 bool Commited = false;
362};
363
364//===----------------------------------------------------------------------===//
365// SweepTracker -- Tracks declarations whose mutations cannot be reported
366// directly by an ASTMutationListener.
367//
368// Each Decl is tracked with the hidden mutation kinds that are still possible.
369// At commit time, sweep() checks the tracked kinds to find mutations made by
370// the current PTU. Once a mutation kind is confirmed or can no longer happen,
371// it is removed from tracking.
372//
373// During restore, a mutation kind can be tracked again so its mutation sites
374// can be restored when needed.
375//===----------------------------------------------------------------------===//
377 llvm::DenseMap<const Decl *, uint32_t> Active;
378
379public:
380 void track(const Decl *D, uint32_t HiddenBits) {
381 if (HiddenBits)
382 Active[D] |= HiddenBits;
383 }
384
385 bool isTrackedFor(const Decl *D, uint32_t Flag) const {
386 auto It = Active.find(D);
387 return It != Active.end() && (It->second & Flag);
388 }
389
390 void untrack(const Decl *D, uint32_t Flag) {
391 auto It = Active.find(D);
392 if (It == Active.end())
393 return;
394 It->second &= ~Flag;
395 if (!It->second)
396 Active.erase(It);
397 }
398
399 // removes every Active entry whose decl matches Predicate.
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)
406 Active.erase(D);
407 }
408
409 // Call at commit/restore time. OnConfirmed is invoked as
410 // (const Decl *D, DeclShape S, uint32_t ConfirmedKinds) for every decl
411 // that had something newly confirmed this sweep.
412 template <typename OnConfirmedFn>
413 void sweep(PTUMutationActions &Act, OnConfirmedFn OnConfirmed);
414};
415
416// Overall flow:
417// - Track changes made by other PTUs so they can be applied to the relevant
418// chains/mutations when those PTUs are committed.
419// - On rollback of a committed PTU, remove the entries created by that PTU
420// and restore the state that existed before it.
421// - On rollback of a PTU that was never committed, restore the chain to its
422// current mostRecent() state, since this PTU never added anything to it.
423// - For the current PTU, collect newly added declarations that are
424// modifiable/visible to other PTUs. Local-only declarations are not exposed.
425//
426// In short, this keeps the shared declaration state in sync across PTUs.
428private:
429 ASTContext &Ctx;
430 PTUCheckpointLedger PTUSlabCheckpoints;
431 PTUID NextID = 0;
432
433 mutable std::vector<PTUStateInfo> PTUStack;
434
435 // One relation for every tracked footprint/value kind.
436 FootprintStore Footprints;
437
438 // Tracks hidden mutations for all supported Decl kinds in one shared tracker,
439 // so they can be restored correctly during rollback.
440 SweepTracker HiddenMutationTracker;
441
442 friend class PTUMutationActions;
443
444public:
446 : Ctx(Ctx), PTUSlabCheckpoints(Ctx) {}
447
448 // Writes a new value to FootprintStore and records that this PTU touched
449 // (Owner, K), so undoLastEntries() knows what to remove if the PTU is rolled
450 // back without committing.
451 template <typename T>
452 void commitFootprint(const Decl *Owner, MutationKind K, PTUID ID,
453 const T &Fresh) {
454 Footprints.commit(Owner, K, ID, Fresh);
455 current().TouchedFootprints.emplace_back(Owner, K);
456 }
457
458 FootprintStore &getFootprints() { return Footprints; }
459
461 assert(!PTUStack.empty() && "no PTU has been started");
462 return PTUStack.back();
463 }
464
465 PTUID currentID() const { return current().ID; }
466 bool hasOpenPTU() const { return !PTUStack.empty(); }
467
468 void beginPTU() {
469 PTUID ID = NextID++;
470 PTUSlabCheckpoints.recordCheckpoint(ID);
471 PTUStack.emplace_back(ID);
472 }
473
474 bool isFromThisPTU(const void *Ptr, PTUID ID) const {
475 return PTUSlabCheckpoints.isFromThisPTU(Ptr, ID);
476 }
477 bool isFromCurrentPTU(const void *Ptr) const {
478 return isFromThisPTU(Ptr, currentID());
479 }
480
481 SweepTracker &getHiddenMutationTracker() { return HiddenMutationTracker; }
482 PTUCheckpointLedger &getPTUSlabCheckpoints() { return PTUSlabCheckpoints; }
483 ASTContext &getASTContext() const { return Ctx; }
484
485 void undoLastEntries();
486
487private:
488 void popCurrentPTU() {
489 PTUID ID = currentID();
490 PTUStack.pop_back();
491 PTUSlabCheckpoints.markDead(ID);
492 }
493};
494
495// // Once place to revert Sema specific cache.
497 Sema &SemaRef;
499
500public:
502 : SemaRef(S), Tracker(Tracker) {}
503
504 // Sema::SpecialMemberCache stores the CXXMethodDecl* found by previous
505 // LookupSpecialMember() calls for each (RD, kind+qualifiers). Remove entries
506 // that refer to methods from the PTU being rolled back.
508
509 // Sema::VTablesUsed records, per class, whether its vtable has already
510 // been marked used.
512};
513
514class PTUMutationActions : public ConstDeclVisitor<PTUMutationActions> {
515private:
517 SweepTracker &HiddenMutationTracker;
518 Sema &SemaRef;
519 CodeGenerator *CodeGen = nullptr;
520 SemaCacheReverter SemaCache;
521
522 MutationRecord *Rec = nullptr;
523
524 PTUID CurrentID() const { return Tracker.currentID(); }
525 MutationRecord &Record() const {
526 assert(Rec && "Invalid MutationRecord");
527 return *Rec;
528 }
529
530public:
532 CodeGenerator *CodeGen = nullptr)
533 : Tracker(Tracker),
534 HiddenMutationTracker(Tracker.getHiddenMutationTracker()), SemaRef(S),
535 CodeGen(CodeGen), SemaCache(S, Tracker) {}
536
537 Sema &getSema() const { return SemaRef; }
538 CodeGenerator *getCodeGen() const { return CodeGen; }
539
541
542 uint32_t confirmMutation(const Decl *D, DeclShape S, uint32_t FlaggedKinds);
543
544 void trackForSweep(const Decl *D, uint32_t Kinds);
545
546 void untrackIfClosed(const Decl *D, DeclShape S, uint32_t Confirmed);
547
548 void syncSweepTracking(const Decl *D, DeclShape S, uint32_t Kinds,
549 bool IsNew);
550
551 bool shouldRecurseInto(const Decl *D);
552
553 void VisitDeclContext(const DeclContext *DC);
556 void VisitVarDecl(const VarDecl *VD) {}
557 void VisitEnumDecl(const EnumDecl *ED) {}
559
560 void CommitDecl(const Decl *D, MutationRecord *Rec);
561
562 // Actual commit action: updates IncrementalStateTracker tracking info for
563 // decls from the previous PTU after a successful PTU. And add tracking info
564 // for newly created Decls
565 //
566 void CommitPTU(TranslationUnitDecl *MostRecentTU);
567
568 // Restore action: restores decls from the previous PTU using
569 // IncrementalStateTracker tracking info and unlinks decls created by this
570 // PTU.
571 void RestorePTU(TranslationUnitDecl *MostRecentTU);
572};
573
575private:
577
578 template <typename TemplateT, typename SpecT>
579 void noteTemplateDeclMutation(const TemplateT *TD, const SpecT *Spec);
580
581 void noteDefinitionInstantiated(const Decl *D);
582
583public:
584 PTUMutationRecorder(IncrementalStateTracker &Tracker) : Tracker(Tracker) {}
585
586 /// A new TagDecl definition was completed.
587 void CompletedTagDefinition(const TagDecl *D) override {}
588
589 /// A new declaration with name has been added to a DeclContext.
590 void AddedVisibleDecl(const DeclContext *DC, const Decl *D) override {}
591
592 /// An implicit member was added after the definition was completed.
593 void AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) override {
594 }
595
596 /// A template specialization (or partial one) was added to the
597 /// template declaration.
599 const ClassTemplateDecl *TD,
600 const ClassTemplateSpecializationDecl *D) override;
601
602 /// A template specialization (or partial one) was added to the
603 /// template declaration.
607
608 /// A template specialization (or partial one) was added to the
609 /// template declaration.
611 const FunctionDecl *D) override {}
612
613 /// A function's exception specification has been evaluated or
614 /// instantiated.
615 void ResolvedExceptionSpec(const FunctionDecl *FD) override {}
616
617 /// A function's return type has been deduced.
618 void DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) override {
619 }
620
621 /// A virtual destructor's operator delete has been resolved.
623 const FunctionDecl *Delete,
624 Expr *ThisArg) override {}
625
626 /// A virtual destructor's operator global delete has been resolved.
628 const FunctionDecl *GlobDelete) override {}
629
630 /// A virtual destructor's operator array delete has been resolved.
632 const FunctionDecl *ArrayDelete) override {}
633
634 /// A virtual destructor's operator global array delete has been resolved.
636 const CXXDestructorDecl *DD,
637 const FunctionDecl *GlobArrayDelete) override {}
638
639 /// An implicit member got a definition.
641 // noteDefinitionInstantiated(D);
642 }
643
644 /// The instantiation of a templated function or variable was
645 /// requested. In particular, the point of instantiation and template
646 /// specialization kind of \p D may have changed.
647 void InstantiationRequested(const ValueDecl *D) override {}
648
649 /// A templated variable's definition was implicitly instantiated.
650 void VariableDefinitionInstantiated(const VarDecl *D) override {}
651
652 /// A function template's definition was instantiated.
654
655 /// A default argument was instantiated.
656 void DefaultArgumentInstantiated(const ParmVarDecl *D) override {}
657
658 /// A default member initializer was instantiated.
660
661 /// A new objc category class was added for an interface.
663 const ObjCInterfaceDecl *IFD) override {}
664
665 /// A declaration is marked used which was not previously marked used.
666 ///
667 /// \param D the declaration marked used
668 void DeclarationMarkedUsed(const Decl *D) override {}
669
670 /// A declaration is marked as OpenMP threadprivate which was not
671 /// previously marked as threadprivate.
672 ///
673 /// \param D the declaration marked OpenMP threadprivate.
675
676 /// A declaration is marked as OpenMP groupprivate which was not
677 /// previously marked as groupprivate.
678 ///
679 /// \param D the declaration marked OpenMP groupprivate.
680 void DeclarationMarkedOpenMPGroupPrivate(const Decl *D) override {}
681
682 /// A declaration is marked as OpenMP declaretarget which was not
683 /// previously marked as declaretarget.
684 ///
685 /// \param D the declaration marked OpenMP declaretarget.
686 /// \param Attr the added attribute.
688 const Attr *Attr) override {}
689
690 /// A declaration is marked as a variable with OpenMP allocator.
691 ///
692 /// \param D the declaration marked as a variable with OpenMP allocator.
693 void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override {}
694
695 /// A declaration is marked as an OpenMP indirect call target.
696 ///
697 /// \param D the declaration marked as an indirect call target.
698 void DeclarationMarkedOpenMPIndirectCall(const Decl *D) override {}
699
700 /// A definition has been made visible by being redefined locally.
701 ///
702 /// \param D The definition that was previously not visible.
703 /// \param M The containing module in which the definition was made visible,
704 /// if any.
705 void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override {}
706
707 /// An attribute was added to a RecordDecl
708 ///
709 /// \param Attr The attribute that was added to the Record
710 ///
711 /// \param Record The RecordDecl that got a new attribute
713 const RecordDecl *Record) override {}
714
715 /// An mangling number was added to a Decl
716 ///
717 /// \param D The decl that got a mangling number
718 ///
719 /// \param Number The mangling number that was added to the Decl
720 void AddedManglingNumber(const Decl *D, unsigned Number) override {}
721
722 /// An static local number was added to a Decl
723 ///
724 /// \param D The decl that got a static local number
725 ///
726 /// \param Number The static local number that was added to the Decl
727 void AddedStaticLocalNumbers(const Decl *D, unsigned Number) override {}
728
729 /// An anonymous namespace was added the translation unit decl
730 ///
731 /// \param TU The translation unit decl that got a new anonymous namespace
732 ///
733 /// \param AnonNamespace The anonymous namespace that was added
735 NamespaceDecl *AnonNamespace) override {}
736};
737} // end namespace clang
738#endif // LLVM_CLANG_INTERPRETER_ERROR_RECOVERY_H
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
Definition MachO.h:31
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:246
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Attr - This represents one attribute.
Definition Attr.h:47
Represents a C++ destructor within a class.
Definition DeclCXX.h:2924
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
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.
Definition DeclVisitor.h:75
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1468
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getLocation() const
Definition DeclBase.h:449
void setLocation(SourceLocation L)
Definition DeclBase.h:450
bool isDefinedOutsideFunctionOrMethod() const
isDefinedOutsideFunctionOrMethod - This predicate returns true if this scoped decl is defined outside...
Definition DeclBase.h:968
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition DeclBase.h:937
void setLexicalDeclContext(DeclContext *DC)
Definition DeclBase.cpp:389
Represents an enum.
Definition Decl.h:4198
This represents one expression.
Definition Expr.h:114
Represents a member of a struct/union/class.
Definition Decl.h:3346
void commit(const Decl *Owner, MutationKind K, PTUID ID, const T &Fresh)
void removeFrom(const Decl *Owner, MutationKind K, PTUID ID)
Remove all entries with IDs greater than or equal to ID for this (Owner, K).
const T * mostRecent(const Decl *Owner, MutationKind K) const
Represents a function declaration or definition.
Definition Decl.h:2082
ConstexprSpecKind getConstexprKind() const
Definition Decl.h:2645
SourceLocation getPointOfInstantiation() const
Retrieve the (first) point of instantiation of a function template specialization or a member of a cl...
Definition Decl.cpp:4622
void setTemplateSpecializationKind(TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4574
void setConstexprKind(ConstexprSpecKind CSK)
Definition Decl.h:2642
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition Decl.cpp:4505
Declaration of a template function.
bool isFromCurrentPTU(const void *Ptr) const
FootprintStore & getFootprints()
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.
Definition Module.h:340
This represents a decl that may have a name.
Definition Decl.h:276
Represent a C++ namespace.
Definition Decl.h:594
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2335
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
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.
Definition Decl.h:1832
A (possibly-)qualified type.
Definition TypeBase.h:938
Represents a struct/union/class.
Definition Decl.h:4512
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.
Definition Sema.h:863
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.
Definition Decl.h:3904
The top declaration context.
Definition Decl.h:107
The base class of the type hierarchy.
Definition TypeBase.h:1879
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
Represents a variable declaration or definition.
Definition Decl.h:934
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.
Definition Specifiers.h:36
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...
Definition Specifiers.h:192
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 update(const ClassTemplateSpecializationDecl &Live)
bool operator!=(const ClassSpecializationFootprint &O) const
bool operator==(const ClassSpecializationFootprint &O) const
void restore(ClassTemplateSpecializationDecl &Live) const
A snapshot of the DefinitionData bits and bitfields that can change after a class gets a special impl...
bool operator==(const DefinitionDataFootprint &O) const
bool operator!=(const DefinitionDataFootprint &O) const
void update(const FunctionDecl &Live)
bool operator!=(const FunctionSpecializationFootprint &O) const
void restore(FunctionDecl &Live) const
bool operator==(const FunctionSpecializationFootprint &O) const
void update(const OwnerT &Live)
void restore(OwnerT &Live) const
bool operator!=(const MemberSpecializationFootprint &O) const
bool operator==(const MemberSpecializationFootprint &O) const
void clear(MutationKind K)
bool has(MutationKind K) const
void add(uint32_t K)
void add(MutationKind K)
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
void restore(VarTemplateSpecializationDecl &Live) const
void update(const VarTemplateSpecializationDecl &Live)
bool operator!=(const VarSpecializationFootprint &O) const
bool operator==(const VarSpecializationFootprint &O) const