Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm %s -o - -DDEFINE_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID |
| 2 | // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-linux -fms-extensions | FileCheck %s |
| 3 | // RUN: %clang_cc1 -emit-llvm %s -o - -DDEFINE_GUID -DWRONG_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-WRONG-GUID |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 4 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 5 | #ifdef DEFINE_GUID |
| 6 | struct _GUID { |
| 7 | #ifdef WRONG_GUID |
| 8 | unsigned int SomethingWentWrong; |
| 9 | #else |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 10 | unsigned long Data1; |
| 11 | unsigned short Data2; |
| 12 | unsigned short Data3; |
| 13 | unsigned char Data4[8]; |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 14 | #endif |
| 15 | }; |
| 16 | #endif |
| 17 | typedef struct _GUID GUID; |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 18 | |
David Majnemer | c8fe011 | 2013-08-09 08:35:59 +0000 | [diff] [blame] | 19 | struct __declspec(uuid("12345678-1234-1234-1234-1234567890aB")) S1 { } s1; |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 20 | struct __declspec(uuid("87654321-4321-4321-4321-ba0987654321")) S2 { }; |
David Majnemer | bb0ed29 | 2013-08-09 08:56:20 +0000 | [diff] [blame] | 21 | struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly; |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 22 | struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly; |
David Majnemer | bb0ed29 | 2013-08-09 08:56:20 +0000 | [diff] [blame] | 23 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 24 | #ifdef DEFINE_GUID |
David Majnemer | bb0ed29 | 2013-08-09 08:56:20 +0000 | [diff] [blame] | 25 | // Make sure we can properly generate code when the UUID has curly braces on it. |
| 26 | GUID thing = __uuidof(Curly); |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 27 | // CHECK-DEFINE-GUID: @thing = global %struct._GUID zeroinitializer, align 4 |
| 28 | // CHECK-DEFINE-WRONG-GUID: @thing = global %struct._GUID zeroinitializer, align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 29 | |
| 30 | // This gets initialized in a static initializer. |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 31 | // CHECK-DEFINE-GUID: @g = global %struct._GUID zeroinitializer, align 4 |
| 32 | // CHECK-DEFINE-WRONG-GUID: @g = global %struct._GUID zeroinitializer, align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 33 | GUID g = __uuidof(S1); |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 34 | #endif |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 35 | |
| 36 | // First global use of __uuidof(S1) forces the creation of the global. |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 37 | // CHECK: @_GUID_12345678_1234_1234_1234_1234567890ab = linkonce_odr constant { i32, i16, i16, [8 x i8] } { i32 305419896, i16 4660, i16 4660, [8 x i8] c"\124\124Vx\90\AB" }, comdat |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 38 | // CHECK: @gr = constant %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to %struct._GUID*), align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 39 | const GUID& gr = __uuidof(S1); |
| 40 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 41 | // CHECK: @gp = global %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to %struct._GUID*), align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 42 | const GUID* gp = &__uuidof(S1); |
| 43 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 44 | // CHECK: @cp = global %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ac to %struct._GUID*), align 4 |
David Majnemer | bb0ed29 | 2013-08-09 08:56:20 +0000 | [diff] [blame] | 45 | const GUID* cp = &__uuidof(Curly); |
| 46 | |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 47 | // Special case: _uuidof(0) |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 48 | // CHECK: @zeroiid = constant %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_00000000_0000_0000_0000_000000000000 to %struct._GUID*), align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 49 | const GUID& zeroiid = __uuidof(0); |
| 50 | |
| 51 | // __uuidof(S2) hasn't been used globally yet, so it's emitted when it's used |
| 52 | // in a function and is emitted at the end of the globals section. |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 53 | // CHECK: @_GUID_87654321_4321_4321_4321_ba0987654321 = linkonce_odr constant { i32, i16, i16, [8 x i8] } { i32 -2023406815, i16 17185, i16 17185, [8 x i8] c"C!\BA\09\87eC!" }, comdat |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 54 | |
| 55 | // The static initializer for thing. |
| 56 | // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct._GUID* @thing to i8*), i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ac to i8*), i32 16, i32 4, i1 false) |
| 57 | // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct._GUID* @thing to i8*), i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ac to i8*), i32 4, i32 4, i1 false) |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 58 | |
| 59 | // The static initializer for g. |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 60 | // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct._GUID* @g to i8*), i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 16, i32 4, i1 false) |
| 61 | // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct._GUID* @g to i8*), i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 4, i32 4, i1 false) |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 62 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 63 | #ifdef DEFINE_GUID |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 64 | void fun() { |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 65 | // CHECK-DEFINE-GUID: %s1_1 = alloca %struct._GUID, align 4 |
| 66 | // CHECK-DEFINE-WRONG-GUID: %s1_1 = alloca %struct._GUID, align 4 |
| 67 | // CHECK-DEFINE-GUID: %s1_2 = alloca %struct._GUID, align 4 |
| 68 | // CHECK-DEFINE-WRONG-GUID: %s1_2 = alloca %struct._GUID, align 4 |
| 69 | // CHECK-DEFINE-GUID: %s1_3 = alloca %struct._GUID, align 4 |
| 70 | // CHECK-DEFINE-WRONG-GUID: %s1_3 = alloca %struct._GUID, align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 71 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 72 | // CHECK-DEFINE-GUID: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8* |
| 73 | // CHECK-DEFINE-WRONG-GUID: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8* |
| 74 | // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U1]], i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 16, i32 4, i1 false) |
| 75 | // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U1]], i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 4, i32 4, i1 false) |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 76 | GUID s1_1 = __uuidof(S1); |
| 77 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 78 | // CHECK-DEFINE-GUID: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8* |
| 79 | // CHECK-DEFINE-WRONG-GUID: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8* |
| 80 | // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U2]], i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 16, i32 4, i1 false) |
| 81 | // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U2]], i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 4, i32 4, i1 false) |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 82 | GUID s1_2 = __uuidof(S1); |
| 83 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 84 | // CHECK-DEFINE-GUID: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8* |
| 85 | // CHECK-DEFINE-WRONG-GUID: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8* |
| 86 | // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U3]], i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 16, i32 4, i1 false) |
| 87 | // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U3]], i8* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to i8*), i32 4, i32 4, i1 false) |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 88 | GUID s1_3 = __uuidof(s1); |
| 89 | } |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 90 | #endif |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 91 | |
| 92 | void gun() { |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 93 | #ifdef DEFINE_GUID |
| 94 | // CHECK-DEFINE-GUID: %s2_1 = alloca %struct._GUID, align 4 |
| 95 | // CHECK-DEFINE-WRONG-GUID: %s2_1 = alloca %struct._GUID, align 4 |
| 96 | // CHECK-DEFINE-GUID: %s2_2 = alloca %struct._GUID, align 4 |
| 97 | // CHECK-DEFINE-WRONG-GUID: %s2_2 = alloca %struct._GUID, align 4 |
| 98 | GUID s2_1 = __uuidof(S2); |
| 99 | GUID s2_2 = __uuidof(S2); |
| 100 | #endif |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 101 | // CHECK: %r = alloca %struct._GUID*, align 4 |
| 102 | // CHECK: %p = alloca %struct._GUID*, align 4 |
| 103 | // CHECK: %zeroiid = alloca %struct._GUID*, align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 104 | |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 105 | // CHECK: store %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_87654321_4321_4321_4321_ba0987654321 to %struct._GUID*), %struct._GUID** %r, align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 106 | const GUID& r = __uuidof(S2); |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 107 | // CHECK: store %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_87654321_4321_4321_4321_ba0987654321 to %struct._GUID*), %struct._GUID** %p, align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 108 | const GUID* p = &__uuidof(S2); |
| 109 | |
| 110 | // Special case _uuidof(0), local scope version. |
David Majnemer | 8effeda | 2013-08-15 19:59:14 +0000 | [diff] [blame] | 111 | // CHECK: store %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_00000000_0000_0000_0000_000000000000 to %struct._GUID*), %struct._GUID** %zeroiid, align 4 |
Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 112 | const GUID& zeroiid = __uuidof(0); |
| 113 | } |