Clang Project

clang_source_code/test/CodeGenCXX/dso-local-executable.cpp
1// RUN: %clang_cc1 -triple x86_64-pc-linux -mrelocation-model static -O1 -emit-llvm %s -o - | FileCheck --check-prefix=STATIC %s
2// RUN: %clang_cc1 -triple x86_64-pc-linux -mrelocation-model static -fno-plt -O1 -emit-llvm %s -o - | FileCheck --check-prefix=NOPLT %s
3// RUN: %clang_cc1 -triple x86_64-w64-mingw32 -O1 -emit-llvm %s -o - | FileCheck --check-prefix=MINGW %s
4
5// STATIC-DAG: @_ZTV1C = linkonce_odr dso_local unnamed_addr constant
6// STATIC-DAG: @_ZTS1C = linkonce_odr dso_local constant
7// STATIC-DAG: @_ZTI1C = linkonce_odr dso_local constant
8// STATIC-DAG: @_ZZ14useStaticLocalvE3obj = linkonce_odr dso_local global
9// STATIC-DAG: @_ZGVZN5guard1gEvE1a = linkonce_odr dso_local global
10// STATIC-DAG: define dso_local void @_ZN1CC2Ev(
11// STATIC-DAG: define dso_local void @_ZN1CC1Ev(
12// STATIC-DAG: define linkonce_odr dso_local void @_ZN1C3fooEv(
13
14// NOPLT-DAG: @_ZTV1C = linkonce_odr dso_local unnamed_addr constant
15// NOPLT-DAG: @_ZTS1C = linkonce_odr dso_local constant
16// NOPLT-DAG: @_ZTI1C = linkonce_odr dso_local constant
17// NOPLT-DAG: @_ZZ14useStaticLocalvE3obj = linkonce_odr dso_local global
18// NOPLT-DAG: @_ZGVZN5guard1gEvE1a = linkonce_odr dso_local global
19// NOPLT-DAG: define dso_local void @_ZN1CC2Ev(
20// NOPLT-DAG: define dso_local void @_ZN1CC1Ev(
21// NOPLT-DAG: define linkonce_odr dso_local void @_ZN1C3fooEv(
22
23// MINGW-DAG: @_ZTV1C = linkonce_odr dso_local unnamed_addr constant
24// MINGW-DAG: @_ZTS1C = linkonce_odr dso_local constant
25// MINGW-DAG: @_ZTI1C = linkonce_odr dso_local constant
26// MINGW-DAG: @_ZZ14useStaticLocalvE3obj = linkonce_odr dso_local global
27// MINGW-DAG: @_ZGVZN5guard1gEvE1a = linkonce_odr dso_local global
28// MINGW-DAG: define dso_local void @_ZN1CC2Ev(
29// MINGW-DAG: define dso_local void @_ZN1CC1Ev(
30// MINGW-DAG: define linkonce_odr dso_local void @_ZN1C3fooEv(
31
32struct C {
33  C();
34  virtual void foo() {}
35};
36C::C() {}
37
38struct HasVTable {
39  virtual void f();
40};
41inline HasVTable &useStaticLocal() {
42  static HasVTable obj;
43  return obj;
44}
45void useit() {
46  useStaticLocal();
47}
48
49namespace guard {
50int f();
51inline int g() {
52  static int a = f();
53  return a;
54}
55int h() {
56  return g();
57}
58} // namespace guard
59
60
61// STATIC-DAG: @_ZN5test23barIiE1xE = available_externally dso_local constant i32
62// STATIC-DAG: define available_externally dso_local void @_ZN5test23barIcEC1Ev(
63// NOPLT-DAG: @_ZN5test23barIiE1xE = available_externally dso_local constant i32
64// NOPLT-DAG: define available_externally void @_ZN5test23barIcEC1Ev(
65// MINGW-DAG: @_ZN5test23barIiE1xE = available_externally constant i32
66// MINGW-DAG: define available_externally dso_local void @_ZN5test23barIcEC1Ev(
67namespace test2 {
68void foo();
69template <typename T>
70struct bar {
71  virtual void zed();
72  static const int x = 42;
73  bar() { foo(); }
74};
75extern template class bar<char>;
76bar<char> abc;
77const int *getX() {
78  return &bar<int>::x;
79}
80} // namespace test2
81