diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index ea4f3476b6c..fe47bfb12e9 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -6748,6 +6748,17 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E, << FixItHint::CreateInsertion(getLocForEndOfToken(E->getLocEnd()), "()"); } +void Sema::CheckAlwaysNonNullPointer(Expr *OrigExpr) { + if (const UnaryOperator *U = dyn_cast<UnaryOperator>(OrigExpr)) + if (U->getOpcode() == UO_LNot) + return CheckAlwaysNonNullPointer(U->getSubExpr()); + + Expr *E = OrigExpr->IgnoreParenImpCasts(); + QualType Source = E->getType(); + if (Source->isPointerType() || Source->canDecayToPointerType()) + DiagnoseAlwaysNonNullPointer(E, Expr::NPCK_NotNull, /*IsEqual*/ false, + SourceRange()); +} /// Diagnoses "dangerous" implicit conversions within the given /// expression (which is a full expression). Implements -Wconversion diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 37a08cfb081..a8429b92ed6 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -8413,7 +8413,10 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14] if (!LHS.get()->getType()->isScalarType() || !RHS.get()->getType()->isScalarType()) return InvalidOperands(Loc, LHS, RHS); - + + CheckAlwaysNonNullPointer(LHS.get()); + CheckAlwaysNonNullPointer(RHS.get()); + return Context.IntTy; } @@ -12971,6 +12974,7 @@ ExprResult Sema::CheckBooleanCondition(Expr *E, SourceLocation Loc) { << T << E->getSourceRange(); return ExprError(); } + CheckAlwaysNonNullPointer(E); } return E; |