• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 struct __declspec(uuid("12345678-1234-1234-1234-1234567890ab")) S1 { } s1;
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.
19 // CHECK: @__uuid_12345678-1234-1234-1234-1234567890ab = private 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* @__uuid_12345678-1234-1234-1234-1234567890ab, align 4
21 const GUID& gr = __uuidof(S1);
22 
23 // CHECK: @gp = global %struct._GUID* @__uuid_12345678-1234-1234-1234-1234567890ab, align 4
24 const GUID* gp = &__uuidof(S1);
25 
26 // Special case: _uuidof(0)
27 // CHECK: @zeroiid = constant %struct._GUID* @__uuid_00000000-0000-0000-0000-000000000000, align 4
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.
32 // CHECK: @__uuid_87654321-4321-4321-4321-ba0987654321 = private unnamed_addr constant %struct._GUID { i32 -2023406815, i16 17185, i16 17185, [8 x i8] c"C!\BA\09\87eC!" }
33 
34 // The static initializer for g.
35 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* bitcast (%struct._GUID* @g to i8*), i8* bitcast (%struct._GUID* @__uuid_12345678-1234-1234-1234-1234567890ab to i8*), i32 16, i32 4, i1 false)
36 
fun()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 
42   // CHECK: [[U1:%.+]] = bitcast %struct._GUID* %s1_1 to i8*
43   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U1]], i8* bitcast (%struct._GUID* @__uuid_12345678-1234-1234-1234-1234567890ab to i8*), i32 16, i32 4, i1 false)
44   GUID s1_1 = __uuidof(S1);
45 
46   // CHECK: [[U2:%.+]] = bitcast %struct._GUID* %s1_2 to i8*
47   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U2]], i8* bitcast (%struct._GUID* @__uuid_12345678-1234-1234-1234-1234567890ab to i8*), i32 16, i32 4, i1 false)
48   GUID s1_2 = __uuidof(S1);
49 
50   // CHECK: [[U3:%.+]] = bitcast %struct._GUID* %s1_3 to i8*
51   // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* [[U3]], i8* bitcast (%struct._GUID* @__uuid_12345678-1234-1234-1234-1234567890ab to i8*), i32 16, i32 4, i1 false)
52   GUID s1_3 = __uuidof(s1);
53 }
54 
gun()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 
64   // CHECK: store %struct._GUID* @__uuid_87654321-4321-4321-4321-ba0987654321, %struct._GUID** %r, align 4
65   const GUID& r = __uuidof(S2);
66   // CHECK: store %struct._GUID* @__uuid_87654321-4321-4321-4321-ba0987654321, %struct._GUID** %p, align 4
67   const GUID* p = &__uuidof(S2);
68 
69   // Special case _uuidof(0), local scope version.
70   // CHECK: store %struct._GUID* @__uuid_00000000-0000-0000-0000-000000000000, %struct._GUID** %zeroiid, align 4
71   const GUID& zeroiid = __uuidof(0);
72 }
73