[PATCH] D156565: Diagnose use of VLAs in C++ by default

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 22 06:13:55 PDT 2023


aaron.ballman added a comment.

In D156565#4654773 <https://reviews.llvm.org/D156565#4654773>, @nathanchance wrote:

> Is it expected that this introduces a warning for C code, as the commit message and tests appear to only affect C++? A trivial example from the Linux kernel:
>
> https://elixir.bootlin.com/linux/v6.5.8/source/tools/lib/bpf/btf_dump.c#L1678
>
>   #include <stddef.h>
>   #include <stdio.h>
>   #include <string.h>
>   
>   void foo(char *orig_name, char **cached_name, size_t dup_cnt)
>   {
>           const size_t max_len = 256;
>           char new_name[max_len];
>   
>           snprintf(new_name, max_len, "%s___%zu", orig_name, dup_cnt);
>           *cached_name = strdup(new_name);
>   }
>
>
>
>   $ clang -std=gnu89 -Wall -fsyntax-only test.c
>   test.c:8:16: warning: variable length arrays are a C99 feature [-Wvla-extension]
>       8 |         char new_name[max_len];
>         |                       ^~~~~~~
>   1 warning generated.

No, that's unintended, I'll get that fixed. Thanks for letting me know!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156565/new/

https://reviews.llvm.org/D156565



More information about the cfe-commits mailing list