diff options
author | Martin Sebor <msebor@redhat.com> | 2016-04-13 23:26:41 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2016-04-13 17:26:41 -0600 |
commit | 342fac9537c6a75e65fe62943ba84b81bddede3f (patch) | |
tree | 1d55385c5ee07d32a08d9279dcb595632d96e73c /gcc/doc | |
parent | 2ecc0c837bf2ac1309f41d30b7b30595331a6eb6 (diff) | |
download | gcc-342fac9537c6a75e65fe62943ba84b81bddede3f.zip gcc-342fac9537c6a75e65fe62943ba84b81bddede3f.tar.gz gcc-342fac9537c6a75e65fe62943ba84b81bddede3f.tar.bz2 |
PR c++/69517 - [5/6 regression] SEGV on a VLA with excess initializer elements
PR c++/69517 - [5/6 regression] SEGV on a VLA with excess initializer elements
PR c++/70019 - VLA size overflow not detected
PR c++/70588 - SIGBUS on a VLA larger than SIZE_MAX / 2
gcc/testsuite/ChangeLog:
2016-04-13 Martin Sebor <msebor@redhat.com>
PR c++/69517
PR c++/70019
PR c++/70588
* c-c++-common/ubsan/vla-1.c (main): Catch exceptions.
* g++.dg/cpp1y/vla11.C: New test.
* g++.dg/cpp1y/vla12.C: New test.
* g++.dg/cpp1y/vla13.C: New test.
* g++.dg/cpp1y/vla14.C: New test.
* g++.dg/cpp1y/vla3.C: Restore deleted test.
* gcc/testsuite/g++.dg/init/array24.C: Fully brace VLA initializer.
* g++.dg/ubsan/vla-1.C: Disable exceptions.
gcc/cp/ChangeLog:
2016-04-13 Martin Sebor <msebor@redhat.com>
PR c++/69517
PR c++/70019
PR c++/70588
* cp-tree.h (throw_bad_array_length, build_vla_check): Declare new
functions.
* decl.c (check_initializer, cp_finish_decl): Call them.
(reshape_init_r): Reject incompletely braced intializer-lists
for VLAs.
* init.c (throw_bad_array_length, build_vla_check)
(build_vla_size_check, build_vla_init_check): Define new functions.
* typeck2.c (split_nonconstant_init_1): Use variably_modified_type_p()
to detect a VLA.
(store_init_value): Same.
gcc/doc/ChangeLog:
2016-04-13 Martin Sebor <msebor@redhat.com>
PR c++/69517
PR c++/70019
PR c++/70588
* extend.texi (Variable Length): Document C++ specifics.
libstdc++-v3/ChangeLog:
2016-04-13 Martin Sebor <msebor@redhat.com>
PR c++/69517
* testsuite/25_algorithms/rotate/moveable2.cc: Make sure VLA
upper bound is positive.
From-SVN: r234966
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/extend.texi | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index a5a8b23..6687d59 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -1638,14 +1638,48 @@ foo (int n) You can use the function @code{alloca} to get an effect much like variable-length arrays. The function @code{alloca} is available in many other C implementations (but not in all). On the other hand, -variable-length arrays are more elegant. +variable-length arrays are available in GCC for all targets and +provide type safety. There are other differences between these two methods. Space allocated with @code{alloca} exists until the containing @emph{function} returns. The space for a variable-length array is deallocated as soon as the array name's scope ends, unless you also use @code{alloca} in this scope. -You can also use variable-length arrays as arguments to functions: +Unlike GCC, G++ instruments variable-length arrays (@xref{Variable Length}) +with checks for erroneous uses: when a variable-length array object is +created its runtime bounds are checked to detect non-positive values, +integer overflows, sizes in excess of SIZE_MAX / 2 bytes, and excess +initializers. When an erroneous variable-length array is detected +the runtime arranges for an exception to be thrown that matches a handler +of type @code{std::bad_array_length}. + +Also unlike GCC, G++ allows variable-length arrays to be initialized. +However, unlike initializer lists for ordinary multidimensional arrays, +those for multidimensional variable-length arrays must be enclosed in +pairs of curly braces delimiting each sequence of values to use to +initialize each subarray. Initializer lists that aren't unambiguously +enclosed in braces are rejected with an error. For example, in the +following function, the initializer list for the ordinary @code{array} +is accepted even though it isn't fully enclosed in braces. The same +initializer list, however, wouldn't be accepted for a multidimensional +variable-length array. To initialize the variable-length array @code{vla}, +the elements of the subarray @code{vla[m]} must be enclosed in braces +as shown. As with ordinary arrays, elements that aren't initialized +explicitly are default-initialized. + +@smallexample +void +foo (int m, int n) +@{ + int array[2][3] = @{ 1, 2, 4, 5, 6 @}; + int vla[m][n] = @{ @{ 1, 2 @}, @{ 4, 5, 6 @} @}; +@} +@end smallexample + + +In C programs (but not in C++) variable-length arrays can also be declared +as function arguments: @smallexample struct entry |