File: pch-dllexport.cpp

package info (click to toggle)
llvm-toolchain-7 1%3A7.0.1-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 733,456 kB
  • sloc: cpp: 3,776,651; ansic: 633,271; asm: 350,301; python: 142,716; objc: 107,612; sh: 22,626; lisp: 11,056; perl: 7,999; pascal: 6,742; ml: 5,537; awk: 3,536; makefile: 2,557; cs: 2,027; xml: 841; ruby: 156
file content (84 lines) | stat: -rw-r--r-- 3,624 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Build PCH without object file, then use it.
// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-pch -o %t %s
// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCH %s

// Build PCH with object file, then use it.
// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-pch -building-pch-with-obj -o %t %s
// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -building-pch-with-obj -o - %s | FileCheck -check-prefix=OBJ %s
// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJ %s

// Check for vars separately to avoid having to reorder the check statements.
// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-obj -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJVARS %s

#ifndef IN_HEADER
#define IN_HEADER

inline void __declspec(dllexport) foo() {}
// OBJ: define weak_odr dso_local dllexport void @"?foo@@YAXXZ"
// PCH: define weak_odr dso_local dllexport void @"?foo@@YAXXZ"
// PCHWITHOBJ-NOT: define {{.*}}foo


// This function is referenced, so gets emitted as usual.
inline void __declspec(dllexport) baz() {}
// OBJ: define weak_odr dso_local dllexport void @"?baz@@YAXXZ"
// PCH: define weak_odr dso_local dllexport void @"?baz@@YAXXZ"
// PCHWITHOBJ: define weak_odr dso_local dllexport void @"?baz@@YAXXZ"


struct __declspec(dllexport) S {
  void bar() {}
// OBJ: define weak_odr dso_local dllexport x86_thiscallcc void @"?bar@S@@QAEXXZ"
// PCH: define weak_odr dso_local dllexport x86_thiscallcc void @"?bar@S@@QAEXXZ"
// PCHWITHOBJ-NOT: define {{.*}}bar
};

// This isn't dllexported, attribute((used)) or referenced, so not emitted.
inline void quux() {}
// OBJ-NOT: define {{.*}}quux
// PCH-NOT: define {{.*}}quux
// PCHWITHOBJ-NOT: define {{.*}}quux

// Referenced non-dllexport function.
inline void referencedNonExported() {}
// OBJ: define {{.*}}referencedNonExported
// PCH: define {{.*}}referencedNonExported
// PCHWITHOBJ: define {{.*}}referencedNonExported

template <typename T> void __declspec(dllexport) implicitInstantiation(T) {}

template <typename T> inline void __declspec(dllexport) explicitSpecialization(T) {}

template <typename T> void __declspec(dllexport) explicitInstantiationDef(T) {}

template <typename T> void __declspec(dllexport) explicitInstantiationDefAfterDecl(T) {}
extern template void explicitInstantiationDefAfterDecl<int>(int);

template <typename T> T __declspec(dllexport) variableTemplate;
extern template int variableTemplate<int>;

#else

void use() {
  baz();
  referencedNonExported();
}

// Templates can be tricky. None of the definitions below come from the PCH.

void useTemplate() { implicitInstantiation(42); }
// PCHWITHOBJ: define weak_odr dso_local dllexport void @"??$implicitInstantiation@H@@YAXH@Z"

template<> inline void __declspec(dllexport) explicitSpecialization<int>(int) {}
// PCHWITHOBJ: define weak_odr dso_local  dllexport void @"??$explicitSpecialization@H@@YAXH@Z"

template void __declspec(dllexport) explicitInstantiationDef<int>(int);
// PCHWITHOBJ: define weak_odr dso_local dllexport void @"??$explicitInstantiationDef@H@@YAXH@Z"

template void __declspec(dllexport) explicitInstantiationDefAfterDecl<int>(int);
// PCHWITHOBJ: define weak_odr dso_local dllexport void @"??$explicitInstantiationDefAfterDecl@H@@YAXH@Z"(i32)

template int __declspec(dllexport) variableTemplate<int>;
// PCHWITHOBJVARS: @"??$variableTemplate@H@@3HA" = weak_odr dso_local dllexport global

#endif