summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2011-09-15 23:51:29 +0000
committerRichard Trieu <rtrieu@google.com>2011-09-15 23:51:29 +0000
commita25995dbb40e09734e1a4afeda6ac8d03a73607c (patch)
tree41e0422ca2f1b9214aaf7a22b361efd8e641ec36 /clang/lib
parent10a93ff8e0d9d24dcb79d5725287401c261b6bf0 (diff)
downloadbcm5719-llvm-a25995dbb40e09734e1a4afeda6ac8d03a73607c.tar.gz
bcm5719-llvm-a25995dbb40e09734e1a4afeda6ac8d03a73607c.zip
Change checkArithmeticNull() to use a NonNullType, instead of checking both the
LHSType and RHSType for everything. llvm-svn: 139878
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp20
1 files changed, 6 insertions, 14 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 16b55f1aee4..73c8283dbd0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7691,20 +7691,14 @@ static void checkArithmeticNull(Sema &S, ExprResult &LHS, ExprResult &RHS,
bool LHSNull = isa<GNUNullExpr>(LHS.get()->IgnoreParenImpCasts());
bool RHSNull = isa<GNUNullExpr>(RHS.get()->IgnoreParenImpCasts());
- // Detect when a NULL constant is used improperly in an expression. These
- // are mainly cases where the null pointer is used as an integer instead
- // of a pointer.
- if (!LHSNull && !RHSNull)
- return;
-
QualType LHSType = LHS.get()->getType();
QualType RHSType = RHS.get()->getType();
+ QualType NonNullType = LHSNull ? RHSType : LHSType;
// Avoid analyzing cases where the result will either be invalid (and
// diagnosed as such) or entirely valid and not something to warn about.
- if (LHSType->isBlockPointerType() || LHSType->isMemberPointerType() ||
- LHSType->isFunctionType() || RHSType->isBlockPointerType() ||
- RHSType->isMemberPointerType() || RHSType->isFunctionType())
+ if ((!LHSNull && !RHSNull) || NonNullType->isBlockPointerType() ||
+ NonNullType->isMemberPointerType() || NonNullType->isFunctionType())
return;
// Comparison operations would not make sense with a null pointer no matter
@@ -7718,14 +7712,12 @@ static void checkArithmeticNull(Sema &S, ExprResult &LHS, ExprResult &RHS,
// The rest of the operations only make sense with a null pointer
// if the other expression is a pointer.
- if (LHSNull == RHSNull || LHSType->isAnyPointerType() ||
- LHSType->canDecayToPointerType() || RHSType->isAnyPointerType() ||
- RHSType->canDecayToPointerType())
+ if (LHSNull == RHSNull || NonNullType->isAnyPointerType() ||
+ NonNullType->canDecayToPointerType())
return;
S.Diag(Loc, diag::warn_null_in_comparison_operation)
- << LHSNull /* LHS is NULL */
- << (LHSNull ? RHS.get()->getType() : LHS.get()->getType())
+ << LHSNull /* LHS is NULL */ << NonNullType
<< LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
}
/// CreateBuiltinBinOp - Creates a new built-in binary operation with
OpenPOWER on IntegriCloud