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