[PATCH] D141784: [clang][Interp] Fix binary comma operators
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 15 00:30:33 PST 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.
We left the result of RHS on the stack in case DiscardResult was true.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D141784
Files:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/SemaCXX/constexpr-duffs-device.cpp
Index: clang/test/SemaCXX/constexpr-duffs-device.cpp
===================================================================
--- clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ clang/test/SemaCXX/constexpr-duffs-device.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -std=c++1y -verify %s
+// RUN: %clang_cc1 -std=c++1y -verify -fexperimental-new-constant-interpreter %s
// expected-no-diagnostics
constexpr void copy(const char *from, unsigned long count, char *to) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -212,22 +212,11 @@
const Expr *LHS = BO->getLHS();
const Expr *RHS = BO->getRHS();
- // Deal with operations which have composite or void types.
- switch (BO->getOpcode()) {
- case BO_Comma:
- if (!discard(LHS))
- return false;
- if (!this->visit(RHS))
- return false;
- return true;
- default:
- break;
- }
-
// Typecheck the args.
std::optional<PrimType> LT = classify(LHS->getType());
std::optional<PrimType> RT = classify(RHS->getType());
std::optional<PrimType> T = classify(BO->getType());
+
if (!LT || !RT || !T) {
return this->bail(BO);
}
@@ -238,6 +227,13 @@
return DiscardResult ? this->emitPop(*T, BO) : true;
};
+ // Deal with operations which have composite or void types.
+ if (BO->isCommaOp()) {
+ if (!discard(LHS))
+ return false;
+ return Discard(this->visit(RHS));
+ }
+
// Pointer arithmetic special case.
if (BO->getOpcode() == BO_Add || BO->getOpcode() == BO_Sub) {
if (*T == PT_Ptr || (*LT == PT_Ptr && *RT == PT_Ptr))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141784.489333.patch
Type: text/x-patch
Size: 1707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230115/5ded7237/attachment.bin>
More information about the cfe-commits
mailing list