1 // REQUIRES: arm-registered-target
2 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECKBASIC %s
3 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | FileCheck -check-prefix=CHECKCC %s
4 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck -check-prefix=CHECKASM %s
5 // RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECKGLOBALS %s
6
7 int g0;
8 // CHECKBASIC-DAG: @g0 = common global i32 0
9 // CHECKASM-DAG: .comm g0,4,4
10 __thread int TL_WITH_ALIAS;
11 // CHECKBASIC-DAG: @TL_WITH_ALIAS = thread_local global i32 0, align 4
12 // CHECKASM-DAG: .globl TL_WITH_ALIAS
13 // CHECKASM-DAG: .size TL_WITH_ALIAS, 4
14 static int bar1 = 42;
15 // CHECKBASIC-DAG: @bar1 = internal global i32 42
16 // CHECKASM-DAG: bar1:
17 // CHECKASM-DAG: .size bar1, 4
18
19 // PR24379: alias variable expected to have same size as aliasee even when types differ
20 const int wacom_usb_ids[] = {1, 1, 2, 3, 5, 8, 13, 0};
21 // CHECKBASIC-DAG: @wacom_usb_ids = constant [8 x i32] [i32 1, i32 1, i32 2, i32 3, i32 5, i32 8, i32 13, i32 0], align 4
22 // CHECKASM-DAG: .globl wacom_usb_ids
23 // CHECKASM-DAG: .size wacom_usb_ids, 32
24 extern const int __mod_usb_device_table __attribute__ ((alias("wacom_usb_ids")));
25 // CHECKBASIC-DAG: @__mod_usb_device_table = alias i32, getelementptr inbounds ([8 x i32], [8 x i32]* @wacom_usb_ids, i32 0, i32 0)
26 // CHECKASM-DAG: .globl __mod_usb_device_table
27 // CHECKASM-DAG: .set __mod_usb_device_table, wacom_usb_ids
28 // CHECKASM-NOT: .size __mod_usb_device_table
29
30 extern int g1;
31 extern int g1 __attribute((alias("g0")));
32 // CHECKBASIC-DAG: @g1 = alias i32, i32* @g0
33 // CHECKASM-DAG: .globl g1
34 // CHECKASM-DAG: .set g1, g0
35 // CHECKASM-NOT: .size g1
36
37 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
38 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32, i32* @TL_WITH_ALIAS
39 // CHECKASM-DAG: .globl __libc_errno
40 // CHECKASM-DAG: .set __libc_errno, TL_WITH_ALIAS
41 // CHECKASM-NOT: .size __libc_errno
42
f0(void)43 void f0(void) { }
44 extern void f1(void);
45 extern void f1(void) __attribute((alias("f0")));
46 // CHECKBASIC-DAG: @f1 = alias void (), void ()* @f0
47 // CHECKBASIC-DAG: @test8_foo = weak alias void (...), bitcast (void ()* @test8_bar to void (...)*)
48 // CHECKBASIC-DAG: @test8_zed = alias void (...), bitcast (void ()* @test8_bar to void (...)*)
49 // CHECKBASIC-DAG: @test9_zed = alias void (), void ()* @test9_bar
50 // CHECKBASIC: define void @f0() [[NUW:#[0-9]+]] {
51
52 // Make sure that aliases cause referenced values to be emitted.
53 // PR3200
foo1()54 static inline int foo1() { return 0; }
55 // CHECKBASIC-LABEL: define internal i32 @foo1()
56 int foo() __attribute__((alias("foo1")));
57 int bar() __attribute__((alias("bar1")));
58
59 extern int test6();
test7()60 void test7() { test6(); } // test6 is emitted as extern.
61
62 // test6 changes to alias.
63 int test6() __attribute__((alias("test7")));
64
inner(int a)65 static int inner(int a) { return 0; }
inner_weak(int a)66 static int inner_weak(int a) { return 0; }
67 extern __typeof(inner) inner_a __attribute__((alias("inner")));
68 static __typeof(inner_weak) inner_weak_a __attribute__((weakref, alias("inner_weak")));
69 // CHECKCC: @inner_a = alias i32 (i32), i32 (i32)* @inner
70 // CHECKCC: define internal arm_aapcs_vfpcc i32 @inner(i32 %a) [[NUW:#[0-9]+]] {
71
outer(int a)72 int outer(int a) { return inner(a); }
73 // CHECKCC: define arm_aapcs_vfpcc i32 @outer(i32 %a) [[NUW]] {
74 // CHECKCC: call arm_aapcs_vfpcc i32 @inner(i32 %{{.*}})
75
outer_weak(int a)76 int outer_weak(int a) { return inner_weak_a(a); }
77 // CHECKCC: define arm_aapcs_vfpcc i32 @outer_weak(i32 %a) [[NUW]] {
78 // CHECKCC: call arm_aapcs_vfpcc i32 @inner_weak(i32 %{{.*}})
79 // CHECKCC: define internal arm_aapcs_vfpcc i32 @inner_weak(i32 %a) [[NUW]] {
80
81 // CHECKBASIC: attributes [[NUW]] = { noinline nounwind{{.*}} }
82
83 // CHECKCC: attributes [[NUW]] = { noinline nounwind{{.*}} }
84
test8_bar()85 void test8_bar() {}
86 void test8_foo() __attribute__((weak, alias("test8_bar")));
87 void test8_zed() __attribute__((alias("test8_foo")));
88
test9_bar(void)89 void test9_bar(void) { }
90 void test9_zed(void) __attribute__((section("test")));
91 void test9_zed(void) __attribute__((alias("test9_bar")));
92
93 // Test that the alias gets its linkage from its declared qual type.
94 // CHECKGLOBALS: @test10_foo = internal
95 // CHECKGLOBALS-NOT: @test10_foo = dso_local
96 int test10;
97 static int test10_foo __attribute__((alias("test10")));
98 // CHECKGLOBALS: @test11_foo = internal
99 // CHECKGLOBALS-NOT: @test11_foo = dso_local
test11(void)100 void test11(void) {}
101 static void test11_foo(void) __attribute__((alias("test11")));
102
103 // Test that gnu_inline+alias work.
104 // CHECKGLOBALS: @test12_alias = alias void (), void ()* @test12
test12(void)105 void test12(void) {}
106 inline void test12_alias(void) __attribute__((gnu_inline, alias("test12")));
107