[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGenObjC / boxing.m
blobc124f172fd37fe75090c923c93396d7bb02390c9
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fexperimental-new-constant-interpreter | FileCheck %s
4 typedef long NSInteger;
5 typedef unsigned long NSUInteger;
6 typedef signed char BOOL;
7 #define nil ((void*) 0)
9 @interface NSObject
10 + (id)alloc;
11 @end
13 @interface NSNumber : NSObject
14 @end
16 @interface NSNumber (NSNumberCreation)
17 - (id)initWithChar:(char)value;
18 - (id)initWithUnsignedChar:(unsigned char)value;
19 - (id)initWithShort:(short)value;
20 - (id)initWithUnsignedShort:(unsigned short)value;
21 - (id)initWithInt:(int)value;
22 - (id)initWithUnsignedInt:(unsigned int)value;
23 - (id)initWithLong:(long)value;
24 - (id)initWithUnsignedLong:(unsigned long)value;
25 - (id)initWithLongLong:(long long)value;
26 - (id)initWithUnsignedLongLong:(unsigned long long)value;
27 - (id)initWithFloat:(float)value;
28 - (id)initWithDouble:(double)value;
29 - (id)initWithBool:(BOOL)value;
30 - (id)initWithInteger:(NSInteger)value;
31 - (id)initWithUnsignedInteger:(NSUInteger)value;
33 + (NSNumber *)numberWithChar:(char)value;
34 + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
35 + (NSNumber *)numberWithShort:(short)value;
36 + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
37 + (NSNumber *)numberWithInt:(int)value;
38 + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
39 + (NSNumber *)numberWithLong:(long)value;
40 + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
41 + (NSNumber *)numberWithLongLong:(long long)value;
42 + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
43 + (NSNumber *)numberWithFloat:(float)value;
44 + (NSNumber *)numberWithDouble:(double)value;
45 + (NSNumber *)numberWithBool:(BOOL)value;
46 + (NSNumber *)numberWithInteger:(NSInteger)value;
47 + (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value;
48 @end
50 @interface NSString : NSObject
51 @end
53 @interface NSString (NSStringExtensionMethods)
54 + (id)stringWithUTF8String:(const char *)nullTerminatedCString;
55 @end
57 // CHECK: [[STRUCT_NSCONSTANT_STRING_TAG:%.*]] = type { ptr, i32, ptr, i64 }
59 // CHECK: [[WithIntMeth:@.*]] = private unnamed_addr constant [15 x i8] c"numberWithInt:\00"
60 // CHECK: [[WithIntSEL:@.*]] = internal externally_initialized global ptr [[WithIntMeth]]
61 // CHECK: [[WithCharMeth:@.*]] = private unnamed_addr constant [16 x i8] c"numberWithChar:\00"
62 // CHECK: [[WithCharSEL:@.*]] = internal externally_initialized global ptr [[WithCharMeth]]
63 // CHECK: [[WithBoolMeth:@.*]] = private unnamed_addr constant [16 x i8] c"numberWithBool:\00"
64 // CHECK: [[WithBoolSEL:@.*]] = internal externally_initialized global ptr [[WithBoolMeth]]
65 // CHECK: [[WithIntegerMeth:@.*]] = private unnamed_addr constant [19 x i8] c"numberWithInteger:\00"
66 // CHECK: [[WithIntegerSEL:@.*]] = internal externally_initialized global ptr [[WithIntegerMeth]]
67 // CHECK: [[WithUnsignedIntegerMeth:@.*]] = private unnamed_addr constant [27 x i8] c"numberWithUnsignedInteger:\00"
68 // CHECK: [[WithUnsignedIntegerSEL:@.*]] = internal externally_initialized global ptr [[WithUnsignedIntegerMeth]]
69 // CHECK: [[stringWithUTF8StringMeth:@.*]] = private unnamed_addr constant [22 x i8] c"stringWithUTF8String:\00"
70 // CHECK: [[stringWithUTF8StringSEL:@.*]] = internal externally_initialized global ptr [[stringWithUTF8StringMeth]]
71 // CHECK: [[STR0:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", section "__TEXT,__cstring,cstring_literals", align 1
72 // CHECK: [[UNNAMED_CFSTRING:.*]] = private global [[STRUCT_NSCONSTANT_STRING_TAG]] { ptr @__CFConstantStringClassReference, i32 1992, ptr [[STR0]], i64 3 }, section "__DATA,__cfstring", align 8
74 int main(void) {
75   // CHECK: [[T:%t]] = alloca ptr, align 8
77   // CHECK: load ptr, ptr [[WithIntSEL]]
78   int i; @(i);
79   // CHECK: load ptr, ptr [[WithCharSEL]]
80   signed char sc; @(sc);
81   // CHECK: load ptr, ptr [[WithBoolSEL]]
82   BOOL b; @(b);
83   // CHECK: load ptr, ptr [[WithBoolSEL]]
84   typeof(b) b2; @(b2);
85   // CHECK: load ptr, ptr [[WithBoolSEL]]
86   typedef const typeof(b) MyBOOL; MyBOOL b3; @(b3);
87   // CHECK: load ptr, ptr [[WithBoolSEL]]
88   @((BOOL)i);
89   // CHECK: load ptr, ptr [[WithIntegerSEL]]
90   @((NSInteger)i);
91   // CHECK: load ptr, ptr [[WithUnsignedIntegerSEL]]
92   @((NSUInteger)i);
93   // CHECK: load ptr, ptr [[stringWithUTF8StringSEL]]
94   const char *s; @(s);
96   typedef enum : NSInteger { Red, Green, Blue } Color;
97   // CHECK: load ptr, ptr [[WithIntegerSEL]]
98   @(Red);
99   Color col = Red;
100   // CHECK: load ptr, ptr [[WithIntegerSEL]]
101   @(col);
103   // CHECK: store ptr [[UNNAMED_CFSTRING]], ptr [[T]], align 8
104   NSString *t = @("abc");