aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/StaticAnalyzer
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/StaticAnalyzer')
-rw-r--r--clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp24
-rw-r--r--clang/unittests/StaticAnalyzer/SValTest.cpp3
2 files changed, 23 insertions, 4 deletions
diff --git a/clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp b/clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp
index 12be228..ab4b8c7 100644
--- a/clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp
+++ b/clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp
@@ -55,11 +55,13 @@ public:
", Stmt = " + S->getStmtClassName());
}
- void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const {
+ void checkBind(SVal Loc, SVal Val, const Stmt *S, bool AtDeclInit,
+ CheckerContext &C) const {
emitErrorReport(C, Bug,
"checkBind: Loc = " + dumpToString(Loc) +
", Val = " + dumpToString(Val) +
- ", Stmt = " + S->getStmtClassName());
+ ", Stmt = " + S->getStmtClassName() +
+ ", AtDeclInit = " + (AtDeclInit ? "true" : "false"));
}
private:
@@ -140,7 +142,7 @@ TEST(ExprEngineVisitTest, checkLocationAndBind) {
"Stmt = ImplicitCastExpr";
std::string BindMsg =
"checkBind: Loc = &MyClassWrite, Val = lazyCompoundVal{0x0,MyClassRead}, "
- "Stmt = CXXOperatorCallExpr";
+ "Stmt = CXXOperatorCallExpr, AtDeclInit = false";
std::size_t LocPos = Diags.find(LocMsg);
std::size_t BindPos = Diags.find(BindMsg);
EXPECT_NE(LocPos, std::string::npos);
@@ -150,4 +152,20 @@ TEST(ExprEngineVisitTest, checkLocationAndBind) {
EXPECT_TRUE(LocPos > BindPos);
}
+TEST(ExprEngineVisitTest, checkLocationAndBindInitialization) {
+ std::string Diags;
+ EXPECT_TRUE(runCheckerOnCode<addMemAccessChecker>(R"(
+ class MyClass{
+ public:
+ int Value;
+ };
+ void top(MyClass param) {
+ MyClass MyClassWrite = param;
+ }
+ )",
+ Diags));
+
+ EXPECT_TRUE(StringRef(Diags).contains("AtDeclInit = true"));
+}
+
} // namespace
diff --git a/clang/unittests/StaticAnalyzer/SValTest.cpp b/clang/unittests/StaticAnalyzer/SValTest.cpp
index 58e9a8d..71f682a 100644
--- a/clang/unittests/StaticAnalyzer/SValTest.cpp
+++ b/clang/unittests/StaticAnalyzer/SValTest.cpp
@@ -61,7 +61,8 @@ using SVals = llvm::StringMap<SVal>;
/// can test whatever we gathered.
class SValCollector : public Checker<check::Bind, check::EndAnalysis> {
public:
- void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const {
+ void checkBind(SVal Loc, SVal Val, const Stmt *S, bool AtDeclInit,
+ CheckerContext &C) const {
// Skip instantly if we finished testing.
// Also, we care only for binds happening in variable initializations.
if (Tested || !isa<DeclStmt>(S))