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
6 int g0;
7 // CHECKBASIC-DAG: @g0 = common global i32 0
8 // CHECKASM-DAG: .comm g0,4,4
9 __thread int TL_WITH_ALIAS;
10 // CHECKBASIC-DAG: @TL_WITH_ALIAS = thread_local global i32 0, align 4
11 // CHECKASM-DAG: .globl TL_WITH_ALIAS
12 // CHECKASM-DAG: .size TL_WITH_ALIAS, 4
13 static int bar1 = 42;
14 // CHECKBASIC-DAG: @bar1 = internal global i32 42
15 // CHECKASM-DAG: bar1:
16 // CHECKASM-DAG: .size bar1, 4
17
18 // PR24379: alias variable expected to have same size as aliasee even when types differ
19 const int wacom_usb_ids[] = {1, 1, 2, 3, 5, 8, 13, 0};
20 // 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
21 // CHECKASM-DAG: .globl wacom_usb_ids
22 // CHECKASM-DAG: .size wacom_usb_ids, 32
23 extern const int __mod_usb_device_table __attribute__ ((alias("wacom_usb_ids")));
24 // CHECKBASIC-DAG: @__mod_usb_device_table = alias i32, getelementptr inbounds ([8 x i32], [8 x i32]* @wacom_usb_ids, i32 0, i32 0)
25 // CHECKASM-DAG: .globl __mod_usb_device_table
26 // CHECKASM-DAG: __mod_usb_device_table = wacom_usb_ids
27 // CHECKASM-NOT: .size __mod_usb_device_table
28
29 extern int g1;
30 extern int g1 __attribute((alias("g0")));
31 // CHECKBASIC-DAG: @g1 = alias i32, i32* @g0
32 // CHECKASM-DAG: .globl g1
33 // CHECKASM-DAG: g1 = g0
34 // CHECKASM-NOT: .size g1
35
36 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
37 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32, i32* @TL_WITH_ALIAS
38 // CHECKASM-DAG: .globl __libc_errno
39 // CHECKASM-DAG: __libc_errno = TL_WITH_ALIAS
40 // CHECKASM-NOT: .size __libc_errno
41
f0(void)42 void f0(void) { }
43 extern void f1(void);
44 extern void f1(void) __attribute((alias("f0")));
45 // CHECKBASIC-DAG: @f1 = alias void (), void ()* @f0
46 // CHECKBASIC-DAG: @test8_foo = weak alias void (...), bitcast (void ()* @test8_bar to void (...)*)
47 // CHECKBASIC-DAG: @test8_zed = alias void (...), bitcast (void ()* @test8_bar to void (...)*)
48 // CHECKBASIC-DAG: @test9_zed = alias void (), void ()* @test9_bar
49 // CHECKBASIC: define void @f0() [[NUW:#[0-9]+]] {
50
51 // Make sure that aliases cause referenced values to be emitted.
52 // PR3200
foo1()53 static inline int foo1() { return 0; }
54 // CHECKBASIC-LABEL: define internal i32 @foo1()
55 int foo() __attribute__((alias("foo1")));
56 int bar() __attribute__((alias("bar1")));
57
58 extern int test6();
test7()59 void test7() { test6(); } // test6 is emitted as extern.
60
61 // test6 changes to alias.
62 int test6() __attribute__((alias("test7")));
63
inner(int a)64 static int inner(int a) { return 0; }
inner_weak(int a)65 static int inner_weak(int a) { return 0; }
66 extern __typeof(inner) inner_a __attribute__((alias("inner")));
67 static __typeof(inner_weak) inner_weak_a __attribute__((weakref, alias("inner_weak")));
68 // CHECKCC: @inner_a = alias i32 (i32), i32 (i32)* @inner
69 // CHECKCC: define internal arm_aapcs_vfpcc i32 @inner(i32 %a) [[NUW:#[0-9]+]] {
70
outer(int a)71 int outer(int a) { return inner(a); }
72 // CHECKCC: define arm_aapcs_vfpcc i32 @outer(i32 %a) [[NUW]] {
73 // CHECKCC: call arm_aapcs_vfpcc i32 @inner(i32 %{{.*}})
74
outer_weak(int a)75 int outer_weak(int a) { return inner_weak_a(a); }
76 // CHECKCC: define arm_aapcs_vfpcc i32 @outer_weak(i32 %a) [[NUW]] {
77 // CHECKCC: call arm_aapcs_vfpcc i32 @inner_weak(i32 %{{.*}})
78 // CHECKCC: define internal arm_aapcs_vfpcc i32 @inner_weak(i32 %a) [[NUW]] {
79
80 // CHECKBASIC: attributes [[NUW]] = { nounwind{{.*}} }
81
82 // CHECKCC: attributes [[NUW]] = { nounwind{{.*}} }
83
test8_bar()84 void test8_bar() {}
85 void test8_foo() __attribute__((weak, alias("test8_bar")));
86 void test8_zed() __attribute__((alias("test8_foo")));
87
test9_bar(void)88 void test9_bar(void) { }
89 void test9_zed(void) __attribute__((section("test")));
90 void test9_zed(void) __attribute__((alias("test9_bar")));
91