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