llvm-project/clang/lib
Ted Kremenek eeccb30b94 Add support for the static analyzer to synthesize function implementations from external model files.
Currently the analyzer lazily models some functions using 'BodyFarm',
which constructs a fake function implementation that the analyzer
can simulate that approximates the semantics of the function when
it is called.  BodyFarm does this by constructing the AST for
such definitions on-the-fly.  One strength of BodyFarm
is that all symbols and types referenced by synthesized function
bodies are contextual adapted to the containing translation unit.
The downside is that these ASTs are hardcoded in Clang's own
source code.

A more scalable model is to allow these models to be defined as source
code in separate "model" files and have the analyzer use those
definitions lazily when a function body is needed.  Among other things,
it will allow more customization of the analyzer for specific APIs
and platforms.

This patch provides the initial infrastructure for this feature.
It extends BodyFarm to use an abstract API 'CodeInjector' that can be
used to synthesize function bodies.  That 'CodeInjector' is
implemented using a new 'ModelInjector' in libFrontend, which lazily
parses a model file and injects the ASTs into the current translation
unit.  

Models are currently found by specifying a 'model-path' as an
analyzer option; if no path is specified the CodeInjector is not
used, thus defaulting to the current behavior in the analyzer.

Models currently contain a single function definition, and can
be found by finding the file <function name>.model.  This is an
initial starting point for something more rich, but it bootstraps
this feature for future evolution.

This patch was contributed by Gábor Horváth as part of his
Google Summer of Code project.

Some notes:

- This introduces the notion of a "model file" into
  FrontendAction and the Preprocessor.  This nomenclature
  is specific to the static analyzer, but possibly could be
  generalized.  Essentially these are sources pulled in
  exogenously from the principal translation.

  Preprocessor gets a 'InitializeForModelFile' and
  'FinalizeForModelFile' which could possibly be hoisted out
  of Preprocessor if Preprocessor exposed a new API to
  change the PragmaHandlers and some other internal pieces.  This
  can be revisited.

  FrontendAction gets a 'isModelParsingAction()' predicate function
  used to allow a new FrontendAction to recycle the Preprocessor
  and ASTContext.  This name could probably be made something
  more general (i.e., not tied to 'model files') at the expense
  of losing the intent of why it exists.  This can be revisited.

- This is a moderate sized patch; it has gone through some amount of
  offline code review.  Most of the changes to the non-analyzer
  parts are fairly small, and would make little sense without
  the analyzer changes.

- Most of the analyzer changes are plumbing, with the interesting
  behavior being introduced by ModelInjector.cpp and
  ModelConsumer.cpp.

- The new functionality introduced by this change is off-by-default.
  It requires an analyzer config option to enable.

llvm-svn: 216550
2014-08-27 15:14:15 +00:00
..
ARCMigrate Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or just letting them be implicitly created. 2014-08-27 06:28:36 +00:00
AST Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or just letting them be implicitly created. 2014-08-27 06:28:36 +00:00
ASTMatchers Add hasAttr matcher for declarations. 2014-08-25 11:23:50 +00:00
Analysis Add support for the static analyzer to synthesize function implementations from external model files. 2014-08-27 15:14:15 +00:00
Basic Return a std::unique_ptr from getBufferForFile. NFC. 2014-08-26 19:54:40 +00:00
CodeGen Move some ARM-specific code from CGCall.cpp to TargetInfo.cpp 2014-08-27 10:43:15 +00:00
Driver [asan] Restore asan-rt name on linux back to pre-r216380. 2014-08-27 09:46:54 +00:00
Edit Objective-C modernization. Convert -initWithUTF8String messaging 2014-08-25 20:22:25 +00:00
Format clang-format: Fix regression in formatting of braced initializers. 2014-08-27 11:53:26 +00:00
Frontend Add support for the static analyzer to synthesize function implementations from external model files. 2014-08-27 15:14:15 +00:00
FrontendTool Make clang's rewrite engine a core feature 2014-07-16 16:48:33 +00:00
Headers arm_acle: Add mappings for dbg intrinsic 2014-08-26 12:48:11 +00:00
Index Header guard canonicalization, clang part. 2014-08-13 16:25:19 +00:00
Lex Add support for the static analyzer to synthesize function implementations from external model files. 2014-08-27 15:14:15 +00:00
Parse PR20760: Don't assert (and produce better diagnostics) if a default initializer 2014-08-27 03:23:12 +00:00
Rewrite Make clang's rewrite engine a core feature 2014-07-16 16:48:33 +00:00
Sema Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or just letting them be implicitly created. 2014-08-27 06:28:36 +00:00
Serialization [modules] Don't assert when merging virtual functions that override other 2014-08-26 23:29:11 +00:00
StaticAnalyzer Add support for the static analyzer to synthesize function implementations from external model files. 2014-08-27 15:14:15 +00:00
Tooling Sure-up MemoryBuffer ownership in JSONCompilationDatabase's ctor. 2014-08-08 22:01:06 +00:00
CMakeLists.txt Fix build with various feature flag combinations 2014-07-14 22:17:22 +00:00
Makefile Make clang's rewrite engine a core feature 2014-07-16 16:48:33 +00:00