1 // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s 2 namespace foo { 3 4 // CHECK-NOT: @a = global i32 5 extern "C" int a; 6 7 // CHECK-NOT: @_ZN3foo1bE = global i32 8 extern int b; 9 10 // CHECK: @_ZN3foo1cE = global i32 11 int c = 5; 12 13 // CHECK-NOT: @_ZN3foo1dE 14 extern "C" struct d; 15 16 } 17 18 namespace test1 { 19 namespace { 20 struct X {}; 21 } 22 extern "C" { 23 // CHECK: @test1_b = global 24 X test1_b = X(); 25 } 26 void *use = &test1_b; 27 // CHECK: @_ZN5test13useE = global 28 } 29 30 namespace test2 { 31 namespace { 32 struct X {}; 33 } 34 35 // CHECK: @test2_b = global 36 extern "C" X test2_b; 37 X test2_b; 38 } 39 40 extern "C" { 41 static int unused_var; 42 static int unused_fn() { return 0; } 43 44 __attribute__((used)) static int internal_var; 45 __attribute__((used)) static int internal_fn() { return 0; } 46 47 __attribute__((used)) static int duplicate_internal_var; 48 __attribute__((used)) static int duplicate_internal_fn() { return 0; } 49 50 namespace N { 51 __attribute__((used)) static int duplicate_internal_var; 52 __attribute__((used)) static int duplicate_internal_fn() { return 0; } 53 } 54 55 // CHECK: @llvm.used = appending global {{.*}} @internal_var {{.*}} @internal_fn 56 57 // CHECK-NOT: @unused 58 // CHECK-NOT: @duplicate_internal 59 // CHECK: @internal_var = alias internal i32* @_Z12internal_var 60 // CHECK-NOT: @unused 61 // CHECK-NOT: @duplicate_internal 62 // CHECK: @internal_fn = alias internal i32 ()* @_Z11internal_fnv 63 // CHECK-NOT: @unused 64 // CHECK-NOT: @duplicate_internal 65 } 66