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