[clang] d29f706 - [clang][Interp] Fix binary comma operators
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 31 05:55:28 PDT 2023
Author: Timm Bäder
Date: 2023-03-31T14:54:51+02:00
New Revision: d29f70670db8ca43a49b6df9112035dc4b646182
URL: https://github.com/llvm/llvm-project/commit/d29f70670db8ca43a49b6df9112035dc4b646182
DIFF: https://github.com/llvm/llvm-project/commit/d29f70670db8ca43a49b6df9112035dc4b646182.diff
LOG: [clang][Interp] Fix binary comma operators
We left the result of RHS on the stack in case DiscardResult was true.
Differential Revision: https://reviews.llvm.org/D141784
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/SemaCXX/constexpr-duffs-device.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index afa5372a5112c..1b605a9e09278 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -198,18 +198,6 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
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());
@@ -224,6 +212,13 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
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))
diff --git a/clang/test/SemaCXX/constexpr-duffs-device.cpp b/clang/test/SemaCXX/constexpr-duffs-device.cpp
index f77d989b9d36f..3c643cbb2af4b 100644
--- a/clang/test/SemaCXX/constexpr-duffs-device.cpp
+++ b/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) {
More information about the cfe-commits
mailing list