]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/86210 (Missing -Wnonnull warning for function defined in the same TU)
authorJakub Jelinek <jakub@redhat.com>
Wed, 20 Jun 2018 16:07:21 +0000 (18:07 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 20 Jun 2018 16:07:21 +0000 (18:07 +0200)
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: r261811

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 18388517e12f31805e0552d829fd3dfcc84e9a65..6b974daae27655887c1c66f80dd47643c4e837df 100644 (file)
@@ -1,3 +1,9 @@
+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-06-18  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/85602
index 0e8efb53f40b84144d94d35f11466efda2eef430..f5e1111a7726ce100cb3b40b9a7c8e1ec49ad219 100644 (file)
@@ -5404,10 +5404,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 36305cb29fa92fb13f77cc1453656854b50eb526..c30af52813fc467097f7a9d583083652ce101626 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/86210
+       * g++.dg/warn/Wnonnull4.C: New test.
+
 2018-06-20  Marek Polacek  <polacek@redhat.com>
 
        PR c++/86240
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;
+}