diff options
author | Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> | 2019-12-20 17:43:07 +0100 |
---|---|---|
committer | Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> | 2019-12-20 17:43:07 +0100 |
commit | c855a9125ade61c046091373bafdae0c719118e0 (patch) | |
tree | 334b33314162c04803fe504a508c52e0724222e7 /gdb/testsuite/gdb.cp/pass-by-ref-2.cc | |
parent | 099a6354dab7e74c990501929f383394fc8efd02 (diff) | |
download | gdb-c855a9125ade61c046091373bafdae0c719118e0.zip gdb-c855a9125ade61c046091373bafdae0c719118e0.tar.gz gdb-c855a9125ade61c046091373bafdae0c719118e0.tar.bz2 |
testsuite, cp: increase the coverage of testing pass-by-ref arguments
Extend testcases for GDB's infcall of call-by-value functions that
take aggregate values as parameters. In particular, existing test has
been substantially extended with class definitions whose definitions
of copy constructor, destructor, and move constructor functions are a
combination of
(1) explicitly defined by the user,
(2) defaulted inside the class declaration,
(3) defaulted outside the class declaration,
(4) deleted
(5) not defined in the source.
For each combination, a small and a large class is generated as well
as a derived class and a container class. Additionally, the following
manually-written cases are provided:
- a dynamic class (i.e. class with a virtual method)
- classes that contain an array field
- a class whose copy ctor is inlined
- a class whose destructor is deleted
- classes with multiple copy and/or move ctors
Test cases check whether GDB makes the right decision to pass an
object by value or implicitly by reference, whether really a copy of
the argument is passed, and whether the copy constructor and
destructor of the clone of the argument are invoked properly.
The input program pass-by-ref.cc is generated in the test's output
directory. The input program pass-by-ref-2.cc is manually-written.
Tests have been verified on the X86_64 architecture with
GCC 7.4.0, 8.2.0, and 9.2.1.
gdb/testsuite/ChangeLog:
2019-12-20 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* gdb.cp/pass-by-ref.cc: Delete. Generated in the output
directory instead.
* gdb.cp/pass-by-ref.exp: Extend with more cases.
* gdb.cp/pass-by-ref-2.cc: New file.
* gdb.cp/pass-by-ref-2.exp: New file.
Change-Id: Ie8ab1f260c6ad5ee4eb34b2c1597ce24af04abb6
Diffstat (limited to 'gdb/testsuite/gdb.cp/pass-by-ref-2.cc')
-rw-r--r-- | gdb/testsuite/gdb.cp/pass-by-ref-2.cc | 295 |
1 files changed, 295 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/pass-by-ref-2.cc b/gdb/testsuite/gdb.cp/pass-by-ref-2.cc new file mode 100644 index 0000000..1cd5a16 --- /dev/null +++ b/gdb/testsuite/gdb.cp/pass-by-ref-2.cc @@ -0,0 +1,295 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2019 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +class ByVal { +public: + ByVal (void); + + int x; +}; + +ByVal::ByVal (void) +{ + x = 2; +} + +class ByRef { +public: + ByRef (void); + + ByRef (const ByRef &rhs); + + int x; +}; + +ByRef::ByRef (void) +{ + x = 2; +} + +ByRef::ByRef (const ByRef &rhs) +{ + x = 3; /* ByRef-cctor */ +} + +class ArrayContainerByVal { +public: + ByVal items[2]; +}; + +int +cbvArrayContainerByVal (ArrayContainerByVal arg) +{ + arg.items[0].x += 4; // intentionally modify + return arg.items[0].x; +} + +class ArrayContainerByRef { +public: + ByRef items[2]; +}; + +int +cbvArrayContainerByRef (ArrayContainerByRef arg) +{ + arg.items[0].x += 4; // intentionally modify + return arg.items[0].x; +} + +class DynamicBase { +public: + DynamicBase (void); + + virtual int get (void); + + int x; +}; + +DynamicBase::DynamicBase (void) +{ + x = 2; +} + +int +DynamicBase::get (void) +{ + return 42; +} + +class Dynamic : public DynamicBase { +public: + virtual int get (void); +}; + +int +Dynamic::get (void) +{ + return 9999; +} + +int +cbvDynamic (DynamicBase arg) +{ + arg.x += 4; // intentionally modify + return arg.x + arg.get (); +} + +class Inlined { +public: + Inlined (void); + + __attribute__((always_inline)) + Inlined (const Inlined &rhs) + { + x = 3; + } + + int x; +}; + +Inlined::Inlined (void) +{ + x = 2; +} + +int +cbvInlined (Inlined arg) +{ + arg.x += 4; // intentionally modify + return arg.x; +} + +class DtorDel { +public: + DtorDel (void); + + ~DtorDel (void) = delete; + + int x; +}; + +DtorDel::DtorDel (void) +{ + x = 2; +} + +int +cbvDtorDel (DtorDel arg) +{ + // Calling this method should be rejected + return arg.x; +} + +class FourCCtor { +public: + FourCCtor (void); + + FourCCtor (FourCCtor &rhs); + FourCCtor (const FourCCtor &rhs); + FourCCtor (volatile FourCCtor &rhs); + FourCCtor (const volatile FourCCtor &rhs); + + int x; +}; + +FourCCtor::FourCCtor (void) +{ + x = 2; +} + +FourCCtor::FourCCtor (FourCCtor &rhs) +{ + x = 3; +} + +FourCCtor::FourCCtor (const FourCCtor &rhs) +{ + x = 4; +} + +FourCCtor::FourCCtor (volatile FourCCtor &rhs) +{ + x = 5; +} + +FourCCtor::FourCCtor (const volatile FourCCtor &rhs) +{ + x = 6; +} + +int +cbvFourCCtor (FourCCtor arg) +{ + arg.x += 10; // intentionally modify + return arg.x; +} + +class TwoMCtor { +public: + TwoMCtor (void); + + /* Even though one move ctor is defaulted, the other + is explicit. */ + TwoMCtor (const TwoMCtor &&rhs); + TwoMCtor (TwoMCtor &&rhs) = default; + + int x; +}; + +TwoMCtor::TwoMCtor (void) +{ + x = 2; +} + +TwoMCtor::TwoMCtor (const TwoMCtor &&rhs) +{ + x = 3; +} + +int +cbvTwoMCtor (TwoMCtor arg) +{ + arg.x += 10; // intentionally modify + return arg.x; +} + +class TwoMCtorAndCCtor { +public: + TwoMCtorAndCCtor (void); + + TwoMCtorAndCCtor (const TwoMCtorAndCCtor &rhs) = default; + + /* Even though one move ctor is defaulted, the other + is explicit. This makes the type pass-by-ref. */ + TwoMCtorAndCCtor (const TwoMCtorAndCCtor &&rhs); + TwoMCtorAndCCtor (TwoMCtorAndCCtor &&rhs) = default; + + int x; +}; + +TwoMCtorAndCCtor::TwoMCtorAndCCtor (void) +{ + x = 2; +} + +TwoMCtorAndCCtor::TwoMCtorAndCCtor (const TwoMCtorAndCCtor &&rhs) +{ + x = 4; +} + +int +cbvTwoMCtorAndCCtor (TwoMCtorAndCCtor arg) +{ + arg.x += 10; // intentionally modify + return arg.x; +} + +ArrayContainerByVal arrayContainerByVal; +ArrayContainerByRef arrayContainerByRef; +Dynamic dynamic; +Inlined inlined; +// Cannot stack-allocate DtorDel +DtorDel *dtorDel; +FourCCtor fourCctor_c0v0; +const FourCCtor fourCctor_c1v0; +volatile FourCCtor fourCctor_c0v1; +const volatile FourCCtor fourCctor_c1v1; +TwoMCtor twoMctor; +TwoMCtorAndCCtor twoMctorAndCctor; + +int +main (void) +{ + int v; + dtorDel = new DtorDel; + /* Explicitly call the cbv function to make sure the compiler + will not omit any code in the binary. */ + v = cbvArrayContainerByVal (arrayContainerByVal); + v = cbvArrayContainerByRef (arrayContainerByRef); + v = cbvDynamic (dynamic); + v = cbvInlined (inlined); + v = cbvFourCCtor (fourCctor_c0v0); + v = cbvFourCCtor (fourCctor_c1v0); + v = cbvFourCCtor (fourCctor_c0v1); + v = cbvFourCCtor (fourCctor_c1v1); + /* v = cbvTwoMCtor (twoMctor); */ // This is illegal, cctor is deleted + v = cbvTwoMCtorAndCCtor (twoMctorAndCctor); + + /* stop here */ + + return 0; +} |