1 // RUN: %clang_cc1 -no-opaque-pointers -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 {{.*}}* %[[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 {{.*}}* %[[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 {{.*}}* %[[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: store i32 2, i32* @x, align 4 57 58 long y = __builtin_abs(-2l); 59 // CHECK: [[Y:%.+]] = call noundef i64 @_Z13__builtin_absl(i64 noundef -2) 60 // CHECK: store i64 [[Y]], i64* @y, align 8 61 62 extern const char char_memchr_arg[32]; 63 char *memchr_result = __builtin_char_memchr(char_memchr_arg, 123, 32); 64 // CHECK: call i8* @memchr(i8* noundef getelementptr inbounds ([32 x i8], [32 x i8]* @char_memchr_arg, i64 0, i64 0), i32 noundef 123, i64 noundef 32) 65 66 int constexpr_overflow_result() { 67 constexpr int x = 1; 68 // CHECK: alloca i32 69 constexpr int y = 2; 70 // CHECK: alloca i32 71 int z; 72 // CHECK: [[Z:%.+]] = alloca i32 73 74 __builtin_sadd_overflow(x, y, &z); 75 return z; 76 // CHECK: [[RET_PTR:%.+]] = extractvalue { i32, i1 } %0, 0 77 // CHECK: store i32 [[RET_PTR]], i32* [[Z]] 78 // CHECK: [[RET_VAL:%.+]] = load i32, i32* [[Z]] 79 // CHECK: ret i32 [[RET_VAL]] 80 } 81