]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/vla-optimized-out.exp
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / vla-optimized-out.exp
CommitLineData
1d506c26 1# Copyright 2018-2024 Free Software Foundation, Inc.
42dc7699
TV
2
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.
7#
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.
12#
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/>.
15
16# Check whether we can determine the size of an optimized-out vla.
17
18standard_testfile
19
e5bbcd0f
AB
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.
25proc vla_optimized_out {exe_suffix options} {
26 global testfile srcfile
27
28 lassign $options compile_flags sizeof_result
f2259ae7 29 lappend_include_file compile_flags $::srcdir/lib/attributes.h
e5bbcd0f
AB
30
31 if { [prepare_for_testing "failed to prepare" "$testfile-$exe_suffix" $srcfile \
32 $compile_flags] } {
33 return -1
34 }
42dc7699 35
42dc7699 36 if ![runto f1] {
42dc7699
TV
37 return
38 }
39
40 gdb_test "p a" \
e5bbcd0f 41 " = <optimized out>" \
42dc7699
TV
42 "printed optimized out vla"
43
44 gdb_test "p sizeof (a)" \
83100a74 45 " = ($sizeof_result)" \
42dc7699 46 "printed size of optimized out vla"
5ff2bbae
AB
47
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>'
52 # is reasonable.
53 #
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'.
58 gdb_test "p a\[0\]" \
59 "(= <optimized out>|no such vector element)" \
60 "print out of range element of vla (0)"
61
62 gdb_test "p a\[6\]" \
63 "no such vector element" \
64 "print out of range element of vla (6)"
65
66 gdb_test "p a\[0xffffffff\]" \
67 "no such vector element" \
68 "print out of range element of vla (0xffffffff)"
42dc7699
TV
69}
70
f3e033f3
TV
71set o1_sizeof_result "6"
72if { [istarget powerpc*-*-*] && [gcc_major_version] != -1 } {
73 set o1_sizeof_result "<optimized out>|6"
74}
75
76set test_matrix {}
77lappend test_matrix \
78 "o1" \
79 [list {debug optimize=-O1 additional_flags=-DNOCLONE} $o1_sizeof_result]
80lappend test_matrix \
81 "o3" \
82 {{debug optimize=-O3} "<optimized out>|6"}
83lappend test_matrix \
84 "o3_strict" \
85 {{debug optimize=-O3 additional_flags=-gstrict-dwarf} "<optimized out>|6"}
86
87foreach {test_prefix options} $test_matrix {
e5bbcd0f
AB
88 with_test_prefix $test_prefix {
89 vla_optimized_out $test_prefix $options
90 }
91}
92