blob: d57ca8380e39f9f447826d4bb9b9ff8714b3571b [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// 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 Weberc5f80462012-10-11 10:13:44 +00004
David Majnemer8effeda2013-08-15 19:59:14 +00005#ifdef DEFINE_GUID
6struct _GUID {
7#ifdef WRONG_GUID
8 unsigned int SomethingWentWrong;
9#else
Nico Weberc5f80462012-10-11 10:13:44 +000010 unsigned long Data1;
11 unsigned short Data2;
12 unsigned short Data3;
13 unsigned char Data4[8];
David Majnemer8effeda2013-08-15 19:59:14 +000014#endif
15};
16#endif
17typedef struct _GUID GUID;
Nico Weberc5f80462012-10-11 10:13:44 +000018
David Majnemerc8fe0112013-08-09 08:35:59 +000019struct __declspec(uuid("12345678-1234-1234-1234-1234567890aB")) S1 { } s1;
Nico Weberc5f80462012-10-11 10:13:44 +000020struct __declspec(uuid("87654321-4321-4321-4321-ba0987654321")) S2 { };
David Majnemerbb0ed292013-08-09 08:56:20 +000021struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly;
22
David Majnemer8effeda2013-08-15 19:59:14 +000023#ifdef DEFINE_GUID
David Majnemerbb0ed292013-08-09 08:56:20 +000024// Make sure we can properly generate code when the UUID has curly braces on it.
25GUID thing = __uuidof(Curly);
David Majnemer8effeda2013-08-15 19:59:14 +000026// CHECK-DEFINE-GUID: @thing = global %struct._GUID zeroinitializer, align 4
27// CHECK-DEFINE-WRONG-GUID: @thing = global %struct._GUID zeroinitializer, align 4
Nico Weberc5f80462012-10-11 10:13:44 +000028
29// This gets initialized in a static initializer.
David Majnemer8effeda2013-08-15 19:59:14 +000030// CHECK-DEFINE-GUID: @g = global %struct._GUID zeroinitializer, align 4
31// CHECK-DEFINE-WRONG-GUID: @g = global %struct._GUID zeroinitializer, align 4
Nico Weberc5f80462012-10-11 10:13:44 +000032GUID g = __uuidof(S1);
David Majnemer8effeda2013-08-15 19:59:14 +000033#endif
Nico Weberc5f80462012-10-11 10:13:44 +000034
35// First global use of __uuidof(S1) forces the creation of the global.
Reid Klecknerdc1ac5e2013-09-03 21:49:32 +000036// 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" }
David Majnemer8effeda2013-08-15 19:59:14 +000037// CHECK: @gr = constant %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to %struct._GUID*), align 4
Nico Weberc5f80462012-10-11 10:13:44 +000038const GUID& gr = __uuidof(S1);
39
David Majnemer8effeda2013-08-15 19:59:14 +000040// CHECK: @gp = global %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to %struct._GUID*), align 4
Nico Weberc5f80462012-10-11 10:13:44 +000041const GUID* gp = &__uuidof(S1);
42
David Majnemer8effeda2013-08-15 19:59:14 +000043// CHECK: @cp = global %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ac to %struct._GUID*), align 4
David Majnemerbb0ed292013-08-09 08:56:20 +000044const GUID* cp = &__uuidof(Curly);
45
Nico Weberc5f80462012-10-11 10:13:44 +000046// Special case: _uuidof(0)
David Majnemer8effeda2013-08-15 19:59:14 +000047// CHECK: @zeroiid = constant %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_00000000_0000_0000_0000_000000000000 to %struct._GUID*), align 4
Nico Weberc5f80462012-10-11 10:13:44 +000048const GUID& zeroiid = __uuidof(0);
49
50// __uuidof(S2) hasn't been used globally yet, so it's emitted when it's used
51// in a function and is emitted at the end of the globals section.
Reid Klecknerdc1ac5e2013-09-03 21:49:32 +000052// 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!" }
David Majnemer8effeda2013-08-15 19:59:14 +000053
54// The static initializer for thing.
55// 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)
56// 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 Weberc5f80462012-10-11 10:13:44 +000057
58// The static initializer for g.
David Majnemer8effeda2013-08-15 19:59:14 +000059// 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)
60// 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 Weberc5f80462012-10-11 10:13:44 +000061
David Majnemer8effeda2013-08-15 19:59:14 +000062#ifdef DEFINE_GUID
Nico Weberc5f80462012-10-11 10:13:44 +000063void fun() {
David Majnemer8effeda2013-08-15 19:59:14 +000064 // CHECK-DEFINE-GUID: %s1_1 = alloca %struct._GUID, align 4
65 // CHECK-DEFINE-WRONG-GUID: %s1_1 = alloca %struct._GUID, align 4
66 // CHECK-DEFINE-GUID: %s1_2 = alloca %struct._GUID, align 4
67 // CHECK-DEFINE-WRONG-GUID: %s1_2 = alloca %struct._GUID, align 4
68 // CHECK-DEFINE-GUID: %s1_3 = alloca %struct._GUID, align 4
69 // CHECK-DEFINE-WRONG-GUID: %s1_3 = alloca %struct._GUID, align 4
Nico Weberc5f80462012-10-11 10:13:44 +000070
David Majnemer8effeda2013-08-15 19:59:14 +000071 // CHECK-DEFINE-GUID: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8*
72 // CHECK-DEFINE-WRONG-GUID: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8*
73 // 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)
74 // 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 Weberc5f80462012-10-11 10:13:44 +000075 GUID s1_1 = __uuidof(S1);
76
David Majnemer8effeda2013-08-15 19:59:14 +000077 // CHECK-DEFINE-GUID: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8*
78 // CHECK-DEFINE-WRONG-GUID: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8*
79 // 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)
80 // 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 Weberc5f80462012-10-11 10:13:44 +000081 GUID s1_2 = __uuidof(S1);
82
David Majnemer8effeda2013-08-15 19:59:14 +000083 // CHECK-DEFINE-GUID: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8*
84 // CHECK-DEFINE-WRONG-GUID: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8*
85 // 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)
86 // 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 Weberc5f80462012-10-11 10:13:44 +000087 GUID s1_3 = __uuidof(s1);
88}
David Majnemer8effeda2013-08-15 19:59:14 +000089#endif
Nico Weberc5f80462012-10-11 10:13:44 +000090
91void gun() {
David Majnemer8effeda2013-08-15 19:59:14 +000092#ifdef DEFINE_GUID
93 // CHECK-DEFINE-GUID: %s2_1 = alloca %struct._GUID, align 4
94 // CHECK-DEFINE-WRONG-GUID: %s2_1 = alloca %struct._GUID, align 4
95 // CHECK-DEFINE-GUID: %s2_2 = alloca %struct._GUID, align 4
96 // CHECK-DEFINE-WRONG-GUID: %s2_2 = alloca %struct._GUID, align 4
97 GUID s2_1 = __uuidof(S2);
98 GUID s2_2 = __uuidof(S2);
99#endif
Nico Weberc5f80462012-10-11 10:13:44 +0000100 // CHECK: %r = alloca %struct._GUID*, align 4
101 // CHECK: %p = alloca %struct._GUID*, align 4
102 // CHECK: %zeroiid = alloca %struct._GUID*, align 4
Nico Weberc5f80462012-10-11 10:13:44 +0000103
David Majnemer8effeda2013-08-15 19:59:14 +0000104 // 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 Weberc5f80462012-10-11 10:13:44 +0000105 const GUID& r = __uuidof(S2);
David Majnemer8effeda2013-08-15 19:59:14 +0000106 // 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 Weberc5f80462012-10-11 10:13:44 +0000107 const GUID* p = &__uuidof(S2);
108
109 // Special case _uuidof(0), local scope version.
David Majnemer8effeda2013-08-15 19:59:14 +0000110 // 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 Weberc5f80462012-10-11 10:13:44 +0000111 const GUID& zeroiid = __uuidof(0);
112}