[clang] c0a36a1 - [clang][Interp] Fix ignoring CompoundLiteralExprs
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 1 02:48:26 PDT 2023
Author: Timm Bäder
Date: 2023-08-01T11:48:04+02:00
New Revision: c0a36a157d978bbb80a57f1ea349fdbfe4f9b870
URL: https://github.com/llvm/llvm-project/commit/c0a36a157d978bbb80a57f1ea349fdbfe4f9b870
DIFF: https://github.com/llvm/llvm-project/commit/c0a36a157d978bbb80a57f1ea349fdbfe4f9b870.diff
LOG: [clang][Interp] Fix ignoring CompoundLiteralExprs
Differential Revision: https://reviews.llvm.org/D149837
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 77fe0412d0dc5c..8fbcc9ae3eec98 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -467,8 +467,13 @@ bool ByteCodeExprGen<Emitter>::VisitArraySubscriptExpr(
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
for (const Expr *Init : E->inits()) {
- if (!this->visit(Init))
- return false;
+ if (DiscardResult) {
+ if (!this->discard(Init))
+ return false;
+ } else {
+ if (!this->visit(Init))
+ return false;
+ }
}
return true;
}
@@ -944,12 +949,16 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundLiteralExpr(
// Otherwise, use a local variable.
if (T) {
// For primitive types, we just visit the initializer.
- return this->visit(Init);
+ return DiscardResult ? this->discard(Init) : this->visit(Init);
} else {
if (std::optional<unsigned> LocalIndex = allocateLocal(Init)) {
if (!this->emitGetPtrLocal(*LocalIndex, E))
return false;
- return this->visitInitializer(Init);
+ if (!this->visitInitializer(Init))
+ return false;
+ if (DiscardResult)
+ return this->emitPopPtr(E);
+ return true;
}
}
diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 7cb01a80c86859..d4ade51b1d71c3 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -897,9 +897,26 @@ namespace DiscardExprs {
1 ? 0 : 1;
__is_trivial(int);
+ (int){1};
+ (int[]){1,2,3};
+
return 0;
}
+ constexpr int oh_my(int x) {
+ (int){ x++ };
+ return x;
+ }
+ static_assert(oh_my(0) == 1, "");
+
+ constexpr int oh_my2(int x) {
+ int y{x++};
+ return x;
+ }
+
+ static_assert(oh_my2(0) == 1, "");
+
+
/// Ignored comma expressions still have their
/// expressions evaluated.
constexpr int Comma(int start) {
More information about the cfe-commits
mailing list