[clang] d31603e - [clang][Interp] Control InitStack activity state in visitInitList
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 19 06:00:51 PDT 2024
Author: Timm Bäder
Date: 2024-07-19T15:00:35+02:00
New Revision: d31603eefc2d8becfd1f41327b6a8db3e0e91a27
URL: https://github.com/llvm/llvm-project/commit/d31603eefc2d8becfd1f41327b6a8db3e0e91a27
DIFF: https://github.com/llvm/llvm-project/commit/d31603eefc2d8becfd1f41327b6a8db3e0e91a27.diff
LOG: [clang][Interp] Control InitStack activity state in visitInitList
This doesn't change anything about the current tests, but helps
once those tests change because of #97308
Added:
Modified:
clang/lib/AST/Interp/Compiler.cpp
clang/lib/AST/Interp/Compiler.h
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp
index 24140b23c1f0b..7da711ed485db 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -1334,6 +1334,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
auto initPrimitiveField = [=](const Record::Field *FieldToInit,
const Expr *Init, PrimType T) -> bool {
+ InitStackScope<Emitter> ISS(this, isa<CXXDefaultInitExpr>(Init));
if (!this->visit(Init))
return false;
@@ -1344,6 +1345,7 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
auto initCompositeField = [=](const Record::Field *FieldToInit,
const Expr *Init) -> bool {
+ InitStackScope<Emitter> ISS(this, isa<CXXDefaultInitExpr>(Init));
InitLinkScope<Emitter> ILS(this, InitLink::Field(FieldToInit->Offset));
// Non-primitive case. Get a pointer to the field-to-initialize
// on the stack and recurse into visitInitializer().
@@ -4088,12 +4090,7 @@ template <class Emitter>
bool Compiler<Emitter>::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E) {
SourceLocScope<Emitter> SLS(this, E);
- bool Old = InitStackActive;
- InitStackActive =
- !(E->getUsedContext()->getDeclKind() == Decl::CXXConstructor);
- bool Result = this->delegate(E->getExpr());
- InitStackActive = Old;
- return Result;
+ return this->delegate(E->getExpr());
}
template <class Emitter>
@@ -4151,6 +4148,9 @@ bool Compiler<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
// instance pointer of the current function frame, but e.g. to the declaration
// currently being initialized. Here we emit the necessary instruction(s) for
// this scenario.
+ if (!InitStackActive || !E->isImplicit())
+ return this->emitThis(E);
+
if (InitStackActive && !InitStack.empty()) {
unsigned StartIndex = 0;
for (StartIndex = InitStack.size() - 1; StartIndex > 0; --StartIndex) {
diff --git a/clang/lib/AST/Interp/Compiler.h b/clang/lib/AST/Interp/Compiler.h
index 6df723df2b444..084f5aef25f8e 100644
--- a/clang/lib/AST/Interp/Compiler.h
+++ b/clang/lib/AST/Interp/Compiler.h
@@ -33,6 +33,7 @@ template <class Emitter> class DestructorScope;
template <class Emitter> class VariableScope;
template <class Emitter> class DeclScope;
template <class Emitter> class InitLinkScope;
+template <class Emitter> class InitStackScope;
template <class Emitter> class OptionScope;
template <class Emitter> class ArrayIndexScope;
template <class Emitter> class SourceLocScope;
@@ -298,6 +299,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
friend class DestructorScope<Emitter>;
friend class DeclScope<Emitter>;
friend class InitLinkScope<Emitter>;
+ friend class InitStackScope<Emitter>;
friend class OptionScope<Emitter>;
friend class ArrayIndexScope<Emitter>;
friend class SourceLocScope<Emitter>;
@@ -612,6 +614,20 @@ template <class Emitter> class InitLinkScope final {
Compiler<Emitter> *Ctx;
};
+template <class Emitter> class InitStackScope final {
+public:
+ InitStackScope(Compiler<Emitter> *Ctx, bool Active)
+ : Ctx(Ctx), OldValue(Ctx->InitStackActive) {
+ Ctx->InitStackActive = Active;
+ }
+
+ ~InitStackScope() { this->Ctx->InitStackActive = OldValue; }
+
+private:
+ Compiler<Emitter> *Ctx;
+ bool OldValue;
+};
+
} // namespace interp
} // namespace clang
More information about the cfe-commits
mailing list