Re: ld plugin bfd_make_readable leak
[binutils-gdb.git] / gdb / testsuite / gdb.arch / amd64-eval.cc
blobb93c6fe57bd639571f1690c18a64de1f2ce37b73
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2019-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #include <cstdint>
19 #include <cstdio>
20 #include <cstdlib>
21 #include <cassert>
23 /* A simple structure with a single integer field. Should be returned in
24 a register. */
25 struct SimpleBase
27 SimpleBase (int32_t x) : x (x) {}
29 int32_t x;
32 /* A simple structure derived from the simple base. Should be returned in
33 a register. */
34 struct SimpleDerived : public SimpleBase
36 SimpleDerived (int32_t x) : SimpleBase (x) {}
39 /* A structure derived from the simple base with a non-trivial destructor.
40 Should be returned on the stack. */
41 struct NonTrivialDestructorDerived : public SimpleBase
43 NonTrivialDestructorDerived (int32_t x) : SimpleBase (x) {}
44 ~NonTrivialDestructorDerived() { x = 1; }
47 /* A structure with unaligned fields. Should be returned on the stack. */
48 struct UnalignedFields
50 UnalignedFields (int32_t x, double y) : x (x), y (y) {}
52 int32_t x;
53 double y;
54 } __attribute__((packed));
56 /* A structure with unaligned fields in its base class. Should be
57 returned on the stack. */
58 struct UnalignedFieldsInBase : public UnalignedFields
60 UnalignedFieldsInBase (int32_t x, double y, int32_t x2)
61 : UnalignedFields (x, y), x2 (x2) {}
63 int32_t x2;
66 struct Bitfields
68 Bitfields(unsigned int x, unsigned int y)
69 : fld(x), fld2(y)
72 unsigned fld : 7;
73 unsigned fld2 : 7;
76 class Foo
78 public:
79 SimpleBase
80 return_simple_base (int32_t x)
82 assert (this->tag == EXPECTED_TAG);
83 return SimpleBase (x);
86 SimpleDerived
87 return_simple_derived (int32_t x)
89 assert (this->tag == EXPECTED_TAG);
90 return SimpleDerived (x);
93 NonTrivialDestructorDerived
94 return_non_trivial_destructor (int32_t x)
96 assert (this->tag == EXPECTED_TAG);
97 return NonTrivialDestructorDerived (x);
100 UnalignedFields
101 return_unaligned (int32_t x, double y)
103 assert (this->tag == EXPECTED_TAG);
104 return UnalignedFields (x, y);
107 UnalignedFieldsInBase
108 return_unaligned_in_base (int32_t x, double y, int32_t x2)
110 assert (this->tag == EXPECTED_TAG);
111 return UnalignedFieldsInBase (x, y, x2);
114 Bitfields
115 return_bitfields (unsigned int x, unsigned int y)
117 assert (this->tag == EXPECTED_TAG);
118 return Bitfields(x, y);
121 private:
122 /* Use a tag to detect if the "this" value is correct. */
123 static const int EXPECTED_TAG = 0xF00F00F0;
124 int tag = EXPECTED_TAG;
128 main (int argc, char *argv[])
130 Foo foo;
131 foo.return_simple_base(1);
132 foo.return_simple_derived(2);
133 foo.return_non_trivial_destructor(3);
134 foo.return_unaligned(4, 5);
135 foo.return_unaligned_in_base(6, 7, 8);
136 foo.return_bitfields(23, 74);
137 return 0; // break-here