[cfe-commits] [PATCH] Add -Wvla support

Rafael Espindola espindola at google.com
Mon Feb 15 11:57:57 PST 2010


On 12 February 2010 19:08, Sam Weinig <weinig at apple.com> wrote:
> The attached patch adds -Wvla support for clang.  This warning (which is not available in GCC 4.2) warns about VLA usage even in C99 mode. This fixes PR5953. I would appreciate a review before I commit.

Thanks a lot for fixing this! My only comment is that it can produce
duplicate warnings:
----------------------------------------------------------------------
$ ./Debug/bin/clang -cc1 -std=c89  -fsyntax-only -pedantic -Wvla ~/llvm/vla.c
/home/espindola/llvm/vla.c:2:12: warning: variable length arrays are a
C99 feature, accepted as an extension
  int array[n];
           ^
/home/espindola/llvm/vla.c:2:12: warning: variable length array used
2 diagnostics generated.
-----------------------------------------------------------------------

The attached patch tries to avoid the duplicate waring. I don't know
if that is the correct way to do it in clang. I am also not sure how
to update to test. The results are
---------------------------------------------------------------------------------------------
$ ./Debug/bin/clang -cc1 -std=c89  -fsyntax-only -pedantic -Wvla ~/llvm/vla.c
/home/espindola/llvm/vla.c:2:12: warning: variable length arrays are a
C99 feature, accepted as an extension
  int array[n];
           ^
1 diagnostic generated.
$ ./Debug/bin/clang -cc1 -std=c89  -fsyntax-only -Wvla ~/llvm/vla.c
/home/espindola/llvm/vla.c:2:12: warning: variable length array used
  int array[n];
           ^
1 diagnostic generated.
$ ./Debug/bin/clang -cc1 -std=c99  -fsyntax-only -Wvla ~/llvm/vla.c
/home/espindola/llvm/vla.c:2:12: warning: variable length array used
  int array[n];
           ^
1 diagnostic generated.
$ ./Debug/bin/clang -cc1 -std=c99  -fsyntax-only -pedantic -Wvla ~/llvm/vla.c
/home/espindola/llvm/vla.c:2:12: warning: variable length array used
  int array[n];
           ^
1 diagnostic generated.
----------------------------------------------------------------------------------

--------------------------
> - Sam

Thanks,
-- 
Rafael Ávila de Espíndola
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wvla.patch
Type: text/x-diff
Size: 2446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100215/6fa09173/attachment.patch>


More information about the cfe-commits mailing list