llvm-project/clang/test/CodeGenObjC/objc-literal-tests.m

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
3.2 KiB
Mathematica
Raw Normal View History

// RUN: %clang_cc1 -x objective-c -triple x86_64-apple-darwin10 -fblocks -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -x objective-c++ -triple x86_64-apple-darwin10 -fblocks -emit-llvm %s -o - | FileCheck %s
// rdar://10111397
#if __has_feature(objc_bool)
#define YES __objc_yes
#define NO __objc_no
#else
#define YES ((BOOL)1)
#define NO ((BOOL)0)
#endif
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef unsigned long NSUInteger;
typedef long NSInteger;
#else
typedef unsigned int NSUInteger;
typedef int NSInteger;
#endif
typedef signed char BOOL;
@interface NSNumber @end
@interface NSNumber (NSNumberCreation)
#if __has_feature(objc_array_literals)
+ (NSNumber *)numberWithChar:(char)value;
+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
+ (NSNumber *)numberWithShort:(short)value;
+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
+ (NSNumber *)numberWithInt:(int)value;
+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
+ (NSNumber *)numberWithLong:(long)value;
+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
+ (NSNumber *)numberWithLongLong:(long long)value;
+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
+ (NSNumber *)numberWithFloat:(float)value;
+ (NSNumber *)numberWithDouble:(double)value;
+ (NSNumber *)numberWithBool:(BOOL)value;
+ (NSNumber *)numberWithInteger:(NSInteger)value ;
+ (NSNumber *)numberWithUnsignedInteger:(NSUInteger)value ;
#endif
@end
@interface NSDate
+ (NSDate *) date;
@end
#if __has_feature(objc_dictionary_literals)
@interface NSDictionary
+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(NSUInteger)cnt;
@end
#endif
id NSUserName();
// CHECK: define i32 @main() [[NUW:#[0-9]+]]
int main() {
// CHECK: call{{.*}}@objc_msgSend{{.*}}i8 signext 97
NSNumber *aNumber = @'a';
// CHECK: call{{.*}}@objc_msgSend{{.*}}i32 42
NSNumber *fortyTwo = @42;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i32 -42
NSNumber *negativeFortyTwo = @-42;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i32 42
NSNumber *positiveFortyTwo = @+42;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i32 42
NSNumber *fortyTwoUnsigned = @42u;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i64 42
NSNumber *fortyTwoLong = @42l;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i64 42
NSNumber *fortyTwoLongLong = @42ll;
// CHECK: call{{.*}}@objc_msgSend{{.*}}float 0x400921FB60000000
NSNumber *piFloat = @3.141592654f;
// CHECK: call{{.*}}@objc_msgSend{{.*}}double 0x400921FB54411744
NSNumber *piDouble = @3.1415926535;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i8 signext 1
NSNumber *yesNumber = @__objc_yes;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i8 signext 0
NSNumber *noNumber = @__objc_no;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i8 signext 1
NSNumber *yesNumber1 = @YES;
// CHECK: call{{.*}}@objc_msgSend{{.*}}i8 signext 0
NSNumber *noNumber1 = @NO;
NSDictionary *dictionary = @{@"name" : NSUserName(),
@"date" : [NSDate date] };
return __objc_yes == __objc_no;
}
// rdar://10579122
typedef BOOL (^foo)(void);
extern void bar(foo a);
void baz(void) {
bar(^(void) { return YES; });
}
Cleanup the handling of noinline function attributes, -fno-inline, -fno-inline-functions, -O0, and optnone. These were really, really tangled together: - We used the noinline LLVM attribute for -fno-inline - But not for -fno-inline-functions (breaking LTO) - But we did use it for -finline-hint-functions (yay, LTO is happy!) - But we didn't for -O0 (LTO is sad yet again...) - We had weird structuring of CodeGenOpts with both an inlining enumeration and a boolean. They interacted in weird ways and needlessly. - A *lot* of set smashing went on with setting these, and then got worse when we considered optnone and other inlining-effecting attributes. - A bunch of inline affecting attributes were managed in a completely different place from -fno-inline. - Even with -fno-inline we failed to put the LLVM noinline attribute onto many generated function definitions because they didn't show up as AST-level functions. - If you passed -O0 but -finline-functions we would run the normal inliner pass in LLVM despite it being in the O0 pipeline, which really doesn't make much sense. - Lastly, we used things like '-fno-inline' to manipulate the pass pipeline which forced the pass pipeline to be much more parameterizable than it really needs to be. Instead we can *just* use the optimization level to select a pipeline and control the rest via attributes. Sadly, this causes a bunch of churn in tests because we don't run the optimizer in the tests and check the contents of attribute sets. It would be awesome if attribute sets were a bit more FileCheck friendly, but oh well. I think this is a significant improvement and should remove the semantic need to change what inliner pass we run in order to comply with the requested inlining semantics by relying completely on attributes. It also cleans up tho optnone and related handling a bit. One unfortunate aspect of this is that for generating alwaysinline routines like those in OpenMP we end up removing noinline and then adding alwaysinline. I tried a bunch of other approaches, but because we recompute function attributes from scratch and don't have a declaration here I couldn't find anything substantially cleaner than this. Differential Revision: https://reviews.llvm.org/D28053 llvm-svn: 290398
2016-12-23 09:24:49 +08:00
// CHECK: attributes [[NUW]] = { noinline {{(norecurse )?}}nounwind{{.*}} }