tweak some pointer sema checking stuff (which was added to implement PR4175) to
avoid emitting a warning on "someptr > 0". This is obviously questionable (they
could use != instead) but is reasonable, and the warning "ordered comparison
between pointer and integer" didn't make a ton of sense because 0 is a valid
null pointer constant.
Just silence the warning in this case, it is unlikely to indicate a bug.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79743 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 5f16ef3..15a3e40 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4350,31 +4350,33 @@
return ResultTy;
}
if (lType->isObjCObjectPointerType() && rType->isObjCObjectPointerType()) {
- if (!Context.areComparableObjCPointerTypes(lType, rType)) {
+ if (!Context.areComparableObjCPointerTypes(lType, rType))
Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
- }
ImpCastExprToType(rex, lType);
return ResultTy;
}
}
if (lType->isAnyPointerType() && rType->isIntegerType()) {
- if (isRelational)
- Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
+ if (!RHSIsNull) {
+ unsigned DiagID = isRelational
+ ? diag::ext_typecheck_ordered_comparison_of_pointer_integer
+ : diag::ext_typecheck_comparison_of_pointer_integer;
+ Diag(Loc, DiagID)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
- else if (!RHSIsNull)
- Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
- << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+ }
ImpCastExprToType(rex, lType); // promote the integer to pointer
return ResultTy;
}
if (lType->isIntegerType() && rType->isAnyPointerType()) {
- if (isRelational)
- Diag(Loc, diag::ext_typecheck_ordered_comparison_of_pointer_integer)
+ if (!LHSIsNull) {
+ unsigned DiagID = isRelational
+ ? diag::ext_typecheck_ordered_comparison_of_pointer_integer
+ : diag::ext_typecheck_comparison_of_pointer_integer;
+
+ Diag(Loc, DiagID)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
- else if (!LHSIsNull)
- Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
- << lType << rType << lex->getSourceRange() << rex->getSourceRange();
+ }
ImpCastExprToType(lex, rType); // promote the integer to pointer
return ResultTy;
}