1// RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-macosx -emit-llvm -O2 -disable-llvm-optzns -o - %s | FileCheck %s
2
3#import "nsvalue-boxed-expressions-support.h"
4
5// CHECK:      [[CLASS:@.*]]        = external global %struct._class_t
6// CHECK:      [[NSVALUE:@.*]]      = {{.*}}[[CLASS]]{{.*}}
7// CHECK:      [[RANGE_STR:.*]]     = {{.*}}_NSRange=QQ{{.*}}
8// CHECK:      [[METH:@.*]]         = private global{{.*}}valueWithBytes:objCType:{{.*}}
9// CHECK:      [[VALUE_SEL:@.*]]    = {{.*}}[[METH]]{{.*}}
10// CHECK:      [[POINT_STR:.*]]     = {{.*}}_NSPoint=dd{{.*}}
11// CHECK:      [[SIZE_STR:.*]]      = {{.*}}_NSSize=dd{{.*}}
12// CHECK:      [[RECT_STR:.*]]      = {{.*}}_NSRect={_NSPoint=dd}{_NSSize=dd}}{{.*}}
13// CHECK:      [[EDGE_STR:.*]]      = {{.*}}NSEdgeInsets=dddd{{.*}}
14
15// CHECK-LABEL: define void @doRange()
16void doRange() {
17  // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct._NSRange{{.*}}
18  // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct._NSRange{{.*}}
19  // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
20  // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct._NSRange* [[TEMP_VAR]]{{.*}}
21  // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct._NSRange* [[LOCAL_VAR]]{{.*}}
22  // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
23  // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct._NSRange* [[TEMP_VAR]]{{.*}}
24  // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
25  // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
26  NSRange ns_range = { .location = 0, .length = 42 };
27  // CHECK:      call {{.*objc_msgSend.*}}(i8* [[RECV]], i8* [[SEL]], i8* [[PARAM_CAST]], i8* {{.*}}[[RANGE_STR]]{{.*}})
28  NSValue *range = @(ns_range);
29  // CHECK:      ret void
30}
31
32// CHECK-LABEL: define void @doPoint()
33void doPoint() {
34  // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct._NSPoint{{.*}}
35  // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct._NSPoint{{.*}}
36  // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
37  // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct._NSPoint* [[TEMP_VAR]]{{.*}}
38  // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct._NSPoint* [[LOCAL_VAR]]{{.*}}
39  // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
40  // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct._NSPoint* [[TEMP_VAR]]{{.*}}
41  // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
42  // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
43  NSPoint ns_point = { .x = 42, .y = 24 };
44  // CHECK:      call {{.*objc_msgSend.*}}(i8* [[RECV]], i8* [[SEL]], i8* [[PARAM_CAST]], i8* {{.*}}[[POINT_STR]]{{.*}})
45  NSValue *point = @(ns_point);
46  // CHECK:      ret void
47}
48
49// CHECK-LABEL: define void @doSize()
50void doSize() {
51  // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct._NSSize{{.*}}
52  // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct._NSSize{{.*}}
53  // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
54  // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct._NSSize* [[TEMP_VAR]]{{.*}}
55  // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct._NSSize* [[LOCAL_VAR]]{{.*}}
56  // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
57  // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct._NSSize* [[TEMP_VAR]]{{.*}}
58  // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
59  // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
60  NSSize ns_size = { .width = 42, .height = 24 };
61  // CHECK:      call {{.*objc_msgSend.*}}(i8* [[RECV]], i8* [[SEL]], i8* [[PARAM_CAST]], i8* {{.*}}[[SIZE_STR]]{{.*}})
62  NSValue *size = @(ns_size);
63  // CHECK:      ret void
64}
65
66// CHECK-LABEL: define void @doRect()
67void doRect() {
68  // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct._NSRect{{.*}}
69  // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct._NSRect{{.*}}
70  // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
71  // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct._NSRect* [[TEMP_VAR]]{{.*}}
72  // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct._NSRect* [[LOCAL_VAR]]{{.*}}
73  // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
74  // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct._NSRect* [[TEMP_VAR]]{{.*}}
75  // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
76  // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
77  NSPoint ns_point = { .x = 42, .y = 24 };
78  NSSize ns_size = { .width = 42, .height = 24 };
79  NSRect ns_rect = { .origin = ns_point, .size = ns_size };
80  // CHECK:      call {{.*objc_msgSend.*}}(i8* [[RECV]], i8* [[SEL]], i8* [[PARAM_CAST]], i8*{{.*}}[[RECT_STR]]{{.*}})
81  NSValue *rect = @(ns_rect);
82  // CHECK:      ret void
83}
84
85// CHECK-LABEL: define void @doNSEdgeInsets()
86void doNSEdgeInsets() {
87  // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct.NSEdgeInsets{{.*}}
88  // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct.NSEdgeInsets{{.*}}
89  // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
90  // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct.NSEdgeInsets* [[TEMP_VAR]]{{.*}}
91  // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct.NSEdgeInsets* [[LOCAL_VAR]]{{.*}}
92  // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
93  // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct.NSEdgeInsets* [[TEMP_VAR]]{{.*}}
94  // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
95  // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
96  NSEdgeInsets ns_edge_insets;
97  // CHECK:      call {{.*objc_msgSend.*}}(i8* [[RECV]], i8* [[SEL]], i8* [[PARAM_CAST]], i8*{{.*}}[[EDGE_STR]]{{.*}})
98  NSValue *edge_insets = @(ns_edge_insets);
99  // CHECK:      ret void
100}
101
102// CHECK-LABEL: define void @doRangeRValue()
103void doRangeRValue() {
104  // CHECK:     [[COERCE:%.*]]          = alloca %struct._NSRange{{.*}}
105  // CHECK:     [[RECV_PTR:%.*]]        = load {{.*}} [[NSVALUE]]
106  // CHECK:     [[RVAL:%.*]]            = call {{.*}} @getRange()
107  // CHECK:     [[COERCE_CAST:%.*]]     = bitcast %struct._NSRange* [[COERCE]]{{.*}}
108  // CHECK:     [[COERCE_CAST_PTR:%.*]] = getelementptr {{.*}} [[COERCE_CAST]], {{.*}}
109  // CHECK:     [[EXTR_RVAL:%.*]]       = extractvalue {{.*}} [[RVAL]]{{.*}}
110  // CHECK:     store {{.*}}[[EXTR_RVAL]]{{.*}}[[COERCE_CAST_PTR]]{{.*}}
111  // CHECK:     [[COERCE_CAST:%.*]]     = bitcast %struct._NSRange* [[COERCE]]{{.*}}
112  // CHECK:     [[SEL:%.*]]             = load i8*, i8** [[VALUE_SEL]]
113  // CHECK:     [[RECV:%.*]]            = bitcast %struct._class_t* [[RECV_PTR]] to i8*
114  // CHECK:     call {{.*objc_msgSend.*}}(i8* [[RECV]], i8* [[SEL]], i8* [[COERCE_CAST]], i8* {{.*}}[[RANGE_STR]]{{.*}})
115  NSValue *range_rvalue = @(getRange());
116  // CHECK: ret void
117}
118
119