1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm -triple i386-linux-gnu -o %t %s
2*f4a2713aSLionel Sambuc // RUN: FileCheck --input-file=%t %s
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc // CHECK: declare extern_weak void @test1_f()
5*f4a2713aSLionel Sambuc void test1_f(void);
6*f4a2713aSLionel Sambuc static void test1_g(void) __attribute__((weakref("test1_f")));
test1_h(void)7*f4a2713aSLionel Sambuc void test1_h(void) {
8*f4a2713aSLionel Sambuc   test1_g();
9*f4a2713aSLionel Sambuc }
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test2_f()
test2_f(void)12*f4a2713aSLionel Sambuc void test2_f(void) {}
13*f4a2713aSLionel Sambuc static void test2_g(void) __attribute__((weakref("test2_f")));
test2_h(void)14*f4a2713aSLionel Sambuc void test2_h(void) {
15*f4a2713aSLionel Sambuc   test2_g();
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc // CHECK: declare void @test3_f()
19*f4a2713aSLionel Sambuc void test3_f(void);
20*f4a2713aSLionel Sambuc static void test3_g(void) __attribute__((weakref("test3_f")));
test3_foo(void)21*f4a2713aSLionel Sambuc void test3_foo(void) {
22*f4a2713aSLionel Sambuc   test3_f();
23*f4a2713aSLionel Sambuc }
test3_h(void)24*f4a2713aSLionel Sambuc void test3_h(void) {
25*f4a2713aSLionel Sambuc   test3_g();
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test4_f()
29*f4a2713aSLionel Sambuc void test4_f(void);
30*f4a2713aSLionel Sambuc static void test4_g(void) __attribute__((weakref("test4_f")));
test4_h(void)31*f4a2713aSLionel Sambuc void test4_h(void) {
32*f4a2713aSLionel Sambuc   test4_g();
33*f4a2713aSLionel Sambuc }
test4_f(void)34*f4a2713aSLionel Sambuc void test4_f(void) {}
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc // CHECK: declare void @test5_f()
37*f4a2713aSLionel Sambuc void test5_f(void);
38*f4a2713aSLionel Sambuc static void test5_g(void) __attribute__((weakref("test5_f")));
test5_h(void)39*f4a2713aSLionel Sambuc void test5_h(void) {
40*f4a2713aSLionel Sambuc   test5_g();
41*f4a2713aSLionel Sambuc }
test5_foo(void)42*f4a2713aSLionel Sambuc void test5_foo(void) {
43*f4a2713aSLionel Sambuc   test5_f();
44*f4a2713aSLionel Sambuc }
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc // CHECK: declare extern_weak void @test6_f()
47*f4a2713aSLionel Sambuc void test6_f(void) __attribute__((weak));
48*f4a2713aSLionel Sambuc static void test6_g(void) __attribute__((weakref("test6_f")));
test6_h(void)49*f4a2713aSLionel Sambuc void test6_h(void) {
50*f4a2713aSLionel Sambuc   test6_g();
51*f4a2713aSLionel Sambuc }
test6_foo(void)52*f4a2713aSLionel Sambuc void test6_foo(void) {
53*f4a2713aSLionel Sambuc   test6_f();
54*f4a2713aSLionel Sambuc }
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc // CHECK: declare extern_weak void @test8_f()
57*f4a2713aSLionel Sambuc static void test8_g(void) __attribute__((weakref("test8_f")));
test8_h(void)58*f4a2713aSLionel Sambuc void test8_h(void) {
59*f4a2713aSLionel Sambuc   if (test8_g)
60*f4a2713aSLionel Sambuc     test8_g();
61*f4a2713aSLionel Sambuc }
62*f4a2713aSLionel Sambuc // CHECK: declare extern_weak void @test7_f()
63*f4a2713aSLionel Sambuc void test7_f(void);
64*f4a2713aSLionel Sambuc static void test7_g(void) __attribute__((weakref("test7_f")));
65*f4a2713aSLionel Sambuc static void *const test7_zed = (void *) &test7_g;
test7_h(void)66*f4a2713aSLionel Sambuc void* test7_h(void) {
67*f4a2713aSLionel Sambuc   return test7_zed;
68*f4a2713aSLionel Sambuc }
69