Skip to content

Commit ff0a540

Browse files
author
tobias.gruber
committed
Adapt unittest to suggested changes
1 parent 1717c42 commit ff0a540

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

clang/unittests/StaticAnalyzer/ExprEngineVisitTest.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ void emitErrorReport(CheckerContext &C, const BugType &Bug,
2929
}
3030
}
3131

32-
inline std::string getMemRegionName(const SVal &Val) {
33-
if (auto MemVal = llvm::dyn_cast<loc::MemRegionVal>(Val))
34-
return MemVal->getRegion()->getDescriptiveName(false);
35-
if (auto ComVal = llvm::dyn_cast<nonloc::LazyCompoundVal>(Val))
36-
return ComVal->getRegion()->getDescriptiveName(false);
37-
return "";
38-
}
39-
4032
#define CREATE_EXPR_ENGINE_CHECKER(CHECKER_NAME, CALLBACK, STMT_TYPE, \
4133
BUG_NAME) \
4234
class CHECKER_NAME : public Checker<check::CALLBACK<STMT_TYPE>> { \
@@ -58,15 +50,22 @@ class MemAccessChecker : public Checker<check::Location, check::Bind> {
5850
public:
5951
void checkLocation(const SVal &Loc, bool IsLoad, const Stmt *S,
6052
CheckerContext &C) const {
61-
emitErrorReport(C, Bug, "checkLocation: Loc = " + getMemRegionName(Loc));
53+
emitErrorReport(C, Bug, "checkLocation: Loc = " + dumpToString(Loc) + ", Stmt = " + S->getStmtClassName());
6254
}
6355

6456
void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &C) const {
65-
emitErrorReport(C, Bug, "checkBind: Loc = " + getMemRegionName(Loc));
57+
emitErrorReport(C, Bug, "checkBind: Loc = " + dumpToString(Loc) + ", Val = " + dumpToString(Val) + ", Stmt = " + S->getStmtClassName());
6658
}
6759

6860
private:
6961
const BugType Bug{this, "MemAccess"};
62+
63+
std::string dumpToString(SVal V) const {
64+
std::string StrBuf;
65+
llvm::raw_string_ostream StrStream{StrBuf};
66+
V.dumpToStream(StrStream);
67+
return StrBuf;
68+
}
7069
};
7170

7271
void addExprEngineVisitPreChecker(AnalysisASTConsumer &AnalysisConsumer,
@@ -132,10 +131,15 @@ TEST(ExprEngineVisitTest, checkLocationAndBind) {
132131
)",
133132
Diags));
134133

135-
std::string RHSMsg = "checkLocation: Loc = MyClassRead";
136-
std::string LHSMsg = "checkBind: Loc = MyClassWrite";
137-
EXPECT_NE(Diags.find(RHSMsg), std::string::npos);
138-
EXPECT_NE(Diags.find(LHSMsg), std::string::npos);
134+
std::string LocMsg = "checkLocation: Loc = lazyCompoundVal{0x0,MyClassRead}, Stmt = ImplicitCastExpr";
135+
std::string BindMsg = "checkBind: Loc = &MyClassWrite, Val = lazyCompoundVal{0x0,MyClassRead}, Stmt = CXXOperatorCallExpr";
136+
std::size_t LocPos = Diags.find(LocMsg);
137+
std::size_t BindPos = Diags.find(BindMsg);
138+
EXPECT_NE(LocPos, std::string::npos);
139+
EXPECT_NE(BindPos, std::string::npos);
140+
// Check order: first checkLocation is called, then checkBind.
141+
// In the diagnosis, however, the messages appear in reverse order.
142+
EXPECT_TRUE(LocPos > BindPos);
139143
}
140144

141145
} // namespace

0 commit comments

Comments
 (0)