| 1 |
// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=MS %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=MS %s |
| 3 |
// RUN: %clang_cc1 -triple i686-windows-gnu -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GNU %s |
| 4 |
// RUN: %clang_cc1 -triple x86_64-windows-gnu -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GNU %s |
| 5 |
// RUN: %clang_cc1 -triple i686-pc-cygwin -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GNU %s |
| 6 |
// RUN: %clang_cc1 -triple x86_64-pc-cygwin -fms-extensions -emit-llvm -std=c11 -O0 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GNU %s |
| 7 |
// RUN: %clang_cc1 -triple i686-windows-msvc -fms-extensions -emit-llvm -std=c11 -O1 -fno-inline -o - %s | FileCheck --check-prefix=O1 --check-prefix=MO1 %s |
| 8 |
// RUN: %clang_cc1 -triple i686-windows-gnu -fms-extensions -emit-llvm -std=c11 -O1 -fno-inline -o - %s | FileCheck --check-prefix=O1 --check-prefix=GO1 %s |
| 9 |
// RUN: %clang_cc1 -triple i686-pc-cygwin -fms-extensions -emit-llvm -std=c11 -O1 -fno-inline -o - %s | FileCheck --check-prefix=O1 --check-prefix=GO1 %s |
| 10 |
|
| 11 |
#define JOIN2(x, y) x##y |
| 12 |
#define JOIN(x, y) JOIN2(x, y) |
| 13 |
#define USEVAR(var) int JOIN(use, __LINE__)(void) { return var; } |
| 14 |
#define USE(func) void JOIN(use, __LINE__)(void) { func(); } |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
//===----------------------------------------------------------------------===// |
| 19 |
// Globals |
| 20 |
//===----------------------------------------------------------------------===// |
| 21 |
|
| 22 |
// Import declaration. |
| 23 |
// CHECK: @ExternGlobalDecl = external dllimport global i32 |
| 24 |
__declspec(dllimport) extern int ExternGlobalDecl; |
| 25 |
USEVAR(ExternGlobalDecl) |
| 26 |
|
| 27 |
// dllimport implies a declaration. |
| 28 |
// CHECK: @GlobalDecl = external dllimport global i32 |
| 29 |
__declspec(dllimport) int GlobalDecl; |
| 30 |
USEVAR(GlobalDecl) |
| 31 |
|
| 32 |
// Redeclarations |
| 33 |
// CHECK: @GlobalRedecl1 = external dllimport global i32 |
| 34 |
__declspec(dllimport) extern int GlobalRedecl1; |
| 35 |
__declspec(dllimport) extern int GlobalRedecl1; |
| 36 |
USEVAR(GlobalRedecl1) |
| 37 |
|
| 38 |
// CHECK: @GlobalRedecl2 = external dllimport global i32 |
| 39 |
__declspec(dllimport) int GlobalRedecl2; |
| 40 |
__declspec(dllimport) int GlobalRedecl2; |
| 41 |
USEVAR(GlobalRedecl2) |
| 42 |
|
| 43 |
// NB: MSVC issues a warning and makes GlobalRedecl3 dllexport. We follow GCC |
| 44 |
// and drop the dllimport with a warning. |
| 45 |
// MS: @GlobalRedecl3 = external dso_local global i32 |
| 46 |
// GNU: @GlobalRedecl3 = external global i32 |
| 47 |
__declspec(dllimport) extern int GlobalRedecl3; |
| 48 |
extern int GlobalRedecl3; // dllimport ignored |
| 49 |
USEVAR(GlobalRedecl3) |
| 50 |
|
| 51 |
// Make sure this works even if the decl has been used before it's defined (PR20792). |
| 52 |
// MS: @GlobalRedecl4 = dso_local dllexport global i32 |
| 53 |
// GNU: @GlobalRedecl4 = dso_local global i32 |
| 54 |
__declspec(dllimport) extern int GlobalRedecl4; |
| 55 |
USEVAR(GlobalRedecl4) |
| 56 |
int GlobalRedecl4; // dllimport ignored |
| 57 |
|
| 58 |
// FIXME: dllimport is dropped in the AST; this should be reflected in codegen (PR02803). |
| 59 |
// CHECK: @GlobalRedecl5 = external dllimport global i32 |
| 60 |
__declspec(dllimport) extern int GlobalRedecl5; |
| 61 |
USEVAR(GlobalRedecl5) |
| 62 |
extern int GlobalRedecl5; // dllimport ignored |
| 63 |
|
| 64 |
// Redeclaration in local context. |
| 65 |
// CHECK: @GlobalRedecl6 = external dllimport global i32 |
| 66 |
__declspec(dllimport) int GlobalRedecl6; |
| 67 |
int functionScope(void) { |
| 68 |
extern int GlobalRedecl6; // still dllimport |
| 69 |
return GlobalRedecl6; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
//===----------------------------------------------------------------------===// |
| 75 |
// Functions |
| 76 |
//===----------------------------------------------------------------------===// |
| 77 |
|
| 78 |
// Import function declaration. |
| 79 |
// CHECK-DAG: declare dllimport void @decl() |
| 80 |
__declspec(dllimport) void decl(void); |
| 81 |
|
| 82 |
// Initialize use_decl with the address of the thunk. |
| 83 |
// CHECK-DAG: @use_decl = dso_local global ptr @decl |
| 84 |
void (*use_decl)(void) = &decl; |
| 85 |
|
| 86 |
// Import inline function. |
| 87 |
// MS-DAG: declare dllimport void @inlineFunc() |
| 88 |
// MO1-DAG: declare dllimport void @inlineFunc() |
| 89 |
// GNU-DAG: declare dso_local void @inlineFunc() |
| 90 |
// GO1-DAG: declare dso_local void @inlineFunc() |
| 91 |
__declspec(dllimport) inline void inlineFunc(void) {} |
| 92 |
USE(inlineFunc) |
| 93 |
|
| 94 |
// inline attributes |
| 95 |
// MS-DAG: declare dllimport void @noinline() |
| 96 |
// MO1-DAG: declare dllimport void @noinline() |
| 97 |
// GNU-DAG: declare dso_local void @noinline() |
| 98 |
// GO1-DAG: declare dso_local void @noinline() |
| 99 |
// CHECK-NOT: @alwaysInline() |
| 100 |
// O1-NOT: @alwaysInline() |
| 101 |
__declspec(dllimport) __attribute__((noinline)) inline void noinline(void) {} |
| 102 |
__declspec(dllimport) __attribute__((always_inline)) inline void alwaysInline(void) {} |
| 103 |
USE(noinline) |
| 104 |
USE(alwaysInline) |
| 105 |
|
| 106 |
// Redeclarations |
| 107 |
// CHECK-DAG: declare dllimport void @redecl1() |
| 108 |
__declspec(dllimport) void redecl1(void); |
| 109 |
__declspec(dllimport) void redecl1(void); |
| 110 |
USE(redecl1) |
| 111 |
|
| 112 |
// NB: MSVC issues a warning and makes redecl2/redecl3 dllexport. We follow GCC |
| 113 |
// and drop the dllimport with a warning. |
| 114 |
// CHECK-DAG: declare dso_local void @redecl2() |
| 115 |
__declspec(dllimport) void redecl2(void); |
| 116 |
void redecl2(void); |
| 117 |
USE(redecl2) |
| 118 |
|
| 119 |
// MS: define dso_local dllexport void @redecl3() |
| 120 |
// GNU: define dso_local void @redecl3() |
| 121 |
__declspec(dllimport) void redecl3(void); |
| 122 |
void redecl3(void) {} // dllimport ignored |
| 123 |
USE(redecl3) |
| 124 |
|
| 125 |
// Make sure this works even if the decl is used before it's defined (PR20792). |
| 126 |
// MS: define dso_local dllexport void @redecl4() |
| 127 |
// GNU: define dso_local void @redecl4() |
| 128 |
__declspec(dllimport) void redecl4(void); |
| 129 |
USE(redecl4) |
| 130 |
void redecl4(void) {} // dllimport ignored |
| 131 |
|
| 132 |
// FIXME: dllimport is dropped in the AST; this should be reflected in codegen (PR20803). |
| 133 |
// CHECK-DAG: declare dllimport |
| 134 |
__declspec(dllimport) void redecl5(void); |
| 135 |
USE(redecl5) |
| 136 |
void redecl5(void); // dllimport ignored |