0

I installed llvm and use scan-build to statically analyze a very simple demo project. In this project, I intentionally created a retain cycle and Xcode can immediately display a retain cycle warning in the editor. However, if I switch to use the following scan-build command line tool, it states that no bugs found and no report is generated in the end.

scan-build xcodebuild -workspace RetainCycleDemo.xcworkspace -scheme RetainCycleDemo -configuration Debug -sdk iphonesimulator15.2

Here's the retain cycle code snippet.

@interface ViewController ()

@property (nonatomic, copy) void(^aBlock)(void);

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.aBlock = ^{
        NSLog(@"current vc = %p", self);
    };
    self.aBlock();
}

What I want to do is use any static analyzer command line tool to find bugs such as some retain cycles. Since Xcode is able to report warnings in the editor, how can we ask it to generate a report that contains these warnings? Or is there any other command line tools we can use?

P. Tsin
  • 435
  • 4
  • 14

1 Answers1

0

If you call scan-build without any checkers, it will use default checkers for analysing. You can check default enabled checker with

scan-build --help

Checkers with "+" are enabled by default. Within the list, there are some checkers, that work with OSX (for example: osx.OSObjectRetainCount Check for leaks and improper reference count management for OSObject). To enable checker, use -enable-checker:

scan-build -enable-checker osx.OSObjectRetainCount <your compile command>

Wish it would help.

Thien Tran
  • 306
  • 1
  • 10