Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / lang / objc / objc_direct-methods / main.m
blob5d8ff17bb43e0957430851191fdf06d6f046e212
1 #import <Foundation/Foundation.h>
3 int side_effect = 0;
5 NSString *str = @"some string";
7 const char *directCallConflictingName() {
8   return "wrong function";
11 @interface Foo : NSObject {
12   int instance_var;
14 -(int) entryPoint;
15 @end
17 @implementation Foo
18 -(int) entryPoint
20   // Try calling directly with self. Same as in the main method otherwise.
21   return 0; //%self.expect_expr("[self directCallNoArgs]", result_summary='"called directCallNoArgs"')
22             //%self.expect_expr("[self directCallArgs: 1111]", result_value="2345")
23             //%self.expect_expr("side_effect = 0; [self directCallVoidReturn]; side_effect", result_value="4321")
24             //%self.expect_expr("[self directCallNSStringArg: str]", result_summary='@"some string"')
25             //%self.expect_expr("[self directCallIdArg: (id)str]", result_summary='@"some string appendix"')
26             //%self.expect_expr("[self directCallConflictingName]", result_summary='"correct function"')
27             //%self.expect_expr("[self directCallWithCategory]", result_summary='"called function with category"')
30 // Declare several objc_direct functions we can test.
31 -(const char *) directCallNoArgs __attribute__((objc_direct))
33   return "called directCallNoArgs";
36 -(void) directCallVoidReturn __attribute__((objc_direct))
38   side_effect = 4321;
41 -(int) directCallArgs:(int)i __attribute__((objc_direct))
43   // Use the arg in some way to make sure that gets passed correctly.
44   return i + 1234;
47 -(NSString *) directCallNSStringArg:(NSString *)str __attribute__((objc_direct))
49   return str;
52 -(NSString *) directCallIdArg:(id)param __attribute__((objc_direct))
54   return [param stringByAppendingString:@" appendix"];
57 // We have another function with the same name above. Make sure this doesn't influence
58 // what we call.
59 -(const char *) directCallConflictingName  __attribute__((objc_direct))
61   return "correct function";
63 @end
66 @interface Foo (Cat)
67 @end
69 @implementation Foo (Cat)
70 -(const char *) directCallWithCategory  __attribute__((objc_direct))
72   return "called function with category";
74 @end
76 int main()
78   Foo *foo = [[Foo alloc] init];
79   [foo directCallNoArgs];
80   [foo directCallArgs: 1];
81   [foo directCallVoidReturn];
82   [foo directCallNSStringArg: str];
83   [foo directCallIdArg: (id)str];
84   [foo entryPoint];  //%self.expect_expr("[foo directCallNoArgs]", result_summary='"called directCallNoArgs"')
85                      //%self.expect_expr("[foo directCallArgs: 1111]", result_value="2345")
86                      //%self.expect_expr("side_effect = 0; [foo directCallVoidReturn]; side_effect", result_value="4321")
87                      //%self.expect_expr("[foo directCallNSStringArg: str]", result_summary='@"some string"')
88                      //%self.expect_expr("[foo directCallIdArg: (id)str]", result_summary='@"some string appendix"')
89                      //%self.expect_expr("[foo directCallConflictingName]", result_summary='"correct function"')
90                      //%self.expect_expr("[foo directCallWithCategory]", result_summary='"called function with category"')
91   return 0;