brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.8 KiB · 2de964a Raw
141 lines · cpp
1// RUN: %clang_cc1 -emit-llvm %s -o - -DDEFINE_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID2// RUN: %clang_cc1 -emit-llvm %s -o - -DDEFINE_GUID -DBRACKET_ATTRIB -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-GUID3// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-linux -fms-extensions | FileCheck %s4// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-645// RUN: %clang_cc1 -emit-llvm %s -o - -DDEFINE_GUID -DWRONG_GUID -triple=i386-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-DEFINE-WRONG-GUID6 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-GUID9// 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-GUID10// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -triple=i386-pc-linux -fms-extensions | FileCheck %s11// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -emit-llvm %s -o - -triple=x86_64-pc-linux -fms-extensions | FileCheck %s --check-prefix=CHECK-6412// 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-GUID13 14#ifdef DEFINE_GUID15struct _GUID {16#ifdef WRONG_GUID17    unsigned int SomethingWentWrong;18#else19    unsigned long  Data1;20    unsigned short Data2;21    unsigned short Data3;22    unsigned char  Data4[8];23#endif24};25#endif26typedef struct _GUID GUID;27 28#ifdef BRACKET_ATTRIB29[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#else34struct __declspec(uuid("12345678-1234-1234-1234-1234567890aB")) S1 { } s1;35struct __declspec(uuid("87654321-4321-4321-4321-ba0987654321")) S2 { };36struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly;37struct __declspec(uuid("{12345678-1234-1234-1234-1234567890ac}")) Curly;38#endif39 40void side_effect();41 42#ifdef DEFINE_GUID43// Make sure we can properly generate code when the UUID has curly braces on it.44GUID thing = (side_effect(), __uuidof(Curly));45// CHECK-DEFINE-GUID: @thing ={{.*}} global %struct._GUID zeroinitializer, align 446// CHECK-DEFINE-WRONG-GUID: @thing ={{.*}} global %struct._GUID zeroinitializer, align 447 48// This gets initialized in a static initializer.49// CHECK-DEFINE-GUID: @g ={{.*}} global %struct._GUID zeroinitializer, align 450// CHECK-DEFINE-WRONG-GUID: @g ={{.*}} global %struct._GUID zeroinitializer, align 451GUID 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 zeroinitializer55GUID const_init = __uuidof(Curly);56#endif57 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" }, comdat60// CHECK: @gr ={{.*}} constant ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 461// CHECK-64: @gr ={{.*}} constant ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 862const GUID& gr = __uuidof(S1);63 64// CHECK: @gp ={{.*}} global ptr @_GUID_12345678_1234_1234_1234_1234567890ab, align 465const GUID* gp = &__uuidof(S1);66 67// CHECK: @cp ={{.*}} global ptr @_GUID_12345678_1234_1234_1234_1234567890ac, align 468const GUID* cp = &__uuidof(Curly);69 70// Special case: _uuidof(0)71// CHECK: @zeroiid ={{.*}} constant ptr @_GUID_00000000_0000_0000_0000_000000000000, align 472const GUID& zeroiid = __uuidof(0);73 74// __uuidof(S2) hasn't been used globally yet, so it's emitted when it's used75// 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!" }, comdat77 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_init88// 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_GUID91void fun() {92  // CHECK-DEFINE-GUID: %s1_1 = alloca %struct._GUID, align 493  // CHECK-DEFINE-WRONG-GUID: %s1_1 = alloca %struct._GUID, align 494  // CHECK-DEFINE-GUID: %s1_2 = alloca %struct._GUID, align 495  // CHECK-DEFINE-WRONG-GUID: %s1_2 = alloca %struct._GUID, align 496  // CHECK-DEFINE-GUID: %s1_3 = alloca %struct._GUID, align 497  // CHECK-DEFINE-WRONG-GUID: %s1_3 = alloca %struct._GUID, align 498 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#endif112 113void gun() {114#ifdef DEFINE_GUID115  // CHECK-DEFINE-GUID: %s2_1 = alloca %struct._GUID, align 4116  // CHECK-DEFINE-WRONG-GUID: %s2_1 = alloca %struct._GUID, align 4117  // CHECK-DEFINE-GUID: %s2_2 = alloca %struct._GUID, align 4118  // CHECK-DEFINE-WRONG-GUID: %s2_2 = alloca %struct._GUID, align 4119  GUID s2_1 = __uuidof(S2);120  GUID s2_2 = __uuidof(S2);121#endif122  // CHECK: %r = alloca ptr, align 4123  // CHECK: %p = alloca ptr, align 4124  // CHECK: %zeroiid = alloca ptr, align 4125 126  // CHECK: store ptr @_GUID_87654321_4321_4321_4321_ba0987654321, ptr %r, align 4127  const GUID& r = __uuidof(S2);128  // CHECK: store ptr @_GUID_87654321_4321_4321_4321_ba0987654321, ptr %p, align 4129  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 4133  const GUID& zeroiid = __uuidof(0);134}135 136namespace 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}141