[PATCH] Fix to PR10837 - Warn when assigning null character to pointer

Ivan A. Kosarev ivan at ivan-labs.com
Fri Nov 8 05:43:09 PST 2013


Hi rnk,

This patch solves the request for adding a diagnostic for assignmets and initialization by "improper" null pointer constants in C.

http://llvm.org/bugs/show_bug.cgi?id=10837

http://llvm-reviews.chandlerc.com/D2124

Files:
  lib/Sema/SemaExpr.cpp

Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10614,6 +10614,15 @@
 
   switch (ConvTy) {
   case Compatible:
+    // See if a proper null pointer constant is to be assigned.
+    if (DstType->isAnyPointerType() &&
+         !SrcType->isAnyPointerType() &&
+         SrcExpr->isNullPointerConstant(Context,
+           Expr::NPC_NeverValueDependent) == Expr::NPCK_ZeroExpression &&
+        !isUnevaluatedContext())
+      Diag(SrcExpr->getExprLoc(), diag::warn_non_literal_null_pointer)
+        << DstType << SrcExpr->getSourceRange();
+
       DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr);
       return false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2124.1.patch
Type: text/x-patch
Size: 728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131108/999b8e7e/attachment.bin>


More information about the cfe-commits mailing list