[analyzer] StdLibraryFunctionsChecker: Associate summaries to FunctionDecls
authorGabor Marton <gabor.marton@ericsson.com>
Tue, 7 Apr 2020 09:44:33 +0000 (11:44 +0200)
committerGabor Marton <gabor.marton@ericsson.com>
Tue, 28 Apr 2020 08:00:50 +0000 (10:00 +0200)
commit62e747f6172942db0e9fd55a6a25f166f338459a
tree52a22eba4f99d47c0a026bd3228c31b05803478c
parente9c9329aa44e803416c3749e5a2e22d5a768f62a
[analyzer] StdLibraryFunctionsChecker: Associate summaries to FunctionDecls

Summary:
Currently we map function summaries to names (i.e. strings). We can
associate more summaries with different signatures to one name, this way
we support overloading. During a call event we check whether the
signature of the summary matches the signature of the callee and we
apply the summary only in that case.

In this patch we change this mapping to associate a summary to a
FunctionDecl. We do lookup operations when the summary map is
initialized. We lookup the given name and we match the signature of the
given summary against the lookup results. If the summary matches the
FunctionDecl (got from the lookup result) then we add that to the
summary map. During a call event we compare FunctionDecl pointers.
Advantages of this new refactor:
- Cleaner mapping and structure for the checker.
- Possibly way more efficient handling of call events.
- A summary is added only if that is relevant for the given TU.
- We can get the concrete FunctionDecl by the time when we create the
  summary, this opens up possibilities of further sanity checks
  regarding the summary cases and argument constraints.
- Opens up to future work when we'd like to store summaries from IR to a
  FunctionDecl (or from the Attributor results of the given
  FunctionDecl).

Note, we cannot support old C functions without prototypes.

Reviewers: NoQ, Szelethus, balazske, jdoerfert, sstefan1, uenoku

Subscribers: whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, gamesh411, Charusso, steakhal, uenoku, ASDenysPetrov, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77641
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp