Skip to content

Commit c99347a

Browse files
authored
[clang][bytecode] Fix discarding CompoundLiteralExprs (#104909)
1 parent 4aacc60 commit c99347a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,9 @@ bool Compiler<Emitter>::VisitCXXBindTemporaryExpr(
23252325
template <class Emitter>
23262326
bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
23272327
const Expr *Init = E->getInitializer();
2328+
if (DiscardResult)
2329+
return this->discard(Init);
2330+
23282331
if (Initializing) {
23292332
// We already have a value, just initialize that.
23302333
return this->visitInitializer(Init) && this->emitFinishInit(E);
@@ -2378,9 +2381,6 @@ bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
23782381
if (!this->visitInitializer(Init) || !this->emitFinishInit(E))
23792382
return false;
23802383
}
2381-
2382-
if (DiscardResult)
2383-
return this->emitPopPtr(E);
23842384
return true;
23852385
}
23862386

clang/test/AST/ByteCode/c23.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter -verify=expected,both %s
22
// RUN: %clang_cc1 -std=c23 -verify=ref,both %s
33

4-
4+
typedef typeof(nullptr) nullptr_t;
55

66
const _Bool inf1 = (1.0/0.0 == __builtin_inf());
77
constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be initialized by a constant expression}} \
@@ -22,3 +22,6 @@ char bar() {
2222
((struct S *)buffer)->c = 'a';
2323
return ((struct S *)buffer)->c;
2424
}
25+
26+
27+
static_assert((nullptr_t){} == 0);

0 commit comments

Comments
 (0)