[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / dllstorage-visibility.cpp
blobcd6e2de555c6dda48000f8506c20245bb031d497
1 /// dllimport and dllexport express non-hidden intention. Don't apply hidden visibility.
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
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
12 #define CONCAT2(x, y) x##y
13 #define CONCAT(x, y) CONCAT2(x, y)
14 #define USE(func) void CONCAT(use, __LINE__)() { func(); }
16 #define HIDDEN __attribute__((visibility("hidden")))
17 #define PROTECTED __attribute__((visibility("protected")))
18 #define DEFAULT __attribute__((visibility("default")))
20 // MSVC-DAG: declare dllimport void @"?bar@foo@@QEAAXXZ"(
21 // GNU-DAG: define linkonce_odr hidden void @_ZN3foo3barEv(
23 struct __attribute__((dllimport)) foo {
24 void bar() {}
26 void zed(foo *p) { p->bar(); }
28 // MSVC-DAG: define dso_local dllexport void @"?exported@@YAXXZ"(
29 // GNU-DAG: define dso_local dllexport void @_Z8exportedv(
30 __attribute__((dllexport)) void exported() {}
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)
37 __attribute__((dllexport)) DEFAULT void exported_default() {}
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
45 #if defined(ERR1)
46 // expected-error@+1 {{non-default visibility cannot be applied to 'dllimport' declaration}}
47 __attribute__((dllimport)) HIDDEN void imported_hidden();
49 // expected-error@+1 {{hidden visibility cannot be applied to 'dllexport' declaration}}
50 __attribute__((dllexport)) HIDDEN void exported_hidden() { imported_hidden(); }
52 #elif defined(ERR2)
53 // expected-error@+1 {{non-default visibility cannot be applied to 'dllimport' declaration}}
54 __attribute__((dllimport)) PROTECTED void imported_protected();
56 void foo() { imported_protected(); }
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() {}
63 #endif