| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 |
// RUN: FileCheck %s --check-prefix=CIR --input-file=%t.cir |
| 3 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 |
// RUN: FileCheck %s --check-prefix=LLVM --input-file=%t-cir.ll |
| 5 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 |
// RUN: FileCheck %s --check-prefix=OGCG --input-file=%t.ll |
| 7 |
|
| 8 |
bool test_add_overflow_uint_uint_uint(unsigned x, unsigned y, unsigned *res) { |
| 9 |
return __builtin_add_overflow(x, y, res); |
| 10 |
} |
| 11 |
|
| 12 |
// CIR: cir.func {{.*}} @_Z32test_add_overflow_uint_uint_uintjjPj |
| 13 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 14 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 15 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u32i>>, !cir.ptr<!u32i> |
| 16 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#LHS]], %[[#RHS]]) : !u32i, (!u32i, !cir.bool) |
| 17 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u32i, !cir.ptr<!u32i> |
| 18 |
// CIR: } |
| 19 |
|
| 20 |
// LLVM: define{{.*}} i1 @_Z32test_add_overflow_uint_uint_uintjjPj(i32{{.*}}, i32{{.*}}, ptr{{.*}}) |
| 21 |
// LLVM: call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}}) |
| 22 |
|
| 23 |
// OGCG: define{{.*}} i1 @_Z32test_add_overflow_uint_uint_uintjjPj(i32{{.*}}, i32{{.*}}, ptr{{.*}}) |
| 24 |
// OGCG: call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %{{.+}}, i32 %{{.+}}) |
| 25 |
|
| 26 |
bool test_add_overflow_int_int_int(int x, int y, int *res) { |
| 27 |
return __builtin_add_overflow(x, y, res); |
| 28 |
} |
| 29 |
|
| 30 |
// CIR: cir.func {{.*}} @_Z29test_add_overflow_int_int_intiiPi |
| 31 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 32 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 33 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 34 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#LHS]], %[[#RHS]]) : !s32i, (!s32i, !cir.bool) |
| 35 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s32i, !cir.ptr<!s32i> |
| 36 |
// CIR: } |
| 37 |
|
| 38 |
bool test_add_overflow_xint31_xint31_xint31(_BitInt(31) x, _BitInt(31) y, _BitInt(31) *res) { |
| 39 |
return __builtin_add_overflow(x, y, res); |
| 40 |
} |
| 41 |
|
| 42 |
// CIR: cir.func {{.*}} @_Z38test_add_overflow_xint31_xint31_xint31DB31_S_PS_ |
| 43 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.int<s, 31>>, !cir.int<s, 31> |
| 44 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.int<s, 31>>, !cir.int<s, 31> |
| 45 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!cir.int<s, 31>>>, !cir.ptr<!cir.int<s, 31>> |
| 46 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#LHS]], %[[#RHS]]) : !cir.int<s, 31>, (!cir.int<s, 31>, !cir.bool) |
| 47 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !cir.int<s, 31>, !cir.ptr<!cir.int<s, 31>> |
| 48 |
// CIR: } |
| 49 |
|
| 50 |
bool test_sub_overflow_uint_uint_uint(unsigned x, unsigned y, unsigned *res) { |
| 51 |
return __builtin_sub_overflow(x, y, res); |
| 52 |
} |
| 53 |
|
| 54 |
// CIR: cir.func {{.*}} @_Z32test_sub_overflow_uint_uint_uintjjPj |
| 55 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 56 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 57 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u32i>>, !cir.ptr<!u32i> |
| 58 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#LHS]], %[[#RHS]]) : !u32i, (!u32i, !cir.bool) |
| 59 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u32i, !cir.ptr<!u32i> |
| 60 |
// CIR: } |
| 61 |
|
| 62 |
bool test_sub_overflow_int_int_int(int x, int y, int *res) { |
| 63 |
return __builtin_sub_overflow(x, y, res); |
| 64 |
} |
| 65 |
|
| 66 |
// CIR: cir.func {{.*}} @_Z29test_sub_overflow_int_int_intiiPi |
| 67 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 68 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 69 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 70 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#LHS]], %[[#RHS]]) : !s32i, (!s32i, !cir.bool) |
| 71 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s32i, !cir.ptr<!s32i> |
| 72 |
// CIR: } |
| 73 |
|
| 74 |
bool test_sub_overflow_xint31_xint31_xint31(_BitInt(31) x, _BitInt(31) y, _BitInt(31) *res) { |
| 75 |
return __builtin_sub_overflow(x, y, res); |
| 76 |
} |
| 77 |
|
| 78 |
// CIR: cir.func {{.*}} @_Z38test_sub_overflow_xint31_xint31_xint31DB31_S_PS_ |
| 79 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.int<s, 31>>, !cir.int<s, 31> |
| 80 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.int<s, 31>>, !cir.int<s, 31> |
| 81 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!cir.int<s, 31>>>, !cir.ptr<!cir.int<s, 31>> |
| 82 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#LHS]], %[[#RHS]]) : !cir.int<s, 31>, (!cir.int<s, 31>, !cir.bool) |
| 83 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !cir.int<s, 31>, !cir.ptr<!cir.int<s, 31>> |
| 84 |
// CIR: } |
| 85 |
|
| 86 |
bool test_mul_overflow_uint_uint_uint(unsigned x, unsigned y, unsigned *res) { |
| 87 |
return __builtin_mul_overflow(x, y, res); |
| 88 |
} |
| 89 |
|
| 90 |
// CIR: cir.func {{.*}} @_Z32test_mul_overflow_uint_uint_uintjjPj |
| 91 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 92 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 93 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u32i>>, !cir.ptr<!u32i> |
| 94 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#LHS]], %[[#RHS]]) : !u32i, (!u32i, !cir.bool) |
| 95 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u32i, !cir.ptr<!u32i> |
| 96 |
// CIR: } |
| 97 |
|
| 98 |
bool test_mul_overflow_int_int_int(int x, int y, int *res) { |
| 99 |
return __builtin_mul_overflow(x, y, res); |
| 100 |
} |
| 101 |
|
| 102 |
// CIR: cir.func {{.*}} @_Z29test_mul_overflow_int_int_intiiPi |
| 103 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 104 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 105 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 106 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#LHS]], %[[#RHS]]) : !s32i, (!s32i, !cir.bool) |
| 107 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s32i, !cir.ptr<!s32i> |
| 108 |
// CIR: } |
| 109 |
|
| 110 |
bool test_mul_overflow_xint31_xint31_xint31(_BitInt(31) x, _BitInt(31) y, _BitInt(31) *res) { |
| 111 |
return __builtin_mul_overflow(x, y, res); |
| 112 |
} |
| 113 |
|
| 114 |
// CIR: cir.func {{.*}} @_Z38test_mul_overflow_xint31_xint31_xint31DB31_S_PS_ |
| 115 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.int<s, 31>>, !cir.int<s, 31> |
| 116 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.int<s, 31>>, !cir.int<s, 31> |
| 117 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!cir.int<s, 31>>>, !cir.ptr<!cir.int<s, 31>> |
| 118 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#LHS]], %[[#RHS]]) : !cir.int<s, 31>, (!cir.int<s, 31>, !cir.bool) |
| 119 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !cir.int<s, 31>, !cir.ptr<!cir.int<s, 31>> |
| 120 |
// CIR: } |
| 121 |
|
| 122 |
bool test_mul_overflow_ulong_ulong_long(unsigned long x, unsigned long y, unsigned long *res) { |
| 123 |
return __builtin_mul_overflow(x, y, res); |
| 124 |
} |
| 125 |
|
| 126 |
// CIR: cir.func {{.*}} @_Z34test_mul_overflow_ulong_ulong_longmmPm |
| 127 |
// CIR: %[[#LHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 128 |
// CIR-NEXT: %[[#RHS:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 129 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u64i>>, !cir.ptr<!u64i> |
| 130 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#LHS]], %[[#RHS]]) : !u64i, (!u64i, !cir.bool) |
| 131 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u64i, !cir.ptr<!u64i> |
| 132 |
// CIR: } |
| 133 |
|
| 134 |
bool test_add_overflow_uint_int_int(unsigned x, int y, int *res) { |
| 135 |
return __builtin_add_overflow(x, y, res); |
| 136 |
} |
| 137 |
|
| 138 |
// CIR: cir.func {{.*}} @_Z30test_add_overflow_uint_int_intjiPi |
| 139 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 140 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 141 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 142 |
// CIR-NEXT: %[[#PROM_X:]] = cir.cast integral %[[#X]] : !u32i -> !cir.int<s, 33> |
| 143 |
// CIR-NEXT: %[[#PROM_Y:]] = cir.cast integral %[[#Y]] : !s32i -> !cir.int<s, 33> |
| 144 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#PROM_X]], %[[#PROM_Y]]) : !cir.int<s, 33>, (!s32i, !cir.bool) |
| 145 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s32i, !cir.ptr<!s32i> |
| 146 |
// CIR: } |
| 147 |
|
| 148 |
bool test_add_overflow_volatile(int x, int y, volatile int *res) { |
| 149 |
return __builtin_add_overflow(x, y, res); |
| 150 |
} |
| 151 |
|
| 152 |
// CIR: cir.func {{.*}} @_Z26test_add_overflow_volatileiiPVi |
| 153 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 154 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 155 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 156 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#X]], %[[#Y]]) : !s32i, (!s32i, !cir.bool) |
| 157 |
// CIR-NEXT: cir.store volatile{{.*}} %[[RES]], %[[#RES_PTR]] : !s32i, !cir.ptr<!s32i> |
| 158 |
// CIR: } |
| 159 |
|
| 160 |
bool test_uadd_overflow(unsigned x, unsigned y, unsigned *res) { |
| 161 |
return __builtin_uadd_overflow(x, y, res); |
| 162 |
} |
| 163 |
|
| 164 |
// CIR: cir.func {{.*}} @_Z18test_uadd_overflowjjPj |
| 165 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 166 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 167 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u32i>>, !cir.ptr<!u32i> |
| 168 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#X]], %[[#Y]]) : !u32i, (!u32i, !cir.bool) |
| 169 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u32i, !cir.ptr<!u32i> |
| 170 |
// CIR: } |
| 171 |
|
| 172 |
bool test_uaddl_overflow(unsigned long x, unsigned long y, unsigned long *res) { |
| 173 |
return __builtin_uaddl_overflow(x, y, res); |
| 174 |
} |
| 175 |
|
| 176 |
// CIR: cir.func {{.*}} @_Z19test_uaddl_overflowmmPm |
| 177 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 178 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 179 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u64i>>, !cir.ptr<!u64i> |
| 180 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#X]], %[[#Y]]) : !u64i, (!u64i, !cir.bool) |
| 181 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u64i, !cir.ptr<!u64i> |
| 182 |
// CIR: } |
| 183 |
|
| 184 |
bool test_uaddll_overflow(unsigned long long x, unsigned long long y, unsigned long long *res) { |
| 185 |
return __builtin_uaddll_overflow(x, y, res); |
| 186 |
} |
| 187 |
|
| 188 |
// CIR: cir.func {{.*}} @_Z20test_uaddll_overflowyyPy |
| 189 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 190 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 191 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u64i>>, !cir.ptr<!u64i> |
| 192 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#X]], %[[#Y]]) : !u64i, (!u64i, !cir.bool) |
| 193 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u64i, !cir.ptr<!u64i> |
| 194 |
// CIR: } |
| 195 |
|
| 196 |
bool test_usub_overflow(unsigned x, unsigned y, unsigned *res) { |
| 197 |
return __builtin_usub_overflow(x, y, res); |
| 198 |
} |
| 199 |
|
| 200 |
// CIR: cir.func {{.*}} @_Z18test_usub_overflowjjPj |
| 201 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 202 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 203 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u32i>>, !cir.ptr<!u32i> |
| 204 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#X]], %[[#Y]]) : !u32i, (!u32i, !cir.bool) |
| 205 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u32i, !cir.ptr<!u32i> |
| 206 |
// CIR: } |
| 207 |
|
| 208 |
bool test_usubl_overflow(unsigned long x, unsigned long y, unsigned long *res) { |
| 209 |
return __builtin_usubl_overflow(x, y, res); |
| 210 |
} |
| 211 |
|
| 212 |
// CIR: cir.func {{.*}} @_Z19test_usubl_overflowmmPm |
| 213 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 214 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 215 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u64i>>, !cir.ptr<!u64i> |
| 216 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#X]], %[[#Y]]) : !u64i, (!u64i, !cir.bool) |
| 217 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u64i, !cir.ptr<!u64i> |
| 218 |
// CIR: } |
| 219 |
|
| 220 |
bool test_usubll_overflow(unsigned long long x, unsigned long long y, unsigned long long *res) { |
| 221 |
return __builtin_usubll_overflow(x, y, res); |
| 222 |
} |
| 223 |
|
| 224 |
// CIR: cir.func {{.*}} @_Z20test_usubll_overflowyyPy |
| 225 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 226 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 227 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u64i>>, !cir.ptr<!u64i> |
| 228 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#X]], %[[#Y]]) : !u64i, (!u64i, !cir.bool) |
| 229 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u64i, !cir.ptr<!u64i> |
| 230 |
// CIR: } |
| 231 |
|
| 232 |
bool test_umul_overflow(unsigned x, unsigned y, unsigned *res) { |
| 233 |
return __builtin_umul_overflow(x, y, res); |
| 234 |
} |
| 235 |
|
| 236 |
// CIR: cir.func {{.*}} @_Z18test_umul_overflowjjPj |
| 237 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 238 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u32i>, !u32i |
| 239 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u32i>>, !cir.ptr<!u32i> |
| 240 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#X]], %[[#Y]]) : !u32i, (!u32i, !cir.bool) |
| 241 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u32i, !cir.ptr<!u32i> |
| 242 |
// CIR: } |
| 243 |
|
| 244 |
bool test_umull_overflow(unsigned long x, unsigned long y, unsigned long *res) { |
| 245 |
return __builtin_umull_overflow(x, y, res); |
| 246 |
} |
| 247 |
|
| 248 |
// CIR: cir.func {{.*}} @_Z19test_umull_overflowmmPm |
| 249 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 250 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 251 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u64i>>, !cir.ptr<!u64i> |
| 252 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#X]], %[[#Y]]) : !u64i, (!u64i, !cir.bool) |
| 253 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u64i, !cir.ptr<!u64i> |
| 254 |
// CIR: } |
| 255 |
|
| 256 |
bool test_umulll_overflow(unsigned long long x, unsigned long long y, unsigned long long *res) { |
| 257 |
return __builtin_umulll_overflow(x, y, res); |
| 258 |
} |
| 259 |
|
| 260 |
// CIR: cir.func {{.*}} @_Z20test_umulll_overflowyyPy |
| 261 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 262 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!u64i>, !u64i |
| 263 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!u64i>>, !cir.ptr<!u64i> |
| 264 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#X]], %[[#Y]]) : !u64i, (!u64i, !cir.bool) |
| 265 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !u64i, !cir.ptr<!u64i> |
| 266 |
// CIR: } |
| 267 |
|
| 268 |
bool test_sadd_overflow(int x, int y, int *res) { |
| 269 |
return __builtin_sadd_overflow(x, y, res); |
| 270 |
} |
| 271 |
|
| 272 |
// CIR: cir.func {{.*}} @_Z18test_sadd_overflowiiPi |
| 273 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 274 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 275 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 276 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#X]], %[[#Y]]) : !s32i, (!s32i, !cir.bool) |
| 277 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s32i, !cir.ptr<!s32i> |
| 278 |
// CIR: } |
| 279 |
|
| 280 |
bool test_saddl_overflow(long x, long y, long *res) { |
| 281 |
return __builtin_saddl_overflow(x, y, res); |
| 282 |
} |
| 283 |
|
| 284 |
// CIR: cir.func {{.*}} @_Z19test_saddl_overflowllPl |
| 285 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 286 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 287 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s64i>>, !cir.ptr<!s64i> |
| 288 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#X]], %[[#Y]]) : !s64i, (!s64i, !cir.bool) |
| 289 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s64i, !cir.ptr<!s64i> |
| 290 |
// CIR: } |
| 291 |
|
| 292 |
bool test_saddll_overflow(long long x, long long y, long long *res) { |
| 293 |
return __builtin_saddll_overflow(x, y, res); |
| 294 |
} |
| 295 |
|
| 296 |
// CIR: cir.func {{.*}} @_Z20test_saddll_overflowxxPx |
| 297 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 298 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 299 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s64i>>, !cir.ptr<!s64i> |
| 300 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(add, %[[#X]], %[[#Y]]) : !s64i, (!s64i, !cir.bool) |
| 301 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s64i, !cir.ptr<!s64i> |
| 302 |
// CIR: } |
| 303 |
|
| 304 |
bool test_ssub_overflow(int x, int y, int *res) { |
| 305 |
return __builtin_ssub_overflow(x, y, res); |
| 306 |
} |
| 307 |
|
| 308 |
// CIR: cir.func {{.*}} @_Z18test_ssub_overflowiiPi |
| 309 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 310 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 311 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 312 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#X]], %[[#Y]]) : !s32i, (!s32i, !cir.bool) |
| 313 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s32i, !cir.ptr<!s32i> |
| 314 |
// CIR: } |
| 315 |
|
| 316 |
bool test_ssubl_overflow(long x, long y, long *res) { |
| 317 |
return __builtin_ssubl_overflow(x, y, res); |
| 318 |
} |
| 319 |
|
| 320 |
// CIR: cir.func {{.*}} @_Z19test_ssubl_overflowllPl |
| 321 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 322 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 323 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s64i>>, !cir.ptr<!s64i> |
| 324 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#X]], %[[#Y]]) : !s64i, (!s64i, !cir.bool) |
| 325 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s64i, !cir.ptr<!s64i> |
| 326 |
// CIR: } |
| 327 |
|
| 328 |
bool test_ssubll_overflow(long long x, long long y, long long *res) { |
| 329 |
return __builtin_ssubll_overflow(x, y, res); |
| 330 |
} |
| 331 |
|
| 332 |
// CIR: cir.func {{.*}} @_Z20test_ssubll_overflowxxPx |
| 333 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 334 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 335 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s64i>>, !cir.ptr<!s64i> |
| 336 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(sub, %[[#X]], %[[#Y]]) : !s64i, (!s64i, !cir.bool) |
| 337 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s64i, !cir.ptr<!s64i> |
| 338 |
// CIR: } |
| 339 |
|
| 340 |
bool test_smul_overflow(int x, int y, int *res) { |
| 341 |
return __builtin_smul_overflow(x, y, res); |
| 342 |
} |
| 343 |
|
| 344 |
// CIR: cir.func {{.*}} @_Z18test_smul_overflowiiPi |
| 345 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 346 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i |
| 347 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> |
| 348 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#X]], %[[#Y]]) : !s32i, (!s32i, !cir.bool) |
| 349 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s32i, !cir.ptr<!s32i> |
| 350 |
// CIR: } |
| 351 |
|
| 352 |
bool test_smull_overflow(long x, long y, long *res) { |
| 353 |
return __builtin_smull_overflow(x, y, res); |
| 354 |
} |
| 355 |
|
| 356 |
// CIR: cir.func {{.*}} @_Z19test_smull_overflowllPl |
| 357 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 358 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 359 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s64i>>, !cir.ptr<!s64i> |
| 360 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#X]], %[[#Y]]) : !s64i, (!s64i, !cir.bool) |
| 361 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s64i, !cir.ptr<!s64i> |
| 362 |
// CIR: } |
| 363 |
|
| 364 |
bool test_smulll_overflow(long long x, long long y, long long *res) { |
| 365 |
return __builtin_smulll_overflow(x, y, res); |
| 366 |
} |
| 367 |
|
| 368 |
// CIR: cir.func {{.*}} @_Z20test_smulll_overflowxxPx |
| 369 |
// CIR: %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 370 |
// CIR-NEXT: %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s64i>, !s64i |
| 371 |
// CIR-NEXT: %[[#RES_PTR:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!s64i>>, !cir.ptr<!s64i> |
| 372 |
// CIR-NEXT: %[[RES:.+]], %{{.+}} = cir.binop.overflow(mul, %[[#X]], %[[#Y]]) : !s64i, (!s64i, !cir.bool) |
| 373 |
// CIR-NEXT: cir.store{{.*}} %[[RES]], %[[#RES_PTR]] : !s64i, !cir.ptr<!s64i> |
| 374 |
// CIR: } |