Skip to content

Static analyzer cherrypicks 1 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
a129173
[analyzer] RetainCount: Add support for OSRequiredCast().
haoNoQ Jun 19, 2019
1a1eb30
[analyzer] DeadStores: Add a crude suppression files generated by Dri…
haoNoQ Jun 19, 2019
fbcd0ff
[analyzer] NFC: Change evalCall() to provide a CallEvent.
haoNoQ Jun 19, 2019
767a5c4
[analyzer] Fix JSON dumps for dynamic type information.
haoNoQ Jun 19, 2019
7a8f00c
[analyzer] Fix JSON dumps for location contexts.
haoNoQ Jun 19, 2019
8ad26fd
[analyzer] Fix JSON dumps for store clusters.
haoNoQ Jun 19, 2019
57a50d2
[analyzer] exploded-graph-rewriter: Fix escaping StringRegions.
haoNoQ Jun 19, 2019
6aecb50
[analyzer] exploded-graph-rewriter: Implement a --diff mode.
haoNoQ Jun 19, 2019
4ba630a
[analyzer] DeadStores: Update the crude suppression for files generat…
haoNoQ Jun 20, 2019
292d81f
[analyzer] Fix JSON dumps for ExplodedNodes
Jun 24, 2019
1c919cf
[analyzer] print() JSONify: ProgramPoint revision
Jun 24, 2019
c08ef72
[analyzer] ExprEngine: Escape pointers in bitwise operations
Jun 25, 2019
7266f07
[analyzer] Add more timers for performance profiling.
haoNoQ Jun 25, 2019
ade7a5e
[analyzer] NFC: exploded-graph-rewriter: Extract some code into funct…
haoNoQ Jun 25, 2019
cec5820
[analyzer] exploded-graph-rewriter: Add support for range constraints.
haoNoQ Jun 25, 2019
26838f1
[analyzer] exploded-graph-rewriter: Fix escaping for bitwise-or.
haoNoQ Jun 25, 2019
db14325
[analyzer] print() JSONify: Create pointers
Jun 25, 2019
a7a7930
[analyzer] exploded-graph-rewriter: Prettier location context dumps.
haoNoQ Jun 26, 2019
8496fee
[analyzer] Fix clang-tidy crash on GCCAsmStmt
nhukc Jun 27, 2019
2a91883
[analyzer] exploded-graph-rewriter: Implement program point tags.
haoNoQ Jul 1, 2019
b30e422
[analyzer] exploded-graph-rewriter: Add support for dynamic types.
haoNoQ Jul 1, 2019
8b8a2a8
[analyzer] NFC: Add a convenient CallDescriptionMap class.
haoNoQ Jul 1, 2019
769533c
[analyzer] NFC: CallDescription: Implement describing C library funct…
haoNoQ Jul 1, 2019
9d48193
[analyzer] CStringChecker: Modernize to use CallDescriptions.
haoNoQ Jul 1, 2019
264ac3e
[analyzer] NonnullGlobalConstants: Don't be confused by a _Nonnull at…
haoNoQ Jul 1, 2019
7f5f4d5
[analyzer] Fix invalidation when returning into a ctor initializer.
haoNoQ Jul 1, 2019
75e90a7
[analyzer] Support kfree in MallocChecker
nhukc Jul 1, 2019
c2680c6
[analyzer] exploded-graph-rewriter: Add support for objects under con…
haoNoQ Jul 2, 2019
dc3ce0e
[analyzer] exploded-graph-rewriter: Improve program point dumps.
haoNoQ Jul 2, 2019
5497e33
[analyzer] exploded-graph-rewriter: Implement a dark color scheme.
haoNoQ Jul 2, 2019
9bb31d3
[IDF] Generalize IDFCalculator to be used with Clang's CFG
Szelethus Jul 2, 2019
8a0a8b3
Removed extra ; after function definition
Szelethus Jul 2, 2019
e2711bb
Attempt to fix buildbot failures with MSVC
Szelethus Jul 2, 2019
76b8d1b
Minor cleanup.
Artem-B Jul 12, 2019
56e5cd9
[analyzer] exploded-graph-rewriter: Implement checker messages.
haoNoQ Jul 3, 2019
0cb9509
[analyzer] exploded-graph-rewriter: Collapse very long statement pret…
haoNoQ Jul 3, 2019
577a874
[analyzer] exploded-graph-rewriter: NFC: Add more comments.
haoNoQ Jul 3, 2019
f7beaf3
[analyzer] exploded-graph-rewriter: Implement bug nodes and sink nodes.
haoNoQ Jul 3, 2019
1bd5a87
[Dominators] PR42041: Skip nullpointer successors
Szelethus Jul 3, 2019
b342985
[analyzer][Dominator] Add post dominators to CFG + a new debug checker
Szelethus Jul 3, 2019
e039601
Specialize an anchor() function in the correct namespace
Szelethus Jul 3, 2019
34e0c85
Make a buildbot using a buggy gcc happy
Szelethus Jul 3, 2019
01bae84
[analyzer][CFG] Return the correct terminator condition
Szelethus Jul 3, 2019
6216514
Revert "[analyzer][CFG] Return the correct terminator condition"
Szelethus Jul 3, 2019
509b06f
[analyzer] exploded-graph-rewriter: Implement a black-and-white color…
haoNoQ Jul 3, 2019
b23a7c1
[analyzer] ReturnValueChecker: Model the guaranteed boolean return va…
Jul 4, 2019
697bc2b
[CTU] Add support for virtual functions
Jul 4, 2019
727894b
[CFG] Add a new function to get the proper condition of a CFGBlock
Szelethus Jul 5, 2019
7197458
[analyzer][Dominators][NFC] Add unit tests
Szelethus Jul 5, 2019
e3c67d0
Fix a buildbot failure due to the AST's lifetime ending before the test
Szelethus Jul 5, 2019
224dd18
[analyzer][IDF] Add a control dependency calculator + a new debug che…
Szelethus Jul 5, 2019
7c6fe06
[analyzer] Track terminator conditions on which a tracked expression …
Szelethus Jul 5, 2019
de2cf58
[analyzer] Add a debug analyzer config to place an event for each tra…
Szelethus Jul 5, 2019
b4f5ac1
Removed the test case added in D63538 due to windows buildbot failures
Szelethus Jul 5, 2019
b502c82
[analyzer] Add analyzer option to limit the number of imported TUs
Jul 8, 2019
25ab0b8
[analyzer] exploded-graph-rewriter: Implement a single-path mode.
haoNoQ Jul 8, 2019
ee6a8d9
[analyzer] exploded-graph-rewriter: Implement a topology-only mode.
haoNoQ Jul 8, 2019
9a4d419
[analyzer] CastValueChecker: Model casts
Jul 10, 2019
f06353d
Revert "[analyzer] CastValueChecker: Model casts"
Jul 9, 2019
52a7a12
[analyzer] CastValueChecker: Model casts
Jul 10, 2019
b153f8e
[analyzer] CastValueChecker: Remove a dump()
Jul 10, 2019
bd14f18
[analyzer] exploded-graph-rewriter: Fix filenames in program point.
haoNoQ Jul 11, 2019
a0b89c7
[analyzer] exploded-graph-rewriter: Improve source location dumps.
haoNoQ Jul 12, 2019
47c09e3
NFC: Unforget a colon in a few CHECK: directives.
haoNoQ Jul 12, 2019
47155f0
[analyzer] MallocChecker: Prevent Integer Set Library false positives
Jul 18, 2019
c443faa
[analyzer] Fix -Wunused-function in NDEBUG builds with #ifdef LLVM_DU…
MaskRay Jul 22, 2019
1bfc7a3
[CrossTU] Added CTU argument to diagnostic consumer create fn.
balazske Jul 23, 2019
c1187cc
PlistDiagnostics Fix for compile warning (NFC).
balazske Jul 23, 2019
c1b1f83
Fix exporting SARIF files from scan-build on Windows.
AaronBallman Jul 24, 2019
34408f6
[CrossTU] Add a function to retrieve original source location.
balazske Jul 24, 2019
83306e8
[CrossTU] Fix plist macro expansion if macro in other file.
balazske Jul 25, 2019
fb6a2e4
Fix failing test plist-macros-with-expansion-ctu.c
balazske Jul 25, 2019
d385af7
[analyzer] Add yaml parser to GenericTaintChecker
boga95 Jul 28, 2019
4f3e566
Buildbot fix for r367190
boga95 Jul 28, 2019
ac22da6
Fix taint-generic.c on Windows, handle case in OS error
rnk Jul 29, 2019
86d1d30
[analyzer] StackFrameContext: Add NodeBuilderContext::blockCount() to…
Aug 1, 2019
0cdd168
[Analyzer] Iterator Checkers - Fix for Crash on Iterator Differences
Aug 5, 2019
da029db
[analyzer] Fix scan-build's plist output in plist-html mode.
haoNoQ Aug 8, 2019
f92e410
[analyzer] ConditionBRVisitor: Fix HTML PathDiagnosticPopUpPieces
Aug 9, 2019
e4f5bee
[analyzer] CastValueChecker: Model castAs(), getAs()
Aug 9, 2019
ae73909
[analyzer][NFC] Refactoring BugReporter.cpp P1.: Store interesting sy…
Szelethus Aug 13, 2019
ceaf317
[analyzer][NFC] Refactoring BugReporter.cpp P2.: Clean up the constru…
Szelethus Aug 13, 2019
830bb80
[analyzer][NFC] Refactoring BugReporter.cpp P3.: std::shared_pointer<…
Szelethus Aug 13, 2019
03ba03c
[analyzer][NFC] Refactoring BugReporter.cpp P4.: If it can be const, …
Szelethus Aug 13, 2019
2bda66a
[analyzer][NFC] Refactoring BugReporter.cpp P5.: Compact mile long fu…
Szelethus Aug 13, 2019
6e8af13
[analyzer][NFC] Address inlines of D65484
Szelethus Aug 13, 2019
b68349e
Remove the extra `;`.
darkbuck Aug 13, 2019
d659255
[analyzer][NFC] Refactoring BugReporter.cpp P6.: Completely get rid o…
Szelethus Aug 13, 2019
8e595b6
[analyzer][NFC] Make sure that the BugReport is not modified during t…
Szelethus Aug 13, 2019
5d52cad
[analyzer] Disable the checker-plugins test on Darwin.
haoNoQ Aug 13, 2019
082a04e
[analyzer] exploded-graph-rewriter: Open the converted graph immediat…
haoNoQ Aug 13, 2019
6fb513c
[analyzer] exploded-graph-rewriter: NFC: Refactor explorers into trim…
haoNoQ Aug 13, 2019
58304c8
[analyzer] exploded-graph-rewriter: Implement manual graph trimming.
haoNoQ Aug 13, 2019
9daf5aa
[analyzer] exploded-graph-rewriter: Implement displaying Store pointers.
haoNoQ Aug 13, 2019
64a7601
[analyzer] Prune calls to functions with linear CFGs that return a no…
Szelethus Aug 13, 2019
c47b77d
[analyzer] Track the right hand side of the last store regardless of …
Szelethus Aug 13, 2019
65cdff4
[analyzer][NFC] Prepare visitors for different tracking kinds
Szelethus Aug 14, 2019
2bc5f14
[analyzer] Don't delete TaintConfig copy constructor
bulbazord Aug 14, 2019
46c51f4
Fix the -Wunused-variable warning.
hokein Aug 14, 2019
915553a
[analyzer] Note last writes to a condition only in a nested stackframe
Szelethus Aug 14, 2019
38af1e5
[analyzer][CFG] Don't track the condition of asserts
Szelethus Aug 14, 2019
76e9a32
[analyzer][NFC] Prove that we only track the evaluated part of the co…
Szelethus Aug 14, 2019
b61668f
[CFG] Introduce CFGElementRef, a wrapper that knows it's position in …
Szelethus Aug 14, 2019
80789df
[NFCI] Always initialize BugReport const fields
bulbazord Aug 15, 2019
23ab9d8
[analyzer] Warn about -analyzer-configs being meant for development p…
Szelethus Aug 15, 2019
b2b970a
[analyzer] Analysis: Silence checkers
Aug 16, 2019
67b9d76
[analyzer] Turn an assert into an if condition
Szelethus Aug 17, 2019
1131e93
[analyzer] NFC: Drop support for extra text attached to bug reports.
haoNoQ Aug 20, 2019
d7d5a99
[analyzer] NFC: Rename GRBugReporter to PathSensitiveBugReporter.
haoNoQ Aug 20, 2019
59d2c07
[CallGraph] Take into accound calls that aren't within any function b…
haoNoQ Aug 20, 2019
859e660
[analyzer] Improve VirtualCallChecker and enable parts of it by default.
haoNoQ Aug 20, 2019
37f9ef0
[analyzer] Fix a crash when destroying a non-region.
haoNoQ Aug 20, 2019
04abbac
[analyzer] NFC: Remove the BugTypes set from BugReporter.
haoNoQ Aug 20, 2019
e6b0eed
Removed some dead code in BugReporter and related files
gribozavr Aug 21, 2019
0f21765
[analyzer] Mention whether an event is about a condition in a bug rep…
Szelethus Aug 21, 2019
cac5f30
[analyzer][NFC] Add different interestingness kinds
Szelethus Aug 21, 2019
280b7ed
[analyzer] Don't make ConditionBRVisitor events prunable when the con…
Szelethus Aug 21, 2019
29ce5ea
[analyzer] Mention whether an event is about a condition in a bug rep…
Szelethus Aug 21, 2019
2e39e0d
[analyzer] TrackConstraintBRVisitor: Do not track unknown values
Aug 22, 2019
372a835
[analyzer] CastValueChecker: Store the dynamic types and casts
Aug 22, 2019
80c6a0d
[analyzer] CastValueChecker: Rewrite dead header hotfix
Aug 22, 2019
f339739
[analyzer] CastValueChecker: Try to fix the buildbots
Aug 22, 2019
0376405
[analyzer] Don't track the condition of foreach loops
Szelethus Aug 22, 2019
818dd65
[analyzer] CastValueChecker: Model isa(), isa_and_nonnull()
Aug 22, 2019
aaa2160
[analyzer] Enable control dependency condition tracking by default
Szelethus Aug 22, 2019
5af8cb0
Remove an unused function, suppress -Wunused-function warning.
hokein Aug 22, 2019
cfe5b5e
[analyzer] DynamicTypeInfo: Avoid putting null regions into dynamic t…
haoNoQ Aug 23, 2019
00e714c
[analyzer] CastValueChecker: Avoid modeling casts between objects.
haoNoQ Aug 23, 2019
fd6e1ad
[analyzer] CastValueChecker: Provide DynamicTypeMap with pointer type…
haoNoQ Aug 23, 2019
e1f0dc2
[analyzer] CastValueChecker: Correctly model results of based-to-deri…
haoNoQ Aug 23, 2019
70e388f
[analyzer] Avoid unnecessary enum range check on LValueToRValue casts
Aug 23, 2019
c867f49
[analyzer] Analysis: Fix checker silencing
Aug 24, 2019
a5881a2
[analyzer] Trust global initializers when analyzing main().
haoNoQ Aug 28, 2019
e4af1c1
[analyzer] pr43036: Fix support for operator 'sizeof...'.
haoNoQ Aug 28, 2019
4538b74
[analyzer] Fix analyzer warnings on analyzer.
haoNoQ Aug 28, 2019
fda60dd
[CFG] Make representation of destructor calls more accurate.
haoNoQ Aug 28, 2019
035b74e
[analyzer] Fix more analyzer warnings on analyzer and libAnalysis.
haoNoQ Aug 28, 2019
807d0ec
[Analyzer] Iterator Checkers - Make range errors and invalidated acce…
Aug 29, 2019
2a829ba
[CFG] Fix CFG for statement-expressions in return values.
haoNoQ Aug 29, 2019
0332d84
[analyzer] Add a checker option to detect nested dead stores
Sep 3, 2019
d0af813
[analyzer] NonNullParamChecker and CStringChecker parameter number in…
Sep 3, 2019
c1a51bd
Unbreak the build after r370798
d0k Sep 3, 2019
8f90df1
[analyzer] scan-build: handle --sysroot=/path in addition to --sysroo…
haoNoQ Sep 5, 2019
69ca3da
[analyzer] pr43179: Make CallDescription defensive against C variadic…
haoNoQ Sep 6, 2019
373f8bc
[analyzer] Add minimal support for fix-it hints.
haoNoQ Sep 6, 2019
67419f1
Move prop-sink branch to monorepo.
boga95 Sep 8, 2019
9dbd22a
[analyzer] NFC: Introduce sub-classes for path-sensitive and basic re…
haoNoQ Sep 9, 2019
decdf63
[analyzer] NFC: Simplify bug report equivalence classes to not be ili…
haoNoQ Sep 9, 2019
707c3f5
[analyzer] NFC: Re-implement stack hints as a side map in BugReport.
haoNoQ Sep 11, 2019
4ed346d
[analyzer] NFC: Move getStmt() and createEndOfPath() out of PathDiagn…
haoNoQ Sep 11, 2019
1c5ee0c
[analyzer] NFC: Move resetDiagnosticLocationToMainFile() to BugReporter.
haoNoQ Sep 11, 2019
fa82362
[analyzer] NFC: Move PathDiagnostic classes to libAnalysis.
haoNoQ Sep 11, 2019
5801e63
[analyzer] Don't run the analyzer for -analyzer-list-enabled-checkers
Sep 12, 2019
080f156
[analyzer][NFC] Fix inconsistent references to checkers as "checks"
Sep 12, 2019
786ed1e
[ClangTidy] Adjust the name getCheckName to getCheckerName due to API…
timshen91 Sep 12, 2019
3346f0b
[CFG] Add dumps for CFGElement and CFGElementRef
Sep 12, 2019
7d0f759
[analyzer] Fix the 'analyzer-enabled-checkers.c' test on non-linux ma…
haoNoQ Sep 12, 2019
804e170
Fix a perl warning: Scalar value @ArgParts[0] better written as $ArgP…
sylvestre Sep 13, 2019
25cbd18
[analyzer] PR43102: Fix an assertion and an out-of-bounds error for d…
Sep 18, 2019
60641f9
[StaticAnalyzer] Use llvm::StringLiteral instead of StringRef in few …
d0k Sep 20, 2019
d0c7973
Reland '[analyzer][MallocChecker][NFC] Document and reorganize some f…
Sep 20, 2019
adc75dc
Fix a documentation error
Sep 20, 2019
d7cbbf0
Attempt to fix a windows buildbot failure
Sep 21, 2019
40f5913
[NFCI] Return PathSensitiveBugReport where appropriate
bulbazord Sep 23, 2019
34eb3ca
[analyzer] Avoid small vectors of non-default-constructibles.
haoNoQ Sep 26, 2019
8bb333a
Don't install example analyzer plugins
aaronpuchert Sep 28, 2019
bee81d3
Teach CallGraph to look into Generic Lambdas.
Sep 30, 2019
da07275
BlockInCriticalSectionChecker - silence static analyzer dyn_cast null…
RKSimon Oct 13, 2019
27bfa17
[analyzer] exploded-graph-rewriter: Make node headers a bit lighter.
haoNoQ Oct 17, 2019
0e07329
[analyzer] Display cast kinds in program point dumps.
haoNoQ Oct 17, 2019
e9b4862
[analyzer] Assign truly stable identifiers to exploded nodes.
haoNoQ Oct 17, 2019
0ebcbd1
[analyzer] exploded-graph-rewriter: Fix typo in r375186. Unbreaks tests.
haoNoQ Oct 17, 2019
00e99fc
[analyzer] Fix hidden node traversal in exploded graph dumps.
haoNoQ Oct 18, 2019
4db5dff
[analyzer] exploded-graph-rewriter: Fix dump for state 0.
haoNoQ Oct 18, 2019
a528b53
[analyzer] Drop the logic for collapsing the state if it's same as in…
haoNoQ Oct 18, 2019
048cc7c
[analyzer] Fix FieldRegion dumps.
haoNoQ Oct 18, 2019
8e66c8b
[analyzer] exploded-graph-rewriter: Rename Environment to Expressions.
haoNoQ Oct 18, 2019
e2698a7
[analyzer] exploded-graph-rewriter: Unforget to censor stmt_ids in th…
haoNoQ Oct 18, 2019
750990e
[analyzer] Specify the C++ standard in more tests.
haoNoQ Oct 19, 2019
dcb65b6
[analyzer] Fix off-by-one in operator call parameter binding.
haoNoQ Oct 23, 2019
7fb1a17
Revert "Teach CallGraph to look into Generic Lambdas."
haoNoQ Oct 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[analyzer] NFC: Change evalCall() to provide a CallEvent.
This changes the checker callback signature to use the modern, easy to
use interface. Additionally, this unblocks future work on allowing
checkers to implement evalCall() for calls that don't correspond to any
call-expression or require additional information that's only available
as part of the CallEvent, such as C++ constructors and destructors.

Differential Revision: https://reviews.llvm.org/D62440

llvm-svn: 363893
(cherry picked from commit 4482063)
  • Loading branch information
haoNoQ committed Oct 25, 2019
commit fbcd0ffa95dce00929c3a664ce6a4f0bc0dfab4e
5 changes: 3 additions & 2 deletions clang/include/clang/StaticAnalyzer/Core/Checker.h
Original file line number Diff line number Diff line change
@@ -474,8 +474,9 @@ class Assume {

class Call {
template <typename CHECKER>
static bool _evalCall(void *checker, const CallExpr *CE, CheckerContext &C) {
return ((const CHECKER *)checker)->evalCall(CE, C);
static bool _evalCall(void *checker, const CallEvent &Call,
CheckerContext &C) {
return ((const CHECKER *)checker)->evalCall(Call, C);
}

public:
2 changes: 1 addition & 1 deletion clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
Original file line number Diff line number Diff line change
@@ -490,7 +490,7 @@ class CheckerManager {
CheckerFn<ProgramStateRef (ProgramStateRef, const SVal &cond,
bool assumption)>;

using EvalCallFunc = CheckerFn<bool (const CallExpr *, CheckerContext &)>;
using EvalCallFunc = CheckerFn<bool (const CallEvent &, CheckerContext &)>;

using CheckEndOfTranslationUnit =
CheckerFn<void (const TranslationUnitDecl *, AnalysisManager &,
31 changes: 18 additions & 13 deletions clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
#include "clang/Basic/Builtins.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"

using namespace clang;
@@ -23,30 +24,32 @@ namespace {

class BuiltinFunctionChecker : public Checker<eval::Call> {
public:
bool evalCall(const CallExpr *CE, CheckerContext &C) const;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;
};

}

bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
CheckerContext &C) const {
ProgramStateRef state = C.getState();
const FunctionDecl *FD = C.getCalleeDecl(CE);
const LocationContext *LCtx = C.getLocationContext();
const auto *FD = dyn_cast_or_null<FunctionDecl>(Call.getDecl());
if (!FD)
return false;

const LocationContext *LCtx = C.getLocationContext();
const Expr *CE = Call.getOriginExpr();

switch (FD->getBuiltinID()) {
default:
return false;

case Builtin::BI__builtin_assume: {
assert (CE->arg_begin() != CE->arg_end());
SVal ArgSVal = C.getSVal(CE->getArg(0));
if (ArgSVal.isUndef())
assert (Call.getNumArgs() > 0);
SVal Arg = Call.getArgSVal(0);
if (Arg.isUndef())
return true; // Return true to model purity.

state = state->assume(ArgSVal.castAs<DefinedOrUnknownSVal>(), true);
state = state->assume(Arg.castAs<DefinedOrUnknownSVal>(), true);
// FIXME: do we want to warn here? Not right now. The most reports might
// come from infeasible paths, thus being false positives.
if (!state) {
@@ -66,9 +69,9 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
// __builtin_assume_aligned, just return the value of the subexpression.
// __builtin_addressof is going from a reference to a pointer, but those
// are represented the same way in the analyzer.
assert (CE->arg_begin() != CE->arg_end());
SVal X = C.getSVal(*(CE->arg_begin()));
C.addTransition(state->BindExpr(CE, LCtx, X));
assert (Call.getNumArgs() > 0);
SVal Arg = Call.getArgSVal(0);
C.addTransition(state->BindExpr(CE, LCtx, Arg));
return true;
}

@@ -82,12 +85,14 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
// Set the extent of the region in bytes. This enables us to use the
// SVal of the argument directly. If we save the extent in bits, we
// cannot represent values like symbol*8.
auto Size = C.getSVal(*(CE->arg_begin())).castAs<DefinedOrUnknownSVal>();
auto Size = Call.getArgSVal(0);
if (Size.isUndef())
return true; // Return true to model purity.

SValBuilder& svalBuilder = C.getSValBuilder();
DefinedOrUnknownSVal Extent = R->getExtent(svalBuilder);
DefinedOrUnknownSVal extentMatchesSizeArg =
svalBuilder.evalEQ(state, Extent, Size);
svalBuilder.evalEQ(state, Extent, Size.castAs<DefinedOrUnknownSVal>());
state = state->assume(extentMatchesSizeArg, true);
assert(state && "The region should not have any previous constraints");

7 changes: 4 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "llvm/ADT/STLExtras.h"
@@ -57,7 +58,7 @@ class CStringChecker : public Checker< eval::Call,

static void *getTag() { static int tag; return &tag; }

bool evalCall(const CallExpr *CE, CheckerContext &C) const;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;
void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const;
void checkLiveSymbols(ProgramStateRef state, SymbolReaper &SR) const;
void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const;
@@ -2334,8 +2335,8 @@ static CStringChecker::FnCheck identifyCall(const CallExpr *CE,
return nullptr;
}

bool CStringChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {

bool CStringChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
const auto *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
FnCheck evalFunction = identifyCall(CE, C);

// If the callee isn't a string function, let another checker handle it.
57 changes: 20 additions & 37 deletions clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
@@ -37,53 +38,44 @@ bool isRootChanged(intptr_t k) { return k == ROOT_CHANGED; }
// ROOT_CHANGED<--chdir(..)-- JAIL_ENTERED<--chdir(..)--
// | |
// bug<--foo()-- JAIL_ENTERED<--foo()--
class ChrootChecker : public Checker<eval::Call, check::PreStmt<CallExpr> > {
mutable IdentifierInfo *II_chroot, *II_chdir;
class ChrootChecker : public Checker<eval::Call, check::PreCall> {
// This bug refers to possibly break out of a chroot() jail.
mutable std::unique_ptr<BuiltinBug> BT_BreakJail;

const CallDescription Chroot{"chroot", 1}, Chdir{"chdir", 1};

public:
ChrootChecker() : II_chroot(nullptr), II_chdir(nullptr) {}
ChrootChecker() {}

static void *getTag() {
static int x;
return &x;
}

bool evalCall(const CallExpr *CE, CheckerContext &C) const;
void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;
void checkPreCall(const CallEvent &Call, CheckerContext &C) const;

private:
void Chroot(CheckerContext &C, const CallExpr *CE) const;
void Chdir(CheckerContext &C, const CallExpr *CE) const;
void evalChroot(const CallEvent &Call, CheckerContext &C) const;
void evalChdir(const CallEvent &Call, CheckerContext &C) const;
};

} // end anonymous namespace

bool ChrootChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
const FunctionDecl *FD = C.getCalleeDecl(CE);
if (!FD)
return false;

ASTContext &Ctx = C.getASTContext();
if (!II_chroot)
II_chroot = &Ctx.Idents.get("chroot");
if (!II_chdir)
II_chdir = &Ctx.Idents.get("chdir");

if (FD->getIdentifier() == II_chroot) {
Chroot(C, CE);
bool ChrootChecker::evalCall(const CallEvent &Call, CheckerContext &C) const {
if (Call.isCalled(Chroot)) {
evalChroot(Call, C);
return true;
}
if (FD->getIdentifier() == II_chdir) {
Chdir(C, CE);
if (Call.isCalled(Chdir)) {
evalChdir(Call, C);
return true;
}

return false;
}

void ChrootChecker::Chroot(CheckerContext &C, const CallExpr *CE) const {
void ChrootChecker::evalChroot(const CallEvent &Call, CheckerContext &C) const {
ProgramStateRef state = C.getState();
ProgramStateManager &Mgr = state->getStateManager();

@@ -93,7 +85,7 @@ void ChrootChecker::Chroot(CheckerContext &C, const CallExpr *CE) const {
C.addTransition(state);
}

void ChrootChecker::Chdir(CheckerContext &C, const CallExpr *CE) const {
void ChrootChecker::evalChdir(const CallEvent &Call, CheckerContext &C) const {
ProgramStateRef state = C.getState();
ProgramStateManager &Mgr = state->getStateManager();

@@ -103,7 +95,7 @@ void ChrootChecker::Chdir(CheckerContext &C, const CallExpr *CE) const {
return;

// After chdir("/"), enter the jail, set the enum value JAIL_ENTERED.
const Expr *ArgExpr = CE->getArg(0);
const Expr *ArgExpr = Call.getArgExpr(0);
SVal ArgVal = C.getSVal(ArgExpr);

if (const MemRegion *R = ArgVal.getAsRegion()) {
@@ -120,19 +112,10 @@ void ChrootChecker::Chdir(CheckerContext &C, const CallExpr *CE) const {
}

// Check the jail state before any function call except chroot and chdir().
void ChrootChecker::checkPreStmt(const CallExpr *CE, CheckerContext &C) const {
const FunctionDecl *FD = C.getCalleeDecl(CE);
if (!FD)
return;

ASTContext &Ctx = C.getASTContext();
if (!II_chroot)
II_chroot = &Ctx.Idents.get("chroot");
if (!II_chdir)
II_chdir = &Ctx.Idents.get("chdir");

void ChrootChecker::checkPreCall(const CallEvent &Call,
CheckerContext &C) const {
// Ignore chroot and chdir.
if (FD->getIdentifier() == II_chroot || FD->getIdentifier() == II_chdir)
if (Call.isCalled(Chroot) || Call.isCalled(Chdir))
return;

// If jail state is ROOT_CHANGED, generate BugReport.
9 changes: 7 additions & 2 deletions clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/IssueHash.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ScopedPrinter.h"
@@ -53,7 +54,7 @@ class ExprInspectionChecker : public Checker<eval::Call, check::DeadSymbols,
ExplodedNode *N) const;

public:
bool evalCall(const CallExpr *CE, CheckerContext &C) const;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
void checkEndAnalysis(ExplodedGraph &G, BugReporter &BR,
ExprEngine &Eng) const;
@@ -63,8 +64,12 @@ class ExprInspectionChecker : public Checker<eval::Call, check::DeadSymbols,
REGISTER_SET_WITH_PROGRAMSTATE(MarkedSymbols, SymbolRef)
REGISTER_MAP_WITH_PROGRAMSTATE(DenotedSymbols, SymbolRef, const StringLiteral *)

bool ExprInspectionChecker::evalCall(const CallExpr *CE,
bool ExprInspectionChecker::evalCall(const CallEvent &Call,
CheckerContext &C) const {
const auto *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
if (!CE)
return false;

// These checks should have no effect on the surrounding environment
// (globals should not be invalidated, etc), hence the use of evalCall.
FnCheck Handler = llvm::StringSwitch<FnCheck>(C.getCalleeName(CE))
Original file line number Diff line number Diff line change
@@ -886,14 +886,19 @@ void RetainCountChecker::processNonLeakError(ProgramStateRef St,
// Handle the return values of retain-count-related functions.
//===----------------------------------------------------------------------===//

bool RetainCountChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
bool RetainCountChecker::evalCall(const CallEvent &Call,
CheckerContext &C) const {
ProgramStateRef state = C.getState();
const FunctionDecl *FD = C.getCalleeDecl(CE);
const auto *FD = dyn_cast_or_null<FunctionDecl>(Call.getDecl());
if (!FD)
return false;

const auto *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
if (!CE)
return false;

RetainSummaryManager &SmrMgr = getSummaryManager(C);
QualType ResultTy = CE->getCallReturnType(C.getASTContext());
QualType ResultTy = Call.getResultType();

// See if the function has 'rc_ownership_trusted_implementation'
// annotate attribute. If it does, we will not inline it.
Original file line number Diff line number Diff line change
@@ -310,7 +310,7 @@ class RetainCountChecker
const CallEvent &Call,
CheckerContext &C) const;

bool evalCall(const CallExpr *CE, CheckerContext &C) const;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;

ProgramStateRef evalAssume(ProgramStateRef state, SVal Cond,
bool Assumption) const;
24 changes: 11 additions & 13 deletions clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
Original file line number Diff line number Diff line change
@@ -26,32 +26,30 @@ using namespace ento;

namespace {
class SmartPtrModeling : public Checker<eval::Call> {
bool isNullAfterMoveMethod(const CXXInstanceCall *Call) const;
bool isNullAfterMoveMethod(const CallEvent &Call) const;

public:
bool evalCall(const CallExpr *CE, CheckerContext &C) const;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;
};
} // end of anonymous namespace

bool SmartPtrModeling::isNullAfterMoveMethod(
const CXXInstanceCall *Call) const {
bool SmartPtrModeling::isNullAfterMoveMethod(const CallEvent &Call) const {
// TODO: Update CallDescription to support anonymous calls?
// TODO: Handle other methods, such as .get() or .release().
// But once we do, we'd need a visitor to explain null dereferences
// that are found via such modeling.
const auto *CD = dyn_cast_or_null<CXXConversionDecl>(Call->getDecl());
const auto *CD = dyn_cast_or_null<CXXConversionDecl>(Call.getDecl());
return CD && CD->getConversionType()->isBooleanType();
}

bool SmartPtrModeling::evalCall(const CallExpr *CE, CheckerContext &C) const {
CallEventRef<> CallRef = C.getStateManager().getCallEventManager().getCall(
CE, C.getState(), C.getLocationContext());
const auto *Call = dyn_cast_or_null<CXXInstanceCall>(CallRef);
if (!Call || !isNullAfterMoveMethod(Call))
bool SmartPtrModeling::evalCall(const CallEvent &Call,
CheckerContext &C) const {
if (!isNullAfterMoveMethod(Call))
return false;

ProgramStateRef State = C.getState();
const MemRegion *ThisR = Call->getCXXThisVal().getAsRegion();
const MemRegion *ThisR =
cast<CXXInstanceCall>(&Call)->getCXXThisVal().getAsRegion();

if (!move::isMovedFrom(State, ThisR)) {
// TODO: Model this case as well. At least, avoid invalidation of globals.
@@ -60,8 +58,8 @@ bool SmartPtrModeling::evalCall(const CallExpr *CE, CheckerContext &C) const {

// TODO: Add a note to bug reports describing this decision.
C.addTransition(
State->BindExpr(CE, C.getLocationContext(),
C.getSValBuilder().makeZeroVal(CE->getType())));
State->BindExpr(Call.getOriginExpr(), C.getLocationContext(),
C.getSValBuilder().makeZeroVal(Call.getResultType())));
return true;
}

10 changes: 7 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
Original file line number Diff line number Diff line change
@@ -224,7 +224,7 @@ class StdLibraryFunctionsChecker : public Checker<check::PostCall, eval::Call> {

public:
void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
bool evalCall(const CallExpr *CE, CheckerContext &C) const;
bool evalCall(const CallEvent &Call, CheckerContext &C) const;

private:
Optional<FunctionSummaryTy> findFunctionSummary(const FunctionDecl *FD,
@@ -367,12 +367,16 @@ void StdLibraryFunctionsChecker::checkPostCall(const CallEvent &Call,
}
}

bool StdLibraryFunctionsChecker::evalCall(const CallExpr *CE,
bool StdLibraryFunctionsChecker::evalCall(const CallEvent &Call,
CheckerContext &C) const {
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CE->getCalleeDecl());
const auto *FD = dyn_cast_or_null<FunctionDecl>(Call.getDecl());
if (!FD)
return false;

const auto *CE = dyn_cast_or_null<CallExpr>(Call.getOriginExpr());
if (!CE)
return false;

Optional<FunctionSummaryTy> FoundSummary = findFunctionSummary(FD, CE, C);
if (!FoundSummary)
return false;
Loading