return true;
}
+static Expr *ignoreIntegerCasts(Expr *E) {
+ while (true) {
+ if (ExplicitCastExpr *ECE = dyn_cast<ExplicitCastExpr>(E)) {
+ if (ECE->getType()->isIntegerType()) {
+ E = ECE->getSubExpr();
+ continue;
+ }
+ }
+
+ return E;
+ }
+}
+
/// CheckPointerConversion - Check the pointer conversion from the
/// expression From to the type ToType. This routine checks for
/// ambiguous or inaccessible derived-to-base pointer
Kind = CK_BitCast;
if (!IsCStyleOrFunctionalCast && !FromType->isAnyPointerType() &&
- From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) ==
+ ignoreIntegerCasts(From)->
+ isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) ==
Expr::NPCK_ZeroExpression) {
if (Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy))
DiagRuntimeBehavior(From->getExprLoc(), From,
// RUN: %clang_cc1 %s -verify
+#define NLL (unsigned long long)0
+
// PR10837: Warn if a non-pointer-typed expression is folded to a null pointer
int *p = 0;
int *q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
p = 0;
q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
r = 1 - 1; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
+ p = NLL;
}