]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use OEP_DECL_NAME when comparing VLA bounds [PR101585].
authorMartin Sebor <msebor@redhat.com>
Tue, 27 Jul 2021 19:51:55 +0000 (13:51 -0600)
committerRichard Biener <rguenther@suse.de>
Thu, 7 Apr 2022 10:01:34 +0000 (12:01 +0200)
Resolves:
PR c/101585 - Bad interaction of -fsanitize=undefined and -Wvla-parameters

gcc/c-family:

PR c/101585
* c-warn.c (warn_parm_ptrarray_mismatch): Use OEP_DECL_NAME.

gcc/testsuite:
PR c/101585
* gcc.dg/Wvla-parameter-13.c: New test.

(cherry picked from commit a0f9a5dcc3bbe6c7de499e17d201d0f2cb512649)

gcc/c-family/c-warn.c
gcc/testsuite/gcc.dg/Wvla-parameter-13.c [new file with mode: 0644]

index 96bee7d198459166c1f5ce0120d698f84801575f..ac9a64108eca6728ba0e125c595f0c90ad8ebf8a 100644 (file)
@@ -3303,7 +3303,8 @@ warn_parm_ptrarray_mismatch (location_t origloc, tree curparms, tree newparms)
          /* Move on if the bounds look the same.  */
          if (!pcurbndpos && !pnewbndpos
              && curbnd && newbnd
-             && operand_equal_p (curbnd, newbnd, OEP_LEXICOGRAPHIC))
+             && operand_equal_p (curbnd, newbnd,
+                                 OEP_DECL_NAME | OEP_LEXICOGRAPHIC))
            continue;
 
          if ((curbnd && TREE_CODE (curbnd) != INTEGER_CST)
diff --git a/gcc/testsuite/gcc.dg/Wvla-parameter-13.c b/gcc/testsuite/gcc.dg/Wvla-parameter-13.c
new file mode 100644 (file)
index 0000000..f64d29c
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR c/101585 - Bad interaction of -fsanitize=undefined and -Wvla-parameters
+   { dg-do compile }
+   { dg-options "-Wall -fsanitize=undefined" } */
+
+void f1 (int n, int (*)[n]);
+void f1 (int n, int (*)[n]);            // { dg-bogus "\\\[-Wvla-parameter" }
+
+void g1 (int m, int (*)[m]);
+void g1 (int n, int (*)[n]);            // { dg-bogus "\\\[-Wvla-parameter" "pr101605" { xfail *-*-* } }
+
+void h1 (int n, int (*)[n]);
+void h1 (int n, int (*)[n + 1]);        // { dg-warning "\\\[-Wvla-parameter" }
+
+void f2 (int m, int n, int (*)[m][n]);
+void f2 (int n, int m, int (*)[n][m]);  // { dg-bogus "\\\[-Wvla-parameter" "pr101605" { xfail *-*-* } }
+
+void g2 (int m, int n, int (*)[m][n]);
+void g2 (int n, int m, int (*)[m][n]);  // { dg-warning "\\\[-Wvla-parameter" "pr101605" { xfail *-*-* } }