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 { }; |
| 13 | |
| 14 | // This gets initialized in a static initializer. |
| 15 | // CHECK: @g = global %struct._GUID zeroinitializer, align 4 |
| 16 | GUID g = __uuidof(S1); |
| 17 | |
| 18 | // First global use of __uuidof(S1) forces the creation of the global. |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 19 | // 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" } |
| 20 | // 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] | 21 | const GUID& gr = __uuidof(S1); |
| 22 | |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 23 | // 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] | 24 | const GUID* gp = &__uuidof(S1); |
| 25 | |
| 26 | // Special case: _uuidof(0) |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 27 | // 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] | 28 | const GUID& zeroiid = __uuidof(0); |
| 29 | |
| 30 | // __uuidof(S2) hasn't been used globally yet, so it's emitted when it's used |
| 31 | // 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^] | 32 | // 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] | 33 | |
| 34 | // The static initializer for g. |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 35 | // 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] | 36 | |
| 37 | void fun() { |
| 38 | // CHECK: %s1_1 = alloca %struct._GUID, align 4 |
| 39 | // CHECK: %s1_2 = alloca %struct._GUID, align 4 |
| 40 | // CHECK: %s1_3 = alloca %struct._GUID, align 4 |
| 41 | |
NAKAMURA Takumi | 5bbb4fa | 2012-10-11 11:20:31 +0000 | [diff] [blame] | 42 | // CHECK: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8* |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 43 | // 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] | 44 | GUID s1_1 = __uuidof(S1); |
| 45 | |
NAKAMURA Takumi | 5bbb4fa | 2012-10-11 11:20:31 +0000 | [diff] [blame] | 46 | // CHECK: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8* |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 47 | // 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] | 48 | GUID s1_2 = __uuidof(S1); |
| 49 | |
NAKAMURA Takumi | 5bbb4fa | 2012-10-11 11:20:31 +0000 | [diff] [blame] | 50 | // CHECK: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8* |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 51 | // 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] | 52 | GUID s1_3 = __uuidof(s1); |
| 53 | } |
| 54 | |
| 55 | void gun() { |
| 56 | // CHECK: %s2_1 = alloca %struct._GUID, align 4 |
| 57 | // CHECK: %s2_2 = alloca %struct._GUID, align 4 |
| 58 | // CHECK: %r = alloca %struct._GUID*, align 4 |
| 59 | // CHECK: %p = alloca %struct._GUID*, align 4 |
| 60 | // CHECK: %zeroiid = alloca %struct._GUID*, align 4 |
| 61 | GUID s2_1 = __uuidof(S2); |
| 62 | GUID s2_2 = __uuidof(S2); |
| 63 | |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 64 | // 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] | 65 | const GUID& r = __uuidof(S2); |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 66 | // 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] | 67 | const GUID* p = &__uuidof(S2); |
| 68 | |
| 69 | // Special case _uuidof(0), local scope version. |
David Majnemer | cf963ce | 2013-08-09 08:35:59 +0000 | [diff] [blame^] | 70 | // 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] | 71 | const GUID& zeroiid = __uuidof(0); |
| 72 | } |