[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / dso-local-executable.c
blob15575d3927f23d18e42050c8786c58d2fcebdacc
1 // RUN: %clang_cc1 -triple x86_64-pc-win32 -emit-llvm %s -o - | FileCheck --check-prefix=COFF %s
2 // COFF: @baz = dso_local global i32 42
3 // COFF-NEXT: @import_var = external dllimport global i32
4 // COFF-NEXT: @weak_bar = extern_weak global i32
5 // COFF-NEXT: @bar = external dso_local global i32
6 // COFF-NEXT: @local_thread_var = dso_local thread_local global i32 42
7 // COFF-NEXT: @thread_var = external dso_local thread_local global i32
8 // COFF-DAG: declare dso_local void @foo()
9 // COFF-DAG: define dso_local ptr @zed()
10 // COFF-DAG: declare dllimport void @import_func()
12 // RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS,MINGW-AUTO-IMPORT %s
13 // RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - -fno-auto-import | FileCheck --check-prefixes=MINGW,MINGW-NATIVE_TLS,MINGW-NO-AUTO-IMPORT %s
14 // RUN: %clang_cc1 -triple x86_64-w64-mingw32 -emit-llvm %s -o - -femulated-tls | FileCheck --check-prefixes=MINGW,MINGW-EMUTLS,MINGW-AUTO-IMPORT %s
15 // MINGW: @baz = dso_local global i32 42
16 // MINGW-NEXT: @import_var = external dllimport global i32
17 // MINGW-NEXT: @weak_bar = extern_weak global i32
18 // MINGW-AUTO-IMPORT-NEXT: @bar = external global i32
19 // MINGW-NO-AUTO-IMPORT-NEXT: @bar = external dso_local global i32
20 // MINGW-NEXT: @local_thread_var = dso_local thread_local global i32 42
21 // MINGW-NATIVE_TLS-NEXT: @thread_var = external dso_local thread_local global i32
22 // MINGW-EMUTLS-NEXT: @thread_var = external thread_local global i32
23 // MINGW-DAG: declare dso_local void @foo()
24 // MINGW-DAG: define dso_local ptr @zed()
25 // MINGW-DAG: declare dllimport void @import_func()
27 /// Static relocation model defaults to -fdirect-access-external-data and sets
28 /// dso_local on most global objects.
29 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static %s -o - | FileCheck --check-prefix=STATIC %s
30 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static -fdirect-access-external-data %s -o - | FileCheck --check-prefix=STATIC %s
31 // STATIC: @baz = dso_local global i32 42
32 // STATIC-NEXT: @import_var = external dso_local global i32
33 // STATIC-NEXT: @weak_bar = extern_weak dso_local global i32
34 // STATIC-NEXT: @bar = external dso_local global i32
35 // STATIC-NEXT: @local_thread_var = dso_local thread_local global i32 42
36 // STATIC-NEXT: @thread_var = external thread_local global i32
37 // STATIC-DAG: declare dso_local void @foo()
38 // STATIC-DAG: define dso_local ptr @zed()
39 // STATIC-DAG: declare dso_local void @import_func()
41 // STATIC-NOT: !"direct-access-external-data"
43 /// If -fno-direct-access-external-data is set, drop dso_local from global variable
44 /// declarations.
45 // RUN: %clang_cc1 -triple x86_64 -emit-llvm %s -mrelocation-model static -fno-direct-access-external-data -o - | FileCheck --check-prefix=STATIC-INDIRECT %s
46 // STATIC-INDIRECT: @baz = dso_local global i32 42
47 // STATIC-INDIRECT-NEXT: @import_var = external global i32
48 // STATIC-INDIRECT-NEXT: @weak_bar = extern_weak global i32
49 // STATIC-INDIRECT-NEXT: @bar = external global i32
50 // STATIC-INDIRECT-NEXT: @local_thread_var = dso_local thread_local global i32 42
51 // STATIC-INDIRECT-NEXT: @thread_var = external thread_local global i32
52 // STATIC-INDIRECT-DAG: declare void @import_func()
53 // STATIC-INDIRECT-DAG: define dso_local ptr @zed()
54 // STATIC-INDIRECT-DAG: declare void @foo()
56 // STATIC-INDIRECT: ![[#]] = !{i32 7, !"direct-access-external-data", i32 0}
58 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie %s -o - | FileCheck --check-prefix=PIE %s
59 // PIE: @baz = dso_local global i32 42
60 // PIE-NEXT: @import_var = external global i32
61 // PIE-NEXT: @weak_bar = extern_weak global i32
62 // PIE-NEXT: @bar = external global i32
63 // PIE-NEXT: @local_thread_var = dso_local thread_local global i32 42
64 // PIE-NEXT: @thread_var = external thread_local global i32
65 // PIE-DAG: declare void @foo()
66 // PIE-DAG: define dso_local ptr @zed()
67 // PIE-DAG: declare void @import_func()
69 // PIE-NOT: !"direct-access-external-data"
71 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie -fdirect-access-external-data %s -o - | FileCheck --check-prefix=PIE-DIRECT %s
72 // PIE-DIRECT: @baz = dso_local global i32 42
73 // PIE-DIRECT-NEXT: @import_var = external dso_local global i32
74 // PIE-DIRECT-NEXT: @weak_bar = extern_weak global i32
75 // PIE-DIRECT-NEXT: @bar = external dso_local global i32
76 // PIE-DIRECT-NEXT: @local_thread_var = dso_local thread_local global i32 42
77 // PIE-DIRECT-NEXT: @thread_var = external thread_local global i32
78 // PIE-DIRECT-DAG: declare void @foo()
79 // PIE-DIRECT-DAG: define dso_local ptr @zed()
80 // PIE-DIRECT-DAG: declare void @import_func()
82 // PIE-DIRECT: ![[#]] = !{i32 7, !"direct-access-external-data", i32 1}
84 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -mrelocation-model static -fno-plt %s -o - | FileCheck --check-prefix=NOPLT %s
85 // NOPLT: @baz = dso_local global i32 42
86 // NOPLT-NEXT: @import_var = external dso_local global i32
87 // NOPLT-NEXT: @weak_bar = extern_weak dso_local global i32
88 // NOPLT-NEXT: @bar = external dso_local global i32
89 // NOPLT-NEXT: @local_thread_var = dso_local thread_local global i32 42
90 // NOPLT-NEXT: @thread_var = external thread_local global i32
91 // NOPLT-DAG: declare void @foo()
92 // NOPLT-DAG: define dso_local ptr @zed()
93 // NOPLT-DAG: declare void @import_func()
95 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -fno-plt -pic-level 1 -pic-is-pie -fdirect-access-external-data %s -o - | FileCheck --check-prefix=PIE-DIRECT-NOPLT %s
96 // PIE-DIRECT-NOPLT: @baz = dso_local global i32 42
97 // PIE-DIRECT-NOPLT-NEXT: @import_var = external dso_local global i32
98 // PIE-DIRECT-NOPLT-NEXT: @weak_bar = extern_weak global i32
99 // PIE-DIRECT-NOPLT-NEXT: @bar = external dso_local global i32
100 // PIE-DIRECT-NOPLT-NEXT: @local_thread_var = dso_local thread_local global i32 42
101 // PIE-DIRECT-NOPLT-NEXT: @thread_var = external thread_local global i32
102 // PIE-DIRECT-NOPLT-DAG: declare void @foo()
103 // PIE-DIRECT-NOPLT-DAG: define dso_local ptr @zed()
104 // PIE-DIRECT-NOPLT-DAG: declare void @import_func()
106 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 1 -pic-is-pie -fno-plt %s -o - | FileCheck --check-prefix=PIE-NO-PLT %s
107 // RUN: %clang_cc1 -triple powerpc64le -emit-llvm -mrelocation-model static %s -o - | FileCheck --check-prefix=PIE-NO-PLT %s
108 // PIE-NO-PLT: @baz = dso_local global i32 42
109 // PIE-NO-PLT-NEXT: @import_var = external global i32
110 // PIE-NO-PLT-NEXT: @weak_bar = extern_weak global i32
111 // PIE-NO-PLT-NEXT: @bar = external global i32
112 // PIE-NO-PLT-NEXT: @local_thread_var = dso_local thread_local global i32 42
113 // PIE-NO-PLT-NEXT: @thread_var = external thread_local global i32
114 // PIE-NO-PLT-DAG: declare void @import_func()
115 // PIE-NO-PLT-DAG: define dso_local ptr @zed()
116 // PIE-NO-PLT-DAG: declare void @foo()
118 /// -fdirect-access-external-data is currently ignored for -fPIC.
119 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 2 %s -o - | FileCheck --check-prefix=SHARED %s
120 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -pic-level 2 -fdirect-access-external-data %s -o - | FileCheck --check-prefix=SHARED %s
121 // SHARED-DAG: @bar = external global i32
122 // SHARED-DAG: @weak_bar = extern_weak global i32
123 // SHARED-DAG: declare void @foo()
124 // SHARED-DAG: @baz ={{.*}} global i32 42
125 // SHARED-DAG: define{{.*}} ptr @zed()
126 // SHARED-DAG: @thread_var = external thread_local global i32
127 // SHARED-DAG: @local_thread_var ={{.*}} thread_local global i32 42
129 int baz = 42;
130 __attribute__((dllimport)) extern int import_var;
131 __attribute__((weak)) extern int weak_bar;
132 extern int bar;
133 __attribute__((dllimport)) void import_func(void);
135 int *use_import(void) {
136 import_func();
137 return &import_var;
140 void foo(void);
142 int *zed(void) {
143 foo();
144 return baz ? &weak_bar : &bar;
147 __thread int local_thread_var = 42;
148 extern __thread int thread_var;
149 int *get_thread_var(int a) {
150 return a ? &thread_var : &local_thread_var;