18

clang-check, Clang's built-in static analysis tool, has an -analyze option, for which the help string just says "Run static analysis engine." With this flag, I see very little output from running clang-check on several of my files; without it, I see a lot of warnings.

Isn't running the static analysis engine the main purpose of running clang-check, which is a static analysis tool? Why do I see less output when running the engine, and what does the tool do without the flag?

Kyle Strand
  • 15,941
  • 8
  • 72
  • 167

1 Answers1

11

Running clang-check without any options runs the -fsyntax-only mode (checking for correct syntax). Only if you specify -analyze, the static analysis tool is executed, see http://clang-analyzer.llvm.org/available_checks.html for a full list of executed checks.

  • Note 1: you can do various other stuff with clang-check, e.g. AST dumping.
  • Note 2: you cannot specify -fsyntax-only and -analyze at the same time.
D.R.
  • 20,268
  • 21
  • 102
  • 205
  • It sounds like `-analyze` should *always* emit *more* output, then, which does not appear to be the behavior I'm seeing... – Kyle Strand Jul 08 '15 at 23:33
  • No, it doesn't. `-analyze` does not combine `-fsyntax-only` and its own checkers. – D.R. Jul 08 '15 at 23:33
  • Oh, it sounds like I misunderstood your second point, then. So `-analyze` won't emit errors for code that (according to Clang) isn't even syntactically valid? – Kyle Strand Jul 08 '15 at 23:59