| 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 |
| 6 |
|
| 7 |
/// The same, but with the new constant interpreter. |
| 8 |
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -DDEFINE_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID |
| 9 |
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -DDEFINE_GUID -DBRACKET_ATTRIB -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID |
| 10 |
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -triple=i386-pc-linux -fms-extensions | FileCheck %s |
| 11 |
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -triple=x86_64-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-64 |
| 12 |
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -DDEFINE_GUID -DWRONG_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-WRONG-GUID |
| 13 |
|
| 14 |
#ifdef DEFINE_GUID |
| 15 |
struct _GUID { |
| 16 |
#ifdef WRONG_GUID |
| 17 |
unsigned int SomethingWentWrong; |
| 18 |
#else |
| 19 |
unsigned long Data1; |
| 20 |
unsigned short Data2; |
| 21 |
unsigned short Data3; |
| 22 |
unsigned char Data4[8]; |
| 23 |
#endif |
| 24 |
}; |
| 25 |
#endif |
| 26 |
typedef struct _GUID GUID; |
| 27 |
|
| 28 |
#ifdef BRACKET_ATTRIB |
| 29 |
[uuid(12345678-1234-1234-1234-1234567890aB)] struct S1 { } s1; |
| 30 |
[uuid(87654321-4321-4321-4321-ba0987654321)] struct S2 { }; |
| 31 |
[uuid({12345678-1234-1234-1234-1234567890ac})] struct Curly; |
| 32 |
[uuid({12345678-1234-1234-1234-1234567890ac})] struct Curly; |
| 33 |
#else |
| 34 |
struct __declspec(uuid("12345678-1234-1234-1234-1234567890aB")) S1 { } s1; |
| 35 |
struct __declspec(uuid("87654321-4321-4321-4321-ba0987654321")) S2 { }; |
| 36 |
struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly; |
| 37 |
struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly; |
| 38 |
#endif |
| 39 |
|
| 40 |
void side_effect(); |
| 41 |
|
| 42 |
#ifdef DEFINE_GUID |
| 43 |
// Make sure we can properly generate code when the UUID has curly braces on it. |
| 44 |
GUID thing = (side_effect(), __uuidof(Curly)); |
| 45 |
// CHECK-DEFINE-GUID: @thing ={{.*}} global %struct._GUID zeroinitializer, align 4 |
| 46 |
// CHECK-DEFINE-WRONG-GUID: @thing ={{.*}} global %struct._GUID zeroinitializer, align 4 |
| 47 |
|
| 48 |
// This gets initialized in a static initializer. |
| 49 |
// CHECK-DEFINE-GUID: @g ={{.*}} global %struct._GUID zeroinitializer, align 4 |
| 50 |
// CHECK-DEFINE-WRONG-GUID: @g ={{.*}} global %struct._GUID zeroinitializer, align 4 |
| 51 |
GUID g = (side_effect(), __uuidof(S1)); |
| 52 |
|
| 53 |
// CHECK-DEFINE-GUID: @const_init ={{.*}} global %struct._GUID { i32 305419896, i16 4660, i16 4660, [8 x i8] c"\124\124Vx\90\AC" } |
| 54 |
// CHECK-DEFINE-WRONG-GUID: @const_init ={{.*}} global %struct._GUID zeroinitializer |
| 55 |
GUID const_init = __uuidof(Curly); |
| 56 |
#endif |
| 57 |
|
| 58 |
// First global use of __uuidof(S1) forces the creation of the global. |
| 59 |
// 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 |
| 60 |
// CHECK: @gr ={{.*}} constant ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 4 |
| 61 |
// CHECK-64: @gr ={{.*}} constant ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 8 |
| 62 |
const GUID& gr = __uuidof(S1); |
| 63 |
|
| 64 |
// CHECK: @gp ={{.*}} global ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 4 |
| 65 |
const GUID* gp = &__uuidof(S1); |
| 66 |
|
| 67 |
// CHECK: @cp ={{.*}} global ptr @_GUID_12345678_1234_1234_1234_1234567890ac, align 4 |
| 68 |
const GUID* cp = &__uuidof(Curly); |
| 69 |
|
| 70 |
// Special case: _uuidof(0) |
| 71 |
// CHECK: @zeroiid ={{.*}} constant ptr @_GUID_00000000_0000_0000_0000_000000000000, align 4 |
| 72 |
const GUID& zeroiid = __uuidof(0); |
| 73 |
|
| 74 |
// __uuidof(S2) hasn't been used globally yet, so it's emitted when it's used |
| 75 |
// in a function and is emitted at the end of the globals section. |
| 76 |
// 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 |
| 77 |
|
| 78 |
// The static initializer for thing. |
| 79 |
// 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) |
| 80 |
// 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) |
| 81 |
|
| 82 |
// The static initializer for g. |
| 83 |
// 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) |
| 84 |
// 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) |
| 85 |
|
| 86 |
// We don't constant-initialize const_init if the definition of _GUID is dodgy. |
| 87 |
// CHECK-DEFINE-GUID-NOT: @const_init |
| 88 |
// 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) |
| 89 |
|
| 90 |
#ifdef DEFINE_GUID |
| 91 |
void fun() { |
| 92 |
// CHECK-DEFINE-GUID: %s1_1 = alloca %struct._GUID, align 4 |
| 93 |
// CHECK-DEFINE-WRONG-GUID: %s1_1 = alloca %struct._GUID, align 4 |
| 94 |
// CHECK-DEFINE-GUID: %s1_2 = alloca %struct._GUID, align 4 |
| 95 |
// CHECK-DEFINE-WRONG-GUID: %s1_2 = alloca %struct._GUID, align 4 |
| 96 |
// CHECK-DEFINE-GUID: %s1_3 = alloca %struct._GUID, align 4 |
| 97 |
// CHECK-DEFINE-WRONG-GUID: %s1_3 = alloca %struct._GUID, align 4 |
| 98 |
|
| 99 |
// 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) |
| 100 |
// 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) |
| 101 |
GUID s1_1 = (side_effect(), __uuidof(S1)); |
| 102 |
|
| 103 |
// 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) |
| 104 |
// 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) |
| 105 |
GUID s1_2 = (side_effect(), __uuidof(S1)); |
| 106 |
|
| 107 |
// 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) |
| 108 |
// 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) |
| 109 |
GUID s1_3 = (side_effect(), __uuidof(s1)); |
| 110 |
} |
| 111 |
#endif |
| 112 |
|
| 113 |
void gun() { |
| 114 |
#ifdef DEFINE_GUID |
| 115 |
// CHECK-DEFINE-GUID: %s2_1 = alloca %struct._GUID, align 4 |
| 116 |
// CHECK-DEFINE-WRONG-GUID: %s2_1 = alloca %struct._GUID, align 4 |
| 117 |
// CHECK-DEFINE-GUID: %s2_2 = alloca %struct._GUID, align 4 |
| 118 |
// CHECK-DEFINE-WRONG-GUID: %s2_2 = alloca %struct._GUID, align 4 |
| 119 |
GUID s2_1 = __uuidof(S2); |
| 120 |
GUID s2_2 = __uuidof(S2); |
| 121 |
#endif |
| 122 |
// CHECK: %r = alloca ptr, align 4 |
| 123 |
// CHECK: %p = alloca ptr, align 4 |
| 124 |
// CHECK: %zeroiid = alloca ptr, align 4 |
| 125 |
|
| 126 |
// CHECK: store ptr @_GUID_87654321_4321_4321_4321_ba0987654321, ptr %r, align 4 |
| 127 |
const GUID& r = __uuidof(S2); |
| 128 |
// CHECK: store ptr @_GUID_87654321_4321_4321_4321_ba0987654321, ptr %p, align 4 |
| 129 |
const GUID* p = &__uuidof(S2); |
| 130 |
|
| 131 |
// Special case _uuidof(0), local scope version. |
| 132 |
// CHECK: store ptr @_GUID_00000000_0000_0000_0000_000000000000, ptr %zeroiid, align 4 |
| 133 |
const GUID& zeroiid = __uuidof(0); |
| 134 |
} |
| 135 |
|
| 136 |
namespace DeclRefExprNamingGUID { |
| 137 |
template<const _GUID &g> const _GUID &f() { return g; } |
| 138 |
struct __declspec(uuid("12345678-1234-1234-1234-123412341234")) S {}; |
| 139 |
auto &r = f<__uuidof(S)>(); |
| 140 |
} |