]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/86210 (Missing -Wnonnull warning for function defined in the...
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 17:54:30 +0000 (19:54 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 17:54:30 +0000 (19:54 +0200)
Backported from mainline
2018-06-20  Jakub Jelinek  <jakub@redhat.com>

PR c++/86210
* c-common.c (check_nonnull_arg): Use fold_for_warn.  Adjust obsolete
comment.

* g++.dg/warn/Wnonnull4.C: New test.

From-SVN: r262102

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wnonnull4.C [new file with mode: 0644]

index c9f7773022d823339dba427e78ce80bf65e3d0b5..7ff31517eadc9d37f47e8781157acca3a9bf74f3 100644 (file)
@@ -1,6 +1,12 @@
 2018-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-06-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/86210
+       * c-common.c (check_nonnull_arg): Use fold_for_warn.  Adjust obsolete
+       comment.
+
        2017-11-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/83059
index ad029ea6b3d2dcd7dc0edb30370485911f237235..0c353b88fc957301a5a95319ac66f97be9745e2b 100644 (file)
@@ -9249,7 +9249,7 @@ check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
   if (TREE_CODE (TREE_TYPE (param)) != POINTER_TYPE)
     return;
 
-  if (integer_zerop (param))
+  if (integer_zerop (fold_for_warn (param)))
     warning_at (*ploc, OPT_Wnonnull, "null argument where non-null required "
                "(argument %lu)", (unsigned long) param_num);
 }
index 9621f65c96f42092547b3ce714532e62b7c24a2a..ccbbdae8d80a9a09697ca37e30892fd94e1a9d2a 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2018-06-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/86210
+       * g++.dg/warn/Wnonnull4.C: New test.
+
        PR tree-optimization/86231
        * gcc.dg/tree-ssa/vrp119.c: New test.
        * gcc.c-torture/execute/pr86231.c: New test.
diff --git a/gcc/testsuite/g++.dg/warn/Wnonnull4.C b/gcc/testsuite/g++.dg/warn/Wnonnull4.C
new file mode 100644 (file)
index 0000000..d07a445
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/86210
+// { dg-do compile }
+// { dg-options "-Wnonnull" }
+
+void *declared_not_defined (void *p) __attribute__((nonnull));
+
+inline void *declared_and_defined (void *p) __attribute__((nonnull));
+
+int
+main ()
+{
+  int *const p = 0;
+  declared_not_defined (p);    // { dg-warning "null argument where non-null required" }
+  declared_and_defined (p);    // { dg-warning "null argument where non-null required" }
+}
+
+void *
+declared_and_defined (void *p)
+{
+  return p;
+}