[PATCH] D22391: [Sema] Add warning for implicitly casting a null constant to a non null pointer type

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 3 14:35:07 PST 2017


ahatanak updated this revision to Diff 87016.
ahatanak marked 2 inline comments as done.
ahatanak added a comment.

Turning the warning on by default caused clang to issue warnings in many other cases, including Objective-C methods returning nil, which was something r240153 tried to avoid. If we want to disable the warning in Sema::ImpCastExprToType when the cast is part of a return statement of an ObjC method, we'll probably have to pass down a flag or something, which is probably not a good idea.

Instead of trying to issue the warning in Sema::ImpCastExprToType, the new patch checks whether there is a null constant in Sema::AddInitializerToDecl (which is needed to issue the first warning in null_constant_to_nonnull.c) and computeConditionalNullability (which is needed for the second warning). Also, it adds method Sema::checkNonNullExpr so that CheckNonNullExpr can be called from files other than SemaChecking.cpp.


https://reviews.llvm.org/D22391

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  test/Analysis/nullability-no-arc.mm
  test/Analysis/nullability_nullonly.mm
  test/Sema/conditional-expr.c
  test/Sema/null_constant_to_nonnull.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22391.87016.patch
Type: text/x-patch
Size: 9548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170203/b6032b39/attachment.bin>


More information about the cfe-commits mailing list