aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Uecker <uecker@tugraz.at>2023-04-13 19:35:15 +0200
committerMartin Uecker <uecker@tugraz.at>2023-08-05 18:09:58 +0200
commit39f413fc4b6979d194f2f736bd663eb7f5045168 (patch)
tree006e649dcafed2c210a10b31bd62dedcbbc2e538
parent54be338589ea93ad4ff53d22adde476a0582537b (diff)
downloadgcc-39f413fc4b6979d194f2f736bd663eb7f5045168.zip
gcc-39f413fc4b6979d194f2f736bd663eb7f5045168.tar.gz
gcc-39f413fc4b6979d194f2f736bd663eb7f5045168.tar.bz2
c: Less warnings for parameters declared as arrays [PR98536]
To avoid false positivies, tune the warnings for parameters declared as arrays with size expressions. Do not warn when more bounds are specified in the declaration than before. PR c/98536 gcc/c-family/: * c-warn.cc (warn_parm_array_mismatch): Do not warn if more bounds are specified. gcc/testsuite: * gcc.dg/Wvla-parameter-4.c: Adapt test. * gcc.dg/attr-access-2.c: Adapt test.
-rw-r--r--gcc/c-family/c-warn.cc20
-rw-r--r--gcc/testsuite/gcc.dg/Wvla-parameter-4.c5
-rw-r--r--gcc/testsuite/gcc.dg/attr-access-2.c10
3 files changed, 3 insertions, 32 deletions
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d4d62c4..b7c5d7c 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3599,23 +3599,13 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms)
continue;
}
- if (newunspec != curunspec)
+ if (newunspec > curunspec)
{
location_t warnloc = newloc, noteloc = origloc;
const char *warnparmstr = newparmstr.c_str ();
const char *noteparmstr = curparmstr.c_str ();
unsigned warnunspec = newunspec, noteunspec = curunspec;
- if (newunspec < curunspec)
- {
- /* If the new declaration has fewer unspecified bounds
- point the warning to the previous declaration to make
- it clear that that's the one to change. Otherwise,
- point it to the new decl. */
- std::swap (warnloc, noteloc);
- std::swap (warnparmstr, noteparmstr);
- std::swap (warnunspec, noteunspec);
- }
if (warning_n (warnloc, OPT_Wvla_parameter, warnunspec,
"argument %u of type %s declared with "
"%u unspecified variable bound",
@@ -3643,14 +3633,10 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms)
}
/* Iterate over the lists of VLA variable bounds, comparing each
- pair for equality, and diagnosing mismatches. The case of
- the lists having different lengths is handled above so at
- this point they do . */
- for (tree newvbl = newa->size, curvbl = cura->size; newvbl;
+ pair for equality, and diagnosing mismatches. */
+ for (tree newvbl = newa->size, curvbl = cura->size; newvbl && curvbl;
newvbl = TREE_CHAIN (newvbl), curvbl = TREE_CHAIN (curvbl))
{
- gcc_assert (curvbl);
-
tree newpos = TREE_PURPOSE (newvbl);
tree curpos = TREE_PURPOSE (curvbl);
diff --git a/gcc/testsuite/gcc.dg/Wvla-parameter-4.c b/gcc/testsuite/gcc.dg/Wvla-parameter-4.c
index 599ad19..f35faea 100644
--- a/gcc/testsuite/gcc.dg/Wvla-parameter-4.c
+++ b/gcc/testsuite/gcc.dg/Wvla-parameter-4.c
@@ -12,11 +12,6 @@ typedef int IA3[3];
/* Verify the warning points to the declaration with more unspecified
bounds, guiding the user to specify them rather than making them all
unspecified. */
-void* f_pIA3ax (IA3 *x[*]); // { dg-warning "argument 1 of type 'int \\\(\\\*\\\[\\\*]\\\)\\\[3]' .aka '\[^\n\r\}\]+'. declared with 1 unspecified variable bound" }
-void* f_pIA3ax (IA3 *x[*]);
-void* f_pIA3ax (IA3 *x[n]); // { dg-message "subsequently declared as 'int \\\(\\\*\\\[n]\\\)\\\[3]' with 0 unspecified variable bounds" "note" }
-void* f_pIA3ax (IA3 *x[n]) { return x; }
-
void* f_pIA3an (IA3 *x[n]); // { dg-message "previously declared as 'int \\\(\\\*\\\[n]\\\)\\\[3]' with 0 unspecified variable bounds" "note" }
void* f_pIA3an (IA3 *x[n]);
diff --git a/gcc/testsuite/gcc.dg/attr-access-2.c b/gcc/testsuite/gcc.dg/attr-access-2.c
index 76baddf..616b7a9 100644
--- a/gcc/testsuite/gcc.dg/attr-access-2.c
+++ b/gcc/testsuite/gcc.dg/attr-access-2.c
@@ -60,16 +60,6 @@ RW (2, 1) void f10 (int n, char a[n]) // { dg-warning "attribute 'access *\\\(
// { dg-warning "argument 2 of type 'char\\\[n]' declared as a variable length array" "" { target *-*-* } .-1 }
{ (void)&n; (void)&a; }
-
-/* The following is diagnosed to point out declarations with the T[*]
- form in headers where specifying the bound is just as important as
- in the definition (to detect bugs). */
- void f11 (int, char[*]); // { dg-warning "argument 2 of type 'char\\\[\\\*\\\]' declared with 1 unspecified variable bound" }
- void f11 (int m, char a[m]); // { dg-message "subsequently declared as 'char\\\[m]' with 0 unspecified variable bounds" "note" }
-RW (2, 1) void f11 (int n, char arr[n]) // { dg-message "subsequently declared as 'char\\\[n]' with 0 unspecified variable bounds" "note" }
-{ (void)&n; (void)&arr; }
-
-
/* Verify that redeclaring a function with attribute access applying
to an array parameter of any form is not diagnosed. */
void f12__ (int, int[]) RW (2, 1);