1 // RUN: %clang_cc1 -no-opaque-pointers -I %S/Inputs -triple x86_64-apple-macosx -emit-llvm -O2 -disable-llvm-passes -o - %s | FileCheck %s
3 #import "nsvalue-boxed-expressions-support.h"
5 // CHECK: [[CLASS:@.*]] = external global %struct._class_t
6 // CHECK: [[NSVALUE:@.*]] = {{.*}}[[CLASS]]{{.*}}
7 // CHECK: [[RANGE_STR:.*]] = {{.*}}_NSRange=QQ{{.*}}
8 // CHECK: [[METH:@.*]] = private unnamed_addr constant {{.*}}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{{.*}}
15 // CHECK-LABEL: define{{.*}} void @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: [[RECV:%.*]] = bitcast %struct._class_t* [[RECV_PTR]] to i8*
25 // CHECK: [[SEL:%.*]] = load i8*, i8** [[VALUE_SEL]]
26 NSRange ns_range = { .location = 0, .length = 42 };
27 // CHECK: call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8* noundef {{.*}}[[RANGE_STR]]{{.*}})
28 NSValue *range = @(ns_range);
32 // CHECK-LABEL: define{{.*}} void @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: [[RECV:%.*]] = bitcast %struct._class_t* [[RECV_PTR]] to i8*
42 // CHECK: [[SEL:%.*]] = load i8*, i8** [[VALUE_SEL]]
43 NSPoint ns_point = { .x = 42, .y = 24 };
44 // CHECK: call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8* noundef {{.*}}[[POINT_STR]]{{.*}})
45 NSValue *point = @(ns_point);
49 // CHECK-LABEL: define{{.*}} void @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: [[RECV:%.*]] = bitcast %struct._class_t* [[RECV_PTR]] to i8*
59 // CHECK: [[SEL:%.*]] = load i8*, i8** [[VALUE_SEL]]
60 NSSize ns_size = { .width = 42, .height = 24 };
61 // CHECK: call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8* noundef {{.*}}[[SIZE_STR]]{{.*}})
62 NSValue *size = @(ns_size);
66 // CHECK-LABEL: define{{.*}} void @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: [[RECV:%.*]] = bitcast %struct._class_t* [[RECV_PTR]] to i8*
76 // CHECK: [[SEL:%.*]] = load i8*, i8** [[VALUE_SEL]]
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* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8*{{.*}}[[RECT_STR]]{{.*}})
81 NSValue *rect = @(ns_rect);
85 // CHECK-LABEL: define{{.*}} void @doNSEdgeInsets()
86 void doNSEdgeInsets(void) {
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: [[RECV:%.*]] = bitcast %struct._class_t* [[RECV_PTR]] to i8*
95 // CHECK: [[SEL:%.*]] = load i8*, i8** [[VALUE_SEL]]
96 NSEdgeInsets ns_edge_insets;
97 // CHECK: call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8*{{.*}}[[EDGE_STR]]{{.*}})
98 NSValue *edge_insets = @(ns_edge_insets);
102 // CHECK-LABEL: define{{.*}} void @doRangeRValue()
103 void doRangeRValue(void) {
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: [[RECV:%.*]] = bitcast %struct._class_t* [[RECV_PTR]] to i8*
113 // CHECK: [[SEL:%.*]] = load i8*, i8** [[VALUE_SEL]]
114 // CHECK: call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[COERCE_CAST]], i8* noundef {{.*}}[[RANGE_STR]]{{.*}})
115 NSValue *range_rvalue = @(getRange());