Skip to content

Commit ae78d15

Browse files
[analyzer] Fix crash on spaceship operator (PR47511)
rdar://68954187 Differential Revision: https://reviews.llvm.org/D99181 (cherry picked from commit 4b958dd)
1 parent 78f4c5d commit ae78d15

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

clang/lib/StaticAnalyzer/Core/SValBuilder.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
423423
return UnknownVal();
424424
}
425425

426+
if (op == BinaryOperatorKind::BO_Cmp) {
427+
// We can't reason about C++20 spaceship operator yet.
428+
//
429+
// FIXME: Support C++20 spaceship operator.
430+
// The main problem here is that the result is not integer.
431+
return UnknownVal();
432+
}
433+
426434
if (Optional<Loc> LV = lhs.getAs<Loc>()) {
427435
if (Optional<Loc> RV = rhs.getAs<Loc>())
428436
return evalBinOpLL(state, op, *LV, *RV, type);

clang/test/Analysis/PR47511.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_analyze_cc1 -std=c++20 -w -analyzer-checker=core -verify %s
2+
3+
// expected-no-diagnostics
4+
5+
namespace std {
6+
struct strong_ordering {
7+
int n;
8+
constexpr operator int() const { return n; }
9+
static const strong_ordering equal, greater, less;
10+
};
11+
constexpr strong_ordering strong_ordering::equal = {0};
12+
constexpr strong_ordering strong_ordering::greater = {1};
13+
constexpr strong_ordering strong_ordering::less = {-1};
14+
} // namespace std
15+
16+
void test() {
17+
// no crash
18+
(void)(0 <=> 0);
19+
}

0 commit comments

Comments
 (0)