r200521 - [Sema] For -Wnon-literal-null-conversion warning, look through integer casts, which are used
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Jan 30 23:51:32 PST 2014
Author: akirtzidis
Date: Fri Jan 31 01:51:32 2014
New Revision: 200521
URL: http://llvm.org/viewvc/llvm-project?rev=200521&view=rev
Log:
[Sema] For -Wnon-literal-null-conversion warning, look through integer casts, which are used
by some projects in their null macro.
rdar://15925483
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/Sema/warn-null.c
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=200521&r1=200520&r2=200521&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Jan 31 01:51:32 2014
@@ -2622,6 +2622,19 @@ bool Sema::FunctionParamTypesAreEqual(co
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
@@ -2638,7 +2651,8 @@ bool Sema::CheckPointerConversion(Expr *
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,
Modified: cfe/trunk/test/Sema/warn-null.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-null.c?rev=200521&r1=200520&r2=200521&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-null.c (original)
+++ cfe/trunk/test/Sema/warn-null.c Fri Jan 31 01:51:32 2014
@@ -1,5 +1,7 @@
// 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}}
@@ -8,4 +10,5 @@ void f() {
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;
}
More information about the cfe-commits
mailing list