Move "register" test out of classes.exp to a separate testcase
The gdb.cp/classes.exp testcase has one test that tries to exercise
the case of calling a method on a variable that has been put in a
register.
See the declaration of small in classes.cc:
/* Try to get the compiler to allocate a class in a register. */
class small {
public:
int x;
int method ();
};
and the comment in classes.exp:
# This class is so small that an instance of it can fit in a register.
# When gdb tries to call a method, it gets embarrassed about taking
# the address of a register.
#
# TODO: I think that message should be a PASS, not an XFAIL.
# gdb prints an informative message and declines to do something
# impossible.
#
# The method call actually succeeds if the compiler allocates very
# small classes in memory instead of registers. So this test does
# not tell us anything interesting if the call succeeds.
#
# -- chastain 2003-12-31
And these comments:
https://gcc.gnu.org/legacy-ml/gcc/2010-05/msg00116.html
https://gcc.gnu.org/legacy-ml/gcc/2010-05/msg00117.html
"register keyword has other uses, e.g. for -O0 code variables
declared with register keyword can be put into registers, while
variables declared without it always get stack slots."
"I think it does, without optimization. There's some unique GDB
tests that use this. It causes them to be live between statements in
a machine register instead of always stored in stack slots."
The "register" keyword seems to be ignored by the compiler nowadays
even at -O0, though. With or without the register keyword, the
variable is given a stack slot, at least on x86-64 with GCC 9.
However, if we use the GCC extension to put the variable
in a specific variable:
https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/Local-Register-Variables.html#Local-Register-Variables
diff --git c/gdb/testsuite/gdb.cp/classes.cc w/gdb/testsuite/gdb.cp/classes.cc
index
5ea360e4d06..
6dcf34689b8 100644
--- c/gdb/testsuite/gdb.cp/classes.cc
+++ w/gdb/testsuite/gdb.cp/classes.cc
@@ -629,7 +629,7 @@ register_class ()
/* We don't call any methods for v, so gcc version cygnus-2.3.3-930220
might put this variable in a register. This is a lose, though, because
it means that GDB can't call any methods for that variable. */
- register small v;
+ register small v asm ("rax");
then it works, and we get an XFAIL:
print v.method ()
Address requested for identifier "v" which is in register $rax
(gdb) XFAIL: gdb.cp/classes.exp: calling method for small class (PRMS 2972)
I think that what we should do here is move this test into its own
file, use that GCC syntax to force it to a register, and do as the
comment says -- issue a pass instead of an XFAIL.
That's what this commit does.
Note that we don't need -Wno-deprecated-register (nor -Wno-register)
anymore in the new testcase, because GNU register-asm local variables
don't trigger the warning, with either GCC or Clang.
gdb/testsuite/ChangeLog:
* gdb.cp/classes.exp: No longer pass -Wno-deprecated-register.
(do_tests): Remove "calling method for small class" test.
* gdb.cp/classes.cc (class small, small::method, marker_reg1)
(register_class): Delete.
(main): Don't call register_class.
* gdb.cp/call-method-register.exp: New file, based on bits removed
from classes.exp.
* gdb.cp/call-method-register.cc: New file, based on bits removed
from classes.cc.