Fixed as suggested. Thanks for reviewing.

Hi rsmith,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2124?vs=5427&id=5461#toc

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/PR10837.c

Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10614,8 +10614,17 @@
 
   switch (ConvTy) {
   case Compatible:
-      DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr);
-      return false;
+    // 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;
 
   case PointerToInt:
     DiagKind = diag::ext_typecheck_convert_pointer_int;
Index: test/Sema/PR10837.c
===================================================================
--- test/Sema/PR10837.c
+++ test/Sema/PR10837.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int *p = 0;
+
+int *q = '\0';  // expected-warning{{expression which evaluates to zero 
treated as a null pointer constant}}
+
+int *r = (1 - 1);  // expected-warning{{expression which evaluates to zero 
treated as a null pointer constant}}
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10614,8 +10614,17 @@
 
   switch (ConvTy) {
   case Compatible:
-      DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr);
-      return false;
+    // 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;
 
   case PointerToInt:
     DiagKind = diag::ext_typecheck_convert_pointer_int;
Index: test/Sema/PR10837.c
===================================================================
--- test/Sema/PR10837.c
+++ test/Sema/PR10837.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+int *p = 0;
+
+int *q = '\0';  // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
+
+int *r = (1 - 1);  // 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

Reply via email to