mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 12:26:52 +08:00
[analyzer] Track null and undef values through expressions with cleanups.
ExprWithCleanups wraps full-expressions that require temporary destructors and highlights the moment of time in which these destructors need to be called (i.e., "at the end of the full-expression..."). Such expressions don't necessarily return an object; they may return anything, including a null or undefined value. When the analyzer tries to understand where the null or undefined value came from in order to present better diagnostics to the user, it will now skip any ExprWithCleanups it encounters and look into the expression itself. Differential Revision: https://reviews.llvm.org/D48204 llvm-svn: 335559
This commit is contained in:
@@ -141,6 +141,8 @@ const Expr *bugreporter::getDerefExpr(const Stmt *S) {
|
||||
E = AE->getBase();
|
||||
} else if (const auto *PE = dyn_cast<ParenExpr>(E)) {
|
||||
E = PE->getSubExpr();
|
||||
} else if (const auto *EWC = dyn_cast<ExprWithCleanups>(E)) {
|
||||
E = EWC->getSubExpr();
|
||||
} else {
|
||||
// Other arbitrary stuff.
|
||||
break;
|
||||
|
||||
@@ -84,3 +84,20 @@ void testRefToField(Bar *b) {
|
||||
int &x = b->x; // no-warning
|
||||
x = 5;
|
||||
}
|
||||
|
||||
namespace get_deref_expr_with_cleanups {
|
||||
struct S {
|
||||
~S();
|
||||
};
|
||||
S *conjure();
|
||||
// The argument won't be used, but it'll cause cleanups
|
||||
// to appear around the call site.
|
||||
S *get_conjured(S _) {
|
||||
S *s = conjure();
|
||||
if (s) {}
|
||||
return s;
|
||||
}
|
||||
void test_conjured() {
|
||||
S &s = *get_conjured(S()); // no-warning
|
||||
}
|
||||
} // namespace get_deref_expr_with_cleanups
|
||||
|
||||
Reference in New Issue
Block a user