[clang] [clang][bytecode] Fix discarding CompoundLiteralExprs (PR #104909)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 20 02:21:32 PDT 2024
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/104909
None
>From 6d45a286525465b4832e4ee01fa747db871f002e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 20 Aug 2024 11:02:25 +0200
Subject: [PATCH] [clang][bytecode] Fix discarding CompoundLiteralExprs
---
clang/lib/AST/ByteCode/Compiler.cpp | 6 +++---
clang/test/AST/ByteCode/c23.c | 5 ++++-
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 131b83ae8eb397..87d7a67e9ca932 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -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);
@@ -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;
}
diff --git a/clang/test/AST/ByteCode/c23.c b/clang/test/AST/ByteCode/c23.c
index e839fc716f5b52..f9157e40610cc3 100644
--- a/clang/test/AST/ByteCode/c23.c
+++ b/clang/test/AST/ByteCode/c23.c
@@ -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}} \
@@ -22,3 +22,6 @@ char bar() {
((struct S *)buffer)->c = 'a';
return ((struct S *)buffer)->c;
}
+
+
+static_assert((nullptr_t){} == 0);
More information about the cfe-commits
mailing list