16a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola// RUN: %clang_cc1 -emit-llvm -triple i386-linux-gnu -o %t %s
26a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola// RUN: FileCheck --input-file=%t %s
36a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola
46a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola// CHECK: declare extern_weak void @test1_f()
56a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test1_f(void);
66a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolastatic void test1_g(void) __attribute__((weakref("test1_f")));
76a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test1_h(void) {
86a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test1_g();
96a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
106a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola
1193ab6bf534fb6c26563c00f28a8fc5581bb71dfdStephen Lin// CHECK-LABEL: define void @test2_f()
126a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test2_f(void) {}
136a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolastatic void test2_g(void) __attribute__((weakref("test2_f")));
146a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test2_h(void) {
156a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test2_g();
166a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
176a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola
186a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola// CHECK: declare void @test3_f()
196a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test3_f(void);
206a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolastatic void test3_g(void) __attribute__((weakref("test3_f")));
216a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test3_foo(void) {
226a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test3_f();
236a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
246a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test3_h(void) {
256a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test3_g();
266a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
276a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola
2893ab6bf534fb6c26563c00f28a8fc5581bb71dfdStephen Lin// CHECK-LABEL: define void @test4_f()
296a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test4_f(void);
306a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolastatic void test4_g(void) __attribute__((weakref("test4_f")));
316a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test4_h(void) {
326a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test4_g();
336a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
346a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test4_f(void) {}
356a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola
366a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola// CHECK: declare void @test5_f()
376a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test5_f(void);
386a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolastatic void test5_g(void) __attribute__((weakref("test5_f")));
396a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test5_h(void) {
406a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test5_g();
416a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
426a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test5_foo(void) {
436a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test5_f();
446a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
456a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola
466a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola// CHECK: declare extern_weak void @test6_f()
476a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test6_f(void) __attribute__((weak));
486a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolastatic void test6_g(void) __attribute__((weakref("test6_f")));
496a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test6_h(void) {
506a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test6_g();
516a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
526a836706c40a31c716952b74785102c90fd6afa7Rafael Espindolavoid test6_foo(void) {
536a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola  test6_f();
546a836706c40a31c716952b74785102c90fd6afa7Rafael Espindola}
55da1826102fcadb5d3c5d2d20dfa51f0e77489004Rafael Espindola
564695f91f4302a90ae462cd64dda59b34c3dad821Joerg Sonnenberger// CHECK: declare extern_weak void @test8_f()
574695f91f4302a90ae462cd64dda59b34c3dad821Joerg Sonnenbergerstatic void test8_g(void) __attribute__((weakref("test8_f")));
584695f91f4302a90ae462cd64dda59b34c3dad821Joerg Sonnenbergervoid test8_h(void) {
594695f91f4302a90ae462cd64dda59b34c3dad821Joerg Sonnenberger  if (test8_g)
604695f91f4302a90ae462cd64dda59b34c3dad821Joerg Sonnenberger    test8_g();
614695f91f4302a90ae462cd64dda59b34c3dad821Joerg Sonnenberger}
62da1826102fcadb5d3c5d2d20dfa51f0e77489004Rafael Espindola// CHECK: declare extern_weak void @test7_f()
63da1826102fcadb5d3c5d2d20dfa51f0e77489004Rafael Espindolavoid test7_f(void);
64da1826102fcadb5d3c5d2d20dfa51f0e77489004Rafael Espindolastatic void test7_g(void) __attribute__((weakref("test7_f")));
65da1826102fcadb5d3c5d2d20dfa51f0e77489004Rafael Espindolastatic void *const test7_zed = (void *) &test7_g;
66da1826102fcadb5d3c5d2d20dfa51f0e77489004Rafael Espindolavoid* test7_h(void) {
67da1826102fcadb5d3c5d2d20dfa51f0e77489004Rafael Espindola  return test7_zed;
68da1826102fcadb5d3c5d2d20dfa51f0e77489004Rafael Espindola}
69