1 # Copyright
2018-2019 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
30 if { [prepare_for_testing
"failed to prepare" "$testfile-$exe_suffix" $srcfile \
36 fail
"can't run to f1"
41 " = <optimized out>" \
42 "printed optimized out vla"
44 gdb_test
"p sizeof (a)" \
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 foreach
{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