1# Copyright 2014-2020 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
16standard_testfile
17
18# Clang says it will never support variable length arrays in structures.
19if {[test_compiler_info clang*]} {
20    unsupported "compiler does not support variable length arrays in structure"
21    return
22}
23
24if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
25    return -1
26}
27
28if ![runto_main] {
29    return -1
30}
31
32gdb_breakpoint [gdb_get_line_number "vlas_filled"]
33gdb_continue_to_breakpoint "vlas_filled"
34
35# Check the values of VLA's.
36gdb_test "print vla_struct_object" \
37    "\\\{something = 5, vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}"
38gdb_test "print vla_union_object" \
39    "\\\{vla_field = \\\{0, 2, 4, 6, 8\\\}\\\}"
40gdb_test "print vla_struct_typedef_struct_member_object" \
41    "\\\{something = 10, vla_object = \\\{something = 15, vla_field = \\\{0, 3, 6, 9, 12\\\}\\\}\\\}"
42gdb_test "print vla_struct_typedef_union_member_object" \
43    "\\\{something = 6, vla_object = \\\{something = 6, vla_field = \\\{-1, 2, 5, 8, 11\\\}\\\}\\\}"
44
45# Check whatis of VLA's.
46gdb_test "whatis vla_struct_object" "type = vla_struct_typedef"
47gdb_test "whatis vla_union_object" "type = union vla_union"
48
49# Check ptype of VLA's.
50gdb_test "ptype vla_struct_object" \
51    "type = struct vla_struct {\r\n\\s+int something;\r\n\\s+int vla_field\\\[5\\\];\r\n}"
52gdb_test "ptype vla_union_object" \
53    "type = union vla_union {\r\n\\s+int vla_field\\\[5\\\];\r\n}"
54
55# Check the size of the VLA's.
56gdb_breakpoint [gdb_get_line_number "break_end_of_vla_factory"]
57gdb_continue_to_breakpoint "break_end_of_vla_factory"
58gdb_test "print vla_struct_object_size == sizeof(vla_struct_object)" \
59    " = 1" "size of vla_struct_object"
60gdb_test "print vla_union_object_size == sizeof(vla_union_object)" \
61    " = 1" "size of vla_union_object"
62
63# Fails due to incorrect debugging information generated by GCC.
64setup_xfail "*-*-*"
65gdb_test \
66    "print inner_vla_struct_object_size == sizeof(inner_vla_struct_object)" \
67    " = 1" "size of inner_vla_struct_object"
68