[Sema] For -Wnon-literal-null-conversion warning, look through integer casts, which are used
by some projects in their null macro. rdar://15925483 llvm-svn: 200521
This commit is contained in:
parent
ec68866f55
commit
278c8d33e2
|
@ -2622,6 +2622,19 @@ bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
|
||||||
return true;
|
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
|
/// CheckPointerConversion - Check the pointer conversion from the
|
||||||
/// expression From to the type ToType. This routine checks for
|
/// expression From to the type ToType. This routine checks for
|
||||||
/// ambiguous or inaccessible derived-to-base pointer
|
/// ambiguous or inaccessible derived-to-base pointer
|
||||||
|
@ -2638,7 +2651,8 @@ bool Sema::CheckPointerConversion(Expr *From, QualType ToType,
|
||||||
Kind = CK_BitCast;
|
Kind = CK_BitCast;
|
||||||
|
|
||||||
if (!IsCStyleOrFunctionalCast && !FromType->isAnyPointerType() &&
|
if (!IsCStyleOrFunctionalCast && !FromType->isAnyPointerType() &&
|
||||||
From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) ==
|
ignoreIntegerCasts(From)->
|
||||||
|
isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) ==
|
||||||
Expr::NPCK_ZeroExpression) {
|
Expr::NPCK_ZeroExpression) {
|
||||||
if (Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy))
|
if (Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy))
|
||||||
DiagRuntimeBehavior(From->getExprLoc(), From,
|
DiagRuntimeBehavior(From->getExprLoc(), From,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
// RUN: %clang_cc1 %s -verify
|
// 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
|
// PR10837: Warn if a non-pointer-typed expression is folded to a null pointer
|
||||||
int *p = 0;
|
int *p = 0;
|
||||||
int *q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
|
int *q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
|
||||||
|
@ -8,4 +10,5 @@ void f() {
|
||||||
p = 0;
|
p = 0;
|
||||||
q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
|
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}}
|
r = 1 - 1; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
|
||||||
|
p = NLL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue