1 # Copyright 2018-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Check whether we can determine the size of an optimized-out vla.
20 # The EXE_SUFFIX is a string appended to the name of the test binary
21 # to make it unique per variation.
22 # The OPTIONS is a two item list, the first item is a list of compiler
23 # flags used for building the test binary, and the second item is a
24 # pattern which matches some expected output within this proc.
25 proc vla_optimized_out {exe_suffix options} {
26 global testfile srcfile
28 lassign $options compile_flags sizeof_result
29 lappend_include_file compile_flags $::srcdir/lib/attributes.h
31 if { [prepare_for_testing "failed to prepare" "$testfile-$exe_suffix" $srcfile \
41 " = <optimized out>" \
42 "printed optimized out vla"
44 gdb_test "p sizeof (a)" \
45 " = ($sizeof_result)" \
46 "printed size of optimized out vla"
48 # At lower optimisation levels, the upper bound of the array is
49 # still defined, it's just the loctaion that tells GDB the array
50 # is optimised out. In that case, when we access an element that
51 # is within the bounds of the array an answer of '<optimized out>'
54 # At higher optimisation levels, the array bounds themselves have
55 # been removed. As such GDB can't be expected to know if the
56 # array contains _any_ elements at all. It seems reasonable in
57 # that case to reply with 'no such vector element'.
59 "(= <optimized out>|no such vector element)" \
60 "print out of range element of vla, 0"
63 "no such vector element" \
64 "print out of range element of vla, 6"
66 gdb_test "p a\[0xffffffff\]" \
67 "no such vector element" \
68 "print out of range element of vla, 0xffffffff"
71 set o1_sizeof_result "6"
72 if { [istarget powerpc*-*-*] && [gcc_major_version] != -1 } {
73 set o1_sizeof_result "<optimized out>|6"
79 [list {debug optimize=-O1 additional_flags=-DNOCLONE} $o1_sizeof_result]
82 {{debug optimize=-O3} "<optimized out>|6"}
85 {{debug optimize=-O3 additional_flags=-gstrict-dwarf} "<optimized out>|6"}
87 foreach {test_prefix options} $test_matrix {
88 with_test_prefix $test_prefix {
89 vla_optimized_out $test_prefix $options