[clang] df2513c - [clang][Interp] Fix three-way comparison detection

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 9 01:12:43 PST 2024


Author: Timm Bäder
Date: 2024-02-09T10:12:25+01:00
New Revision: df2513c80bbd444ce97d28961bd5c20ffd7d3c44

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

LOG: [clang][Interp] Fix three-way comparison detection

Instead of using !T && CPlusPlus, just check the BinaryOperator's
opcode. Turns out we also hit this code path for some assignments
of structs in C++.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/SemaCXX/conditional-expr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 21bc29ff8ee2e5..bf456155b241b8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -464,7 +464,7 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
   // Special case for C++'s three-way/spaceship operator <=>, which
   // returns a std::{strong,weak,partial}_ordering (which is a class, so doesn't
   // have a PrimType).
-  if (!T && Ctx.getLangOpts().CPlusPlus) {
+  if (!T && BO->getOpcode() == BO_Cmp) {
     if (DiscardResult)
       return true;
     const ComparisonCategoryInfo *CmpInfo =

diff  --git a/clang/test/SemaCXX/conditional-expr.cpp b/clang/test/SemaCXX/conditional-expr.cpp
index 9a5e2bac43413d..01effaa189322b 100644
--- a/clang/test/SemaCXX/conditional-expr.cpp
+++ b/clang/test/SemaCXX/conditional-expr.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,expected-cxx11 -std=c++11 -Wsign-conversion %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,expected-cxx11 -std=c++11 -Wsign-conversion %s -fexperimental-new-constant-interpreter
 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,expected-cxx17 -std=c++17 -Wsign-conversion %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify=expected,expected-cxx17 -std=c++17 -Wsign-conversion %s -fexperimental-new-constant-interpreter
 
 // C++ rules for ?: are a lot stricter than C rules, and have to take into
 // account more conversion options.


        


More information about the cfe-commits mailing list