[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()
Artem Dergachev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 8 13:11:13 PDT 2019
NoQ added inline comments.
================
Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:94
+ [CastFromName, CastToName, IsNullReturn,
+ IsSimpleCast](BugReport &) -> std::string {
SmallString<128> Msg;
----------------
`IsDynamicCast`.
================
Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:98
- Out << "Assuming dynamic cast from '" << CastFromName << "' to '"
- << CastToName << "' succeeds";
- return Out.str();
- },
- /*IsPrunable=*/true);
+ Out << (!IsSimpleCast ? "Assuming dynamic cast " : "Dynamic cast ");
+ if (CastFromName)
----------------
More suggestions for the `:`-branch: "Hard cast" (a bit too jargon-y), "Safe cast", "Checked cast".
================
Comment at: clang/test/Analysis/cast-value.cpp:156-167
+void evalNonNullParamNonNullReturn(const Shape *S) {
+ const auto *C = cast<Circle>(S);
+ // expected-note at -1 {{Dynamic cast from 'Shape' to 'Circle' succeeds}}
+ // expected-note at -2 {{Assuming pointer value is null}}
+ // expected-note at -3 {{'C' initialized here}}
+
+ (void)(1 / !(bool)C);
----------------
Mmm, wait a sec. That's a false positive. `cast<>` doesn't accept null pointers. We have `cast_or_null` for this.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65889/new/
https://reviews.llvm.org/D65889
More information about the cfe-commits
mailing list