[PATCH] D147840: [clang][Interp] Handle DiscardResult for DeclRef- and ParenExprs
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 7 22:29:44 PDT 2023
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, tahonermann, shafik, erichkeane.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/62004
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147840
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
@@ -780,4 +780,18 @@
return F{12}.a;
}
static_assert(ignoredDecls() == 12, "");
+
+struct A{};
+constexpr int ignoredExprs() {
+ (void)(1 / 2);
+ A a;
+ a; // expected-warning {{unused}} \
+ // ref-warning {{unused}}
+ (void)a;
+ (a); // expected-warning {{unused}} \
+ // ref-warning {{unused}}
+
+ return 0;
+}
+
#endif
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -231,7 +231,15 @@
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitParenExpr(const ParenExpr *PE) {
- return this->visit(PE->getSubExpr());
+ if (!this->visit(PE->getSubExpr()))
+ return false;
+
+ if (DiscardResult) {
+ std::optional<PrimType> T = classify(PE->getSubExpr()).value_or(PT_Ptr);
+ return this->emitPop(*T, PE);
+ }
+
+ return true;
}
template <class Emitter>
@@ -2058,6 +2066,9 @@
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
+ if (DiscardResult)
+ return true;
+
const auto *D = E->getDecl();
if (const auto *ECD = dyn_cast<EnumConstantDecl>(D)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147840.511851.patch
Type: text/x-patch
Size: 1407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230408/fd5829a6/attachment.bin>
More information about the cfe-commits
mailing list