| 1 |
/// dllimport and dllexport express non-hidden intention. Don't apply hidden visibility. |
| 2 |
|
| 3 |
// RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-msvc -fdeclspec -fvisibility-inlines-hidden -o - %s | FileCheck %s --check-prefix=MSVC |
| 4 |
// RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-gnu -fdeclspec -fvisibility-inlines-hidden -o - %s | FileCheck %s --check-prefix=GNU |
| 5 |
// RUN: %clang_cc1 -emit-llvm -triple x86_64-windows-gnu -fdeclspec -fvisibility=hidden -o - %s | FileCheck %s --check-prefix=GNU |
| 6 |
|
| 7 |
// RUN: %clang_cc1 -emit-llvm-only -verify -triple x86_64-windows-gnu -fdeclspec -DERR1 -o - %s |
| 8 |
// RUN: %clang_cc1 -emit-llvm-only -verify -triple x86_64-windows-gnu -fdeclspec -fvisibility=hidden -DERR1 -o - %s |
| 9 |
// RUN: %clang_cc1 -emit-llvm-only -verify -triple x86_64-windows-gnu -fdeclspec -DERR2 -o - %s |
| 10 |
// RUN: %clang_cc1 -emit-llvm-only -verify -triple x86_64-windows-gnu -fdeclspec -DERR3 -o - %s |
| 11 |
|
| 12 |
#define CONCAT2(x, y) x##y |
| 13 |
#define CONCAT(x, y) CONCAT2(x, y) |
| 14 |
#define USE(func) void CONCAT(use, __LINE__)() { func(); } |
| 15 |
|
| 16 |
#define HIDDEN __attribute__((visibility("hidden"))) |
| 17 |
#define PROTECTED __attribute__((visibility("protected"))) |
| 18 |
#define DEFAULT __attribute__((visibility("default"))) |
| 19 |
|
| 20 |
// MSVC-DAG: declare dllimport void @"?bar@foo@@QEAAXXZ"( |
| 21 |
// GNU-DAG: define linkonce_odr hidden void @_ZN3foo3barEv( |
| 22 |
|
| 23 |
struct __attribute__((dllimport)) foo { |
| 24 |
void bar() {} |
| 25 |
}; |
| 26 |
void zed(foo *p) { p->bar(); } |
| 27 |
|
| 28 |
// MSVC-DAG: define dso_local dllexport void @"?exported@@YAXXZ"( |
| 29 |
// GNU-DAG: define dso_local dllexport void @_Z8exportedv( |
| 30 |
__attribute__((dllexport)) void exported() {} |
| 31 |
|
| 32 |
// MSVC-DAG: define weak_odr dso_local dllexport void @"?exported_inline@@YAXXZ"( |
| 33 |
// GNU-DAG: define weak_odr dso_local dllexport void @_Z15exported_inlinev( |
| 34 |
__declspec(dllexport) inline void exported_inline() {} |
| 35 |
USE(exported_inline) |
| 36 |
|
| 37 |
__attribute__((dllexport)) DEFAULT void exported_default() {} |
| 38 |
|
| 39 |
// MSVC-DAG: define protected dllexport void @"?exported_protected@@YAXXZ"( |
| 40 |
// GNU-DAG: define protected dllexport void @_Z18exported_protectedv( |
| 41 |
#pragma GCC visibility push(protected) |
| 42 |
__attribute__((dllexport)) void exported_protected() {} |
| 43 |
#pragma GCC visibility pop |
| 44 |
|
| 45 |
#if defined(ERR1) |
| 46 |
// expected-error@+1 {{non-default visibility cannot be applied to 'dllimport' declaration}} |
| 47 |
__attribute__((dllimport)) HIDDEN void imported_hidden(); |
| 48 |
|
| 49 |
// expected-error@+1 {{hidden visibility cannot be applied to 'dllexport' declaration}} |
| 50 |
__attribute__((dllexport)) HIDDEN void exported_hidden() { imported_hidden(); } |
| 51 |
|
| 52 |
#elif defined(ERR2) |
| 53 |
// expected-error@+1 {{non-default visibility cannot be applied to 'dllimport' declaration}} |
| 54 |
__attribute__((dllimport)) PROTECTED void imported_protected(); |
| 55 |
|
| 56 |
void foo() { imported_protected(); } |
| 57 |
|
| 58 |
#elif defined(ERR3) |
| 59 |
struct HIDDEN C2 { |
| 60 |
// expected-error@+1 {{hidden visibility cannot be applied to 'dllexport' declaration}} |
| 61 |
__attribute__((dllexport)) void exported_hidden() {} |
| 62 |
}; |
| 63 |
#endif |