[clang] [clang][bytecode] Fix discarding CompoundLiteralExprs (PR #104909)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 20 02:22:06 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/104909.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3-3)
- (modified) clang/test/AST/ByteCode/c23.c (+4-1)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/104909
More information about the cfe-commits
mailing list