Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / visibility-inlines-hidden-staticvar.cpp
blob49e246005935d925beebb0d67879ff83315060f3
1 // RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -fvisibility-inlines-hidden -emit-llvm -o - %s -O2 -disable-llvm-passes | FileCheck %s
2 // RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -emit-llvm -o - %s -O2 -disable-llvm-passes | FileCheck -check-prefixes=CHECK-NO-VIH %s
3 // RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden -emit-llvm -o - %s -O2 -disable-llvm-passes | FileCheck %s --check-prefix=CHECK-VIS-HIDDEN
4 // RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -fvisibility=protected -fvisibility-inlines-hidden -emit-llvm -o - %s -O2 -disable-llvm-passes | FileCheck %s --check-prefix=CHECK-VIS-PROTECTED
6 // When a function is hidden due to -fvisibility-inlines-hidden option, static local variables of the function should not be hidden by the option.
8 // CHECK-DAG: @_ZZ4funcvE3var = internal global i32 0
9 // CHECK-DAG: @_ZZ11hidden_funcvE3var = internal global i32 0
10 // CHECK-DAG: @_ZZ12default_funcvE3var = internal global i32 0
11 // CHECK-DAG: @_ZZ11inline_funcvE3var = linkonce_odr global i32 0, comdat
12 // CHECK-DAG: @_ZZ18inline_hidden_funcvE3var = linkonce_odr hidden global i32 0, comdat
13 // CHECK-DAG: @_ZZ19inline_default_funcvE3var = linkonce_odr global i32 0, comdat
14 // CHECK-DAG: @_ZZN13ExportedClass10inl_methodEvE3var = linkonce_odr global i32 0, comdat, align 4
15 // CHECK-DAG: define{{.*}} i32 @_Z4funcv()
16 // CHECK-DAG: define hidden noundef i32 @_Z11hidden_funcv()
17 // CHECK-DAG: define{{.*}} i32 @_Z12default_funcv()
18 // CHECK-DAG: define linkonce_odr hidden noundef i32 @_Z11inline_funcv()
19 // CHECK-DAG: define linkonce_odr hidden noundef i32 @_Z18inline_hidden_funcv()
20 // CHECK-DAG: define linkonce_odr noundef i32 @_Z19inline_default_funcv()
21 // CHECK-DAG: define linkonce_odr hidden noundef i32 @_ZN13ExportedClass10inl_methodEv({{.*}})
22 // CHECK-DAG: define{{.*}} i32 @_ZN13ExportedClass10ext_methodEv({{.*}})
24 // CHECK-NO-VIH-DAG: @_ZZ4funcvE3var = internal global i32 0
25 // CHECK-NO-VIH-DAG: @_ZZ11hidden_funcvE3var = internal global i32 0
26 // CHECK-NO-VIH-DAG: @_ZZ12default_funcvE3var = internal global i32 0
27 // CHECK-NO-VIH-DAG: @_ZZ11inline_funcvE3var = linkonce_odr global i32 0, comdat
28 // CHECK-NO-VIH-DAG: @_ZZ18inline_hidden_funcvE3var = linkonce_odr hidden global i32 0, comdat
29 // CHECK-NO-VIH-DAG: @_ZZ19inline_default_funcvE3var = linkonce_odr global i32 0, comdat
30 // CHECK-NO-VIH-DAG: @_ZZN13ExportedClass10inl_methodEvE3var = linkonce_odr global i32 0, comdat, align 4
31 // CHECK-NO-VIH-DAG: define{{.*}} i32 @_Z4funcv()
32 // CHECK-NO-VIH-DAG: define hidden noundef i32 @_Z11hidden_funcv()
33 // CHECK-NO-VIH-DAG: define{{.*}} i32 @_Z12default_funcv()
34 // CHECK-NO-VIH-DAG: define linkonce_odr noundef i32 @_Z11inline_funcv()
35 // CHECK-NO-VIH-DAG: define linkonce_odr hidden noundef i32 @_Z18inline_hidden_funcv()
36 // CHECK-NO-VIH-DAG: define linkonce_odr noundef i32 @_Z19inline_default_funcv()
37 // CHECK-NO-VIH-DAG: define linkonce_odr noundef i32 @_ZN13ExportedClass10inl_methodEv({{.*}})
38 // CHECK-NO-VIH-DAG: define{{.*}} i32 @_ZN13ExportedClass10ext_methodEv({{.*}})
40 // CHECK-VIS-HIDDEN-DAG: @_ZZ4funcvE3var = internal global i32 0
41 // CHECK-VIS-HIDDEN-DAG: @_ZZ11hidden_funcvE3var = internal global i32 0
42 // CHECK-VIS-HIDDEN-DAG: @_ZZ12default_funcvE3var = internal global i32 0
43 // CHECK-VIS-HIDDEN-DAG: @_ZZ11inline_funcvE3var = linkonce_odr hidden global i32 0, comdat
44 // CHECK-VIS-HIDDEN-DAG: @_ZZ18inline_hidden_funcvE3var = linkonce_odr hidden global i32 0, comdat
45 // CHECK-VIS-HIDDEN-DAG: @_ZZ19inline_default_funcvE3var = linkonce_odr global i32 0, comdat
46 // CHECK-VIS-HIDDEN-DAG: @_ZZN13ExportedClass10inl_methodEvE3var = linkonce_odr global i32 0, comdat, align 4
47 // CHECK-VIS-HIDDEN-DAG: define hidden noundef i32 @_Z4funcv()
48 // CHECK-VIS-HIDDEN-DAG: define hidden noundef i32 @_Z11hidden_funcv()
49 // CHECK-VIS-HIDDEN-DAG: define{{.*}} i32 @_Z12default_funcv()
50 // CHECK-VIS-HIDDEN-DAG: define linkonce_odr hidden noundef i32 @_Z11inline_funcv()
51 // CHECK-VIS-HIDDEN-DAG: define linkonce_odr hidden noundef i32 @_Z18inline_hidden_funcv()
52 // CHECK-VIS-HIDDEN-DAG: define linkonce_odr noundef i32 @_Z19inline_default_funcv()
53 // CHECK-VIS-HIDDEN-DAG: define linkonce_odr hidden noundef i32 @_ZN13ExportedClass10inl_methodEv({{.*}})
54 // CHECK-VIS-HIDDEN-DAG: define{{.*}} i32 @_ZN13ExportedClass10ext_methodEv({{.*}})
56 // CHECK-VIS-PROTECTED-DAG: @_ZZ4funcvE3var = internal global i32 0
57 // CHECK-VIS-PROTECTED-DAG: @_ZZ11hidden_funcvE3var = internal global i32 0
58 // CHECK-VIS-PROTECTED-DAG: @_ZZ12default_funcvE3var = internal global i32 0
59 // CHECK-VIS-PROTECTED-DAG: @_ZZ11inline_funcvE3var = linkonce_odr protected global i32 0, comdat
60 // CHECK-VIS-PROTECTED-DAG: @_ZZ18inline_hidden_funcvE3var = linkonce_odr hidden global i32 0, comdat
61 // CHECK-VIS-PROTECTED-DAG: @_ZZ19inline_default_funcvE3var = linkonce_odr global i32 0, comdat
62 // CHECK-VIS-PROTECTED-DAG: @_ZZN13ExportedClass10inl_methodEvE3var = linkonce_odr global i32 0, comdat, align 4
63 // CHECK-VIS-PROTECTED-DAG: define protected noundef i32 @_Z4funcv()
64 // CHECK-VIS-PROTECTED-DAG: define hidden noundef i32 @_Z11hidden_funcv()
65 // CHECK-VIS-PROTECTED-DAG: define{{.*}} i32 @_Z12default_funcv()
66 // CHECK-VIS-PROTECTED-DAG: define linkonce_odr hidden noundef i32 @_Z11inline_funcv()
67 // CHECK-VIS-PROTECTED-DAG: define linkonce_odr hidden noundef i32 @_Z18inline_hidden_funcv()
68 // CHECK-VIS-PROTECTED-DAG: define linkonce_odr noundef i32 @_Z19inline_default_funcv()
69 // CHECK-VIS-PROTECTED-DAG: define linkonce_odr hidden noundef i32 @_ZN13ExportedClass10inl_methodEv({{.*}})
70 // CHECK-VIS-PROTECTED-DAG: define{{.*}} i32 @_ZN13ExportedClass10ext_methodEv({{.*}})
72 int func(void) {
73 static int var = 0;
74 return var++;
76 inline int inline_func(void) {
77 static int var = 0;
78 return var++;
80 int __attribute__((visibility("hidden"))) hidden_func(void) {
81 static int var = 0;
82 return var++;
84 inline int __attribute__((visibility("hidden"))) inline_hidden_func(void) {
85 static int var = 0;
86 return var++;
88 int __attribute__((visibility("default"))) default_func(void) {
89 static int var = 0;
90 return var++;
92 inline int __attribute__((visibility("default"))) inline_default_func(void) {
93 static int var = 0;
94 return var++;
96 struct __attribute__((visibility("default"))) ExportedClass {
97 int inl_method() {
98 static int var = 0;
99 return var++;
101 int ext_method();
103 int ExportedClass::ext_method() { return inl_method(); }
104 void bar(void) {
105 func();
106 inline_func();
107 hidden_func();
108 inline_hidden_func();
109 default_func();
110 inline_default_func();