]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/70295
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 22 Mar 2016 08:11:14 +0000 (08:11 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 22 Mar 2016 08:11:14 +0000 (08:11 +0000)
* gimplify.c (gimplify_modify_expr): Call gimple_set_no_warning
on assign if (*from_p) is a comparison, set it to
TREE_NO_WARNING (*from_p).

* c-c++-common/nonnull-1.c (func): Remove parens around cp4 != 0.
(func2): New function for cond with parens, xfail warning for c++.
* g++.dg/warn/Wnonnull-compare-8.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234392 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/nonnull-1.c
gcc/testsuite/g++.dg/warn/Wnonnull-compare-8.C [new file with mode: 0644]

index c98a2092ce9eff2f4be77baf35e61f15e13e7b05..5193c97ecb71f15c5cd68aa0098dbfde6179742d 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/70295
+       * gimplify.c (gimplify_modify_expr): Call gimple_set_no_warning
+       on assign if (*from_p) is a comparison, set it to
+       TREE_NO_WARNING (*from_p).
+
 2016-03-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/70326
index 3687e7aa1833d4513808163e7efcf42179cf019e..5d03435cb0ac39d3be7874da1f010b0d205f8119 100644 (file)
@@ -4850,6 +4850,8 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
     {
       assign = gimple_build_assign (*to_p, *from_p);
       gimple_set_location (assign, EXPR_LOCATION (*expr_p));
+      if (COMPARISON_CLASS_P (*from_p))
+       gimple_set_no_warning (assign, TREE_NO_WARNING (*from_p));
     }
 
   if (gimplify_ctxp->into_ssa && is_gimple_reg (*to_p))
index dc47ef1a84692d0ac4253f47a13b57e8fbd59f4a..25a36ddbc207885f591e77c8bd86c60d288f6929 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/70295
+       * c-c++-common/nonnull-1.c (func): Remove parens around cp4 != 0.
+       (func2): New function for cond with parens, xfail warning for c++.
+       * g++.dg/warn/Wnonnull-compare-8.C: New test.
+
 2016-03-22  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/70096
index fb2814c44981cfbccc74fb926f61aabb6b92f8e9..2446d6fbcfa65b177f69e746ac30333998e263ab 100644 (file)
@@ -24,5 +24,11 @@ func (char *cp1, char *cp2, char *cp3, char *cp4)
   if (NULL != cp3) /* { dg-warning "nonnull argument" "cp3 compared to NULL" } */
     return 3;
 
-  return (cp4 != 0) ? 0 : 1; /* { dg-warning "nonnull argument" "cp4 compared to NULL" } */
+  return cp4 != 0 ? 0 : 1; /* { dg-warning "nonnull argument" "cp4 compared to NULL" } */
+}
+
+__attribute__((nonnull (1))) int
+func2 (char *cp)
+{
+  return (cp != NULL) ? 1 : 0; /* { dg-warning "nonnull argument" "cp compared to NULL" { xfail c++ } } */
 }
diff --git a/gcc/testsuite/g++.dg/warn/Wnonnull-compare-8.C b/gcc/testsuite/g++.dg/warn/Wnonnull-compare-8.C
new file mode 100644 (file)
index 0000000..28dcac8
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/70295
+// { dg-do compile }
+// { dg-options "-O2 -Wnonnull-compare" }
+
+struct A { A (); virtual ~A (); bool foo (bool); };
+struct B : virtual public A { B (); virtual ~B (); };
+
+bool
+A::foo (bool x)
+{
+  if (x && dynamic_cast<B *>(this) != (B *) 0) // { dg-bogus "nonnull argument" }
+    return true;
+  return false;
+}