Skip to content

Commit c79d1fa

Browse files
authored
[clang][bytecode] Don't discard all void-typed expressions (#105625)
For void-types InitListExprs, we need to diagnose them as invalid. But only if we are _not_ discarding.
1 parent e338936 commit c79d1fa

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,15 +1318,6 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
13181318
template <class Emitter>
13191319
bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
13201320
const Expr *ArrayFiller, const Expr *E) {
1321-
1322-
QualType QT = E->getType();
1323-
1324-
if (const auto *AT = QT->getAs<AtomicType>())
1325-
QT = AT->getValueType();
1326-
1327-
if (QT->isVoidType())
1328-
return this->emitInvalid(E);
1329-
13301321
// Handle discarding first.
13311322
if (DiscardResult) {
13321323
for (const Expr *Init : Inits) {
@@ -1336,6 +1327,13 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
13361327
return true;
13371328
}
13381329

1330+
QualType QT = E->getType();
1331+
if (const auto *AT = QT->getAs<AtomicType>())
1332+
QT = AT->getValueType();
1333+
1334+
if (QT->isVoidType())
1335+
return this->emitInvalid(E);
1336+
13391337
// Primitive values.
13401338
if (std::optional<PrimType> T = classify(QT)) {
13411339
assert(!DiscardResult);
@@ -3251,12 +3249,9 @@ template <class Emitter> bool Compiler<Emitter>::visit(const Expr *E) {
32513249
if (E->getType().isNull())
32523250
return false;
32533251

3254-
if (E->getType()->isVoidType())
3255-
return this->discard(E);
3256-
32573252
// Create local variable to hold the return value.
3258-
if (!E->isGLValue() && !E->getType()->isAnyComplexType() &&
3259-
!classify(E->getType())) {
3253+
if (!E->getType()->isVoidType() && !E->isGLValue() &&
3254+
!E->getType()->isAnyComplexType() && !classify(E->getType())) {
32603255
std::optional<unsigned> LocalIndex = allocateLocal(E);
32613256
if (!LocalIndex)
32623257
return false;

clang/test/AST/ByteCode/literals.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static_assert(Failed2 == 0, ""); // both-error {{not an integral constant expres
4646
// both-note {{initializer of 'Failed2' is not a constant expression}}
4747

4848
const int x = *(volatile int*)0x1234;
49+
static_assert((void{}, true), "");
4950

5051
namespace ScalarTypes {
5152
constexpr int ScalarInitInt = int();

0 commit comments

Comments
 (0)