[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / CodeGenObjC / nsvalue-objc-boxable-ios-arc.m
blob43c6894fd0df64358f38f1cb705c46495aa3c150
1 // RUN: %clang_cc1 -no-opaque-pointers -I %S/Inputs -triple armv7-apple-ios8.0.0 -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=II{{.*}}
8 // CHECK:      [[METH:@.*]]         = private unnamed_addr constant {{.*}}valueWithBytes:objCType:{{.*}}
9 // CHECK:      [[VALUE_SEL:@.*]]    = {{.*}}[[METH]]{{.*}}
10 // CHECK:      [[POINT_STR:.*]]     = {{.*}}CGPoint=dd{{.*}}
11 // CHECK:      [[SIZE_STR:.*]]      = {{.*}}CGSize=dd{{.*}}
12 // CHECK:      [[RECT_STR:.*]]      = {{.*}}CGRect={CGPoint=dd}{CGSize=dd}}{{.*}}
13 // CHECK:      [[EDGE_STR:.*]]      = {{.*}}NSEdgeInsets=dddd{{.*}}
15 // CHECK-LABEL: define{{.*}} void @doRange()
16 void doRange(void) {
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* {{.*}}[[RANGE_STR]]{{.*}})
28   // CHECK:      call i8* @llvm.objc.retainAutoreleasedReturnValue
29   NSValue *range = @(ns_range);
30   // CHECK:      call void @llvm.objc.release
31   // CHECK:      ret void
34 // CHECK-LABEL: define{{.*}} void @doPoint()
35 void doPoint(void) {
36   // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct.CGPoint{{.*}}
37   // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct.CGPoint{{.*}}
38   // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
39   // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct.CGPoint* [[TEMP_VAR]]{{.*}}
40   // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct.CGPoint* [[LOCAL_VAR]]{{.*}}
41   // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
42   // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct.CGPoint* [[TEMP_VAR]]{{.*}}
43   // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
44   // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
45   CGPoint cg_point = { .x = 42, .y = 24 };
46   // CHECK:      call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8* {{.*}}[[POINT_STR]]{{.*}})
47   // CHECK:      call i8* @llvm.objc.retainAutoreleasedReturnValue
48   NSValue *point = @(cg_point);
49   // CHECK:      call void @llvm.objc.release
50   // CHECK:      ret void
53 // CHECK-LABEL: define{{.*}} void @doSize()
54 void doSize(void) {
55   // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct.CGSize{{.*}}
56   // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct.CGSize{{.*}}
57   // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
58   // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct.CGSize* [[TEMP_VAR]]{{.*}}
59   // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct.CGSize* [[LOCAL_VAR]]{{.*}}
60   // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
61   // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct.CGSize* [[TEMP_VAR]]{{.*}}
62   // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
63   // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
64   CGSize cg_size = { .width = 42, .height = 24 };
65   // CHECK:      call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8* {{.*}}[[SIZE_STR]]{{.*}})
66   // CHECK:      call i8* @llvm.objc.retainAutoreleasedReturnValue
67   NSValue *size = @(cg_size);
68   // CHECK:      call void @llvm.objc.release
69   // CHECK:      ret void
72 // CHECK-LABEL: define{{.*}} void @doRect()
73 void doRect(void) {
74   // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct.CGRect{{.*}}
75   // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct.CGRect{{.*}}
76   // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
77   // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct.CGRect* [[TEMP_VAR]]{{.*}}
78   // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct.CGRect* [[LOCAL_VAR]]{{.*}}
79   // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
80   // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct.CGRect* [[TEMP_VAR]]{{.*}}
81   // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
82   // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
83   CGPoint cg_point = { .x = 42, .y = 24 };
84   CGSize cg_size = { .width = 42, .height = 24 };
85   CGRect cg_rect = { .origin = cg_point, .size = cg_size };
86   // CHECK:      call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8*{{.*}}[[RECT_STR]]{{.*}})
87   // CHECK:      call i8* @llvm.objc.retainAutoreleasedReturnValue
88   NSValue *rect = @(cg_rect);
89   // CHECK:      call void @llvm.objc.release
90   // CHECK:      ret void
93 // CHECK-LABEL: define{{.*}} void @doNSEdgeInsets()
94 void doNSEdgeInsets(void) {
95   // CHECK:      [[LOCAL_VAR:%.*]]  = alloca %struct.NSEdgeInsets{{.*}}
96   // CHECK:      [[TEMP_VAR:%.*]]   = alloca %struct.NSEdgeInsets{{.*}}
97   // CHECK:      [[RECV_PTR:%.*]]   = load {{.*}} [[NSVALUE]]
98   // CHECK:      [[TEMP_CAST:%.*]]  = bitcast %struct.NSEdgeInsets* [[TEMP_VAR]]{{.*}}
99   // CHECK:      [[LOCAL_CAST:%.*]] = bitcast %struct.NSEdgeInsets* [[LOCAL_VAR]]{{.*}}
100   // CHECK:      call void @llvm.memcpy{{.*}} [[TEMP_CAST]]{{.*}} [[LOCAL_CAST]]{{.*}}
101   // CHECK:      [[PARAM_CAST:%.*]] = bitcast %struct.NSEdgeInsets* [[TEMP_VAR]]{{.*}}
102   // CHECK:      [[RECV:%.*]]       = bitcast %struct._class_t* [[RECV_PTR]] to i8*
103   // CHECK:      [[SEL:%.*]]        = load i8*, i8** [[VALUE_SEL]]
104   NSEdgeInsets ns_edge_insets;
105   // CHECK:      call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[PARAM_CAST]], i8*{{.*}}[[EDGE_STR]]{{.*}})
106   // CHECK:      call i8* @llvm.objc.retainAutoreleasedReturnValue
107   NSValue *edge_insets = @(ns_edge_insets);
108   // CHECK:      call void @llvm.objc.release
109   // CHECK:      ret void
112 // CHECK-LABEL: define{{.*}} void @doRangeRValue() 
113 void doRangeRValue(void) {
114   // CHECK:     [[COERCE:%.*]]          = alloca %struct._NSRange{{.*}}
115   // CHECK:     [[RECV_PTR:%.*]]        = load {{.*}} [[NSVALUE]]
116   // CHECK:     call {{.*}} @getRange({{.*}} [[COERCE]])
117   // CHECK:     [[COERCE_CAST:%.*]]     = bitcast %struct._NSRange* [[COERCE]]{{.*}}
118   // CHECK:     [[RECV:%.*]]            = bitcast %struct._class_t* [[RECV_PTR]] to i8*
119   // CHECK:     [[SEL:%.*]]             = load i8*, i8** [[VALUE_SEL]]
120   // CHECK:     call {{.*objc_msgSend.*}}(i8* noundef [[RECV]], i8* noundef [[SEL]], i8* noundef [[COERCE_CAST]], i8* {{.*}}[[RANGE_STR]]{{.*}})
121   // CHECK:     call i8* @llvm.objc.retainAutoreleasedReturnValue
122   NSValue *range_rvalue = @(getRange());
123   // CHECK:     call void @llvm.objc.release
124   // CHECK:     ret void