cxx2a-three-way-comparison.cpp
2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple %itanium_abi_triple | FileCheck %s --check-prefixes=CHECK,ITANIUM
// RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple x86_64-pc-win32 2>&1 | FileCheck %s --check-prefixes=CHECK,MSABI
namespace std {
struct strong_ordering {
int n;
constexpr operator int() const { return n; }
static const strong_ordering less, equal, greater;
};
constexpr strong_ordering strong_ordering::less = {-1};
constexpr strong_ordering strong_ordering::equal = {0};
constexpr strong_ordering strong_ordering::greater = {1};
}
struct Primary {
virtual void f();
std::strong_ordering operator<=>(const Primary&) const = default;
};
struct X {
virtual struct Y &operator=(Y&&);
virtual struct Y &operator=(const Y&);
std::strong_ordering operator<=>(const X&) const = default;
};
// The vtable for Y should contain the following entries in order:
// - Primary::f
// - Y::operator<=>
// - Y::operator=(const Y&) (implicit)
// - Y::operator=(Y&&) (implicit)
// - Y::operator==(const Y&) const (implicit)
// See:
// https://github.com/itanium-cxx-abi/cxx-abi/issues/83 for assignment operator
// https://github.com/itanium-cxx-abi/cxx-abi/issues/88 for equality comparison
// FIXME: What rule does MSVC use?
struct Y : Primary, X {
virtual std::strong_ordering operator<=>(const Y&) const = default;
};
Y y;
// ITANIUM: @_ZTV1Y = {{.*}}constant {{.*}} null, {{.*}} @_ZTI1Y {{.*}} @_ZN7Primary1fEv {{.*}} @_ZNK1YssERKS_ {{.*}} @_ZN1YaSERKS_ {{.*}} @_ZN1YaSEOS_ {{.*}} @_ZNK1YeqERKS_ {{.*}} -[[POINTERSIZE:4|8]]
// ITANIUM-SAME: @_ZTI1Y {{.*}} @_ZThn[[POINTERSIZE]]_N1YaSERKS_
struct A {
void operator<=>(int);
};
// ITANIUM: define {{.*}}@_ZN1AssEi(
// MSABI: define {{.*}}@"??__MA@@QEAAXH@Z"(
void A::operator<=>(int) {}
// ITANIUM: define {{.*}}@_Zssi1A(
// MSABI: define {{.*}}@"??__M@YAXHUA@@@Z"(
void operator<=>(int, A) {}
int operator<=>(A, A);
// ITANIUM: define {{.*}}_Z1f1A(
// MSABI: define {{.*}}@"?f@@YAHUA@@@Z"(
int f(A a) {
// ITANIUM: %[[RET:.*]] = call {{.*}}_Zss1AS_(
// ITANIUM: ret i32 %[[RET]]
// MSABI: %[[RET:.*]] = call {{.*}}"??__M@YAHUA@@0@Z"(
// MSABI: ret i32 %[[RET]]
return a <=> a;
}
// CHECK-LABEL: define {{.*}}builtin_cmp
void builtin_cmp(int a) {
// CHECK: icmp slt
// CHECK: select
// CHECK: icmp eq
// CHECK: select
a <=> a;
}