[clang] 5334afc - [clang][Interp] Don't forget to visit condition variable decls
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 15 04:30:49 PDT 2024
Author: Timm Bäder
Date: 2024-03-15T12:30:37+01:00
New Revision: 5334afcad827a6284ff56f5bde81d4e3416aae8c
URL: https://github.com/llvm/llvm-project/commit/5334afcad827a6284ff56f5bde81d4e3416aae8c
DIFF: https://github.com/llvm/llvm-project/commit/5334afcad827a6284ff56f5bde81d4e3416aae8c.diff
LOG: [clang][Interp] Don't forget to visit condition variable decls
We did this for if statements, but switch and loop constructs
need to do it as well.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/SemaCXX/decomposed-condition.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index b9e8e6a77a7205..675063e7489886 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -423,6 +423,11 @@ bool ByteCodeStmtGen<Emitter>::visitWhileStmt(const WhileStmt *S) {
LoopScope<Emitter> LS(this, EndLabel, CondLabel);
this->emitLabel(CondLabel);
+
+ if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
+ if (!visitDeclStmt(CondDecl))
+ return false;
+
if (!this->visitBool(Cond))
return false;
if (!this->jumpFalse(EndLabel))
@@ -487,6 +492,10 @@ bool ByteCodeStmtGen<Emitter>::visitForStmt(const ForStmt *S) {
if (Init && !this->visitStmt(Init))
return false;
this->emitLabel(CondLabel);
+
+ if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
+ if (!visitDeclStmt(CondDecl))
+ return false;
if (Cond) {
if (!this->visitBool(Cond))
return false;
@@ -585,17 +594,21 @@ bool ByteCodeStmtGen<Emitter>::visitContinueStmt(const ContinueStmt *S) {
template <class Emitter>
bool ByteCodeStmtGen<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
const Expr *Cond = S->getCond();
- PrimType CondT = this->classifyPrim(Cond->getType());
LabelTy EndLabel = this->getLabel();
OptLabelTy DefaultLabel = std::nullopt;
- unsigned CondVar = this->allocateLocalPrimitive(Cond, CondT, true, false);
if (const auto *CondInit = S->getInit())
if (!visitStmt(CondInit))
return false;
+ if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
+ if (!visitDeclStmt(CondDecl))
+ return false;
+
// Initialize condition variable.
+ PrimType CondT = this->classifyPrim(Cond->getType());
+ unsigned CondVar = this->allocateLocalPrimitive(Cond, CondT, true, false);
if (!this->visit(Cond))
return false;
if (!this->emitSetLocal(CondT, CondVar, S))
diff --git a/clang/test/SemaCXX/decomposed-condition.cpp b/clang/test/SemaCXX/decomposed-condition.cpp
index ab011f6ae4ba43..e55bbee3134ca2 100644
--- a/clang/test/SemaCXX/decomposed-condition.cpp
+++ b/clang/test/SemaCXX/decomposed-condition.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -std=c++1z -Wno-binding-in-condition -verify %s
+// RUN: %clang_cc1 -std=c++1z -Wno-binding-in-condition -verify %s -fexperimental-new-constant-interpreter
struct X {
bool flag;
More information about the cfe-commits
mailing list