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