On Feb 11, 2014, at 10:27 AM, jahanian <[email protected]> wrote:

> 
> On Feb 11, 2014, at 9:53 AM, Argyrios Kyrtzidis <[email protected]> wrote:
> 
>> Author: akirtzidis
>> Date: Tue Feb 11 11:53:22 2014
>> New Revision: 201165
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=201165&view=rev
>> Log:
>> [Sema] Revert the change in r200622 that allowed integer casts to silence 
>> -Wnon-literal-null-conversion in C code.
>> 
>> It is actually useful to warn in such cases, thanks to Dmitri for pushing on 
>> this and making us see the light!
>> 
>> Related to rdar://15925483 and rdar://15922612. The latter radar is where 
>> the usefulness of the warning is most clear.
> 
> People cannot read radars. Please provide content here.

In the latter radar the warning triggered on this:

error: expression which evaluates to zero treated as a null pointer constant of 
type 'uint64_t *' (aka 'unsigned long long *') 
[-Werror,-Wnon-literal-null-conversion]
                (uint64_t)0, (uint64_t)0);
                             ^~~~~~~~~~~

This is clearly either a copy-paster error at best or a lurking bug at worst. 
The parameter should be passed as NULL, otherwise it is misleading.

> - Fariborz
> 
>> 
>> Modified:
>>   cfe/trunk/lib/AST/Expr.cpp
>>   cfe/trunk/test/Sema/warn-null.c
>> 
>> Modified: cfe/trunk/lib/AST/Expr.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=201165&r1=201164&r2=201165&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/AST/Expr.cpp (original)
>> +++ cfe/trunk/lib/AST/Expr.cpp Tue Feb 11 11:53:22 2014
>> @@ -3061,9 +3061,6 @@ Expr::isNullPointerConstant(ASTContext &
>>            Pointee->isVoidType() &&                              // to void*
>>            CE->getSubExpr()->getType()->isIntegerType())         // from int.
>>          return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
>> -      // Or an integer cast.
>> -      } else if (CE->getType()->isIntegerType()) {
>> -        return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
>>      }
>>    }
>>  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
>> 
>> Modified: cfe/trunk/test/Sema/warn-null.c
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-null.c?rev=201165&r1=201164&r2=201165&view=diff
>> ==============================================================================
>> --- cfe/trunk/test/Sema/warn-null.c (original)
>> +++ cfe/trunk/test/Sema/warn-null.c Tue Feb 11 11:53:22 2014
>> @@ -1,6 +1,6 @@
>> // RUN: %clang_cc1 %s -verify
>> 
>> -#define NLL (unsigned long long)0
>> +#define SOME_ADDR (unsigned long long)0
>> 
>> // PR10837: Warn if a non-pointer-typed expression is folded to a null 
>> pointer
>> int *p = 0;
>> @@ -10,5 +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;
>> +  p = SOME_ADDR; // expected-warning{{expression which evaluates to zero 
>> treated as a null pointer constant}}
>> }
>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> [email protected]
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to