diff options
author | John McCall <rjmccall@apple.com> | 2010-05-06 23:53:00 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-05-06 23:53:00 +0000 |
commit | 8eb662ed5e04bd0f494c7dbefacb7d45660ab9fa (patch) | |
tree | b890e9507d9fd8a0405c719916eeaefc9de2ba37 /lib | |
parent | 25a767835262562dc9e8809c057f984d2812cb46 (diff) |
After some discussion, conservatively extend our sentinel check to discard
casts, but still require the (casted) type to be a pointer. Fixes PR5685.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103216 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index f35a2e866a..3ac4d133fe 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -160,16 +160,19 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, ++sentinel; } Expr *sentinelExpr = Args[sentinel]; - if (sentinelExpr && (!isa<GNUNullExpr>(sentinelExpr) && - !sentinelExpr->isTypeDependent() && - !sentinelExpr->isValueDependent() && - (!sentinelExpr->getType()->isPointerType() || - !sentinelExpr->isNullPointerConstant(Context, - Expr::NPC_ValueDependentIsNull)))) { - Diag(Loc, diag::warn_missing_sentinel) << isMethod; - Diag(D->getLocation(), diag::note_sentinel_here) << isMethod; - } - return; + if (!sentinelExpr) return; + if (sentinelExpr->isTypeDependent()) return; + if (sentinelExpr->isValueDependent()) return; + if (sentinelExpr->getType()->isPointerType() && + sentinelExpr->IgnoreParenCasts()->isNullPointerConstant(Context, + Expr::NPC_ValueDependentIsNull)) + return; + + // Unfortunately, __null has type 'int'. + if (isa<GNUNullExpr>(sentinelExpr)) return; + + Diag(Loc, diag::warn_missing_sentinel) << isMethod; + Diag(D->getLocation(), diag::note_sentinel_here) << isMethod; } SourceRange Sema::getExprRange(ExprTy *E) const { |