[clang] 48439bd - [clang][Interp] Handle rewritten binary operators

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 19 04:06:11 PST 2024


Author: Timm Bäder
Date: 2024-02-19T13:05:56+01:00
New Revision: 48439bd7a79b117b3072f422fdf7e5599925ec72

URL: https://github.com/llvm/llvm-project/commit/48439bd7a79b117b3072f422fdf7e5599925ec72
DIFF: https://github.com/llvm/llvm-project/commit/48439bd7a79b117b3072f422fdf7e5599925ec72.diff

LOG: [clang][Interp] Handle rewritten binary operators

Just delegate to the syntactic form.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/lib/AST/Interp/ByteCodeExprGen.h
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 74ed436bdb544b..2fdc6f4f32bed9 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2156,6 +2156,12 @@ bool ByteCodeExprGen<Emitter>::VisitConceptSpecializationExpr(
   return this->emitConstBool(E->isSatisfied(), E);
 }
 
+template <class Emitter>
+bool ByteCodeExprGen<Emitter>::VisitCXXRewrittenBinaryOperator(
+    const CXXRewrittenBinaryOperator *E) {
+  return this->delegate(E->getSemanticForm());
+}
+
 template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
   if (E->containsErrors())
     return false;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h
index abaf28ac7d447d..3ede86a6979eea 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -116,6 +116,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
   bool VisitCXXUuidofExpr(const CXXUuidofExpr *E);
   bool VisitRequiresExpr(const RequiresExpr *E);
   bool VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E);
+  bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 0fc5d977b59f4c..78c09661c6dd73 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -763,3 +763,16 @@ namespace IgnoredConstantExpr {
     ReferenceToNestedMembers j{0};
   } test_reference_to_nested_members;
 }
+
+namespace RewrittenBinaryOperators {
+  template <class T, T Val>
+  struct Conv {
+    constexpr operator T() const { return Val; }
+    operator T() { return Val; }
+  };
+
+  struct X {
+    constexpr const Conv<int, -1> operator<=>(X) { return {}; }
+  };
+  static_assert(X() < X(), "");
+}


        


More information about the cfe-commits mailing list