1 // 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 6 // RUN: %clang_cc1 -Werror -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s 7 8 // PR8926 9 namespace 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 21 namespace 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 38 namespace 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 56 namespace 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 67 namespace { 68 // CHECK: define void @test4( 69 extern "C" void test4(void) {} 70 } 71 72 // PR9316: Ensure that even non-namespace-scope function declarations in 73 // a C declaration context respect that over the anonymous namespace. 74 extern "C" { 75 namespace { 76 struct X { 77 int f() { 78 extern int g(); 79 extern int a; 80 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( 84 // CHECK: load i32* @a, 85 return g() + a; 86 } 87 }; 88 } 89 // Force the above function to be emitted by codegen. 90 int test(X& x) { 91 return x.f(); 92 } 93 } 94 95 // CHECK: define linkonce_odr i8* @_ZN5test21A1BILj0EE3fooEv( 96 // CHECK: define linkonce_odr i8* @_ZN5test11A3fooILj0EEEPvv( 97 98 namespace test5 { 99 struct foo { 100 }; 101 extern "C" { 102 const foo bar[] = { 103 }; 104 } 105 } 106