| 1 |
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s |
| 2 |
|
| 3 |
// Builtins inside a namespace inside an extern "C" must be considered builtins. |
| 4 |
extern "C" { |
| 5 |
namespace X { |
| 6 |
double __builtin_fabs(double); |
| 7 |
float __builtin_fabsf(float) noexcept; |
| 8 |
} // namespace X |
| 9 |
} |
| 10 |
|
| 11 |
int o = X::__builtin_fabs(-2.0); |
| 12 |
// CHECK: @o ={{.*}} global i32 2, align 4 |
| 13 |
|
| 14 |
long p = X::__builtin_fabsf(-3.0f); |
| 15 |
// CHECK: @p ={{.*}} global i64 3, align 8 |
| 16 |
|
| 17 |
// PR8839 |
| 18 |
extern "C" char memmove(); |
| 19 |
|
| 20 |
int main() { |
| 21 |
// CHECK: call {{signext i8|i8}} @memmove() |
| 22 |
return memmove(); |
| 23 |
} |
| 24 |
|
| 25 |
struct S; |
| 26 |
// CHECK: define {{.*}} @_Z9addressofbR1SS0_( |
| 27 |
S *addressof(bool b, S &s, S &t) { |
| 28 |
// CHECK: %[[LVALUE:.*]] = phi |
| 29 |
// CHECK: ret ptr %[[LVALUE]] |
| 30 |
return __builtin_addressof(b ? s : t); |
| 31 |
} |
| 32 |
|
| 33 |
namespace std { template<typename T> T *addressof(T &); } |
| 34 |
|
| 35 |
// CHECK: define {{.*}} @_Z13std_addressofbR1SS0_( |
| 36 |
S *std_addressof(bool b, S &s, S &t) { |
| 37 |
// CHECK: %[[LVALUE:.*]] = phi |
| 38 |
// CHECK: ret ptr %[[LVALUE]] |
| 39 |
return std::addressof(b ? s : t); |
| 40 |
} |
| 41 |
|
| 42 |
namespace std { template<typename T> T *__addressof(T &); } |
| 43 |
|
| 44 |
// CHECK: define {{.*}} @_Z15std___addressofbR1SS0_( |
| 45 |
S *std___addressof(bool b, S &s, S &t) { |
| 46 |
// CHECK: %[[LVALUE:.*]] = phi |
| 47 |
// CHECK: ret ptr %[[LVALUE]] |
| 48 |
return std::__addressof(b ? s : t); |
| 49 |
} |
| 50 |
|
| 51 |
extern "C" int __builtin_abs(int); // #1 |
| 52 |
long __builtin_abs(long); // #2 |
| 53 |
extern "C" int __builtin_abs(int); // #3 |
| 54 |
|
| 55 |
int x = __builtin_abs(-2); |
| 56 |
// CHECK: [[X:%.+]] = call i32 @llvm.abs.i32(i32 -2, i1 true) |
| 57 |
// CHECK-NEXT: store i32 [[X]], ptr @x, align 4 |
| 58 |
|
| 59 |
long y = __builtin_abs(-2l); |
| 60 |
// CHECK: [[Y:%.+]] = call noundef i64 @_Z13__builtin_absl(i64 noundef -2) |
| 61 |
// CHECK: store i64 [[Y]], ptr @y, align 8 |
| 62 |
|
| 63 |
extern const char char_memchr_arg[32]; |
| 64 |
char *memchr_result = __builtin_char_memchr(char_memchr_arg, 123, 32); |
| 65 |
// CHECK: call ptr @memchr(ptr noundef @char_memchr_arg, i32 noundef 123, i64 noundef 32) |
| 66 |
|
| 67 |
int constexpr_overflow_result() { |
| 68 |
constexpr int x = 1; |
| 69 |
// CHECK: alloca i32 |
| 70 |
constexpr int y = 2; |
| 71 |
// CHECK: alloca i32 |
| 72 |
int z; |
| 73 |
// CHECK: [[Z:%.+]] = alloca i32 |
| 74 |
|
| 75 |
__builtin_sadd_overflow(x, y, &z); |
| 76 |
return z; |
| 77 |
// CHECK: [[RET_PTR:%.+]] = extractvalue { i32, i1 } %0, 0 |
| 78 |
// CHECK: store i32 [[RET_PTR]], ptr [[Z]] |
| 79 |
// CHECK: [[RET_VAL:%.+]] = load i32, ptr [[Z]] |
| 80 |
// CHECK: ret i32 [[RET_VAL]] |
| 81 |
} |