[PATCH] D149837: [clang][Interp] Fix ignoring CompoundLiteralExprs
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun May 7 00:43:15 PDT 2023
tbaeder updated this revision to Diff 520153.
tbaeder marked an inline comment as done.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149837/new/
https://reviews.llvm.org/D149837
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp
Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -875,9 +875,26 @@
sizeof(A);
alignof(A);
+ (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) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -527,8 +527,13 @@
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;
}
@@ -1024,12 +1029,16 @@
// 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;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149837.520153.patch
Type: text/x-patch
Size: 1840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230507/2b399487/attachment.bin>
More information about the cfe-commits
mailing list