GCC and static analysis
lwn.net
lwn.net
1. Lexing: http://en.wikipedia.org/wiki/Lexical_analysis
2. Parsing: http://en.wikipedia.org/wiki/Parsing This is where you would do static analysis on the high level language. [edited because zeugma's comment made we realize it was ambiguous which kind of static analysis I meant]
3. High-level (C, C++, etc.) source is transformed to a three-address intermediate representation called Gimple: http://gcc.gnu.org/onlinedocs/gccint/GIMPLE.html This phase exists for two reasons. One, gcc support many languages, so all of those high-level languages are translated to a single representation. That way they can all share the same optimization and code generation back-end. "Three address" languages are kind of like a simplified version of assembly, but it's completely machine agnostic.
4. Various optimization passes are performed on the architecture agnostic intermediate representation (which, again, in gcc is Gimple). These are optimizations that have nothing to do with the target machine. Many modern compilers transform the code into SSA form (http://en.wikipedia.org/wiki/Static_single_assignment_form) to enable other optimizations.
5. The optimized intermediate representation gets transformed into the assembly language for the target architecture. Architecture specific optimizations will typically happen at this phase.
6. The assembly language for the particular architecture is passed to an assembler for that architecture, which does the job of producing an actual binary-executable. gcc calls as, which means that what you probably think of as "compiling" isn't even done by gcc itself!
In theory, you could ask a compiler to stop and produce output at any one of those phases. In practice, I'm not sure how many of these phases you can ask gcc to stop at. I know, for example, that if you pass -S to gcc, it will stop at the end of step 5, and you can see the assembly it produces for the high-level source you give it. I'm not sure about stopping earlier.
Now. Back to your actual questions. No, you can't install the "static analyzer," because it is deeply integrated into the compiler - it's part of phase 2 from above. You may be able to ask gcc to stop after it produces Gimple, which would allow you to take advantage of its static analysis. But, as this article mentions, that means you're married to the Gimple format for doing all further work with the program.
Clang/LLVM is much more modular, library oriented.(which is why the Google engineer wanted to switch to it). You can just link to the needed front-end and do the static analysis without generating the LLVM bytecode.
So yes, you could install a static-analyzer without the whole compiler.
You can install a static analyzer without the whole compiler, but not gcc's static analyzer. I assumed "the static analyzer" that sp332 was talking about was specifically gcc's, not any generic static analyzer.
> Did you like this article? Please accept our trial subscription offer to be able to see more content like it and to participate in the discussion.