Nico Rieck | 6047866 | 2014-02-22 19:47:30 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple i686-win32 -fsyntax-only -verify -std=c99 %s |
| 2 | // RUN: %clang_cc1 -triple x86_64-win32 -fsyntax-only -verify -std=c11 %s |
| 3 | // RUN: %clang_cc1 -triple i686-mingw32 -fsyntax-only -verify -std=c11 %s |
| 4 | // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -verify -std=c99 %s |
| 5 | |
| 6 | // Invalid usage. |
| 7 | __declspec(dllimport) typedef int typedef1; // expected-warning{{'dllimport' attribute only applies to variables and functions}} |
| 8 | typedef __declspec(dllimport) int typedef2; // expected-warning{{'dllimport' attribute only applies to variables and functions}} |
| 9 | typedef int __declspec(dllimport) typedef3; // expected-warning{{'dllimport' attribute only applies to variables and functions}} |
| 10 | typedef __declspec(dllimport) void (*FunTy)(); // expected-warning{{'dllimport' attribute only applies to variables and functions}} |
| 11 | enum __declspec(dllimport) Enum { EnumVal }; // expected-warning{{'dllimport' attribute only applies to variables and functions}} |
| 12 | struct __declspec(dllimport) Record {}; // expected-warning{{'dllimport' attribute only applies to variables and functions}} |
| 13 | |
| 14 | |
| 15 | |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | // Globals |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
| 20 | // Import declaration. |
| 21 | __declspec(dllimport) extern int ExternGlobalDecl; |
| 22 | |
Nico Rieck | 8e9791f | 2014-02-26 21:27:13 +0000 | [diff] [blame^] | 23 | // dllimport implies a declaration. |
| 24 | __declspec(dllimport) int GlobalDecl; |
Nico Rieck | 6047866 | 2014-02-22 19:47:30 +0000 | [diff] [blame] | 25 | |
| 26 | // Not allowed on definitions. |
Nico Rieck | 8e9791f | 2014-02-26 21:27:13 +0000 | [diff] [blame^] | 27 | __declspec(dllimport) extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}} |
| 28 | __declspec(dllimport) int GlobalInit1 = 1; // expected-error{{definition of dllimport data}} |
| 29 | int __declspec(dllimport) GlobalInit2 = 1; // expected-error{{definition of dllimport data}} |
Nico Rieck | 6047866 | 2014-02-22 19:47:30 +0000 | [diff] [blame] | 30 | |
| 31 | // Declare, then reject definition. |
| 32 | __declspec(dllimport) extern int ExternGlobalDeclInit; |
Nico Rieck | 8e9791f | 2014-02-26 21:27:13 +0000 | [diff] [blame^] | 33 | int ExternGlobalDeclInit = 1; // expected-error{{definition of dllimport data}} |
Nico Rieck | 6047866 | 2014-02-22 19:47:30 +0000 | [diff] [blame] | 34 | |
| 35 | // Redeclarations |
| 36 | __declspec(dllimport) extern int GlobalRedecl1; |
| 37 | __declspec(dllimport) extern int GlobalRedecl1; |
| 38 | |
| 39 | // Import in local scope. |
| 40 | void functionScope() { |
Nico Rieck | 8e9791f | 2014-02-26 21:27:13 +0000 | [diff] [blame^] | 41 | __declspec(dllimport) int LocalVarDecl; |
| 42 | __declspec(dllimport) int LocalVarDef = 1; // expected-error{{definition of dllimport data}} |
Nico Rieck | 6047866 | 2014-02-22 19:47:30 +0000 | [diff] [blame] | 43 | __declspec(dllimport) extern int ExternLocalVarDecl; |
Nico Rieck | 8e9791f | 2014-02-26 21:27:13 +0000 | [diff] [blame^] | 44 | __declspec(dllimport) extern int ExternLocalVarDef = 1; // expected-error{{definition of dllimport data}} |
Nico Rieck | 6047866 | 2014-02-22 19:47:30 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | |
| 48 | |
| 49 | //===----------------------------------------------------------------------===// |
| 50 | // Functions |
| 51 | //===----------------------------------------------------------------------===// |
| 52 | |
| 53 | // Import function declaration. Check different placements. |
| 54 | __attribute__((dllimport)) void decl1A(); // Sanity check with __attribute__ |
| 55 | __declspec(dllimport) void decl1B(); |
| 56 | |
| 57 | void __attribute__((dllimport)) decl2A(); |
| 58 | void __declspec(dllimport) decl2B(); |
| 59 | |
| 60 | // Not allowed on function definitions. |
| 61 | __declspec(dllimport) void def() {} // expected-error{{'dllimport' attribute can be applied only to symbol declaration}} |
| 62 | |
| 63 | // Import inline function. |
| 64 | __declspec(dllimport) inline void inlineFunc1() {} // expected-warning{{'dllimport' attribute ignored}} |
| 65 | inline void __attribute__((dllimport)) inlineFunc2() {} // expected-warning{{'dllimport' attribute ignored}} |
| 66 | |
| 67 | // Redeclarations |
| 68 | __declspec(dllimport) void redecl1(); |
| 69 | __declspec(dllimport) void redecl1(); |
| 70 | |
| 71 | __declspec(dllimport) void redecl3(); |
| 72 | void redecl3() {} // expected-warning{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}} |