|
| 1 | +// RUN: %clang_cc1 -triple x86_64-win32 -fms-extensions -emit-llvm -o - %s | FileCheck %s --check-prefixes=MSC --implicit-check-not=to_be_ |
| 2 | +// RUN: %clang_cc1 -triple x86_64-mingw -emit-llvm -o - %s | FileCheck %s --check-prefixes=GNU --implicit-check-not=to_be_ |
| 3 | +// RUN: %clang_cc1 -triple x86_64-cygwin -emit-llvm -o - %s | FileCheck %s --check-prefixes=GNU --implicit-check-not=to_be_ |
| 4 | + |
| 5 | +// Test that __declspec(dllexport) doesn't instantiate entities marked with |
| 6 | +// the exclude_from_explicit_instantiation attribute unless marked as dllexport explicitly. |
| 7 | + |
| 8 | +#define EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__((exclude_from_explicit_instantiation)) |
| 9 | + |
| 10 | +template <class T> |
| 11 | +struct C { |
| 12 | + // This will be instantiated explicitly as an exported function because it |
| 13 | + // inherits dllexport from the class instantiation. |
| 14 | + void to_be_exported() noexcept; |
| 15 | + |
| 16 | + // This will be instantiated implicitly as an exported function because it is |
| 17 | + // marked as dllexport explicitly. |
| 18 | + EXCLUDE_FROM_EXPLICIT_INSTANTIATION __declspec(dllexport) void to_be_exported_explicitly() noexcept; |
| 19 | + |
| 20 | + // This will be instantiated implicitly as an exported function unintentionally. |
| 21 | + EXCLUDE_FROM_EXPLICIT_INSTANTIATION void not_to_be_exported() noexcept; |
| 22 | + |
| 23 | + // This won't be instantiated. |
| 24 | + EXCLUDE_FROM_EXPLICIT_INSTANTIATION void not_to_be_instantiated() noexcept; |
| 25 | +}; |
| 26 | + |
| 27 | +template <class T> void C<T>::to_be_exported() noexcept {} |
| 28 | +template <class T> void C<T>::to_be_exported_explicitly() noexcept {} |
| 29 | +template <class T> void C<T>::not_to_be_exported() noexcept {} |
| 30 | +template <class T> void C<T>::not_to_be_instantiated() noexcept {} |
| 31 | + |
| 32 | +// MSC: $"?to_be_exported@?$C@H@@QEAAXXZ" = comdat any |
| 33 | +// MSC: $"?to_be_exported_explicitly@?$C@H@@QEAAXXZ" = comdat any |
| 34 | +// MSC: $"?not_to_be_exported@?$C@H@@QEAAXXZ" = comdat any |
| 35 | +// MSC: $"?not_to_be_instantiated@?$C@H@@QEAAXXZ" = comdat any |
| 36 | +// GNU: $_ZN1CIiE14to_be_exportedEv = comdat any |
| 37 | +// GNU: $_ZN1CIiE25to_be_exported_explicitlyEv = comdat any |
| 38 | +// GNU: $_ZN1CIiE18not_to_be_exportedEv = comdat any |
| 39 | +// GNU: $_ZN1CIiE22not_to_be_instantiatedEv = comdat any |
| 40 | + |
| 41 | +// MSC: define weak_odr dso_local dllexport{{.*}} void @"?to_be_exported@?$C@H@@QEAAXXZ" |
| 42 | +// GNU: define weak_odr dso_local dllexport{{.*}} void @_ZN1CIiE14to_be_exportedEv |
| 43 | +template struct __declspec(dllexport) C<int>; |
| 44 | + |
| 45 | +void use() { |
| 46 | + C<int> c; |
| 47 | + |
| 48 | + // MSC: call void @"?to_be_exported_explicitly@?$C@H@@QEAAXXZ" |
| 49 | + // GNU: call void @_ZN1CIiE25to_be_exported_explicitlyEv |
| 50 | + c.to_be_exported_explicitly(); // implicitly instantiated here |
| 51 | + |
| 52 | + // MSC: call void @"?not_to_be_exported@?$C@H@@QEAAXXZ" |
| 53 | + // GNU: call void @_ZN1CIiE18not_to_be_exportedEv |
| 54 | + c.not_to_be_exported(); // implicitly instantiated here |
| 55 | +}; |
| 56 | + |
| 57 | +// MSC: define weak_odr dso_local dllexport{{.*}} void @"?to_be_exported_explicitly@?$C@H@@QEAAXXZ" |
| 58 | +// GNU: define weak_odr dso_local dllexport{{.*}} void @_ZN1CIiE25to_be_exported_explicitlyEv |
| 59 | + |
| 60 | +// MSC: define weak_odr dso_local dllexport void @"?not_to_be_exported@?$C@H@@QEAAXXZ" |
| 61 | +// GNU: define weak_odr dso_local dllexport void @_ZN1CIiE18not_to_be_exportedEv |
| 62 | + |
| 63 | +// MSC: define weak_odr dso_local dllexport void @"?not_to_be_instantiated@?$C@H@@QEAAXXZ" |
| 64 | +// GNU: define weak_odr dso_local dllexport void @_ZN1CIiE22not_to_be_instantiatedEv |
0 commit comments