toolchain: gcc: backport v11.3.0 fix for false positive VLA params warnings
authorAndrey Erokhin <a.erokhin@inango-systems.com>
Wed, 22 Mar 2023 15:27:01 +0000 (16:27 +0100)
committerChristian Marangi <ansuelsmth@gmail.com>
Thu, 2 Nov 2023 17:45:50 +0000 (18:45 +0100)
commitde2162d27d811b84fcde022a556c9e31a6d77156
treec7b3dfd254ab88d28c003567e1226102b1b5d28a
parent8bc8db9ad26da98ebe2d4f861f03f09ece165694
toolchain: gcc: backport v11.3.0 fix for false positive VLA params warnings

If the vla parameter has a const specifier, the compiler will warn about
mismatched bounds:

 $ cat mwe.c
 extern void mwe(const int len, char buf[len]);
 void mwe(const int len, char buf[len]) {}

 $ make CFLAGS=-Wvla-parameter mwe.o
 cc -Wvla-parameter   -c -o mwe.o mwe.c
 mwe.c:2:30: warning: argument 2 of type ‘char[len]’ declared with mismatched bound ‘len’ [-Wvla-parameter]
     2 | void mwe(const int len, char buf[len]) {}
       |                         ~~~~~^~~~~~~~
 mwe.c:1:37: note: previously declared as ‘char[len]’ with bound ‘len’
     1 | extern void mwe(const int len, char buf[len]);
       |                                ~~~~~^~~~~~~~

On some code bases it might result in a lot of false positive warnings,
which can indeed be easily disabled, but on the other this workaround
might hide some real issues, so lets rather fix the compiler and make it
more reliable.

References: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101289
Signed-off-by: Andrey Erokhin <a.erokhin@inango-systems.com>
Signed-off-by: Petr Štetiar <ynezz@true.cz> [commit message]
toolchain/gcc/patches/11.2.0/400-v11.3.0-bogus-Wvla-parameter.patch [new file with mode: 0644]