Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / vla-sideeffect.exp
CommitLineData
88b9d363 1# Copyright 2014-2022 Free Software Foundation, Inc.
5ecaaa66
SA
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# Tests side-effects of sizeof evaluation.
17# Based on gcc/testsuite/gcc.dg/vla-4.c; vla-15.c
18
19standard_testfile
20
5b362f04 21if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
5ecaaa66
SA
22 return -1
23}
24
25if ![runto_main] {
26 return -1
27}
28
29gdb_breakpoint [gdb_get_line_number "vla-filled"]
30gdb_continue_to_breakpoint "vla-filled"
31
32# Check side effects for sizeof argument.
33set sizeof_int [get_sizeof "int" 4]
34set sizeof_vla [ expr "10" * "$sizeof_int" ]
35
11af934b 36gdb_test "print sizeof (vla1\[i++\])" " = ${sizeof_int}"
5ecaaa66
SA
37gdb_test "print i" " = 0" \
38 "print i - sizeof no side effects"
39
11af934b 40gdb_test "print sizeof (++vla1\[0\])" " = ${sizeof_int}"
5ecaaa66
SA
41gdb_test "print vla1\[0\]" " = 10" \
42 "print vla1\[0\] - sizeof no side effects"
43
11af934b 44gdb_test "ptype ++vla1\[0\]" "type = int"
5ecaaa66
SA
45gdb_test "print vla1\[0\]" " = 10" \
46 "print vla1\[0\] - ptype no side effects"
47
11af934b 48gdb_test "whatis ++vla1\[0\]" "type = int"
5ecaaa66
SA
49gdb_test "print vla1\[0\]" " = 10" \
50 "print vla1\[0\] - whatis no side effects"
51
52
11af934b 53gdb_test "print sizeof (vla2\[i++\])" " = ${sizeof_vla}"
5ecaaa66
SA
54gdb_test "print i" " = 1" \
55 "print i - sizeof with side effects (1)"
56
11af934b 57gdb_test "print sizeof (vla2\[i++ + sizeof(j++)\])" " = ${sizeof_vla}"
5ecaaa66
SA
58gdb_test "print i" " = 2" \
59 "print i - sizeof with side effects (2)"
60gdb_test "print j" " = 0" \
61 "print j - sizeof with no side effects"
62
11af934b 63gdb_test "ptype vla2\[i++\]" "type = int \\\[10\\\]"
5ecaaa66
SA
64gdb_test "print i" " = 2" \
65 "print i - ptype with side effects (1)"
66
11af934b 67gdb_test "ptype vla2\[i++ + sizeof(j++)\]" "type = int \\\[10\\\]"
5ecaaa66
SA
68gdb_test "print i" " = 2" \
69 "print i - ptype with side effects (2)"
70gdb_test "print j" " = 0" \
71 "print j - ptype with no side effects"
72
11af934b 73gdb_test "whatis vla2\[i++\]" "type = int \\\[10\\\]"
5ecaaa66
SA
74gdb_test "print i" " = 2" \
75 "print i - whatis with side effects (1)"
76
11af934b 77gdb_test "whatis vla2\[i++ + sizeof(j++)\]" "type = int \\\[10\\\]"
5ecaaa66
SA
78gdb_test "print i" " = 2" \
79 "print i - whatis with side effects (2)"
80gdb_test "print j" " = 0" \
81 "print j - whatis with no side effects"
This page took 1.013826 seconds and 4 git commands to generate.