Skip to content

Commit 886d24d

Browse files
authored
[clang][bytecode] Fix fallthrough to switch labels (#168484)
We need to fallthrough here in case we're not jumping to the labels. This is only needed in expression contexts.
1 parent 7354533 commit 886d24d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6057,13 +6057,15 @@ bool Compiler<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
60576057
DefaultLabel);
60586058
if (!this->visitStmt(S->getBody()))
60596059
return false;
6060+
this->fallthrough(EndLabel);
60606061
this->emitLabel(EndLabel);
60616062

60626063
return LS.destroyLocals();
60636064
}
60646065

60656066
template <class Emitter>
60666067
bool Compiler<Emitter>::visitCaseStmt(const CaseStmt *S) {
6068+
this->fallthrough(CaseLabels[S]);
60676069
this->emitLabel(CaseLabels[S]);
60686070
return this->visitStmt(S->getSubStmt());
60696071
}

clang/test/AST/ByteCode/literals.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,17 @@ namespace StmtExprs {
12701270
namespace CrossFuncLabelDiff {
12711271
constexpr long a(bool x) { return x ? 0 : (intptr_t)&&lbl + (0 && ({lbl: 0;})); }
12721272
}
1273+
1274+
/// GCC agrees with the bytecode interpreter here.
1275+
void switchInSE() {
1276+
static_assert(({ // ref-error {{not an integral constant expression}}
1277+
int i = 20;
1278+
switch(10) {
1279+
case 10: i = 300; // ref-note {{a constant expression cannot modify an object that is visible outside that expression}}
1280+
}
1281+
i;
1282+
}) == 300);
1283+
}
12731284
}
12741285
#endif
12751286

0 commit comments

Comments
 (0)