Skip to content

[clang][bytecode] Fix discarding CompoundLiteralExprs #104909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,9 @@ bool Compiler<Emitter>::VisitCXXBindTemporaryExpr(
template <class Emitter>
bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
const Expr *Init = E->getInitializer();
if (DiscardResult)
return this->discard(Init);

if (Initializing) {
// We already have a value, just initialize that.
return this->visitInitializer(Init) && this->emitFinishInit(E);
Expand Down Expand Up @@ -2378,9 +2381,6 @@ bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
if (!this->visitInitializer(Init) || !this->emitFinishInit(E))
return false;
}

if (DiscardResult)
return this->emitPopPtr(E);
return true;
}

Expand Down
5 changes: 4 additions & 1 deletion clang/test/AST/ByteCode/c23.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter -verify=expected,both %s
// RUN: %clang_cc1 -std=c23 -verify=ref,both %s


typedef typeof(nullptr) nullptr_t;

const _Bool inf1 = (1.0/0.0 == __builtin_inf());
constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be initialized by a constant expression}} \
Expand All @@ -22,3 +22,6 @@ char bar() {
((struct S *)buffer)->c = 'a';
return ((struct S *)buffer)->c;
}


static_assert((nullptr_t){} == 0);
Loading