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 - -DDEFINE_GUID -DBRACKET_ATTRIB -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID
3 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-linux -fms-extensions | FileCheck %s
4 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-64
5 // 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
10 unsigned int SomethingWentWrong
;
15 unsigned char Data4
[8];
19 typedef struct _GUID GUID
;
22 [uuid(12345678-1234-1234-1234-1234567890aB
)] struct S1
{ } s1
;
23 [uuid(87654321-4321-4321-4321-ba0987654321
)] struct S2
{ };
24 [uuid({12345678-1234-1234-1234-1234567890ac
})] struct Curly
;
25 [uuid({12345678-1234-1234-1234-1234567890ac
})] struct Curly
;
27 struct __declspec(uuid("12345678-1234-1234-1234-1234567890aB")) S1
{ } s1
;
28 struct __declspec(uuid("87654321-4321-4321-4321-ba0987654321")) S2
{ };
29 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly
;
30 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly
;
36 // Make sure we can properly generate code when the UUID has curly braces on it.
37 GUID thing
= (side_effect(), __uuidof(Curly
));
38 // CHECK-DEFINE-GUID: @thing ={{.*}} global %struct._GUID zeroinitializer, align 4
39 // CHECK-DEFINE-WRONG-GUID: @thing ={{.*}} global %struct._GUID zeroinitializer, align 4
41 // This gets initialized in a static initializer.
42 // CHECK-DEFINE-GUID: @g ={{.*}} global %struct._GUID zeroinitializer, align 4
43 // CHECK-DEFINE-WRONG-GUID: @g ={{.*}} global %struct._GUID zeroinitializer, align 4
44 GUID g
= (side_effect(), __uuidof(S1
));
46 // CHECK-DEFINE-GUID: @const_init ={{.*}} global %struct._GUID { i32 305419896, i16 4660, i16 4660, [8 x i8] c"\124\124Vx\90\AC" }
47 // CHECK-DEFINE-WRONG-GUID: @const_init ={{.*}} global %struct._GUID zeroinitializer
48 GUID const_init
= __uuidof(Curly
);
51 // First global use of __uuidof(S1) forces the creation of the global.
52 // 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
53 // CHECK: @gr ={{.*}} constant ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 4
54 // CHECK-64: @gr ={{.*}} constant ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 8
55 const GUID
& gr
= __uuidof(S1
);
57 // CHECK: @gp ={{.*}} global ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 4
58 const GUID
* gp
= &__uuidof(S1
);
60 // CHECK: @cp ={{.*}} global ptr @_GUID_12345678_1234_1234_1234_1234567890ac, align 4
61 const GUID
* cp
= &__uuidof(Curly
);
63 // Special case: _uuidof(0)
64 // CHECK: @zeroiid ={{.*}} constant ptr @_GUID_00000000_0000_0000_0000_000000000000, align 4
65 const GUID
& zeroiid
= __uuidof(0);
67 // __uuidof(S2) hasn't been used globally yet, so it's emitted when it's used
68 // in a function and is emitted at the end of the globals section.
69 // 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
71 // The static initializer for thing.
72 // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 @thing, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ac, i32 16, i1 false)
73 // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 @thing, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ac, i32 4, i1 false)
75 // The static initializer for g.
76 // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 @g, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ab, i32 16, i1 false)
77 // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 @g, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ab, i32 4, i1 false)
79 // We don't constant-initialize const_init if the definition of _GUID is dodgy.
80 // CHECK-DEFINE-GUID-NOT: @const_init
81 // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 @const_init, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ac, i32 4, i1 false)
85 // CHECK-DEFINE-GUID: %s1_1 = alloca %struct._GUID, align 4
86 // CHECK-DEFINE-WRONG-GUID: %s1_1 = alloca %struct._GUID, align 4
87 // CHECK-DEFINE-GUID: %s1_2 = alloca %struct._GUID, align 4
88 // CHECK-DEFINE-WRONG-GUID: %s1_2 = alloca %struct._GUID, align 4
89 // CHECK-DEFINE-GUID: %s1_3 = alloca %struct._GUID, align 4
90 // CHECK-DEFINE-WRONG-GUID: %s1_3 = alloca %struct._GUID, align 4
92 // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 %s1_1, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ab, i32 16, i1 false)
93 // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 %s1_1, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ab, i32 4, i1 false)
94 GUID s1_1
= (side_effect(), __uuidof(S1
));
96 // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 %s1_2, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ab, i32 16, i1 false)
97 // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 %s1_2, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ab, i32 4, i1 false)
98 GUID s1_2
= (side_effect(), __uuidof(S1
));
100 // CHECK-DEFINE-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 %s1_3, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ab, i32 16, i1 false)
101 // CHECK-DEFINE-WRONG-GUID: call void @llvm.memcpy.p0.p0.i32(ptr align 4 %s1_3, ptr align 4 @_GUID_12345678_1234_1234_1234_1234567890ab, i32 4, i1 false)
102 GUID s1_3
= (side_effect(), __uuidof(s1
));
108 // CHECK-DEFINE-GUID: %s2_1 = alloca %struct._GUID, align 4
109 // CHECK-DEFINE-WRONG-GUID: %s2_1 = alloca %struct._GUID, align 4
110 // CHECK-DEFINE-GUID: %s2_2 = alloca %struct._GUID, align 4
111 // CHECK-DEFINE-WRONG-GUID: %s2_2 = alloca %struct._GUID, align 4
112 GUID s2_1
= __uuidof(S2
);
113 GUID s2_2
= __uuidof(S2
);
115 // CHECK: %r = alloca ptr, align 4
116 // CHECK: %p = alloca ptr, align 4
117 // CHECK: %zeroiid = alloca ptr, align 4
119 // CHECK: store ptr @_GUID_87654321_4321_4321_4321_ba0987654321, ptr %r, align 4
120 const GUID
& r
= __uuidof(S2
);
121 // CHECK: store ptr @_GUID_87654321_4321_4321_4321_ba0987654321, ptr %p, align 4
122 const GUID
* p
= &__uuidof(S2
);
124 // Special case _uuidof(0), local scope version.
125 // CHECK: store ptr @_GUID_00000000_0000_0000_0000_000000000000, ptr %zeroiid, align 4
126 const GUID
& zeroiid
= __uuidof(0);
129 namespace DeclRefExprNamingGUID
{
130 template<const _GUID
&g
> const _GUID
&f() { return g
; }
131 struct __declspec(uuid("12345678-1234-1234-1234-123412341234")) S
{};
132 auto &r
= f
<__uuidof(S
)>();