1 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s 2 namespace foo { 3 4 // CHECK-NOT: @a = global 5 extern "C" int a; 6 7 // CHECK-NOT: @_ZN3foo1bE = global 8 extern int b; 9 10 // CHECK: @_ZN3foo1cE = {{(dso_local )?}}global 11 int c = 5; 12 13 // CHECK-NOT: @_ZN3foo1dE 14 extern "C" struct d; 15 16 // CHECK-NOT: should_not_appear 17 extern "C++" int should_not_appear; 18 19 // CHECK: @_ZN3foo10extern_cxxE = {{(dso_local )?}}global 20 extern "C++" int extern_cxx = 0; 21 22 } 23 24 // CHECK-NOT: @global_a = {{(dso_local )?}}global 25 extern "C" int global_a; 26 27 // CHECK: @global_b = {{(dso_local )?}}global 28 extern "C" int global_b = 0; 29 30 // CHECK-NOT: should_not_appear 31 extern "C++" int should_not_appear; 32 33 // CHECK: @extern_cxx = {{(dso_local )?}}global 34 extern "C++" int extern_cxx = 0; 35 36 namespace test1 { 37 namespace { 38 struct X {}; 39 } 40 extern "C" { 41 // CHECK: @test1_b = {{(dso_local )?}}global 42 X test1_b = X(); 43 } 44 void *use = &test1_b; 45 // CHECK: @_ZN5test13useE = {{(dso_local )?}}global 46 } 47 48 namespace test2 { 49 namespace { 50 struct X {}; 51 } 52 53 // CHECK: @test2_b = {{(dso_local )?}}global 54 extern "C" X test2_b; 55 X test2_b; 56 } 57 58 extern "C" { 59 static int unused_var; unused_fn()60 static int unused_fn() { return 0; } 61 62 __attribute__((used)) static int internal_var; internal_fn()63 __attribute__((used)) static int internal_fn() { return 0; } 64 65 __attribute__((used)) static int duplicate_internal_var; duplicate_internal_fn()66 __attribute__((used)) static int duplicate_internal_fn() { return 0; } 67 68 namespace N { 69 __attribute__((used)) static int duplicate_internal_var; duplicate_internal_fn()70 __attribute__((used)) static int duplicate_internal_fn() { return 0; } 71 } 72 73 // CHECK: @llvm.used = appending global {{.*}} @internal_var {{.*}} @internal_fn 74 75 // CHECK-NOT: @unused 76 // CHECK-NOT: @duplicate_internal 77 // CHECK: @internal_var = internal alias i32, i32* @_ZL12internal_var 78 // CHECK-NOT: @unused 79 // CHECK-NOT: @duplicate_internal 80 // CHECK: @internal_fn = internal alias i32 (), i32 ()* @_ZL11internal_fnv 81 // CHECK-NOT: @unused 82 // CHECK-NOT: @duplicate_internal 83 } 84 85 namespace PR19411 { 86 struct A { void f(); }; f()87 extern "C" void A::f() { void g(); g(); } 88 // CHECK-LABEL: @_ZN7PR194111A1fEv( 89 // CHECK: call {{.*}}void @g() 90 } 91