Skip to content

Commit

Permalink
[clang][Interp] Fix three-way comparison detection
Browse files Browse the repository at this point in the history
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++.
  • Loading branch information
tbaederr committed Feb 9, 2024
1 parent d72e8c2 commit df2513c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions clang/test/SemaCXX/conditional-expr.cpp
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit df2513c

Please sign in to comment.