blob: 13d295a5d59b03bd252a1dd6c57b0db68f99deb6 [file] [log] [blame]
John McCallf9536f42011-02-08 22:28:39 +00001// This is an IR generation test because the calculation of visibility
2// during IR gen will cause linkage to be implicitly recomputed and
3// compared against the earlier cached value. If we had a way of
4// testing linkage directly in Sema, that would be better.
5
Chandler Carruth10aad442011-02-25 00:05:02 +00006// RUN: %clang_cc1 -Werror -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s
John McCallf9536f42011-02-08 22:28:39 +00007
8// PR8926
9namespace test0 {
10 typedef struct {
11 void *foo() { return 0; }
12 } A;
13
14 // CHECK: define linkonce_odr i8* @_ZN5test01A3fooEv(
15
16 void test(A *a) {
17 a->foo();
18 }
19}
20
21namespace test1 {
22 typedef struct {
23 template <unsigned n> void *foo() { return 0; }
24
25 void foo() {
26 foo<0>();
27 }
28 } A;
29
30 // CHECK: define linkonce_odr void @_ZN5test11A3fooEv(
31 // another at the end
32
33 void test(A *a) {
34 a->foo();
35 }
36}
37
38namespace test2 {
39 typedef struct {
40 template <unsigned n> struct B {
41 void *foo() { return 0; }
42 };
43
44 void foo(B<0> *b) {
45 b->foo();
46 }
47 } A;
48
49 // CHECK: define linkonce_odr void @_ZN5test21A3fooEPNS0_1BILj0EEE(
50
51 void test(A *a) {
52 a->foo(0);
53 }
54}
55
John McCallaf8ca372011-02-10 06:50:24 +000056namespace test3 {
57 namespace { struct A {}; }
58
59 // CHECK: define internal void @_ZN5test34testENS_12_GLOBAL__N_11AE(
60 void test(A a) {}
61 void force() { test(A()); }
62
63 // CHECK: define void @test3(
64 extern "C" void test3(A a) {}
65}
66
Chandler Carruth094b6432011-02-24 19:03:39 +000067namespace {
68 // CHECK: define void @test4(
69 extern "C" void test4(void) {}
70}
71
Chandler Carruth10aad442011-02-25 00:05:02 +000072// PR9316: Ensure that even non-namespace-scope function declarations in
73// a C declaration context respect that over the anonymous namespace.
74extern "C" {
75 namespace {
76 struct X {
77 int f() {
78 extern int g();
Eli Friedman750dc2b2012-01-15 01:23:58 +000079 extern int a;
Chandler Carruth10aad442011-02-25 00:05:02 +000080
81 // Test both for mangling in the code generation and warnings from use
82 // of internal, undefined names via -Werror.
83 // CHECK: call i32 @g(
Eli Friedman750dc2b2012-01-15 01:23:58 +000084 // CHECK: load i32* @a,
85 return g() + a;
Chandler Carruth10aad442011-02-25 00:05:02 +000086 }
87 };
88 }
89 // Force the above function to be emitted by codegen.
90 int test(X& x) {
91 return x.f();
92 }
93}
94
John McCallf9536f42011-02-08 22:28:39 +000095// CHECK: define linkonce_odr i8* @_ZN5test21A1BILj0EE3fooEv(
96// CHECK: define linkonce_odr i8* @_ZN5test11A3fooILj0EEEPvv(
Rafael Espindola88e37c22013-04-26 00:29:11 +000097
98namespace test5 {
99 struct foo {
100 };
101 extern "C" {
102 const foo bar[] = {
103 };
104 }
105}