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