xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/vla-optimized-out.exp (revision 4d342c046e3288fb5a1edcd33cfec48c41c80664)
1# Copyright 2018-2019 Free Software Foundation, Inc.
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
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
29
30    if { [prepare_for_testing "failed to prepare" "$testfile-$exe_suffix" $srcfile \
31	      $compile_flags] } {
32	return -1
33    }
34
35    if ![runto f1] {
36	fail "can't run to f1"
37	return
38    }
39
40    gdb_test "p a" \
41	" = <optimized out>" \
42	"printed optimized out vla"
43
44    gdb_test "p sizeof (a)" \
45	" = $sizeof_result" \
46	"printed size of optimized out vla"
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)"
69}
70
71foreach {test_prefix options} \
72    { "o1" {{debug optimize=-O1 additional_flags=-DNOCLONE} "6"} \
73      "o3" {{debug optimize=-O3} "<optimized out>|6"} \
74      "o3_strict" {{debug optimize=-O3 \
75			additional_flags=-gstrict-dwarf} \
76		       "<optimized out>|6"}} {
77    with_test_prefix $test_prefix {
78	vla_optimized_out $test_prefix $options
79    }
80}
81
82