xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/microsoft-uuidof.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -o - -DDEFINE_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-linux -fms-extensions | FileCheck %s
3*0a6a1f1dSLionel Sambuc // 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
4f4a2713aSLionel Sambuc 
5f4a2713aSLionel Sambuc #ifdef DEFINE_GUID
6f4a2713aSLionel Sambuc struct _GUID {
7f4a2713aSLionel Sambuc #ifdef WRONG_GUID
8f4a2713aSLionel Sambuc     unsigned int SomethingWentWrong;
9f4a2713aSLionel Sambuc #else
10f4a2713aSLionel Sambuc     unsigned long  Data1;
11f4a2713aSLionel Sambuc     unsigned short Data2;
12f4a2713aSLionel Sambuc     unsigned short Data3;
13f4a2713aSLionel Sambuc     unsigned char  Data4[8];
14f4a2713aSLionel Sambuc #endif
15f4a2713aSLionel Sambuc };
16f4a2713aSLionel Sambuc #endif
17f4a2713aSLionel Sambuc typedef struct _GUID GUID;
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc struct __declspec(uuid("12345678-1234-1234-1234-1234567890aB")) S1 { } s1;
20f4a2713aSLionel Sambuc struct __declspec(uuid("87654321-4321-4321-4321-ba0987654321")) S2 { };
21f4a2713aSLionel Sambuc struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly;
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc #ifdef DEFINE_GUID
24f4a2713aSLionel Sambuc // Make sure we can properly generate code when the UUID has curly braces on it.
25f4a2713aSLionel Sambuc GUID thing = __uuidof(Curly);
26f4a2713aSLionel Sambuc // CHECK-DEFINE-GUID: @thing = global %struct._GUID zeroinitializer, align 4
27f4a2713aSLionel Sambuc // CHECK-DEFINE-WRONG-GUID: @thing = global %struct._GUID zeroinitializer, align 4
28f4a2713aSLionel Sambuc 
29f4a2713aSLionel Sambuc // This gets initialized in a static initializer.
30f4a2713aSLionel Sambuc // CHECK-DEFINE-GUID: @g = global %struct._GUID zeroinitializer, align 4
31f4a2713aSLionel Sambuc // CHECK-DEFINE-WRONG-GUID: @g = global %struct._GUID zeroinitializer, align 4
32f4a2713aSLionel Sambuc GUID g = __uuidof(S1);
33f4a2713aSLionel Sambuc #endif
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc // First global use of __uuidof(S1) forces the creation of the global.
36f4a2713aSLionel Sambuc // 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" }
37f4a2713aSLionel Sambuc // CHECK: @gr = constant %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to %struct._GUID*), align 4
38f4a2713aSLionel Sambuc const GUID& gr = __uuidof(S1);
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc // CHECK: @gp = global %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ab to %struct._GUID*), align 4
41f4a2713aSLionel Sambuc const GUID* gp = &__uuidof(S1);
42f4a2713aSLionel Sambuc 
43f4a2713aSLionel Sambuc // CHECK: @cp = global %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_12345678_1234_1234_1234_1234567890ac to %struct._GUID*), align 4
44f4a2713aSLionel Sambuc const GUID* cp = &__uuidof(Curly);
45f4a2713aSLionel Sambuc 
46f4a2713aSLionel Sambuc // Special case: _uuidof(0)
47f4a2713aSLionel Sambuc // CHECK: @zeroiid = constant %struct._GUID* bitcast ({ i32, i16, i16, [8 x i8] }* @_GUID_00000000_0000_0000_0000_000000000000 to %struct._GUID*), align 4
48f4a2713aSLionel Sambuc const GUID& zeroiid = __uuidof(0);
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc // __uuidof(S2) hasn't been used globally yet, so it's emitted when it's used
51f4a2713aSLionel Sambuc // in a function and is emitted at the end of the globals section.
52f4a2713aSLionel Sambuc // 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!" }
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc // The static initializer for thing.
55f4a2713aSLionel Sambuc // 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)
56f4a2713aSLionel Sambuc // 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)
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc // The static initializer for g.
59f4a2713aSLionel Sambuc // 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)
60f4a2713aSLionel Sambuc // 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)
61f4a2713aSLionel Sambuc 
62f4a2713aSLionel Sambuc #ifdef DEFINE_GUID
fun()63f4a2713aSLionel Sambuc void fun() {
64f4a2713aSLionel Sambuc   // CHECK-DEFINE-GUID: %s1_1 = alloca %struct._GUID, align 4
65f4a2713aSLionel Sambuc   // CHECK-DEFINE-WRONG-GUID: %s1_1 = alloca %struct._GUID, align 4
66f4a2713aSLionel Sambuc   // CHECK-DEFINE-GUID: %s1_2 = alloca %struct._GUID, align 4
67f4a2713aSLionel Sambuc   // CHECK-DEFINE-WRONG-GUID: %s1_2 = alloca %struct._GUID, align 4
68f4a2713aSLionel Sambuc   // CHECK-DEFINE-GUID: %s1_3 = alloca %struct._GUID, align 4
69f4a2713aSLionel Sambuc   // CHECK-DEFINE-WRONG-GUID: %s1_3 = alloca %struct._GUID, align 4
70f4a2713aSLionel Sambuc 
71f4a2713aSLionel Sambuc   // CHECK-DEFINE-GUID: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8*
72f4a2713aSLionel Sambuc   // CHECK-DEFINE-WRONG-GUID: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8*
73f4a2713aSLionel Sambuc   // 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)
74f4a2713aSLionel Sambuc   // 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)
75f4a2713aSLionel Sambuc   GUID s1_1 = __uuidof(S1);
76f4a2713aSLionel Sambuc 
77f4a2713aSLionel Sambuc   // CHECK-DEFINE-GUID: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8*
78f4a2713aSLionel Sambuc   // CHECK-DEFINE-WRONG-GUID: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8*
79f4a2713aSLionel Sambuc   // 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)
80f4a2713aSLionel Sambuc   // 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)
81f4a2713aSLionel Sambuc   GUID s1_2 = __uuidof(S1);
82f4a2713aSLionel Sambuc 
83f4a2713aSLionel Sambuc   // CHECK-DEFINE-GUID: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8*
84f4a2713aSLionel Sambuc   // CHECK-DEFINE-WRONG-GUID: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8*
85f4a2713aSLionel Sambuc   // 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)
86f4a2713aSLionel Sambuc   // 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)
87f4a2713aSLionel Sambuc   GUID s1_3 = __uuidof(s1);
88f4a2713aSLionel Sambuc }
89f4a2713aSLionel Sambuc #endif
90f4a2713aSLionel Sambuc 
gun()91f4a2713aSLionel Sambuc void gun() {
92f4a2713aSLionel Sambuc #ifdef DEFINE_GUID
93f4a2713aSLionel Sambuc   // CHECK-DEFINE-GUID: %s2_1 = alloca %struct._GUID, align 4
94f4a2713aSLionel Sambuc   // CHECK-DEFINE-WRONG-GUID: %s2_1 = alloca %struct._GUID, align 4
95f4a2713aSLionel Sambuc   // CHECK-DEFINE-GUID: %s2_2 = alloca %struct._GUID, align 4
96f4a2713aSLionel Sambuc   // CHECK-DEFINE-WRONG-GUID: %s2_2 = alloca %struct._GUID, align 4
97f4a2713aSLionel Sambuc   GUID s2_1 = __uuidof(S2);
98f4a2713aSLionel Sambuc   GUID s2_2 = __uuidof(S2);
99f4a2713aSLionel Sambuc #endif
100f4a2713aSLionel Sambuc   // CHECK: %r = alloca %struct._GUID*, align 4
101f4a2713aSLionel Sambuc   // CHECK: %p = alloca %struct._GUID*, align 4
102f4a2713aSLionel Sambuc   // CHECK: %zeroiid = alloca %struct._GUID*, align 4
103f4a2713aSLionel Sambuc 
104f4a2713aSLionel Sambuc   // 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
105f4a2713aSLionel Sambuc   const GUID& r = __uuidof(S2);
106f4a2713aSLionel Sambuc   // 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
107f4a2713aSLionel Sambuc   const GUID* p = &__uuidof(S2);
108f4a2713aSLionel Sambuc 
109f4a2713aSLionel Sambuc   // Special case _uuidof(0), local scope version.
110f4a2713aSLionel Sambuc   // 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
111f4a2713aSLionel Sambuc   const GUID& zeroiid = __uuidof(0);
112f4a2713aSLionel Sambuc }
113