[PATCH] D149837: [clang][Interp] Fix ignoring CompoundLiteralExprs
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 4 03:08:42 PDT 2023
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
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,6 +875,9 @@
sizeof(A);
alignof(A);
+ (int){1};
+ (int[]){1,2,3};
+
return 0;
}
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.519415.patch
Type: text/x-patch
Size: 1499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230504/0cc7a937/attachment-0001.bin>
More information about the cfe-commits
mailing list