1 // RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-macosx -emit-llvm -fobjc-arc -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: call void @llvm.memcpy{{.*}} [[TEMP_VAR]]{{.*}} [[LOCAL_VAR]]{{.*}}
21 // CHECK: [[SEL:%.*]] = load ptr, ptr [[VALUE_SEL]]
22 NSRange ns_range = { .location = 0, .length = 42 };
23 // CHECK: call {{.*objc_msgSend.*}}(ptr noundef [[RECV_PTR]], ptr noundef [[SEL]], ptr noundef [[TEMP_VAR]], ptr {{.*}}[[RANGE_STR]]{{.*}}) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
24 NSValue *range = @(ns_range);
25 // CHECK: call void @llvm.objc.release
29 // CHECK-LABEL: define{{.*}} void @doPoint()
31 // CHECK: [[LOCAL_VAR:%.*]] = alloca %struct._NSPoint{{.*}}
32 // CHECK: [[TEMP_VAR:%.*]] = alloca %struct._NSPoint{{.*}}
33 // CHECK: [[RECV_PTR:%.*]] = load {{.*}} [[NSVALUE]]
34 // CHECK: call void @llvm.memcpy{{.*}} [[TEMP_VAR]]{{.*}} [[LOCAL_VAR]]{{.*}}
35 // CHECK: [[SEL:%.*]] = load ptr, ptr [[VALUE_SEL]]
36 NSPoint ns_point = { .x = 42, .y = 24 };
37 // CHECK: call {{.*objc_msgSend.*}}(ptr noundef [[RECV_PTR]], ptr noundef [[SEL]], ptr noundef [[TEMP_VAR]], ptr {{.*}}[[POINT_STR]]{{.*}}) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
38 NSValue *point = @(ns_point);
39 // CHECK: call void @llvm.objc.release
43 // CHECK-LABEL: define{{.*}} void @doSize()
45 // CHECK: [[LOCAL_VAR:%.*]] = alloca %struct._NSSize{{.*}}
46 // CHECK: [[TEMP_VAR:%.*]] = alloca %struct._NSSize{{.*}}
47 // CHECK: [[RECV_PTR:%.*]] = load {{.*}} [[NSVALUE]]
48 // CHECK: call void @llvm.memcpy{{.*}} [[TEMP_VAR]]{{.*}} [[LOCAL_VAR]]{{.*}}
49 // CHECK: [[SEL:%.*]] = load ptr, ptr [[VALUE_SEL]]
50 NSSize ns_size = { .width = 42, .height = 24 };
51 // CHECK: call {{.*objc_msgSend.*}}(ptr noundef [[RECV_PTR]], ptr noundef [[SEL]], ptr noundef [[TEMP_VAR]], ptr {{.*}}[[SIZE_STR]]{{.*}}) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
52 NSValue *size = @(ns_size);
53 // CHECK: call void @llvm.objc.release
57 // CHECK-LABEL: define{{.*}} void @doRect()
59 // CHECK: [[LOCAL_VAR:%.*]] = alloca %struct._NSRect{{.*}}
60 // CHECK: [[TEMP_VAR:%.*]] = alloca %struct._NSRect{{.*}}
61 // CHECK: [[RECV_PTR:%.*]] = load {{.*}} [[NSVALUE]]
62 // CHECK: call void @llvm.memcpy{{.*}} [[TEMP_VAR]]{{.*}} [[LOCAL_VAR]]{{.*}}
63 // CHECK: [[SEL:%.*]] = load ptr, ptr [[VALUE_SEL]]
64 NSPoint ns_point = { .x = 42, .y = 24 };
65 NSSize ns_size = { .width = 42, .height = 24 };
66 NSRect ns_rect = { .origin = ns_point, .size = ns_size };
67 // CHECK: call {{.*objc_msgSend.*}}(ptr noundef [[RECV_PTR]], ptr noundef [[SEL]], ptr noundef [[TEMP_VAR]], ptr{{.*}}[[RECT_STR]]{{.*}}) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
68 NSValue *rect = @(ns_rect);
69 // CHECK: call void @llvm.objc.release
73 // CHECK-LABEL: define{{.*}} void @doNSEdgeInsets()
74 void doNSEdgeInsets(void) {
75 // CHECK: [[LOCAL_VAR:%.*]] = alloca %struct.NSEdgeInsets{{.*}}
76 // CHECK: [[TEMP_VAR:%.*]] = alloca %struct.NSEdgeInsets{{.*}}
77 // CHECK: [[RECV_PTR:%.*]] = load {{.*}} [[NSVALUE]]
78 // CHECK: call void @llvm.memcpy{{.*}} [[TEMP_VAR]]{{.*}} [[LOCAL_VAR]]{{.*}}
79 // CHECK: [[SEL:%.*]] = load ptr, ptr [[VALUE_SEL]]
80 NSEdgeInsets ns_edge_insets;
81 // CHECK: call {{.*objc_msgSend.*}}(ptr noundef [[RECV_PTR]], ptr noundef [[SEL]], ptr noundef [[TEMP_VAR]], ptr{{.*}}[[EDGE_STR]]{{.*}}) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
82 NSValue *edge_insets = @(ns_edge_insets);
83 // CHECK: call void @llvm.objc.release
87 // CHECK-LABEL: define{{.*}} void @doRangeRValue()
88 void doRangeRValue(void) {
89 // CHECK: [[COERCE:%.*]] = alloca %struct._NSRange{{.*}}
90 // CHECK: [[RECV_PTR:%.*]] = load {{.*}} [[NSVALUE]]
91 // CHECK: [[RVAL:%.*]] = call {{.*}} @getRange()
92 // CHECK: [[COERCE_VAR_PTR:%.*]] = getelementptr {{.*}} [[COERCE]], {{.*}}
93 // CHECK: [[EXTR_RVAL:%.*]] = extractvalue {{.*}} [[RVAL]]{{.*}}
94 // CHECK: store {{.*}}[[EXTR_RVAL]]{{.*}}[[COERCE_VAR_PTR]]{{.*}}
95 // CHECK: [[SEL:%.*]] = load ptr, ptr [[VALUE_SEL]]
96 // CHECK: call {{.*objc_msgSend.*}}(ptr noundef [[RECV_PTR]], ptr noundef [[SEL]], ptr noundef [[COERCE]], ptr {{.*}}[[RANGE_STR]]{{.*}}) [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
97 NSValue *range_rvalue = @(getRange());
98 // CHECK: call void @llvm.objc.release