Skip to content

Commit 1760289

Browse files
authored
[clang][bytecode] Fix three-way unordered non-pointer comparisions (llvm#127759)
This _can_ happen with non-pointers, but we shouldn't diagnose it in that case.
1 parent 8615f9a commit 1760289

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,13 +1132,14 @@ bool CMP3(InterpState &S, CodePtr OpPC, const ComparisonCategoryInfo *CmpInfo) {
11321132
const Pointer &P = S.Stk.peek<Pointer>();
11331133

11341134
ComparisonCategoryResult CmpResult = LHS.compare(RHS);
1135-
if (CmpResult == ComparisonCategoryResult::Unordered) {
1136-
// This should only happen with pointers.
1137-
const SourceInfo &Loc = S.Current->getSource(OpPC);
1138-
S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
1139-
<< LHS.toDiagnosticString(S.getASTContext())
1140-
<< RHS.toDiagnosticString(S.getASTContext());
1141-
return false;
1135+
if constexpr (std::is_same_v<T, Pointer>) {
1136+
if (CmpResult == ComparisonCategoryResult::Unordered) {
1137+
const SourceInfo &Loc = S.Current->getSource(OpPC);
1138+
S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
1139+
<< LHS.toDiagnosticString(S.getASTContext())
1140+
<< RHS.toDiagnosticString(S.getASTContext());
1141+
return false;
1142+
}
11421143
}
11431144

11441145
assert(CmpInfo);

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ namespace ThreeWayCmp {
626626
constexpr int k = (1 <=> 1, 0); // both-warning {{comparison result unused}}
627627
static_assert(k== 0, "");
628628

629+
static_assert(__builtin_nanf("") <=> __builtin_nanf("") == -127, "");
630+
629631
/// Pointers.
630632
constexpr int a[] = {1,2,3};
631633
constexpr int b[] = {1,2,3};

0 commit comments

Comments
 (0)