Add Sema::isNullPointerConstant which extwarns if necessary. Use it in Sema::CheckConditionalOperands.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60319 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 0c17c75..fa4b71b 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1582,13 +1582,13 @@
// the type of the other operand."
if ((lexT->isPointerType() || lexT->isBlockPointerType() ||
Context.isObjCObjectPointerType(lexT)) &&
- rex->isNullPointerConstant(Context)) {
+ isNullPointerConstant(rex)) {
ImpCastExprToType(rex, lexT); // promote the null to a pointer.
return lexT;
}
if ((rexT->isPointerType() || rexT->isBlockPointerType() ||
Context.isObjCObjectPointerType(rexT)) &&
- lex->isNullPointerConstant(Context)) {
+ isNullPointerConstant(lex)) {
ImpCastExprToType(lex, rexT); // promote the null to a pointer.
return rexT;
}
@@ -3706,3 +3706,23 @@
*Result = EvalResult.Val.getInt();
return false;
}
+
+bool Sema::isNullPointerConstant(const Expr *E)
+{
+ Expr::EvalResult EvalResult;
+
+ if (!E->isNullPointerConstant(EvalResult, Context))
+ return false;
+
+ if (EvalResult.Diag) {
+ Diag(E->getExprLoc(), diag::ext_null_pointer_expr_not_ice) <<
+ E->getSourceRange();
+
+ // Print the reason it's not a constant.
+ if (Diags.getDiagnosticLevel(diag::ext_null_pointer_expr_not_ice) !=
+ Diagnostic::Ignored)
+ Diag(EvalResult.DiagLoc, EvalResult.Diag);
+ }
+
+ return true;
+}