[clang] 43e6770 - Revert "[clang][Interp] Implement C++ Range-for loops"
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 2 02:04:19 PST 2023
Author: Timm Bäder
Date: 2023-03-02T11:04:09+01:00
New Revision: 43e67707f9ab14deafc57006aad69a263c700450
URL: https://github.com/llvm/llvm-project/commit/43e67707f9ab14deafc57006aad69a263c700450
DIFF: https://github.com/llvm/llvm-project/commit/43e67707f9ab14deafc57006aad69a263c700450.diff
LOG: Revert "[clang][Interp] Implement C++ Range-for loops"
This reverts commit bce8b3c1830434c10b8a30380db522d7c6a8658d.
This commit breaks memory-sanitizer builds:
https://lab.llvm.org/buildbot/#/builders/5/builds/31899
Added:
Modified:
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/lib/AST/Interp/ByteCodeStmtGen.h
clang/test/AST/Interp/loops.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 80a81c67df40..ff2727cc4d35 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -172,8 +172,6 @@ bool ByteCodeStmtGen<Emitter>::visitStmt(const Stmt *S) {
return visitDoStmt(cast<DoStmt>(S));
case Stmt::ForStmtClass:
return visitForStmt(cast<ForStmt>(S));
- case Stmt::CXXForRangeStmtClass:
- return visitCXXForRangeStmt(cast<CXXForRangeStmt>(S));
case Stmt::BreakStmtClass:
return visitBreakStmt(cast<BreakStmt>(S));
case Stmt::ContinueStmtClass:
@@ -371,56 +369,6 @@ bool ByteCodeStmtGen<Emitter>::visitForStmt(const ForStmt *S) {
return true;
}
-template <class Emitter>
-bool ByteCodeStmtGen<Emitter>::visitCXXForRangeStmt(const CXXForRangeStmt *S) {
- const Stmt *Init = S->getInit();
- const Expr *Cond = S->getCond();
- const Expr *Inc = S->getInc();
- const Stmt *Body = S->getBody();
- const Stmt *BeginStmt = S->getBeginStmt();
- const Stmt *RangeStmt = S->getRangeStmt();
- const Stmt *EndStmt = S->getEndStmt();
- const VarDecl *LoopVar = S->getLoopVariable();
-
- LabelTy EndLabel = this->getLabel();
- LabelTy CondLabel = this->getLabel();
- LabelTy IncLabel = this->getLabel();
- ExprScope<Emitter> ES(this);
- LoopScope<Emitter> LS(this, EndLabel, IncLabel);
-
- // Emit declarations needed in the loop.
- if (Init && !this->visitStmt(Init))
- return false;
- if (!this->visitStmt(RangeStmt))
- return false;
- if (!this->visitStmt(BeginStmt))
- return false;
- if (!this->visitStmt(EndStmt))
- return false;
-
- // Now the condition as well as the loop variable assignment.
- this->emitLabel(CondLabel);
- if (!this->visitBool(Cond))
- return false;
- if (!this->jumpFalse(EndLabel))
- return false;
-
- if (!this->visitVarDecl(LoopVar))
- return false;
-
- // Body.
- if (!this->visitStmt(Body))
- return false;
- this->emitLabel(IncLabel);
- if (!this->discard(Inc))
- return false;
- if (!this->jump(CondLabel))
- return false;
-
- this->emitLabel(EndLabel);
- return true;
-}
-
template <class Emitter>
bool ByteCodeStmtGen<Emitter>::visitBreakStmt(const BreakStmt *S) {
if (!BreakLabel)
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 6b3644ad1346..7a30f7b69470 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -60,7 +60,6 @@ class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> {
bool visitWhileStmt(const WhileStmt *S);
bool visitDoStmt(const DoStmt *S);
bool visitForStmt(const ForStmt *S);
- bool visitCXXForRangeStmt(const CXXForRangeStmt *S);
bool visitBreakStmt(const BreakStmt *S);
bool visitContinueStmt(const ContinueStmt *S);
bool visitSwitchStmt(const SwitchStmt *S);
diff --git a/clang/test/AST/Interp/loops.cpp b/clang/test/AST/Interp/loops.cpp
index 2e235123af76..d0386e3ac759 100644
--- a/clang/test/AST/Interp/loops.cpp
+++ b/clang/test/AST/Interp/loops.cpp
@@ -3,6 +3,10 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify=expected-cpp20 %s
// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+// ref-no-diagnostics
+// expected-no-diagnostics
+// expected-cpp20-no-diagnostics
+
namespace WhileLoop {
constexpr int f() {
int i = 0;
@@ -270,57 +274,3 @@ namespace ForLoop {
#endif
};
-
-namespace RangeForLoop {
- constexpr int localArray() {
- int a[] = {1,2,3,4};
- int s = 0;
- for(int i : a) {
- s += i;
- }
- return s;
- }
- static_assert(localArray() == 10, "");
-
- constexpr int localArray2() {
- int a[] = {1,2,3,4};
- int s = 0;
- for(const int &i : a) {
- s += i;
- }
- return s;
- }
- static_assert(localArray2() == 10, "");
-
- constexpr int nested() {
- int s = 0;
- for (const int i : (int[]){1,2,3,4}) {
- int a[] = {i, i};
- for(int m : a) {
- s += m;
- }
- }
- return s;
- }
- static_assert(nested() == 20, "");
-
- constexpr int withBreak() {
- int s = 0;
- for (const int &i: (bool[]){false, true}) {
- if (i)
- break;
- s++;
- }
- return s;
- }
- static_assert(withBreak() == 1, "");
-
- constexpr void NoBody() {
- for (const int &i: (bool[]){false, true}); // expected-warning {{empty body}} \
- // expected-note {{semicolon on a separate line}} \
- // expected-cpp20-warning {{empty body}} \
- // expected-cpp20-note {{semicolon on a separate line}} \
- // ref-warning {{empty body}} \
- // ref-note {{semicolon on a separate line}}
- }
-}
More information about the cfe-commits
mailing list