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
main()20 int main() {
21 // CHECK: call {{signext i8|i8}} @memmove()
22 return memmove();
23 }
24
25 struct S;
26 // CHECK: define {{.*}} @_Z9addressofbR1SS0_(
addressof(bool b,S & s,S & t)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 extern "C" int __builtin_abs(int); // #1
34 long __builtin_abs(long); // #2
35 extern "C" int __builtin_abs(int); // #3
36
37 int x = __builtin_abs(-2);
38 // CHECK: store i32 2, i32* @x, align 4
39
40 long y = __builtin_abs(-2l);
41 // CHECK: [[Y:%.+]] = call i64 @_Z13__builtin_absl(i64 -2)
42 // CHECK: store i64 [[Y]], i64* @y, align 8
43
44 extern const char char_memchr_arg[32];
45 char *memchr_result = __builtin_char_memchr(char_memchr_arg, 123, 32);
46 // CHECK: call i8* @memchr(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @char_memchr_arg, i64 0, i64 0), i32 123, i64 32)
47
constexpr_overflow_result()48 int constexpr_overflow_result() {
49 constexpr int x = 1;
50 // CHECK: alloca i32
51 constexpr int y = 2;
52 // CHECK: alloca i32
53 int z;
54 // CHECK: [[Z:%.+]] = alloca i32
55
56 __builtin_sadd_overflow(x, y, &z);
57 return z;
58 // CHECK: [[RET_PTR:%.+]] = extractvalue { i32, i1 } %0, 0
59 // CHECK: store i32 [[RET_PTR]], i32* [[Z]]
60 // CHECK: [[RET_VAL:%.+]] = load i32, i32* [[Z]]
61 // CHECK: ret i32 [[RET_VAL]]
62 }
63