1 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECKBASIC %s
2 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | FileCheck -check-prefix=CHECKCC %s
3 
4 int g0;
5 // CHECKBASIC: @g0 = common global i32 0
6 __thread int TL_WITH_ALIAS;
7 // CHECKBASIC-DAG: @TL_WITH_ALIAS = thread_local global i32 0, align 4
8 static int bar1 = 42;
9 // CHECKBASIC: @bar1 = internal global i32 42
10 
11 extern int g1;
12 extern int g1 __attribute((alias("g0")));
13 // CHECKBASIC-DAG: @g1 = alias i32* @g0
14 
15 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
16 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32* @TL_WITH_ALIAS
17 
f0(void)18 void f0(void) { }
19 extern void f1(void);
20 extern void f1(void) __attribute((alias("f0")));
21 // CHECKBASIC-DAG: @f1 = alias void ()* @f0
22 // CHECKBASIC-DAG: @test8_foo = weak alias bitcast (void ()* @test8_bar to void (...)*)
23 // CHECKBASIC-DAG: @test8_zed = alias bitcast (void ()* @test8_bar to void (...)*)
24 // CHECKBASIC-DAG: @test9_zed = alias void ()* @test9_bar
25 // CHECKBASIC: define void @f0() [[NUW:#[0-9]+]] {
26 
27 // Make sure that aliases cause referenced values to be emitted.
28 // PR3200
foo1()29 static inline int foo1() { return 0; }
30 // CHECKBASIC-LABEL: define internal i32 @foo1()
31 int foo() __attribute__((alias("foo1")));
32 int bar() __attribute__((alias("bar1")));
33 
34 extern int test6();
test7()35 void test7() { test6(); }  // test6 is emitted as extern.
36 
37 // test6 changes to alias.
38 int test6() __attribute__((alias("test7")));
39 
inner(int a)40 static int inner(int a) { return 0; }
inner_weak(int a)41 static int inner_weak(int a) { return 0; }
42 extern __typeof(inner) inner_a __attribute__((alias("inner")));
43 static __typeof(inner_weak) inner_weak_a __attribute__((weakref, alias("inner_weak")));
44 // CHECKCC: @inner_a = alias i32 (i32)* @inner
45 // CHECKCC: define internal arm_aapcs_vfpcc i32 @inner(i32 %a) [[NUW:#[0-9]+]] {
46 
outer(int a)47 int outer(int a) { return inner(a); }
48 // CHECKCC: define arm_aapcs_vfpcc i32 @outer(i32 %a) [[NUW]] {
49 // CHECKCC: call arm_aapcs_vfpcc  i32 @inner(i32 %{{.*}})
50 
outer_weak(int a)51 int outer_weak(int a) { return inner_weak_a(a); }
52 // CHECKCC: define arm_aapcs_vfpcc i32 @outer_weak(i32 %a) [[NUW]] {
53 // CHECKCC: call arm_aapcs_vfpcc  i32 @inner_weak(i32 %{{.*}})
54 // CHECKCC: define internal arm_aapcs_vfpcc i32 @inner_weak(i32 %a) [[NUW]] {
55 
56 // CHECKBASIC: attributes [[NUW]] = { nounwind{{.*}} }
57 
58 // CHECKCC: attributes [[NUW]] = { nounwind{{.*}} }
59 
test8_bar()60 void test8_bar() {}
61 void test8_foo() __attribute__((weak, alias("test8_bar")));
62 void test8_zed() __attribute__((alias("test8_foo")));
63 
test9_bar(void)64 void test9_bar(void) { }
65 void test9_zed(void) __attribute__((section("test")));
66 void test9_zed(void) __attribute__((alias("test9_bar")));
67