PR middle-end/101216 - spurious notes for function calls
authorMartin Sebor <msebor@redhat.com>
Fri, 25 Jun 2021 23:01:01 +0000 (17:01 -0600)
committerMartin Sebor <msebor@redhat.com>
Fri, 25 Jun 2021 23:01:01 +0000 (17:01 -0600)
PR middle-end/101216

gcc/ChangeLog:

* calls.c (maybe_warn_rdwr_sizes): Use the no_warning constant.

gcc/testsuite/ChangeLog:

* gcc.dg/Wnonnull-7.c: New test.

gcc/calls.c
gcc/testsuite/gcc.dg/Wnonnull-7.c [new file with mode: 0644]

index 27e8c45..f8a4b79 100644 (file)
@@ -2054,7 +2054,7 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
        *sizstr = '\0';
 
       /* Set if a warning has been issued for the current argument.  */
-      opt_code arg_warned = N_OPTS;
+      opt_code arg_warned = no_warning;
       location_t loc = EXPR_LOCATION (exp);
       tree ptr = access.second.ptr;
       if (*sizstr
@@ -2080,7 +2080,7 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
                               exp, sizidx + 1, sizstr))
            arg_warned = OPT_Wstringop_overflow_;
 
-         if (arg_warned != N_OPTS)
+         if (arg_warned != no_warning)
            {
              append_attrname (access, attrstr, sizeof attrstr);
              /* Remember a warning has been issued and avoid warning
@@ -2152,7 +2152,7 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
                arg_warned = OPT_Wnonnull;              
            }
 
-         if (arg_warned)
+         if (arg_warned != no_warning)
            {
              append_attrname (access, attrstr, sizeof attrstr);
              /* Remember a warning has been issued and avoid warning
diff --git a/gcc/testsuite/gcc.dg/Wnonnull-7.c b/gcc/testsuite/gcc.dg/Wnonnull-7.c
new file mode 100644 (file)
index 0000000..e7b331a
--- /dev/null
@@ -0,0 +1,15 @@
+/* PR middle-end/101216 - spurious notes for function calls
+   { dg-do compile }
+   { dg-options "-O2 -w" } */
+
+__attribute__ ((access (write_only, 1, 2))) char*
+getcwd (char *, __SIZE_TYPE__);
+
+char* f (void)
+{
+  char a[8];
+  return getcwd (0, 8);
+}
+
+/* Expect no messages of any kind on output.
+   { dg-bogus "" "" { target *-*-* } 0 } */