[clang] [clang][bytecode] Fix three-way unordered non-pointer comparisions (PR #127759)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 18 23:56:59 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This _can_ happen with non-pointers, but we shouldn't diagnose it in that case.
---
Full diff: https://github.com/llvm/llvm-project/pull/127759.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.h (+8-7)
- (modified) clang/test/AST/ByteCode/cxx20.cpp (+2)
``````````diff
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};
``````````
</details>
https://github.com/llvm/llvm-project/pull/127759
More information about the cfe-commits
mailing list