Skip to content

Commit 8ab0632

Browse files
committed
[clang][Interp] Handle goto and label statements
1 parent c42bc2e commit 8ab0632

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,18 @@ bool ByteCodeStmtGen<Emitter>::visitStmt(const Stmt *S) {
273273
return visitCaseStmt(cast<CaseStmt>(S));
274274
case Stmt::DefaultStmtClass:
275275
return visitDefaultStmt(cast<DefaultStmt>(S));
276-
case Stmt::GCCAsmStmtClass:
277-
case Stmt::MSAsmStmtClass:
278-
return visitAsmStmt(cast<AsmStmt>(S));
279276
case Stmt::AttributedStmtClass:
280277
return visitAttributedStmt(cast<AttributedStmt>(S));
281278
case Stmt::CXXTryStmtClass:
282279
return visitCXXTryStmt(cast<CXXTryStmt>(S));
283280
case Stmt::NullStmtClass:
284281
return true;
282+
// Always invalid statements.
283+
case Stmt::GCCAsmStmtClass:
284+
case Stmt::MSAsmStmtClass:
285+
case Stmt::GotoStmtClass:
286+
case Stmt::LabelStmtClass:
287+
return this->emitInvalid(S);
285288
default: {
286289
if (auto *Exp = dyn_cast<Expr>(S))
287290
return this->discard(Exp);
@@ -657,11 +660,6 @@ bool ByteCodeStmtGen<Emitter>::visitDefaultStmt(const DefaultStmt *S) {
657660
return this->visitStmt(S->getSubStmt());
658661
}
659662

660-
template <class Emitter>
661-
bool ByteCodeStmtGen<Emitter>::visitAsmStmt(const AsmStmt *S) {
662-
return this->emitInvalid(S);
663-
}
664-
665663
template <class Emitter>
666664
bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) {
667665
// Ignore all attributes.

clang/lib/AST/Interp/ByteCodeStmtGen.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> {
6363
bool visitSwitchStmt(const SwitchStmt *S);
6464
bool visitCaseStmt(const CaseStmt *S);
6565
bool visitDefaultStmt(const DefaultStmt *S);
66-
bool visitAsmStmt(const AsmStmt *S);
6766
bool visitAttributedStmt(const AttributedStmt *S);
6867
bool visitCXXTryStmt(const CXXTryStmt *S);
6968

clang/test/AST/Interp/cxx23.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref20,all,all-20 %s
1+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref20,all,all20 %s
22
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=ref23,all %s
3-
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected20,all,all-20 %s -fexperimental-new-constant-interpreter
3+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected20,all,all20 %s -fexperimental-new-constant-interpreter
44
// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23,all %s -fexperimental-new-constant-interpreter
55

66
/// FIXME: The new interpreter is missing all the 'control flows through...' diagnostics.
@@ -108,9 +108,9 @@ namespace StaticOperators {
108108
static_assert(f2() == 3);
109109

110110
struct S1 {
111-
constexpr S1() { // all-20-error {{never produces a constant expression}}
111+
constexpr S1() { // all20-error {{never produces a constant expression}}
112112
throw; // all-note {{not valid in a constant expression}} \
113-
// all-20-note {{not valid in a constant expression}}
113+
// all20-note {{not valid in a constant expression}}
114114
}
115115
static constexpr int operator()() { return 3; } // ref20-warning {{C++23 extension}} \
116116
// expected20-warning {{C++23 extension}}
@@ -121,3 +121,19 @@ namespace StaticOperators {
121121

122122

123123
}
124+
125+
int test_in_lambdas() {
126+
auto c = [](int n) constexpr {
127+
if (n == 0)
128+
return 0;
129+
else
130+
goto test; // all-note {{subexpression not valid in a constant expression}} \
131+
// all20-warning {{use of this statement in a constexpr function is a C++23 extension}}
132+
test:
133+
return 1;
134+
};
135+
c(0);
136+
constexpr auto A = c(1); // all-error {{must be initialized by a constant expression}} \
137+
// all-note {{in call to}}
138+
return 0;
139+
}

0 commit comments

Comments
 (0)