Skip to content

Commit

Permalink
[clang][bytecode] Fix discarding CompoundLiteralExprs (llvm#104909)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Aug 20, 2024
1 parent 4aacc60 commit c99347a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
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);

0 comments on commit c99347a

Please sign in to comment.