Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -fms-extensions | FileCheck %s |
| 2 | |
| 3 | typedef struct _GUID |
| 4 | { |
| 5 | unsigned long Data1; |
| 6 | unsigned short Data2; |
| 7 | unsigned short Data3; |
| 8 | unsigned char Data4[8]; |
| 9 | } GUID; |
| 10 | |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 11 | struct __declspec(uuid("12345678-1234-1234-1234-1234567890aB")) S1 { } s1; |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 12 | struct __declspec(uuid("87654321-4321-4321-4321-ba0987654321")) S2 { }; |
David Majnemer | 8908534 | 2013-08-09 08:56:20 +0000 | [diff] [blame^] | 13 | struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly; |
| 14 | |
| 15 | // Make sure we can properly generate code when the UUID has curly braces on it. |
| 16 | GUID thing = __uuidof(Curly); |
| 17 | // CHECK: @thing = global %struct._GUID zeroinitializer, align 4 |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 18 | |
| 19 | // This gets initialized in a static initializer. |
| 20 | // CHECK: @g = global %struct._GUID zeroinitializer, align 4 |
| 21 | GUID g = __uuidof(S1); |
| 22 | |
| 23 | // First global use of __uuidof(S1) forces the creation of the global. |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 24 | // CHECK: @_GUID_12345678_1234_1234_1234_1234567890ab = unnamed_addr constant %struct._GUID { i32 305419896, i16 4660, i16 4660, [8 x i8] c"\124\124Vx\90\AB" } |
| 25 | // CHECK: @gr = constant %struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ab, align 4 |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 26 | const GUID& gr = __uuidof(S1); |
| 27 | |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 28 | // CHECK: @gp = global %struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ab, align 4 |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 29 | const GUID* gp = &__uuidof(S1); |
| 30 | |
David Majnemer | 8908534 | 2013-08-09 08:56:20 +0000 | [diff] [blame^] | 31 | // CHECK: @cp = global %struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ac, align 4 |
| 32 | const GUID* cp = &__uuidof(Curly); |
| 33 | |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 34 | // Special case: _uuidof(0) |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 35 | // CHECK: @zeroiid = constant %struct._GUID* @_GUID_00000000_0000_0000_0000_000000000000, align 4 |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 36 | const GUID& zeroiid = __uuidof(0); |
| 37 | |
| 38 | // __uuidof(S2) hasn't been used globally yet, so it's emitted when it's used |
| 39 | // in a function and is emitted at the end of the globals section. |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 40 | // CHECK: @_GUID_87654321_4321_4321_4321_ba0987654321 = unnamed_addr constant %struct._GUID { i32 -2023406815, i16 17185, i16 17185, [8 x i8] c"C!\BA\09\87eC!" } |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 41 | |
| 42 | // The static initializer for g. |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 43 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct._GUID* @g to i8*), i8* bitcast (%struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 16, i32 4, i1 false) |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 44 | |
| 45 | void fun() { |
| 46 | // CHECK: %s1_1 = alloca %struct._GUID, align 4 |
| 47 | // CHECK: %s1_2 = alloca %struct._GUID, align 4 |
| 48 | // CHECK: %s1_3 = alloca %struct._GUID, align 4 |
| 49 | |
NAKAMURA Takumi | 5bbb4fa | 2012-10-11 11:20:31 +0000 | [diff] [blame] | 50 | // CHECK: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8* |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 51 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U1]], i8* bitcast (%struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 16, i32 4, i1 false) |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 52 | GUID s1_1 = __uuidof(S1); |
| 53 | |
NAKAMURA Takumi | 5bbb4fa | 2012-10-11 11:20:31 +0000 | [diff] [blame] | 54 | // CHECK: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8* |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 55 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U2]], i8* bitcast (%struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 16, i32 4, i1 false) |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 56 | GUID s1_2 = __uuidof(S1); |
| 57 | |
NAKAMURA Takumi | 5bbb4fa | 2012-10-11 11:20:31 +0000 | [diff] [blame] | 58 | // CHECK: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8* |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 59 | // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U3]], i8* bitcast (%struct._GUID* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 16, i32 4, i1 false) |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 60 | GUID s1_3 = __uuidof(s1); |
| 61 | } |
| 62 | |
| 63 | void gun() { |
| 64 | // CHECK: %s2_1 = alloca %struct._GUID, align 4 |
| 65 | // CHECK: %s2_2 = alloca %struct._GUID, align 4 |
| 66 | // CHECK: %r = alloca %struct._GUID*, align 4 |
| 67 | // CHECK: %p = alloca %struct._GUID*, align 4 |
| 68 | // CHECK: %zeroiid = alloca %struct._GUID*, align 4 |
| 69 | GUID s2_1 = __uuidof(S2); |
| 70 | GUID s2_2 = __uuidof(S2); |
| 71 | |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 72 | // CHECK: store %struct._GUID* @_GUID_87654321_4321_4321_4321_ba0987654321, %struct._GUID** %r, align 4 |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 73 | const GUID& r = __uuidof(S2); |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 74 | // CHECK: store %struct._GUID* @_GUID_87654321_4321_4321_4321_ba0987654321, %struct._GUID** %p, align 4 |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 75 | const GUID* p = &__uuidof(S2); |
| 76 | |
| 77 | // Special case _uuidof(0), local scope version. |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 78 | // CHECK: store %struct._GUID* @_GUID_00000000_0000_0000_0000_000000000000, %struct._GUID** %zeroiid, align 4 |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 79 | const GUID& zeroiid = __uuidof(0); |
| 80 | } |