[clang] 1760289 - [clang][bytecode] Fix three-way unordered non-pointer comparisions (#127759)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 19 01:22:40 PST 2025
Author: Timm Baeder
Date: 2025-02-19T10:22:37+01:00
New Revision: 17602893409a0d396d37162a3b42254689e02e09
URL: https://github.com/llvm/llvm-project/commit/17602893409a0d396d37162a3b42254689e02e09
DIFF: https://github.com/llvm/llvm-project/commit/17602893409a0d396d37162a3b42254689e02e09.diff
LOG: [clang][bytecode] Fix three-way unordered non-pointer comparisions (#127759)
This _can_ happen with non-pointers, but we shouldn't diagnose it in
that case.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/cxx20.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index ca74046038072..fa113aa0bb157 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1132,13 +1132,14 @@ bool CMP3(InterpState &S, CodePtr OpPC, const ComparisonCategoryInfo *CmpInfo) {
const Pointer &P = S.Stk.peek<Pointer>();
ComparisonCategoryResult CmpResult = LHS.compare(RHS);
- if (CmpResult == ComparisonCategoryResult::Unordered) {
- // This should only happen with pointers.
- const SourceInfo &Loc = S.Current->getSource(OpPC);
- S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
- << LHS.toDiagnosticString(S.getASTContext())
- << RHS.toDiagnosticString(S.getASTContext());
- return false;
+ if constexpr (std::is_same_v<T, Pointer>) {
+ if (CmpResult == ComparisonCategoryResult::Unordered) {
+ const SourceInfo &Loc = S.Current->getSource(OpPC);
+ S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
+ << LHS.toDiagnosticString(S.getASTContext())
+ << RHS.toDiagnosticString(S.getASTContext());
+ return false;
+ }
}
assert(CmpInfo);
diff --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp
index 6f65fa5c7cfd3..06501de64916a 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -626,6 +626,8 @@ namespace ThreeWayCmp {
constexpr int k = (1 <=> 1, 0); // both-warning {{comparison result unused}}
static_assert(k== 0, "");
+ static_assert(__builtin_nanf("") <=> __builtin_nanf("") == -127, "");
+
/// Pointers.
constexpr int a[] = {1,2,3};
constexpr int b[] = {1,2,3};
More information about the cfe-commits
mailing list