brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · b0b5c24 Raw
105 lines · cpp
1// Build PCH without object file, then use it.2// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-pch -o %t %s3// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCH %s4 5// Build PCH with object file, then use it.6// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -fms-extensions -emit-pch -building-pch-with-obj -o %t %s7// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -disable-llvm-optzns -fms-extensions -emit-llvm -include-pch %t -building-pch-with-obj -o - %s | FileCheck -check-prefix=OBJ %s8// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -disable-llvm-optzns -fms-extensions -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJ -check-prefix=PCHWITHOBJ-O1 %s9 10// Check for vars separately to avoid having to reorder the check statements.11// RUN: %clang_cc1 -triple i686-pc-win32 -O1 -disable-llvm-optzns -fms-extensions -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJVARS %s12 13// Test the PCHWITHOBJ at -O0 where available_externally definitions are not14// provided:15// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-pch -building-pch-with-obj -o %t %s16// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJ -check-prefix=PCHWITHOBJ-O0 %s17// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-llvm -include-pch %t -o - %s | FileCheck -check-prefix=PCHWITHOBJVARS %s18 19 20#ifndef IN_HEADER21#define IN_HEADER22 23inline void __declspec(dllexport) foo() {}24// OBJ: define weak_odr dso_local dllexport void @"?foo@@YAXXZ"25// PCH: define weak_odr dso_local dllexport void @"?foo@@YAXXZ"26// PCHWITHOBJ-NOT: define {{.*}}foo27 28 29// This function is referenced, so gets emitted as usual.30inline void __declspec(dllexport) baz() {}31// OBJ: define weak_odr dso_local dllexport void @"?baz@@YAXXZ"32// PCH: define weak_odr dso_local dllexport void @"?baz@@YAXXZ"33// PCHWITHOBJ-O1: define available_externally dso_local void @"?baz@@YAXXZ"34// PCHWITHOBJ-O0-NOT: define {{.*}}"?baz@@YAXXZ"35 36 37struct __declspec(dllexport) S {38  void bar() {}39// OBJ: define weak_odr dso_local dllexport x86_thiscallcc void @"?bar@S@@QAEXXZ"40// PCH: define weak_odr dso_local dllexport x86_thiscallcc void @"?bar@S@@QAEXXZ"41// PCHWITHOBJ-NOT: define {{.*}}bar42};43 44// This isn't dllexported, attribute((used)) or referenced, so not emitted.45inline void quux() {}46// OBJ-NOT: define {{.*}}quux47// PCH-NOT: define {{.*}}quux48// PCHWITHOBJ-NOT: define {{.*}}quux49 50// Referenced non-dllexport function.51inline void referencedNonExported() {}52// OBJ: define {{.*}}referencedNonExported53// PCH: define {{.*}}referencedNonExported54// PCHWITHOBJ: define {{.*}}referencedNonExported55 56template <typename T> void __declspec(dllexport) implicitInstantiation(T) {}57 58template <typename T> inline void __declspec(dllexport) explicitSpecialization(T) {}59 60template <typename T> void __declspec(dllexport) explicitInstantiationDef(T) {}61 62template <typename T> void __declspec(dllexport) explicitInstantiationDefAfterDecl(T) {}63extern template void explicitInstantiationDefAfterDecl<int>(int);64 65template <typename T> T __declspec(dllexport) variableTemplate;66extern template int variableTemplate<int>;67 68namespace pr38934 {69template <typename T> struct S {};70extern template struct S<int>;71// The use here causes the S<int>::operator= decl to go into the PCH.72inline void use(S<int> *a, S<int> *b) { *a = *b; };73}74 75#else76 77void use() {78  baz();79  referencedNonExported();80}81 82// Templates can be tricky. None of the definitions below come from the PCH.83 84void useTemplate() { implicitInstantiation(42); }85// PCHWITHOBJ: define weak_odr dso_local dllexport void @"??$implicitInstantiation@H@@YAXH@Z"86 87template<> inline void __declspec(dllexport) explicitSpecialization<int>(int) {}88// PCHWITHOBJ: define weak_odr dso_local dllexport void @"??$explicitSpecialization@H@@YAXH@Z"89 90template void __declspec(dllexport) explicitInstantiationDef<int>(int);91// PCHWITHOBJ: define weak_odr dso_local dllexport void @"??$explicitInstantiationDef@H@@YAXH@Z"92 93template void __declspec(dllexport) explicitInstantiationDefAfterDecl<int>(int);94// PCHWITHOBJ: define weak_odr dso_local dllexport void @"??$explicitInstantiationDefAfterDecl@H@@YAXH@Z"(i32 noundef %0)95 96template int __declspec(dllexport) variableTemplate<int>;97// PCHWITHOBJVARS: @"??$variableTemplate@H@@3HA" = weak_odr dso_local dllexport global98 99// PR38934: Make sure S<int>::operator= gets emitted. While it itself isn't a100// template specialization, its parent is.101template struct __declspec(dllexport) pr38934::S<int>;102// PCHWITHOBJ: define weak_odr dso_local dllexport x86_thiscallcc noundef nonnull align 1 dereferenceable(1) ptr @"??4?$S@H@pr38934@@QAEAAU01@ABU01@@Z"103 104#endif105