PR44406: Follow behavior of array bound constant folding in more recent versions...
authorRichard Smith <richard@metafoo.co.uk>
Fri, 16 Oct 2020 02:32:15 +0000 (19:32 -0700)
committerRichard Smith <richard@metafoo.co.uk>
Fri, 16 Oct 2020 21:34:35 +0000 (14:34 -0700)
commit552c6c2328723a248c2b4d2765f75d49129dff20
treec1583c5245e03d4aad54ecde9463158585a3b8a1
parent109113015ebeeceec862fc53a678b3619a879ce4
PR44406: Follow behavior of array bound constant folding in more recent versions of GCC.

Old GCC used to aggressively fold VLAs to constant-bound arrays at block
scope in GNU mode. That's non-conforming, and more modern versions of
GCC only do this at file scope. Update Clang to do the same.

Also promote the warning for this from off-by-default to on-by-default
in all cases; more recent versions of GCC likewise warn on this by
default.

This is still slightly more permissive than GCC, as pointed out in
PR44406, as we still fold VLAs to constant arrays in structs, but that
seems justifiable given that we don't support VLA-in-struct (and don't
intend to ever support it), but GCC does.

Differential Revision: https://reviews.llvm.org/D89523
32 files changed:
clang/docs/UsersManual.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/basic/basic.types/p10.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CodeGen/vla.c
clang/test/Misc/warning-flags.c
clang/test/PCH/cxx-constexpr.cpp
clang/test/Profile/misexpect-switch-default.c
clang/test/Profile/misexpect-switch-nonconst.c
clang/test/Profile/misexpect-switch-only-default-case.c
clang/test/Profile/misexpect-switch.c
clang/test/Sema/builtin-assume.c
clang/test/Sema/builtins.c
clang/test/Sema/complex-int.c
clang/test/Sema/const-eval-64.c
clang/test/Sema/const-eval.c
clang/test/Sema/darwin-align-cast.c
clang/test/Sema/decl-in-prototype.c
clang/test/Sema/gnu-flags.c
clang/test/Sema/i-c-e.c
clang/test/Sema/offsetof-64.c
clang/test/Sema/rounding-math.c
clang/test/Sema/struct-decl.c
clang/test/Sema/typedef-variable-type.c
clang/test/Sema/vla.c
clang/test/SemaCXX/anonymous-struct.cpp
clang/test/SemaCXX/constant-expression.cpp
clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
clang/test/SemaCXX/i-c-e-cxx.cpp
clang/test/SemaObjC/gcc-cast-ext.m