]> 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>
Fri, 22 Jun 2018 21:33:58 +0000 (23:33 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 21:33:58 +0000 (23:33 +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: r261970

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 00653a6029da09c239377ab11cfea0e61af436c8..a3e153a13db3a1aed5bed16c8028f57e715054ab 100644 (file)
@@ -1,6 +1,12 @@
 2018-06-22  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.
+
        2018-05-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/85696
index ade84866709bffff98f43973842387a87f7eac80..45be4bd1cbe3217a4f555d8fff57478f3df53bfb 100644 (file)
@@ -5434,10 +5434,8 @@ check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
   if (TREE_CODE (TREE_TYPE (param)) != POINTER_TYPE)
     return;
 
-  /* When not optimizing diagnose the simple cases of null arguments.
-     When optimization is enabled defer the checking until expansion
-     when more cases can be detected.  */
-  if (integer_zerop (param))
+  /* Diagnose the simple cases of null arguments.  */
+  if (integer_zerop (fold_for_warn (param)))
     {
       warning_at (pctx->loc, OPT_Wnonnull, "null argument where non-null "
                  "required (argument %lu)", (unsigned long) param_num);
index b24c781d102a9e80e5eee27d060faebd117f1196..65ecc947e5c3ae63ee41e70bc9b15166e4a38aa7 100644 (file)
@@ -8,6 +8,9 @@
 
        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;
+}