e3e27ca7839d1247ef9d9f4d1b8905f4eb9a46bb
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / call-method-register.cc
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 1993-2021 Free Software Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 #if defined __x86_64__
19 # define ASM_REG "rax"
20 #elif defined __i386__
21 # define ASM_REG "eax"
22 #else
23 # error "port me"
24 #endif
25
26 /* A class small enough that it fits in a register. */
27 struct small
28 {
29 int x;
30 int method ();
31 };
32
33 int
34 small::method ()
35 {
36 return x + 5;
37 }
38
39 int
40 register_class ()
41 {
42 /* Given the use of the GNU register-asm local variables extension,
43 the compiler puts this variable in a register. This means that
44 GDB can't call any methods for this variable, which is what we
45 want to test. */
46 register small v asm (ASM_REG);
47
48 int i;
49
50 /* Perform a computation sufficiently complicated that optimizing
51 compilers won't optimize out the variable. If some compiler
52 constant-folds this whole loop, maybe using a parameter to this
53 function here would help. */
54 v.x = 0;
55 for (i = 0; i < 13; ++i)
56 v.x += i;
57 --v.x; /* v.x is now 77 */
58 return v.x + 5; /* set breakpoint here */
59 }
60
61 int
62 main ()
63 {
64 register_class ();
65 return 0;
66 }
This page took 0.03145 seconds and 3 git commands to generate.