public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v6 00/11] c++/14441: Rvalue reference support
@ 2017-03-10 20:04 Keith Seitz
  2017-03-10 20:04 ` [PATCH v6 01/11] Add definitions for rvalue reference types Keith Seitz
                   ` (11 more replies)
  0 siblings, 12 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:04 UTC (permalink / raw)
  To: gdb-patches

This patch series was submitted in June, 2016, and the original author does
not have the time to see this through. Given that we would like this in the
8.0 release, I have contacted the orginal author, who is allowing me to
champion his patch on his behalf.

When this series was last reviewed, revisions were requested in patches 8
and 11. I have highlighted in those patches what I have changed over the last
submitted patch version (v5).

Keith Seitz (11):
  Add definitions for rvalue reference types
  Change {lookup,make}_reference_type API
  Add ability to return rvalue reference values from value_ref
  Support rvalue reference type in parser
  Implement demangling for rvalue reference type names
  Implement printing of rvalue reference types and values
  Support DW_TAG_rvalue_reference type
  Support rvalue references in the gdb python module (includes doc/)
  Convert lvalue reference type check to general reference type check
  Add rvalue references to overloading resolution
  Add rvalue reference tests and NEWS entry

 gdb/ChangeLog                                      | 188 +++++++++++++++++++++
 gdb/NEWS                                           |   3 +
 gdb/aarch64-tdep.c                                 |   5 +-
 gdb/ada-lang.c                                     |   2 +-
 gdb/amd64-tdep.c                                   |   2 +-
 gdb/amd64-windows-tdep.c                           |   1 +
 gdb/arm-tdep.c                                     |   5 +-
 gdb/ax-gdb.c                                       |   2 +
 gdb/c-exp.y                                        |   6 +-
 gdb/c-typeprint.c                                  |  10 +-
 gdb/c-valprint.c                                   |  14 +-
 gdb/c-varobj.c                                     |  10 +-
 gdb/compile/compile-c-symbols.c                    |   2 +-
 gdb/completer.c                                    |   3 +-
 gdb/cp-name-parser.y                               |   4 +
 gdb/cp-support.c                                   |   3 +-
 gdb/darwin-nat-info.c                              |   2 +-
 gdb/doc/python.texi                                |   4 +
 gdb/dwarf2loc.c                                    |   4 +-
 gdb/dwarf2read.c                                   |  15 +-
 gdb/eval.c                                         |  16 +-
 gdb/f-exp.y                                        |   2 +-
 gdb/findvar.c                                      |   6 +-
 gdb/gdbtypes.c                                     | 105 ++++++++++--
 gdb/gdbtypes.h                                     |  20 ++-
 gdb/guile/scm-type.c                               |   2 +-
 gdb/guile/scm-value.c                              |   2 +-
 gdb/hppa-tdep.c                                    |   1 +
 gdb/infcall.c                                      |   5 +-
 gdb/language.c                                     |   3 +-
 gdb/m32c-tdep.c                                    |   8 +-
 gdb/m88k-tdep.c                                    |   1 +
 gdb/mn10300-tdep.c                                 |   1 +
 gdb/msp430-tdep.c                                  |   2 +-
 gdb/parse.c                                        |  39 +++--
 gdb/parser-defs.h                                  |   1 +
 gdb/ppc-sysv-tdep.c                                |   7 +-
 gdb/printcmd.c                                     |   2 +-
 gdb/python/lib/gdb/command/explore.py              |   2 +-
 gdb/python/lib/gdb/types.py                        |   4 +-
 gdb/python/py-type.c                               |  14 +-
 gdb/python/py-value.c                              |  37 ++--
 gdb/python/py-xmethods.c                           |  10 +-
 gdb/s390-linux-tdep.c                              |   2 +-
 gdb/sparc-tdep.c                                   |   1 +
 gdb/sparc64-tdep.c                                 |   1 +
 gdb/spu-tdep.c                                     |   1 +
 gdb/stabsread.c                                    |   3 +-
 gdb/symtab.c                                       |   3 +-
 gdb/testsuite/ChangeLog                            |  20 +++
 gdb/testsuite/gdb.cp/demangle.exp                  |  42 ++++-
 gdb/testsuite/gdb.cp/rvalue-ref-casts.cc           |  75 ++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-casts.exp          |  76 +++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-overload.cc        |  86 ++++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-overload.exp       |  69 ++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-params.cc          |  83 +++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-params.exp         |  64 +++++++
 gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc          |  75 ++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp         |  43 +++++
 gdb/testsuite/gdb.cp/rvalue-ref-types.cc           |  79 +++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-types.exp          | 165 ++++++++++++++++++
 gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc |  55 ++++++
 .../gdb.python/py-rvalue-ref-value-cc.exp          |  56 ++++++
 gdb/typeprint.c                                    |   4 +-
 gdb/valarith.c                                     |   6 +-
 gdb/valops.c                                       |  70 ++++----
 gdb/valprint.c                                     |   5 +-
 gdb/value.c                                        |  12 +-
 gdb/value.h                                        |   2 +-
 gdb/varobj.c                                       |   2 +-
 70 files changed, 1507 insertions(+), 168 deletions(-)
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-casts.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-overload.exp
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-params.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-params.exp
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-types.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-types.exp
 create mode 100644 gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc
 create mode 100644 gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp

-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 01/11] Add definitions for rvalue reference types
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
@ 2017-03-10 20:04 ` Keith Seitz
  2017-03-10 20:05 ` [PATCH v6 02/11] Change {lookup,make}_reference_type API Keith Seitz
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:04 UTC (permalink / raw)
  To: gdb-patches

This patch introduces preliminal definitions regarding C++11 rvalue references
to the gdb type system. In addition to an enum type_code entry, a field in
struct type and an accessor macro for that which are created similarly to the
lvalue references counterparts, we also introduce a TYPE_REFERENCE convenience
macro used to check for both kinds of references simultaneously as they are
equivalent in many contexts.

There are no changes to this patch from v5.

gdb/Changelog

    PR gdb/14441
    From Artemiy Volkov  <artemiyv@acm.org>
    * gdbtypes.h (enum type_code) <TYPE_CODE_RVALUE_REF>: New constant.
    (TYPE_IS_REFERENCE): New macro.
    (struct type): Add rvalue_reference_type field.
    (TYPE_RVALUE_REFERENCE_TYPE): New macro.
---
 gdb/ChangeLog  |  9 +++++++++
 gdb/gdbtypes.h | 12 ++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e4c4432..7f2e2e5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
+	* gdbtypes.h (enum type_code) <TYPE_CODE_RVALUE_REF>: New constant.
+	(TYPE_IS_REFERENCE): New macro.
+	(struct type): Add rvalue_reference_type field.
+	(TYPE_RVALUE_REFERENCE_TYPE): New macro.
+
 2017-03-10  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/8218
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index e094ece..7d107fa 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -160,6 +160,8 @@ enum type_code
 
     TYPE_CODE_REF,		/**< C++ Reference types */
 
+    TYPE_CODE_RVALUE_REF,	/**< C++ rvalue reference types */
+
     TYPE_CODE_CHAR,		/**< *real* character type */
 
     /* * Boolean type.  0 is false, 1 is true, and other values are
@@ -335,6 +337,11 @@ enum type_instance_flag_value
 #define TYPE_ATOMIC(t) \
   (TYPE_INSTANCE_FLAGS (t) & TYPE_INSTANCE_FLAG_ATOMIC)
 
+/* * True if this type represents either an lvalue or lvalue reference type.  */
+
+#define TYPE_IS_REFERENCE(t) \
+  (TYPE_CODE (t) == TYPE_CODE_REF || TYPE_CODE (t) == TYPE_CODE_RVALUE_REF)
+
 /* * Instruction-space delimited type.  This is for Harvard architectures
    which have separate instruction and data address spaces (and perhaps
    others).
@@ -740,6 +747,10 @@ struct type
 
   struct type *reference_type;
 
+  /* * A C++ rvalue reference type added in C++11. */
+
+  struct type *rvalue_reference_type;
+
   /* * Variant chain.  This points to a type that differs from this
      one only in qualifiers and length.  Currently, the possible
      qualifiers are const, volatile, code-space, data-space, and
@@ -1196,6 +1207,7 @@ extern void allocate_gnat_aux_type (struct type *);
 #define TYPE_TARGET_TYPE(thistype) TYPE_MAIN_TYPE(thistype)->target_type
 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
+#define TYPE_RVALUE_REFERENCE_TYPE(thistype) (thistype)->rvalue_reference_type
 #define TYPE_CHAIN(thistype) (thistype)->chain
 /* * Note that if thistype is a TYPEDEF type, you have to call check_typedef.
    But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (2 preceding siblings ...)
  2017-03-10 20:05 ` [PATCH v6 03/11] Add ability to return rvalue reference values from value_ref Keith Seitz
@ 2017-03-10 20:05 ` Keith Seitz
  2017-03-10 22:02   ` Eli Zaretskii
                     ` (2 more replies)
  2017-03-10 20:10 ` [PATCH v6 07/11] Support DW_TAG_rvalue_reference type Keith Seitz
                   ` (7 subsequent siblings)
  11 siblings, 3 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:05 UTC (permalink / raw)
  To: gdb-patches

This patch adds tests for the initial rvalue reference support patchset.  All
of the new tests are practically mirrored regular references tests and, except
for the demangler ones, are introduced in new files, which are set to be
compiled with -std=gnu++11.  Tested are printing of rvalue reference types and
values, rvalue reference parameters in function overloading, demangling of
function names containing rvalue reference parameters, casts to rvalue
reference types, application of the sizeof operator to rvalue reference types
and values, and support for rvalue references within the gdb python module.

Changes since v5:
o Added NEWS entries
o Rewrote rvalue-ref-overload.{cc,exp}
o Updated all tests to current coding standard
o Added missing copyright headers, maintaining dates from copied files
o KFAIL failing overload resolution tests

gdb/ChnageLog

	* NEWS: Mention support for ravlue references in GDB and python.

gdb/testsuite/ChangeLog

	PR gdb/14441
	* gdb.cp/rvalue-ref-overload.cc: New file.
	* gdb.cp/rvalue-ref-overload.exp: New file.

	PR gdb/14441
	From Artemiy Volkov  <artemiyv@acm.org>
	* gdb.cp/demangle.exp: Add rvalue reference tests.
	* gdb.cp/rvalue-ref-casts.cc: New file.
	* gdb.cp/rvalue-ref-casts.exp: New file.
	* gdb.cp/rvalue-ref-params.cc: New file.
	* gdb.cp/rvalue-ref-params.exp: New file.
	* gdb.cp/rvalue-ref-sizeof.cc: New file.
	* gdb.cp/rvalue-ref-sizeof.exp: New file.
	* gdb.cp/rvalue-ref-types.cc: New file.
	* gdb.cp/rvalue-ref-types.exp: New file.
	* gdb.python/py-rvalue-ref-value-cc.cc: New file.
	* gdb.python/py-rvalue-ref-value-cc.exp: New file.
---
 gdb/ChangeLog                                      |   5 +
 gdb/NEWS                                           |   3 +
 gdb/testsuite/ChangeLog                            |  20 +++
 gdb/testsuite/gdb.cp/demangle.exp                  |  42 +++++-
 gdb/testsuite/gdb.cp/rvalue-ref-casts.cc           |  75 ++++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-casts.exp          |  76 ++++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-overload.cc        |  86 +++++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-overload.exp       |  69 +++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-params.cc          |  83 +++++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-params.exp         |  64 ++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc          |  75 ++++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp         |  43 ++++++
 gdb/testsuite/gdb.cp/rvalue-ref-types.cc           |  79 ++++++++++
 gdb/testsuite/gdb.cp/rvalue-ref-types.exp          | 165 +++++++++++++++++++++
 gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc |  59 ++++++++
 .../gdb.python/py-rvalue-ref-value-cc.exp          |  57 +++++++
 16 files changed, 1000 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-casts.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-overload.exp
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-params.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-params.exp
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-types.cc
 create mode 100644 gdb/testsuite/gdb.cp/rvalue-ref-types.exp
 create mode 100644 gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc
 create mode 100644 gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 338f412..6d9cb4c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,6 +1,11 @@
 2017-MM-DD  Keith Seitz  <keiths@redhat.com>
 
 	PR gdb/14441
+	* NEWS: Mention support for ravlue references in GDB and python.
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
 	* gdbtypes.c (rank_one_type): Implement overloading
 	resolution rules regarding rvalue references.
diff --git a/gdb/NEWS b/gdb/NEWS
index cf58595..edbe41f 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -7,9 +7,12 @@
   added by the Memory Protection Keys for Userspace feature which will be
   available in future Intel CPUs.
 
+* GDB now supports C++11 ravlue references.
+
 * Python Scripting
 
   ** New functions to start, stop and access a running btrace recording.
+  ** Rvalue references are now supported in gdb.Type.
 
 * GDB now supports recording and replaying rdrand and rdseed Intel 64
   instructions.
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 0718d76..6e2a80f 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,23 @@
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	Based on work from Artemiy Volkov  <artemiyv@acm.org>
+	* gdb.cp/rvalue-ref-overload.cc: New file.
+	* gdb.cp/rvalue-ref-overload.exp: New file.
+
+	From Artemiy Volkov  <artemiyv@acm.org>
+	* gdb.cp/demangle.exp: Add rvalue reference tests.
+	* gdb.cp/rvalue-ref-casts.cc: New file.
+	* gdb.cp/rvalue-ref-casts.exp: New file.
+	* gdb.cp/rvalue-ref-params.cc: New file.
+	* gdb.cp/rvalue-ref-params.exp: New file.
+	* gdb.cp/rvalue-ref-sizeof.cc: New file.
+	* gdb.cp/rvalue-ref-sizeof.exp: New file.
+	* gdb.cp/rvalue-ref-types.cc: New file.
+	* gdb.cp/rvalue-ref-types.exp: New file.
+	* gdb.python/py-rvalue-ref-value-cc.cc: New file.
+	* gdb.python/py-rvalue-ref-value-cc.exp: New file.
+
 2017-03-10  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/8128
diff --git a/gdb/testsuite/gdb.cp/demangle.exp b/gdb/testsuite/gdb.cp/demangle.exp
index 0ecf95d..fe51c55 100644
--- a/gdb/testsuite/gdb.cp/demangle.exp
+++ b/gdb/testsuite/gdb.cp/demangle.exp
@@ -70,7 +70,9 @@ proc test_demangling_core {tester test result} {
     }
 
     if {[string compare $style $current_demangling_style]} {
-	set_demangling_style $style
+	with_test_prefix $test {
+	    set_demangling_style $style
+	}
     }
 
     $tester "demangle $name" $result $test
@@ -521,6 +523,44 @@ proc test_gnu_style_demangling {} {
     test_demangling_exact "gnu: foo__I_200_" "foo(int512_t)"
     test_demangling_exact "gnu: foo__I_200" "Can't demangle \"foo__I_200\""
 
+    # Rvalue reference tests
+    test_demangling_exact "gnu-v3: _ZN9ArrowLine19ArrowheadIntersectsEP9ArrowheadO6BoxObjP7Graphic" "ArrowLine::ArrowheadIntersects(Arrowhead*, BoxObj&&, Graphic*)"
+    test_demangling "gnu-v3: _Z13BitPatterntoaOK10BitPatternccc" \
+	"BitPatterntoa\[(\]+(const BitPattern|BitPattern const)&&, char, char, char\[)\]+"
+    test_demangling_exact "gnu-v3: _ZN8TextCode14CoreConstDeclsEO7ostream" "TextCode::CoreConstDecls(ostream&&)"
+    test_demangling "gnu-v3: _Z31DrawDestinationTransformedImageP7_XImageiiS0_iimjiijmmP4_XGCOK13ivTransformeriiii" \
+	"DrawDestinationTransformedImage\[(\]+_XImage\[*\]+, int, int, _XImage\[*\]+, int, int, unsigned long, unsigned int, int, int, unsigned int, unsigned long, unsigned long, _XGC\[*\]+, (const ivTransformer|ivTransformer const)&&, int, int, int, int\[)\]+"
+    test_demangling_exact "gnu-v3: _ZN11RelateManip6EffectEO7ivEvent" "RelateManip::Effect(ivEvent&&)"
+    test_demangling_exact "gnu-v3: _ZN20DisplayList_IteratorC4EO11DisplayList" "DisplayList_Iterator::DisplayList_Iterator(DisplayList&&)"
+    test_demangling_exact "gnu-v3: _ZN3fooC4EOS_" "foo::foo(foo&&)"
+    test_demangling_exact "gnu-v3: _ZN3fooC4EiOS_iS0_iS0_" "foo::foo(int, foo&&, int, foo&&, int, foo&&)"
+    test_demangling "gnu-v3: _ZN7ivWorldC2EPKcOiPPcPK12ivOptionDescPK14ivPropertyData" \
+	"ivWorld::ivWorld\[(\]+(const char|char const)\[*\]+, int&&, char\[*\]+\[*\]+, (const ivOptionDesc|ivOptionDesc const)\[*\]+, (const ivPropertyData|ivPropertyData const)\[*\]+\[)\]+"
+    test_demangling "gnu-v3: _Z3argOK7Complex" \
+	"arg\[(\]+(const Complex|Complex const)&&\[)\]+"
+    test_demangling "gnu-v3: _ZNK9BitString8containsEOK10BitPattern" \
+	"BitString::contains\[(\]+(const BitPattern|BitPattern const)&&\[)\]+ const"
+    test_demangling "gnu-v3: _ZNK9BitString8containsEOK12BitSubStringi" \
+	"BitString::contains\[(\]+(const BitSubString|BitSubString const)&&, int\[)\]+ const"
+    test_demangling "gnu-v3: _ZNK9BitString8containsEOKS_" \
+	"BitString::contains\[(\]+(const BitString|BitString const)&&\[)\]+ const"
+    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE3PixC4EOKS2_" \
+	"List<VHDLEntity>::Pix::Pix(List<VHDLEntity>::Pix const&&)"
+    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC2EOKS0_PS2_" \
+	"List<VHDLEntity>::element::element(VHDLEntity const&&, List<VHDLEntity>::element*)"
+    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC4EOKS2_" \
+	"List<VHDLEntity>::element::element(List<VHDLEntity>::element const&&)"
+    test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityEclEOKNS1_3PixE" \
+	"List<VHDLEntity>::operator()(List<VHDLEntity>::Pix const&&) const"
+    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityEC4EOKS1_" \
+	"List<VHDLEntity>::List(List<VHDLEntity> const&&)"
+    test_demangling_exact "gnu-v3: _ZN4PixXI11VHDLLibrary14VHDLLibraryRep4ListI10VHDLEntityEEC2EOKS5_" \
+	"PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> >::PixX(PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> > const&&)"
+    test_demangling_exact "gnu-v3: _ZNK11VHDLLibrary5nextEEO4PixXIS_14VHDLLibraryRep4ListI10VHDLEntityEE" \
+	"VHDLLibrary::nextE(PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> >&&) const"
+    test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityE4nextEONS1_3PixE" \
+	"List<VHDLEntity>::next(List<VHDLEntity>::Pix&&) const"
+
     ## Buffer overrun.  Should make GDB crash.  Woo hoo!
     test_demangling_exact "gnu: foo__I_4000000000000000000000000000000000000000000000000000000000000000000000000" "Can't demangle \"foo__I_4000000000000000000000000000000000000000000000000000000000000000000000000\""
 
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc b/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc
new file mode 100644
index 0000000..1f81fe0
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc
@@ -0,0 +1,75 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2002-2017 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/>.  */
+
+/* Rvalue references casting tests, based on casts.cc.  */
+
+#include <utility>
+
+struct A
+{
+  int a;
+  A (int aa): a (aa) {}
+};
+
+struct B: public A
+{
+  int b;
+  B (int aa, int bb): A (aa), b (bb) {}
+};
+
+
+struct Alpha
+{
+  virtual void x () { }
+};
+
+struct Gamma
+{
+};
+
+struct Derived : public Alpha
+{
+};
+
+struct VirtuallyDerived : public virtual Alpha
+{
+};
+
+struct DoublyDerived : public VirtuallyDerived,
+		       public virtual Alpha,
+		       public Gamma
+{
+};
+
+int
+main (int argc, char **argv)
+{
+  A *a = new B (42, 1729);
+  B *b = (B *) a;
+  A &ar = *b;
+  B &br = (B&)ar;
+  A &&arr = std::move (A (42));
+  B &&brr = std::move (B (42, 1729));
+
+  Derived derived;
+  DoublyDerived doublyderived;
+
+  Alpha *ad = &derived;
+  Alpha *add = &doublyderived;
+
+  return 0;  /* breakpoint spot: rvalue-ref-casts.exp: 1 */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp b/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
new file mode 100644
index 0000000..7ae4ef0
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
@@ -0,0 +1,76 @@
+# Copyright 2002-2017 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/>.
+
+# This file is part of the gdb testsuite
+
+# C++11 rvalue reference type casting tests, based on gdb.cp/casts.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[get_compiler_info "c++"]} {
+    return -1
+}
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}]} {
+    return -1
+}
+
+if {![runto_main]} {
+    untested "couldn't run to main"
+    return -1
+}
+
+# Prevent symbol on address 0x0 being printed.
+gdb_test_no_output "set print symbol off"
+
+set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}]
+gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\."
+
+gdb_test "continue" "Breakpoint .* at .*$srcfile:$line.*"
+
+# Check upcasting.
+gdb_test "print (A &&) br" ".* = .A &&.* {a = 42}" \
+    "cast derived class rvalue reference to base class rvalue reference"
+
+# Check downcasting.
+gdb_test "print (B &&) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
+    "cast base class rvalue reference to derived class rvalue reference"
+
+# Check compiler casting
+
+set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+"
+
+gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
+    [concat "let compiler cast base class rvalue reference to derived " \
+	 "class rvalue reference"]
+
+gdb_test "print static_cast<A &&> (*b)" " = \\(A \\&\\&\\) @$hex: {a = 42}" \
+    "static_cast to rvalue reference type"
+
+gdb_test "print reinterpret_cast<A &&> (*b)" \
+    " = \\(A \\&\\&\\) @$hex: {a = 42}" \
+    "reinterpret_cast to rvalue reference type"
+
+gdb_test "print dynamic_cast<Alpha &&> (derived)" \
+    [format " = \\(Alpha \\&\\&\\) @%s: {.* = %s( <vtable for Derived.*>)?}" \
+	 $nonzero_hex $nonzero_hex] \
+    "dynamic_cast simple upcast to rvalue reference"
+
+gdb_test "print dynamic_cast<VirtuallyDerived &&> (*ad)" \
+    "dynamic_cast failed" \
+    "dynamic_cast to rvalue reference to non-existing base"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc b/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
new file mode 100644
index 0000000..c12eb03
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
@@ -0,0 +1,86 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 1998-2017 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/>.  */
+
+/* Rvalue references overload tests for GDB, based on overload.cc.  */
+
+#include <stddef.h>
+#include <utility>
+
+class foo;
+
+typedef foo &foo_lval_ref;
+typedef foo &&foo_rval_ref;
+
+class foo
+{
+public:
+  foo ();
+  foo (foo_lval_ref);
+  foo (foo_rval_ref);
+  ~foo ();
+
+  int overload1arg (foo_lval_ref);
+  int overload1arg (foo_rval_ref);
+};
+
+void
+marker1 ()
+{
+}
+
+static int
+f (int &x)
+{
+  return 1;
+}
+
+static int
+f (const int &x)
+{
+  return 2;
+}
+
+static int
+f (int &&x)
+{
+  return 3;
+}
+
+int
+main ()
+{
+  foo foo_rr_instance1;
+  foo arg;
+  int i = 0;
+  const int ci = 0;
+
+  // result = 1 + 2 + 3 + 3 = 9
+  int result = f (i) + f (ci) + f (0) + f (std::move (i));
+
+  marker1 (); // marker1-returns-here
+  return result;
+}
+
+foo::foo  ()                       {}
+foo::foo  (foo_lval_ref afoo)      {}
+foo::foo  (foo_rval_ref afoo)      {}
+foo::~foo ()                       {}
+
+/* Some functions to test overloading by varying one argument type. */
+
+int foo::overload1arg (foo_lval_ref arg)           { return 1; }
+int foo::overload1arg (foo_rval_ref arg)           { return 2; }
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp b/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp
new file mode 100644
index 0000000..e729209
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp
@@ -0,0 +1,69 @@
+# Copyright 1998-2017 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/>.
+
+# This file is part of the gdb testsuite
+
+# Tests for overloaded member functions with rvalue reference parameters,
+# based on gdb.cp/overload.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+load_lib "cp-support.exp"
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}]} {
+    return -1
+}
+
+# Set it up at a breakpoint so we can play with the variable values.
+
+if {![runto 'marker1']} {
+    untested "couldn't run to marker1"
+    return -1
+}
+
+# Prevent symbol on address 0x0 being printed.
+gdb_test_no_output "set print symbol off"
+gdb_test "up" ".*main.*" "up from marker1"
+
+# Print the monster class type.
+cp_test_ptype_class "foo_rr_instance1" "" "class" "foo" \
+    {
+	{ method public "foo(void);" }
+	{ method public "foo(foo_lval_ref);" }
+	{ method public "foo(foo_rval_ref);" }
+	{ method public "~foo();" }
+	{ method public "int overload1arg(foo_lval_ref);" }
+	{ method public "int overload1arg(foo_rval_ref);" }
+    }
+
+gdb_test "print foo_rr_instance1.overload1arg(arg)" \
+    "\\$\[0-9\]+ = 1" \
+    "print call overloaded func foo & arg"
+
+gdb_test "print foo_rr_instance1.overload1arg(static_cast<foo&&>(arg))" \
+    "\\$\[0-9\]+ = 2" \
+    "print call overloaded func foo && arg"
+
+# Test lvalue vs rvalue function overloads
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f (i)" "= 1" "lvalue reference overload"
+
+gdb_test "print f (ci)" "= 2" "lvalue reference to const overload"
+
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f (3)" "= 3" "rvalue reference overload"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-params.cc b/gdb/testsuite/gdb.cp/rvalue-ref-params.cc
new file mode 100644
index 0000000..59f459b
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-params.cc
@@ -0,0 +1,83 @@
+/* This test script is part of GDB, the GNU debugger.
+
+   Copyright 2006-2017 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/>.  */
+
+/* Rvalue reference parameter tests, based on ref-params.cc.  */
+
+#include <utility>
+
+struct Parent
+{
+  Parent (int id0) : id (id0) { }
+  int id;
+};
+
+struct Child : public Parent
+{
+  Child (int id0) : Parent (id0) { }
+};
+
+int
+f1 (Parent &&R)
+{
+  return R.id;			/* Set breakpoint marker3 here.  */
+}
+
+int
+f2 (Child &&C)
+{
+  return f1 (std::move (C));                 /* Set breakpoint marker2 here.  */
+}
+
+struct OtherParent
+{
+  OtherParent (int other_id0) : other_id (other_id0) { }
+  int other_id;
+};
+
+struct MultiChild : public Parent, OtherParent
+{
+  MultiChild (int id0) : Parent (id0), OtherParent (id0 * 2) { }
+};
+
+int
+mf1 (OtherParent &&R)
+{
+  return R.other_id;
+}
+
+int
+mf2 (MultiChild &&C)
+{
+  return mf1 (std::move (C));
+}
+
+int
+main ()
+{
+  Child Q(40);
+  Child &QR = Q;
+
+  /* Set breakpoint marker1 here.  */
+
+  f1 (Child (41));
+  f2 (Child (42));
+
+  MultiChild MQ (53);
+  MultiChild &MQR = MQ;
+
+  mf2 (std::move (MQ));			/* Set breakpoint MQ here.  */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-params.exp b/gdb/testsuite/gdb.cp/rvalue-ref-params.exp
new file mode 100644
index 0000000..7ffb344
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-params.exp
@@ -0,0 +1,64 @@
+# Copyright 2006-2017 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/>.
+
+# Tests for rvalue reference parameters of types and their subtypes in GDB,
+# based on gdb.cp/ref-params.exp.
+
+#
+# test running programs
+#
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}] == 1} {
+    return -1
+}
+
+proc gdb_start_again {text} {
+    global binfile
+    global srcfile
+
+    clean_restart $binfile
+
+    runto ${srcfile}:[gdb_get_line_number $text]
+}
+
+gdb_start_again "marker1 here"
+gdb_test "print f1(static_cast<Child&&>(Q))" ".* = 40.*" \
+    "print value of f1 on (Child&&) in main"
+
+gdb_start_again "marker1 here"
+gdb_test "print f2(static_cast<Child&&>(Q))" ".* = 40.*" \
+    "print value of f2 on (Child&&) in main"
+
+gdb_start_again "marker2 here"
+gdb_test "print C" ".*id = 42.*" "print value of Child&& in f2"
+
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f1 (static_cast<Child&&> (C))" ".* = 42.*" \
+    "print value of f1 on Child&& in f2"
+
+gdb_start_again "marker3 here"
+gdb_test "print R" ".*id = 41.*" "print value of Parent&& in f1"
+
+gdb_start_again "breakpoint MQ here"
+gdb_test "print f1(static_cast<MultiChild&&>(MQ))" ".* = 53"
+gdb_start_again "breakpoint MQ here"
+gdb_test "print mf1(static_cast<MultiChild&&>(MQ))" ".* = 106"
+gdb_start_again "breakpoint MQ here"
+gdb_test "print mf2(static_cast<MultiChild&&>(MQ))" ".* = 106"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc
new file mode 100644
index 0000000..ab42c67
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc
@@ -0,0 +1,75 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014-2017 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/>.  */
+
+/* Sizeof tests for rvalue references, based on cpsizeof.cc.  */
+
+#include <utility>
+
+struct Class
+{
+  int a;
+  char b;
+  long c;
+
+  Class () : a (1), b ('2'), c (3) { }
+};
+
+union Union
+{
+  Class *kp;
+  char a;
+  int b;
+  long c;
+};
+
+enum Enum { A, B, C, D };
+
+typedef unsigned char a4[4];
+typedef unsigned char a8[8];
+typedef unsigned char a12[12];
+typedef Class c4[4];
+typedef Union u8[8];
+typedef Enum e12[12];
+
+#define T(N)					\
+  N N ## obj;					\
+  N&& N ## _rref = std::move (N ## obj);        \
+  N* N ## p = &(N ## obj);			\
+  N*&& N ## p_rref = std::move (N ## p);        \
+  int size_ ## N = sizeof (N ## _rref);		\
+  int size_ ## N ## p = sizeof (N ## p_rref);	\
+
+int
+main ()
+{
+  T (char);
+  T (int);
+  T (long);
+  T (float);
+  T (double);
+  T (a4);
+  T (a8);
+  T (a12);
+  T (Class);
+  T (Union);
+  T (Enum);
+  T (c4);
+  T (u8);
+  T (e12);
+
+  return 0; /* break here */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp
new file mode 100644
index 0000000..c6c2d21
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp
@@ -0,0 +1,43 @@
+# Copyright 2014-2017 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/>.
+
+# sizeof() tests with rvalue reference parameter types, based on
+# gdb.cp/cpsizeof.exp.
+
+standard_testfile .cc
+
+if {[skip_cplus_tests]} { continue }
+
+if {[prepare_for_testing ${testfile}.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}] } {
+     return -1
+}
+
+if {![runto_main]} {
+    perror "could not run to main"
+    continue
+}
+
+gdb_breakpoint [gdb_get_line_number "break here"]
+gdb_continue_to_breakpoint "break here"
+
+# Compare sizeof from the compiler and gdb.  Do this once with the actual
+# type name and once with a reference variable.
+foreach v {char int long float double a4 a8 a12 Class Union Enum c4 u8 e12} {
+    gdb_test "print size_$v == sizeof (${v}&&)" "= true"
+    gdb_test "print size_$v == sizeof (${v}_rref)" "= true"
+    gdb_test "print size_${v}p == sizeof (${v}*&&)" "= true"
+    gdb_test "print size_${v}p == sizeof (${v}p_rref)" "= true"
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-types.cc b/gdb/testsuite/gdb.cp/rvalue-ref-types.cc
new file mode 100644
index 0000000..62a665d
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-types.cc
@@ -0,0 +1,79 @@
+/* This test script is part of GDB, the GNU debugger.
+
+   Copyright 1999-2017 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/>.  */
+
+/* Tests for reference types with short type variables in GDB, based on
+   gdb.cp/ref-types.cc.  */
+
+#include <utility>
+
+int main2 ();
+
+void
+marker1 ()
+{
+}
+
+int
+main ()
+{
+  short t = -1;
+  short *pt;
+  short &&rrt = std::move (t);
+  pt = &rrt;
+
+  short *&&rrpt = std::move (pt);
+  short at[4];
+  at[0] = 0;
+  at[1] = 1;
+  at[2] = 2;
+  at[3] = 3;
+
+  short (&&rrat)[4] = std::move( at);
+
+    marker1();
+
+    main2();
+
+    return 0;
+}
+
+int
+f ()
+{
+  int f1;
+  f1 = 1;
+  return f1;
+}
+
+int
+main2 ()
+{
+  char &&rrC = 'A';
+  unsigned char &&rrUC = 21;
+  short &&rrS = -14;
+  unsigned short &&rrUS = 7;
+  int &&rrI = 102;
+  unsigned int &&rrUI = 1002;
+  long &&rrL = -234;
+  unsigned long &&rrUL = 234;
+  float &&rrF = 1.25E10;
+  double &&rrD = -1.375E-123;
+
+  f ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-types.exp b/gdb/testsuite/gdb.cp/rvalue-ref-types.exp
new file mode 100644
index 0000000..9067b3b
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-types.exp
@@ -0,0 +1,165 @@
+# Copyright 1999-2017 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/>.
+
+# Tests for reference types with short type variables in GDB, based on
+# gdb.cp/ref-types.exp.
+
+#
+# test running programs
+#
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}]} {
+    return -1
+}
+
+#
+# Set it up at a breakpoint so we can play with the variable values.
+#
+if {![runto_main]} {
+    untested "couldn't run to breakpoint"
+    return -1
+}
+
+if {![runto 'marker1']} {
+    untested "couldn't run to marker1"
+    return -1
+}
+
+gdb_test "up" ".*main.*" "up from marker1 1"
+
+proc gdb_start_again {} {
+    global srcdir
+    global subdir
+    global binfile
+    global gdb_prompt
+    global decimal
+
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load ${binfile}
+
+    #
+    # set it up at a breakpoint so we can play with the variable values
+    #
+    if {![runto_main]} {
+	perror "couldn't run to breakpoint"
+	continue
+    }
+
+    if {![runto 'marker1']} {
+	perror "couldn't run to marker1"
+	continue
+    }
+
+    gdb_test "up" ".*main.*" "up from marker1 2"
+}
+
+
+gdb_test_multiple "print rrt" "print value of rrt" {
+    -re ".\[0-9\]* = \\(short( int)? &&\\) @$hex: -1.*$gdb_prompt $" {
+        pass "print value of rrt"
+    }
+    eof { fail "print rrt ($gdb dumped core) (fixme)" ; gdb_start_again ; }
+}
+
+gdb_test "ptype rrt" "type = short( int)? &&" "ptype rrt"
+
+gdb_test "print *rrpt" ".$decimal = -1" "print value of *rrpt"
+
+# gdb had a bug about dereferencing a pointer type
+# that would lead to wrong results
+# if we try to examine memory at pointer value.
+
+gdb_test "x /hd rrpt" "$hex:\[ \t\]*-1" "examine value at rrpt"
+
+gdb_test "ptype rrpt" "type = short( int)? \\*&&" "ptype rrpt"
+
+gdb_test "print rrat\[0\]" ".$decimal = 0" "print value of rrat\[0\]"
+
+gdb_test "ptype rrat" "type = short( int)? \\\(&&\\\)\\\[4\\\]" "ptype rrat"
+
+gdb_test "print rrat\[1\]" ".$decimal = 1" "print value of rrat\[1\]"
+gdb_test "print rrat\[2\]" ".$decimal = 2" "print value of rrat\[2\]"
+gdb_test "print rrat\[3\]" ".$decimal = 3" "print value of rrat\[3\]"
+
+
+if {![runto 'f']} then {
+    perror "couldn't run to f"
+    continue
+}
+
+gdb_test "up" ".main2.*" "up from f"
+
+gdb_test "ptype rrC" "type = char &&"
+
+gdb_test "ptype rrUC" "type = unsigned char &&"
+
+gdb_test "ptype rrS" "type = short( int)? &&" "ptype rrS"
+
+gdb_test "ptype rrUS" "type = unsigned short( int)? &&" "ptype rrUS"
+
+gdb_test "ptype rrI" "type = int &&"
+
+gdb_test "ptype rrUI" "type = unsigned int &&"
+
+gdb_test "ptype rrL" "type = long( int)? &&" "ptype rrL"
+
+gdb_test "ptype rrUL" "type = unsigned long( int)? &&" "ptype rrUL"
+
+gdb_test "ptype rrF" "type = float &&"
+
+gdb_test "ptype rrD" "type = double &&"
+
+gdb_test "print rrC" "$decimal = \\(char &&\\) @$hex: 65 \'A\'" \
+    "print value of rrC"
+
+gdb_test "print rrUC" \
+    "$decimal = \\(unsigned char &&\\) @$hex: 21 \'.025\'" \
+    "print value of rrUC"
+
+gdb_test "print rrS" "$decimal = \\(short( int)? &&\\) @$hex: -14" \
+                  "print value of rrS"
+
+gdb_test "print rrUS" \
+         "$decimal = \\(unsigned short( int)? &&\\) @$hex: 7" \
+         "print value of rrUS"
+
+gdb_test "print rrI" "$decimal = \\(int &&\\) @$hex: 102" \
+       "print value of rrI"
+
+gdb_test "print rrUI" \
+    "$decimal = \\(unsigned int &&\\) @$hex: 1002" \
+        "print value of rrUI"
+
+gdb_test "print rrL" \
+       "$decimal = \\(long( int)? &&\\) @$hex: -234" \
+         "print value of rrL"
+
+gdb_test "print rrUL" \
+    "$decimal = \\((unsigned long|long unsigned int)? &&\\) @$hex: 234" \
+    "print value of rrUL"
+
+gdb_test "print rrF" \
+    "$decimal = \\(float &&\\) @$hex: 1.2${decimal}e\\+0?10.*" \
+    "print value of rrF"
+
+gdb_test "print rrD" \
+    "$decimal = \\(double &&\\) @$hex: -1.375e-123.*" \
+    "print value of rrD"
diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc
new file mode 100644
index 0000000..8943be1
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc
@@ -0,0 +1,59 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012-2017 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/>.  */
+
+/* Test rvalue references in python.  Based on py-value-cc.cc.  */
+
+#include <utility>
+
+class A
+{
+public:
+  int operator+ (const int a1);
+
+ public:
+  int a;
+};
+
+int
+A::operator+ (const int a1)
+{
+  return a + a1;
+}
+
+class B : public A
+{
+ public:
+  char a;
+};
+
+typedef int *int_ptr;
+
+int
+main ()
+{
+  int val = 10;
+  int &&int_rref = std::move (val);
+  int_ptr ptr = &val;
+  int_ptr &&int_ptr_rref = std::move (ptr);
+
+  B b;
+  b.a = 'b';
+  (&b)->A::a = 100;
+  B &&b_rref = std::move (b);
+
+  return 0; /* Break here.  */
+}
diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp
new file mode 100644
index 0000000..dde5a94
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp
@@ -0,0 +1,57 @@
+# Copyright (C) 2012-2017 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/>.
+
+# This file is part of the GDB testsuite.  It tests the mechanism
+# exposing rvalue reference values to Python.  It is based on
+# gdb.python/py-value-cc.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=c++11"}]} {
+    return -1
+}
+
+# Skip all tests if Python scripting is not enabled.
+if {[skip_python_tests]} { continue }
+
+if {![runto_main]} {
+    untested "couldn't run to main"
+   return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "Break here."]
+gdb_continue_to_breakpoint "Break here" ".*Break here.*"
+
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").type))" "int &&"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").referenced_value().type))" "int"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").referenced_value()))" "10"
+
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").dereference().type))" "int"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().type))" "int_ptr"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().dereference()))" "10"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().referenced_value()))" "10"
+
+gdb_test_no_output "python b = gdb.parse_and_eval('b')" "init b"
+gdb_test_no_output "python b_rref = gdb.parse_and_eval('b_rref')" "init b_rref"
+gdb_test_no_output "python b_fields = b.type.fields()" "init b_fields"
+
+gdb_test "python print(b_rref\[b_fields\[1\]\])" "98 'b'" "b_rref.a via field"
+gdb_test "python print(b_rref\[b_fields\[0\]\].type.target())" "A" \
+  "type of b_rref's base class via field"
+gdb_test "python print(b_rref\[b_fields\[0\]\]\['a'\])" "100" \
+  "b_rref.A::a via field"
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 02/11] Change {lookup,make}_reference_type API
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
  2017-03-10 20:04 ` [PATCH v6 01/11] Add definitions for rvalue reference types Keith Seitz
@ 2017-03-10 20:05 ` Keith Seitz
  2017-03-10 20:05 ` [PATCH v6 03/11] Add ability to return rvalue reference values from value_ref Keith Seitz
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:05 UTC (permalink / raw)
  To: gdb-patches

Parameterize lookup_reference_type() and make_reference_type() by the kind of
reference type we want to look up. Create two wrapper functions
lookup_{lvalue,rvalue}_reference_type() for lookup_reference_type() to simplify
the API. Change all callers to use the new API.

There are no changes to this patch from v5.

gdb/Changelog

	PR gdb/14441
	From  Artemiy Volkov  <artemiyv@acm.org>
	* dwarf2read.c (read_tag_reference_type): Use
	lookup_lvalue_reference_type() instead of lookup_reference_type().
	* eval.c (evaluate_subexp_standard): Likewise.
	* f-exp.y: Likewise.
	* gdbtypes.c (make_reference_type, lookup_reference_type):
	Generalize with rvalue reference types.
	(lookup_lvalue_reference_type, lookup_rvalue_reference_type): New
	convenience wrappers for lookup_reference_type().
	* gdbtypes.h (make_reference_type, lookup_reference_type): Add a
	reference kind parameter.
	(lookup_lvalue_reference_type, lookup_rvalue_reference_type): Add
	wrappers for lookup_reference_type().
	* guile/scm-type.c (gdbscm_type_reference): Use
	lookup_lvalue_reference_type() instead of lookup_reference_type().
	* guile/scm-value.c (gdbscm_value_dynamic_type): Likewise.
	* parse.c (follow_types): Likewise.
	* python/py-type.c (typy_reference, typy_lookup_type): Likewise.
	* python/py-value.c (valpy_get_dynamic_type, valpy_getitem):
	Likewise.
	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
	(gdbpy_invoke_xmethod): Likewise.
	* stabsread.c: Provide extra argument to make_reference_type()
	call.
	* valops.c (value_ref, value_rtti_indirect_type): Use
	lookup_lvalue_reference_type() instead of lookup_reference_type().
---
 gdb/ChangeLog            | 30 ++++++++++++++++++++++++++++++
 gdb/dwarf2read.c         |  2 +-
 gdb/eval.c               |  2 +-
 gdb/f-exp.y              |  2 +-
 gdb/gdbtypes.c           | 42 +++++++++++++++++++++++++++++++++---------
 gdb/gdbtypes.h           |  8 ++++++--
 gdb/guile/scm-type.c     |  2 +-
 gdb/guile/scm-value.c    |  2 +-
 gdb/parse.c              |  2 +-
 gdb/python/py-type.c     |  4 ++--
 gdb/python/py-value.c    |  5 +++--
 gdb/python/py-xmethods.c |  4 ++--
 gdb/stabsread.c          |  3 ++-
 gdb/valops.c             |  4 ++--
 14 files changed, 86 insertions(+), 26 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7f2e2e5..0ec9777 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -2,6 +2,36 @@
 
 	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
+	* dwarf2read.c (read_tag_reference_type): Use
+	lookup_lvalue_reference_type() instead of lookup_reference_type().
+	* eval.c (evaluate_subexp_standard): Likewise.
+	* f-exp.y: Likewise.
+	* gdbtypes.c (make_reference_type, lookup_reference_type):
+	Generalize with rvalue reference types.
+	(lookup_lvalue_reference_type, lookup_rvalue_reference_type): New
+	convenience wrappers for lookup_reference_type().
+	* gdbtypes.h (make_reference_type, lookup_reference_type): Add a
+	reference kind parameter.
+	(lookup_lvalue_reference_type, lookup_rvalue_reference_type): Add
+	wrappers for lookup_reference_type().
+	* guile/scm-type.c (gdbscm_type_reference): Use
+	lookup_lvalue_reference_type() instead of lookup_reference_type().
+	* guile/scm-value.c (gdbscm_value_dynamic_type): Likewise.
+	* parse.c (follow_types): Likewise.
+	* python/py-type.c (typy_reference, typy_lookup_type): Likewise.
+	* python/py-value.c (valpy_get_dynamic_type, valpy_getitem):
+	Likewise.
+	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
+	(gdbpy_invoke_xmethod): Likewise.
+	* stabsread.c: Provide extra argument to make_reference_type()
+	call.
+	* valops.c (value_ref, value_rtti_indirect_type): Use
+	lookup_lvalue_reference_type() instead of lookup_reference_type().
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
 	* gdbtypes.h (enum type_code) <TYPE_CODE_RVALUE_REF>: New constant.
 	(TYPE_IS_REFERENCE): New macro.
 	(struct type): Add rvalue_reference_type field.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 40b99d9..f3a8cc6 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -14584,7 +14584,7 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
   if (type)
     return type;
 
-  type = lookup_reference_type (target_type);
+  type = lookup_lvalue_reference_type (target_type);
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr)
     {
diff --git a/gdb/eval.c b/gdb/eval.c
index 76d7f73..61d8d19 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2771,7 +2771,7 @@ evaluate_subexp_standard (struct type *expect_type,
 
 	      if (TYPE_CODE (check_typedef (type)) != TYPE_CODE_REF)
 		{
-		  type = lookup_reference_type (type);
+		  type = lookup_lvalue_reference_type (type);
 		  result = allocate_value (type);
 		}
 	    }
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index a791d2c..49d797d 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -513,7 +513,7 @@ ptype	:	typebase
 			follow_type = lookup_pointer_type (follow_type);
 			break;
 		      case tp_reference:
-			follow_type = lookup_reference_type (follow_type);
+			follow_type = lookup_lvalue_reference_type (follow_type);
 			break;
 		      case tp_array:
 			array_size = pop_type_int ();
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 5e5db27..60cef68 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -384,15 +384,21 @@ lookup_pointer_type (struct type *type)
 /* Lookup a C++ `reference' to a type TYPE.  TYPEPTR, if nonzero,
    points to a pointer to memory where the reference type should be
    stored.  If *TYPEPTR is zero, update it to point to the reference
-   type we return.  We allocate new memory if needed.  */
+   type we return.  We allocate new memory if needed. REFCODE denotes
+   the kind of reference type to lookup (lvalue or rvalue reference).  */
 
 struct type *
-make_reference_type (struct type *type, struct type **typeptr)
+make_reference_type (struct type *type, struct type **typeptr,
+                      enum type_code refcode)
 {
   struct type *ntype;	/* New type */
+  struct type **reftype;
   struct type *chain;
 
-  ntype = TYPE_REFERENCE_TYPE (type);
+  gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
+
+  ntype = (refcode == TYPE_CODE_REF ? TYPE_REFERENCE_TYPE (type)
+           : TYPE_RVALUE_REFERENCE_TYPE (type));
 
   if (ntype)
     {
@@ -421,7 +427,10 @@ make_reference_type (struct type *type, struct type **typeptr)
     }
 
   TYPE_TARGET_TYPE (ntype) = type;
-  TYPE_REFERENCE_TYPE (type) = ntype;
+  reftype = (refcode == TYPE_CODE_REF ? &TYPE_REFERENCE_TYPE (type)
+             : &TYPE_RVALUE_REFERENCE_TYPE (type));
+
+  *reftype = ntype;
 
   /* FIXME!  Assume the machine has only one representation for
      references, and that it matches the (only) representation for
@@ -429,10 +438,9 @@ make_reference_type (struct type *type, struct type **typeptr)
 
   TYPE_LENGTH (ntype) =
     gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
-  TYPE_CODE (ntype) = TYPE_CODE_REF;
+  TYPE_CODE (ntype) = refcode;
 
-  if (!TYPE_REFERENCE_TYPE (type))	/* Remember it, if don't have one.  */
-    TYPE_REFERENCE_TYPE (type) = ntype;
+  *reftype = ntype;
 
   /* Update the length of all the other variants of this type.  */
   chain = TYPE_CHAIN (ntype);
@@ -449,9 +457,25 @@ make_reference_type (struct type *type, struct type **typeptr)
    details.  */
 
 struct type *
-lookup_reference_type (struct type *type)
+lookup_reference_type (struct type *type, enum type_code refcode)
+{
+  return make_reference_type (type, (struct type **) 0, refcode);
+}
+
+/* Lookup the lvalue reference type for the type TYPE.  */
+
+struct type *
+lookup_lvalue_reference_type (struct type *type)
+{
+  return lookup_reference_type (type, TYPE_CODE_REF);
+}
+
+/* Lookup the rvalue reference type for the type TYPE.  */
+
+struct type *
+lookup_rvalue_reference_type (struct type *type)
 {
-  return make_reference_type (type, (struct type **) 0);
+  return lookup_reference_type (type, TYPE_CODE_RVALUE_REF);
 }
 
 /* Lookup a function type that returns type TYPE.  TYPEPTR, if
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 7d107fa..4abeaf3 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1714,9 +1714,13 @@ extern void append_flags_type_flag (struct type *type, int bitpos,
 extern void make_vector_type (struct type *array_type);
 extern struct type *init_vector_type (struct type *elt_type, int n);
 
-extern struct type *lookup_reference_type (struct type *);
+extern struct type *lookup_reference_type (struct type *, enum type_code);
+extern struct type *lookup_lvalue_reference_type (struct type *);
+extern struct type *lookup_rvalue_reference_type (struct type *);
 
-extern struct type *make_reference_type (struct type *, struct type **);
+
+extern struct type *make_reference_type (struct type *, struct type **,
+                                         enum type_code);
 
 extern struct type *make_cv_type (int, int, struct type *, struct type **);
 
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 42a8ad2..9f1a216 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -832,7 +832,7 @@ gdbscm_type_reference (SCM self)
 
   TRY
     {
-      type = lookup_reference_type (type);
+      type = lookup_lvalue_reference_type (type);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index ebccfb6..8c06b39 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -591,7 +591,7 @@ gdbscm_value_dynamic_type (SCM self)
 	      if (was_pointer)
 		type = lookup_pointer_type (type);
 	      else
-		type = lookup_reference_type (type);
+		type = lookup_lvalue_reference_type (type);
 	    }
 	}
       else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
diff --git a/gdb/parse.c b/gdb/parse.c
index 9f89b1e..d864970 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1686,7 +1686,7 @@ follow_types (struct type *follow_type)
 	make_addr_space = 0;
 	break;
       case tp_reference:
-	follow_type = lookup_reference_type (follow_type);
+	follow_type = lookup_lvalue_reference_type (follow_type);
 	if (make_const)
 	  follow_type = make_cv_type (make_const, 
 				      TYPE_VOLATILE (follow_type), 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index d3506ca..c4d5917 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -626,7 +626,7 @@ typy_reference (PyObject *self, PyObject *args)
 
   TRY
     {
-      type = lookup_reference_type (type);
+      type = lookup_lvalue_reference_type (type);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -786,7 +786,7 @@ typy_lookup_type (struct demangle_component *demangled,
 	  switch (demangled_type)
 	    {
 	    case DEMANGLE_COMPONENT_REFERENCE:
-	      rtype =  lookup_reference_type (type);
+	      rtype = lookup_lvalue_reference_type (type);
 	      break;
 	    case DEMANGLE_COMPONENT_POINTER:
 	      rtype = lookup_pointer_type (type);
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index eb3d307..399978a 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -369,7 +369,7 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
 	      if (was_pointer)
 		type = lookup_pointer_type (type);
 	      else
-		type = lookup_reference_type (type);
+		type = lookup_lvalue_reference_type (type);
 	    }
 	}
       else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
@@ -741,7 +741,8 @@ valpy_getitem (PyObject *self, PyObject *key)
 	  if (TYPE_CODE (val_type) == TYPE_CODE_PTR)
 	    res_val = value_cast (lookup_pointer_type (base_class_type), tmp);
 	  else if (TYPE_CODE (val_type) == TYPE_CODE_REF)
-	    res_val = value_cast (lookup_reference_type (base_class_type), tmp);
+	    res_val = value_cast (lookup_lvalue_reference_type (base_class_type),
+	                          tmp);
 	  else
 	    res_val = value_cast (base_class_type, tmp);
 	}
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index d293c71..8a9bb9b 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -466,7 +466,7 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
     }
   else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
     {
-      struct type *this_ref = lookup_reference_type (this_type);
+      struct type *this_ref = lookup_lvalue_reference_type (this_type);
 
       if (!types_equal (obj_type, this_ref))
 	obj = value_cast (this_ref, obj);
@@ -554,7 +554,7 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
     }
   else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
     {
-      struct type *this_ref = lookup_reference_type (this_type);
+      struct type *this_ref = lookup_lvalue_reference_type (this_type);
 
       if (!types_equal (obj_type, this_ref))
 	obj = value_cast (this_ref, obj);
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index da7241a..1412202 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1794,7 +1794,8 @@ again:
 
     case '&':			/* Reference to another type */
       type1 = read_type (pp, objfile);
-      type = make_reference_type (type1, dbx_lookup_type (typenums, objfile));
+      type = make_reference_type (type1, dbx_lookup_type (typenums, objfile),
+                                  TYPE_CODE_REF);
       break;
 
     case 'f':			/* Function returning another type */
diff --git a/gdb/valops.c b/gdb/valops.c
index fa25ff9..d218c92 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1536,7 +1536,7 @@ value_ref (struct value *arg1)
     return arg1;
 
   arg2 = value_addr (arg1);
-  deprecated_set_value_type (arg2, lookup_reference_type (type));
+  deprecated_set_value_type (arg2, lookup_lvalue_reference_type (type));
   return arg2;
 }
 
@@ -3639,7 +3639,7 @@ value_rtti_indirect_type (struct value *v, int *full,
       real_type = make_cv_type (TYPE_CONST (target_type),
 				TYPE_VOLATILE (target_type), real_type, NULL);
       if (TYPE_CODE (type) == TYPE_CODE_REF)
-        real_type = lookup_reference_type (real_type);
+        real_type = lookup_lvalue_reference_type (real_type);
       else if (TYPE_CODE (type) == TYPE_CODE_PTR)
         real_type = lookup_pointer_type (real_type);
       else
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 03/11] Add ability to return rvalue reference values from value_ref
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
  2017-03-10 20:04 ` [PATCH v6 01/11] Add definitions for rvalue reference types Keith Seitz
  2017-03-10 20:05 ` [PATCH v6 02/11] Change {lookup,make}_reference_type API Keith Seitz
@ 2017-03-10 20:05 ` Keith Seitz
  2017-03-10 20:05 ` [PATCH v6 11/11] Add rvalue reference tests and NEWS entry Keith Seitz
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:05 UTC (permalink / raw)
  To: gdb-patches

Parameterize value_ref() by the kind of reference type the value of which
is requested. Change all callers to use the new API.

There are no changes to this patch from v5.

gdb/ChangeLog

	PR gdb/14441
	From  Artemiy Volkov  <artemiyv@acm.org>
	* ada-lang.c (ada_evaluate_subexp): Adhere to the new
	value_ref() interface.
	* c-valprint.c (c_value_print): Likewise.
	* infcall.c (value_arg_coerce): Likewise.
	* python/py-value.c (valpy_reference_value): Likewise.
	* valops.c (value_cast, value_reinterpret_cast)
	(value_dynamic_cast, typecmp): Likewise.
	(value_ref): Parameterize by kind of return value reference type.
	* value.h (value_ref): Add new parameter "refcode".
---
 gdb/ChangeLog            | 14 ++++++++++++++
 gdb/ada-lang.c           |  2 +-
 gdb/c-valprint.c         | 10 +++++++---
 gdb/infcall.c            |  2 +-
 gdb/python/py-value.c    |  2 +-
 gdb/python/py-xmethods.c |  5 +++--
 gdb/valops.c             | 25 +++++++++++++++++--------
 gdb/value.h              |  2 +-
 8 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0ec9777..4768848 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -2,6 +2,20 @@
 
 	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
+	* ada-lang.c (ada_evaluate_subexp): Adhere to the new
+	value_ref() interface.
+	* c-valprint.c (c_value_print): Likewise.
+	* infcall.c (value_arg_coerce): Likewise.
+	* python/py-value.c (valpy_reference_value): Likewise.
+	* valops.c (value_cast, value_reinterpret_cast)
+	(value_dynamic_cast, typecmp): Likewise.
+	(value_ref): Parameterize by kind of return value reference type.
+	* value.h (value_ref): Add new parameter "refcode".
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
 	* dwarf2read.c (read_tag_reference_type): Use
 	lookup_lvalue_reference_type() instead of lookup_reference_type().
 	* eval.c (evaluate_subexp_standard): Likewise.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 753409c..9b91e0c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10707,7 +10707,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 		     should return a ref as it should be valid to ask
 		     for its address; so rebuild a ref after coerce.  */
 		  arg1 = ada_coerce_ref (arg1);
-		  return value_ref (arg1);
+		  return value_ref (arg1, TYPE_CODE_REF);
 		}
 	    }
 
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 5993195..d29b20e 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -606,10 +606,14 @@ c_value_print (struct value *val, struct ui_file *stream,
       else if (options->objectprint
 	       && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
 	{
-	  int is_ref = TYPE_CODE (type) == TYPE_CODE_REF;
+	  int is_ref = TYPE_IS_REFERENCE (type);
+	  enum type_code refcode = TYPE_CODE_UNDEF;
 
 	  if (is_ref)
-	    val = value_addr (val);
+	    {
+	      val = value_addr (val);
+	      refcode = TYPE_CODE (type);
+	    }
 
 	  /* Pointer to class, check real type of object.  */
 	  fprintf_filtered (stream, "(");
@@ -635,7 +639,7 @@ c_value_print (struct value *val, struct ui_file *stream,
 
 	  if (is_ref)
 	    {
-	      val = value_ref (value_ind (val));
+	      val = value_ref (value_ind (val), refcode);
 	      type = value_type (val);
 	    }
 
diff --git a/gdb/infcall.c b/gdb/infcall.c
index f55acb5..713738e 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -168,7 +168,7 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
 	   if the value was not previously in memory - in some cases
 	   we should clearly be allowing this, but how?  */
 	new_value = value_cast (TYPE_TARGET_TYPE (type), arg);
-	new_value = value_ref (new_value);
+	new_value = value_ref (new_value, TYPE_CODE (type));
 	return new_value;
       }
     case TYPE_CODE_INT:
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 399978a..c0199ea 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -248,7 +248,7 @@ valpy_reference_value (PyObject *self, PyObject *args)
       scoped_value_mark free_values;
 
       self_val = ((value_object *) self)->value;
-      result = value_to_value_object (value_ref (self_val));
+      result = value_to_value_object (value_ref (self_val, TYPE_CODE_REF));
     }
   CATCH (except, RETURN_MASK_ALL)
     {
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index 8a9bb9b..d01488f 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -552,9 +552,10 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
       if (!types_equal (obj_type, this_ptr))
 	obj = value_cast (this_ptr, obj);
     }
-  else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
+  else if (TYPE_IS_REFERENCE (obj_type))
     {
-      struct type *this_ref = lookup_lvalue_reference_type (this_type);
+      struct type *this_ref
+	= lookup_reference_type (this_type, TYPE_CODE (obj_type));
 
       if (!types_equal (obj_type, this_ref))
 	obj = value_cast (this_ref, obj);
diff --git a/gdb/valops.c b/gdb/valops.c
index d218c92..21f4008 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -373,7 +373,7 @@ value_cast (struct type *type, struct value *arg2)
       struct type *dereftype = check_typedef (TYPE_TARGET_TYPE (t1));
       struct value *val =  value_cast (dereftype, arg2);
 
-      return value_ref (val); 
+      return value_ref (val, TYPE_CODE (t1));
     }
 
   code2 = TYPE_CODE (check_typedef (value_type (arg2)));
@@ -623,7 +623,8 @@ value_reinterpret_cast (struct type *type, struct value *arg)
     error (_("Invalid reinterpret_cast"));
 
   if (is_ref)
-    result = value_cast (type, value_ref (value_ind (result)));
+    result = value_cast (type, value_ref (value_ind (result),
+                                          TYPE_CODE (type)));
 
   return result;
 }
@@ -819,7 +820,9 @@ value_dynamic_cast (struct type *type, struct value *arg)
 				arg_type,
 				&result) == 1)
 	return value_cast (type,
-			   is_ref ? value_ref (result) : value_addr (result));
+			   is_ref
+			   ? value_ref (result, TYPE_CODE (resolved_type))
+			   : value_addr (result));
     }
 
   /* The second dynamic check specified in 5.2.7.  */
@@ -831,7 +834,9 @@ value_dynamic_cast (struct type *type, struct value *arg)
 			       value_address (tem), tem,
 			       rtti_type, &result) == 1)
     return value_cast (type,
-		       is_ref ? value_ref (result) : value_addr (result));
+		       is_ref
+		       ? value_ref (result, TYPE_CODE (resolved_type))
+		       : value_addr (result));
 
   if (TYPE_CODE (resolved_type) == TYPE_CODE_PTR)
     return value_zero (type, not_lval);
@@ -1527,16 +1532,20 @@ value_addr (struct value *arg1)
    contents.  */
 
 struct value *
-value_ref (struct value *arg1)
+value_ref (struct value *arg1, enum type_code refcode)
 {
   struct value *arg2;
   struct type *type = check_typedef (value_type (arg1));
 
-  if (TYPE_CODE (type) == TYPE_CODE_REF)
+  gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
+
+  if ((TYPE_CODE (type) == TYPE_CODE_REF
+       || TYPE_CODE (type) == TYPE_CODE_RVALUE_REF)
+      && TYPE_CODE (type) == refcode)
     return arg1;
 
   arg2 = value_addr (arg1);
-  deprecated_set_value_type (arg2, lookup_lvalue_reference_type (type));
+  deprecated_set_value_type (arg2, lookup_reference_type (type, refcode));
   return arg2;
 }
 
@@ -1743,7 +1752,7 @@ typecmp (int staticp, int varargs, int nargs,
 	  if (TYPE_CODE (tt2) == TYPE_CODE_ARRAY)
 	    t2[i] = value_coerce_array (t2[i]);
 	  else
-	    t2[i] = value_ref (t2[i]);
+	    t2[i] = value_ref (t2[i], TYPE_CODE (tt1));
 	  continue;
 	}
 
diff --git a/gdb/value.h b/gdb/value.h
index c57ea79..a1d1609 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -775,7 +775,7 @@ extern struct value *value_ind (struct value *arg1);
 
 extern struct value *value_addr (struct value *arg1);
 
-extern struct value *value_ref (struct value *arg1);
+extern struct value *value_ref (struct value *arg1, enum type_code refcode);
 
 extern struct value *value_assign (struct value *toval,
 				   struct value *fromval);
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 06/11] Implement printing of rvalue reference types and values
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (4 preceding siblings ...)
  2017-03-10 20:10 ` [PATCH v6 07/11] Support DW_TAG_rvalue_reference type Keith Seitz
@ 2017-03-10 20:10 ` Keith Seitz
  2017-03-10 20:10 ` [PATCH v6 04/11] Support rvalue reference type in parser Keith Seitz
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:10 UTC (permalink / raw)
  To: gdb-patches

This patch provides the ability to print out names of rvalue reference types
and values of those types. This is done in full similarity to regular
references, and as with them, we don't print out "const" suffix because all
rvalue references are const.

There are no changes to this patch from v5.

gdb/ChangeLog

	PR gdb/14441
	From Artemiy Volkov  <artemiyv@acm.org>
	* c-typeprint.c (c_print_type, c_type_print_varspec_prefix)
	(c_type_print_modifier, c_type_print_varspec_suffix)
	(c_type_print_base): Support printing rvalue reference types.
	* c-valprint.c (c_val_print, c_value_print): Support printing
	rvalue reference values.
---
 gdb/ChangeLog     | 10 ++++++++++
 gdb/c-typeprint.c | 10 ++++++----
 gdb/c-valprint.c  |  4 ++--
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e7d5a6b..50fd34a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -2,6 +2,16 @@
 
 	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
+	* c-typeprint.c (c_print_type, c_type_print_varspec_prefix)
+	(c_type_print_modifier, c_type_print_varspec_suffix)
+	(c_type_print_base): Support printing rvalue reference types.
+	* c-valprint.c (c_val_print, c_value_print): Support printing
+	rvalue reference values.
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
 	* cp-name-parser.y (ptr_operator): Handle the '&&' token in
 	typename.
 	* cp-support.c (replace_typedefs): Handle
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index b97216e..9e197f5 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -110,7 +110,7 @@ c_print_type (struct type *type,
 		      && !TYPE_VECTOR (type))
 		  || code == TYPE_CODE_MEMBERPTR
 		  || code == TYPE_CODE_METHODPTR
-		  || code == TYPE_CODE_REF)))
+		  || TYPE_IS_REFERENCE (type))))
 	fputs_filtered (" ", stream);
       need_post_space = (varstring != NULL && strcmp (varstring, "") != 0);
       c_type_print_varspec_prefix (type, stream, show, 0, need_post_space,
@@ -347,9 +347,10 @@ c_type_print_varspec_prefix (struct type *type,
       break;
 
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type),
 				   stream, show, 1, 0, flags);
-      fprintf_filtered (stream, "&");
+      fprintf_filtered (stream, TYPE_CODE(type) == TYPE_CODE_REF ? "&" : "&&");
       c_type_print_modifier (type, stream, 1, need_post_space);
       break;
 
@@ -416,8 +417,7 @@ c_type_print_modifier (struct type *type, struct ui_file *stream,
   /* We don't print `const' qualifiers for references --- since all
      operators affect the thing referenced, not the reference itself,
      every reference is `const'.  */
-  if (TYPE_CONST (type)
-      && TYPE_CODE (type) != TYPE_CODE_REF)
+  if (TYPE_CONST (type) && !TYPE_IS_REFERENCE (type))
     {
       if (need_pre_space)
 	fprintf_filtered (stream, " ");
@@ -728,6 +728,7 @@ c_type_print_varspec_suffix (struct type *type,
 
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       c_type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream,
 				   show, 1, 0, flags);
       break;
@@ -896,6 +897,7 @@ c_type_print_base (struct type *type, struct ui_file *stream,
     case TYPE_CODE_PTR:
     case TYPE_CODE_MEMBERPTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_FUNC:
     case TYPE_CODE_METHOD:
     case TYPE_CODE_METHODPTR:
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index d29b20e..ab1de5c 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -541,6 +541,7 @@ c_val_print (struct type *type,
       break;
 
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_ENUM:
     case TYPE_CODE_FLAGS:
     case TYPE_CODE_FUNC:
@@ -587,8 +588,7 @@ c_value_print (struct value *val, struct ui_file *stream,
   val_type = value_type (val);
   type = check_typedef (val_type);
 
-  if (TYPE_CODE (type) == TYPE_CODE_PTR
-      || TYPE_CODE (type) == TYPE_CODE_REF)
+  if (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type))
     {
       /* Hack:  remove (char *) for char strings.  Their
          type is indicated by the quoted string anyway.
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 07/11] Support DW_TAG_rvalue_reference type
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (3 preceding siblings ...)
  2017-03-10 20:05 ` [PATCH v6 11/11] Add rvalue reference tests and NEWS entry Keith Seitz
@ 2017-03-10 20:10 ` Keith Seitz
  2017-03-10 20:10 ` [PATCH v6 06/11] Implement printing of rvalue reference types and values Keith Seitz
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:10 UTC (permalink / raw)
  To: gdb-patches

Make gdb DWARF reader understand the DW_TAG_rvalue_reference type tag. Handling
of this tag is done in the existing read_tag_reference_type() function, to
which we add a new parameter representing the kind of reference type
(lvalue vs rvalue).

There are no changes to this patch from v5.

gdb/ChangeLog

	PR gdb/14441
	From Artemiy Volkov  <artemiyv@acm.org>
	* dwarf2read.c (process_die, read_type_die_1): Handle the
	DW_TAG_rvalue_reference_type DIE.
	(read_tag_reference_type): Add new parameter "refcode".
---
 gdb/ChangeLog    |  8 ++++++++
 gdb/dwarf2read.c | 15 +++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 50fd34a..b95ea9e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -2,6 +2,14 @@
 
 	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
+	* dwarf2read.c (process_die, read_type_die_1): Handle the
+	DW_TAG_rvalue_reference_type DIE.
+	(read_tag_reference_type): Add new parameter "refcode".
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
 	* c-typeprint.c (c_print_type, c_type_print_varspec_prefix)
 	(c_type_print_modifier, c_type_print_varspec_suffix)
 	(c_type_print_base): Support printing rvalue reference types.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index f3a8cc6..834dbc0 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -8388,6 +8388,7 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
     case DW_TAG_pointer_type:
     case DW_TAG_ptr_to_member_type:
     case DW_TAG_reference_type:
+    case DW_TAG_rvalue_reference_type:
     case DW_TAG_string_type:
       break;
 
@@ -14567,16 +14568,19 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
   return set_die_type (die, type, cu);
 }
 
-/* Extract all information from a DW_TAG_reference_type DIE and add to
+/* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
    the user defined type vector.  */
 
 static struct type *
-read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
+read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu,
+                          enum type_code refcode)
 {
   struct comp_unit_head *cu_header = &cu->header;
   struct type *type, *target_type;
   struct attribute *attr;
 
+  gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
+
   target_type = die_type (die, cu);
 
   /* The die_type call above may have already set the type for this DIE.  */
@@ -14584,7 +14588,7 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
   if (type)
     return type;
 
-  type = lookup_lvalue_reference_type (target_type);
+  type = lookup_reference_type (target_type, refcode);
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr)
     {
@@ -19620,7 +19624,10 @@ read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu)
       this_type = read_tag_ptr_to_member_type (die, cu);
       break;
     case DW_TAG_reference_type:
-      this_type = read_tag_reference_type (die, cu);
+      this_type = read_tag_reference_type (die, cu, TYPE_CODE_REF);
+      break;
+    case DW_TAG_rvalue_reference_type:
+      this_type = read_tag_reference_type (die, cu, TYPE_CODE_RVALUE_REF);
       break;
     case DW_TAG_const_type:
       this_type = read_tag_const_type (die, cu);
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 05/11] Implement demangling for rvalue reference type names
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (7 preceding siblings ...)
  2017-03-10 20:10 ` [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/) Keith Seitz
@ 2017-03-10 20:10 ` Keith Seitz
  2017-03-10 20:12 ` [PATCH v6 09/11] Convert lvalue reference type check to general reference type check Keith Seitz
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:10 UTC (permalink / raw)
  To: gdb-patches

This patch fixes demangling of names containing rvalue reference typenames by
handling DEMANGLE_COMPONENT_RVALUE_REFERENCE demangle component.

There are no changes to this patch from v5.

gdb/ChangeLog

	PR gdb/14441
	From Artemiy Volkov  <artemiyv@acm.org>
	* cp-name-parser.y (ptr_operator): Handle the '&&' token in
	typename.
	* cp-support.c (replace_typedefs): Handle
	DEMANGLE_COMPONENT_RVALUE_REFERENCE.
	* python/py-type.c (typy_lookup_type): Likewise.
---
 gdb/ChangeLog        | 10 ++++++++++
 gdb/cp-name-parser.y |  4 ++++
 gdb/cp-support.c     |  1 +
 gdb/python/py-type.c |  4 ++++
 4 files changed, 19 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f7685ad..e7d5a6b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -2,6 +2,16 @@
 
 	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
+	* cp-name-parser.y (ptr_operator): Handle the '&&' token in
+	typename.
+	* cp-support.c (replace_typedefs): Handle
+	DEMANGLE_COMPONENT_RVALUE_REFERENCE.
+	* python/py-type.c (typy_lookup_type): Likewise.
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
 	* c-exp.y (ptr_operator): Handle the '&&' token in the typename.
 	* parse.c (insert_type): Change assert statement.
 	(follow_types): Handle rvalue reference types.
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index fd1e949..89e4d79 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -769,6 +769,10 @@ ptr_operator	:	'*' qualifiers_opt
 			{ $$.comp = make_empty (DEMANGLE_COMPONENT_REFERENCE);
 			  $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL;
 			  $$.last = &d_left ($$.comp); }
+		|	ANDAND
+			{ $$.comp = make_empty (DEMANGLE_COMPONENT_RVALUE_REFERENCE);
+			  $$.comp->u.s_binary.left = $$.comp->u.s_binary.right = NULL;
+			  $$.last = &d_left ($$.comp); }
 		|	nested_name '*' qualifiers_opt
 			{ $$.comp = make_empty (DEMANGLE_COMPONENT_PTRMEM_TYPE);
 			  $$.comp->u.s_binary.left = $1.comp;
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 1b0900e..b1b96c8 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -494,6 +494,7 @@ replace_typedefs (struct demangle_parse_info *info,
 	case DEMANGLE_COMPONENT_RESTRICT_THIS:
 	case DEMANGLE_COMPONENT_POINTER:
 	case DEMANGLE_COMPONENT_REFERENCE:
+	case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
 	  replace_typedefs (info, d_left (ret_comp), finder, data);
 	  break;
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index c4d5917..0249cbb 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -770,6 +770,7 @@ typy_lookup_type (struct demangle_component *demangled,
 
   if (demangled_type == DEMANGLE_COMPONENT_POINTER
       || demangled_type == DEMANGLE_COMPONENT_REFERENCE
+      || demangled_type == DEMANGLE_COMPONENT_RVALUE_REFERENCE
       || demangled_type == DEMANGLE_COMPONENT_CONST
       || demangled_type == DEMANGLE_COMPONENT_VOLATILE)
     {
@@ -788,6 +789,9 @@ typy_lookup_type (struct demangle_component *demangled,
 	    case DEMANGLE_COMPONENT_REFERENCE:
 	      rtype = lookup_lvalue_reference_type (type);
 	      break;
+	    case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
+	      rtype = lookup_rvalue_reference_type (type);
+	      break;
 	    case DEMANGLE_COMPONENT_POINTER:
 	      rtype = lookup_pointer_type (type);
 	      break;
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 04/11] Support rvalue reference type in parser
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (5 preceding siblings ...)
  2017-03-10 20:10 ` [PATCH v6 06/11] Implement printing of rvalue reference types and values Keith Seitz
@ 2017-03-10 20:10 ` Keith Seitz
  2017-03-10 20:10 ` [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/) Keith Seitz
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:10 UTC (permalink / raw)
  To: gdb-patches

This patch implements correct parsing of C++11 rvalue reference typenames.
This is done in full similarity to the handling of regular references by adding
a '&&' token handling in c-exp.y, defining an rvalue reference type piece, and
implementing a follow type derivation in follow_types().

There are no changes to this patch from v5.

gdb/ChangeLog

	PR gdb/14441
	From Artemiy Volkov  <artemiyv@acm.org>
	* c-exp.y (ptr_operator): Handle the '&&' token in the typename.
	* parse.c (insert_type): Change assert statement.
	(follow_types): Handle rvalue reference types.
	* parser-defs.h (enum type_pieces) <tp_rvalue_reference>: New
	constant.
---
 gdb/ChangeLog     | 10 ++++++++++
 gdb/c-exp.y       |  6 +++++-
 gdb/parse.c       | 39 ++++++++++++++++++++++-----------------
 gdb/parser-defs.h |  1 +
 4 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4768848..f7685ad 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -2,6 +2,16 @@
 
 	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
+	* c-exp.y (ptr_operator): Handle the '&&' token in the typename.
+	* parse.c (insert_type): Change assert statement.
+	(follow_types): Handle rvalue reference types.
+	* parser-defs.h (enum type_pieces) <tp_rvalue_reference>: New
+	constant.
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
 	* ada-lang.c (ada_evaluate_subexp): Adhere to the new
 	value_ref() interface.
 	* c-valprint.c (c_value_print): Likewise.
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 2753c6e..7c25641 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -744,7 +744,7 @@ exp	:	SIZEOF '(' type ')'	%prec UNARY
 			       says of sizeof:  "When applied to a reference
 			       or a reference type, the result is the size of
 			       the referenced type."  */
-			  if (TYPE_CODE (type) == TYPE_CODE_REF)
+			  if (TYPE_IS_REFERENCE (type))
 			    type = check_typedef (TYPE_TARGET_TYPE (type));
 			  write_exp_elt_longcst (pstate,
 						 (LONGEST) TYPE_LENGTH (type));
@@ -1085,6 +1085,10 @@ ptr_operator:
 			{ insert_type (tp_reference); }
 	|	'&' ptr_operator
 			{ insert_type (tp_reference); }
+	|       ANDAND
+			{ insert_type (tp_rvalue_reference); }
+	|       ANDAND ptr_operator
+			{ insert_type (tp_rvalue_reference); }
 	;
 
 ptr_operator_ts: ptr_operator
diff --git a/gdb/parse.c b/gdb/parse.c
index d864970..bf27598 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1461,10 +1461,10 @@ insert_into_type_stack (int slot, union type_stack_elt element)
 }
 
 /* Insert a new type, TP, at the bottom of the type stack.  If TP is
-   tp_pointer or tp_reference, it is inserted at the bottom.  If TP is
-   a qualifier, it is inserted at slot 1 (just above a previous
-   tp_pointer) if there is anything on the stack, or simply pushed if
-   the stack is empty.  Other values for TP are invalid.  */
+   tp_pointer, tp_reference or tp_rvalue_reference, it is inserted at the
+   bottom.  If TP is a qualifier, it is inserted at slot 1 (just above a
+   previous tp_pointer) if there is anything on the stack, or simply pushed
+   if the stack is empty.  Other values for TP are invalid.  */
 
 void
 insert_type (enum type_pieces tp)
@@ -1473,7 +1473,8 @@ insert_type (enum type_pieces tp)
   int slot;
 
   gdb_assert (tp == tp_pointer || tp == tp_reference
-	      || tp == tp_const || tp == tp_volatile);
+	      || tp == tp_rvalue_reference || tp == tp_const
+	      || tp == tp_volatile);
 
   /* If there is anything on the stack (we know it will be a
      tp_pointer), insert the qualifier above it.  Otherwise, simply
@@ -1686,18 +1687,22 @@ follow_types (struct type *follow_type)
 	make_addr_space = 0;
 	break;
       case tp_reference:
-	follow_type = lookup_lvalue_reference_type (follow_type);
-	if (make_const)
-	  follow_type = make_cv_type (make_const, 
-				      TYPE_VOLATILE (follow_type), 
-				      follow_type, 0);
-	if (make_volatile)
-	  follow_type = make_cv_type (TYPE_CONST (follow_type), 
-				      make_volatile, 
-				      follow_type, 0);
-	if (make_addr_space)
-	  follow_type = make_type_with_address_space (follow_type, 
-						      make_addr_space);
+	 follow_type = lookup_lvalue_reference_type (follow_type);
+	 goto process_reference;
+	case tp_rvalue_reference:
+	 follow_type = lookup_rvalue_reference_type (follow_type);
+	process_reference:
+	 if (make_const)
+	   follow_type = make_cv_type (make_const,
+				       TYPE_VOLATILE (follow_type),
+				       follow_type, 0);
+	 if (make_volatile)
+	   follow_type = make_cv_type (TYPE_CONST (follow_type),
+				       make_volatile,
+				       follow_type, 0);
+	 if (make_addr_space)
+	   follow_type = make_type_with_address_space (follow_type,
+						       make_addr_space);
 	make_const = make_volatile = 0;
 	make_addr_space = 0;
 	break;
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index 85da6a4..a291aed 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -127,6 +127,7 @@ enum type_pieces
     tp_end = -1, 
     tp_pointer, 
     tp_reference, 
+    tp_rvalue_reference,
     tp_array, 
     tp_function,
     tp_function_with_arguments,
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/)
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (6 preceding siblings ...)
  2017-03-10 20:10 ` [PATCH v6 04/11] Support rvalue reference type in parser Keith Seitz
@ 2017-03-10 20:10 ` Keith Seitz
  2017-03-10 22:04   ` Eli Zaretskii
  2017-03-10 20:10 ` [PATCH v6 05/11] Implement demangling for rvalue reference type names Keith Seitz
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:10 UTC (permalink / raw)
  To: gdb-patches

This patch adds the ability to inspect rvalue reference types and values using
the gdb python module. This is achieved by creating two wrappers for
valpy_reference_value(), using the ReferenceExplorer class to handle the
objects of rvalue reference types and placing necessary checks for a
TYPE_CODE_RVALUE_REF type code next to the checks for a TYPE_CODE_REF type
code.

Changes since v5:
o Update python documenation

gdb/ChangeLog

	PR gdb/14441
	* doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to
	table of constants.

	From Artemiy Volkov  <artemiyv@acm.org>
	* python/lib/gdb/command/explore.py: Support exploring values
	of rvalue reference types.
	* python/lib/gdb/types.py: Implement get_basic_type() for
	rvalue reference types.
	* python/py-type.c (pyty_codes) <TYPE_CODE_RVALUE_REF>: New
	constant.
	* python/py-value.c (valpy_getitem): Add an rvalue reference
	check.
	(valpy_reference_value): Add new parameter "refcode".
	(valpy_lvalue_reference_value, valpy_rvalue_reference_value):
	New wrappers for valpy_reference_value().
	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
	(gdbpy_invoke_xmethod): Likewise.
---
 gdb/ChangeLog                         | 20 ++++++++++++++++++++
 gdb/doc/python.texi                   |  4 ++++
 gdb/python/lib/gdb/command/explore.py |  2 +-
 gdb/python/lib/gdb/types.py           |  4 +++-
 gdb/python/py-type.c                  |  1 +
 gdb/python/py-value.c                 | 26 +++++++++++++++++++++-----
 gdb/python/py-xmethods.c              |  5 +++--
 7 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b95ea9e..b7dd758 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,25 @@
 2017-MM-DD  Keith Seitz  <keiths@redhat.com>
 
+	* doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to
+	table of constants.
+
+	From Artemiy Volkov  <artemiyv@acm.org>
+	* python/lib/gdb/command/explore.py: Support exploring values
+	of rvalue reference types.
+	* python/lib/gdb/types.py: Implement get_basic_type() for
+	rvalue reference types.
+	* python/py-type.c (pyty_codes) <TYPE_CODE_RVALUE_REF>: New
+	constant.
+	* python/py-value.c (valpy_getitem): Add an rvalue reference
+	check.
+	(valpy_reference_value): Add new parameter "refcode".
+	(valpy_lvalue_reference_value, valpy_rvalue_reference_value):
+	New wrappers for valpy_reference_value().
+	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
+	(gdbpy_invoke_xmethod): Likewise.
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
 	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
 	* dwarf2read.c (process_die, read_type_die_1): Handle the
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index c3ea203..d463afe 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -1162,6 +1162,10 @@ A pointer-to-member.
 @item gdb.TYPE_CODE_REF
 A reference type.
 
+@vindex TYPE_CODE_RVALUE_REF
+@item gdb.TYPE_CODE_RVALUE_REF
+An rvalue reference type.
+
 @vindex TYPE_CODE_CHAR
 @item gdb.TYPE_CODE_CHAR
 A character type.
diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py
index b2878b9..4eb2e24 100644
--- a/gdb/python/lib/gdb/command/explore.py
+++ b/gdb/python/lib/gdb/command/explore.py
@@ -132,6 +132,7 @@ class Explorer(object):
             gdb.TYPE_CODE_UNION : CompoundExplorer,
             gdb.TYPE_CODE_PTR : PointerExplorer,
             gdb.TYPE_CODE_REF : ReferenceExplorer,
+            gdb.TYPE_CODE_RVALUE_REF : ReferenceExplorer,
             gdb.TYPE_CODE_TYPEDEF : TypedefExplorer,
             gdb.TYPE_CODE_ARRAY : ArrayExplorer
         }
@@ -318,7 +319,6 @@ class ReferenceExplorer(object):
         Explorer.explore_type(name, target_type, is_child)
         return False
 
-
 class ArrayExplorer(object):
     """Internal class used to explore arrays."""
 
diff --git a/gdb/python/lib/gdb/types.py b/gdb/python/lib/gdb/types.py
index 799a07d..26a5027 100644
--- a/gdb/python/lib/gdb/types.py
+++ b/gdb/python/lib/gdb/types.py
@@ -31,8 +31,10 @@ def get_basic_type(type_):
     """
 
     while (type_.code == gdb.TYPE_CODE_REF or
+           type_.code == gdb.TYPE_CODE_RVALUE_REF or
            type_.code == gdb.TYPE_CODE_TYPEDEF):
-        if type_.code == gdb.TYPE_CODE_REF:
+        if (type_.code == gdb.TYPE_CODE_REF or
+            type_.code == gdb.TYPE_CODE_RVALUE_REF):
             type_ = type_.target()
         else:
             type_ = type_.strip_typedefs()
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 0249cbb..c063d2c 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -106,6 +106,7 @@ static struct pyty_code pyty_codes[] =
   ENTRY (TYPE_CODE_METHODPTR),
   ENTRY (TYPE_CODE_MEMBERPTR),
   ENTRY (TYPE_CODE_REF),
+  ENTRY (TYPE_CODE_RVALUE_REF),
   ENTRY (TYPE_CODE_CHAR),
   ENTRY (TYPE_CODE_BOOL),
   ENTRY (TYPE_CODE_COMPLEX),
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index c0199ea..aacf628 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -238,7 +238,7 @@ valpy_referenced_value (PyObject *self, PyObject *args)
 /* Return a value which is a reference to the value.  */
 
 static PyObject *
-valpy_reference_value (PyObject *self, PyObject *args)
+valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode)
 {
   PyObject *result = NULL;
 
@@ -248,7 +248,7 @@ valpy_reference_value (PyObject *self, PyObject *args)
       scoped_value_mark free_values;
 
       self_val = ((value_object *) self)->value;
-      result = value_to_value_object (value_ref (self_val, TYPE_CODE_REF));
+      result = value_to_value_object (value_ref (self_val, refcode));
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -259,6 +259,18 @@ valpy_reference_value (PyObject *self, PyObject *args)
   return result;
 }
 
+static PyObject *
+valpy_lvalue_reference_value (PyObject *self, PyObject *args)
+{
+  return valpy_reference_value (self, args, TYPE_CODE_REF);
+}
+
+static PyObject *
+valpy_rvalue_reference_value (PyObject *self, PyObject *args)
+{
+  return valpy_reference_value (self, args, TYPE_CODE_RVALUE_REF);
+}
+
 /* Return a "const" qualified version of the value.  */
 
 static PyObject *
@@ -585,8 +597,7 @@ value_has_field (struct value *v, PyObject *field)
     {
       val_type = value_type (v);
       val_type = check_typedef (val_type);
-      if (TYPE_CODE (val_type) == TYPE_CODE_REF
-	  || TYPE_CODE (val_type) == TYPE_CODE_PTR)
+      if (TYPE_IS_REFERENCE (val_type) || TYPE_CODE (val_type) == TYPE_CODE_PTR)
       val_type = check_typedef (TYPE_TARGET_TYPE (val_type));
 
       type_code = TYPE_CODE (val_type);
@@ -743,6 +754,9 @@ valpy_getitem (PyObject *self, PyObject *key)
 	  else if (TYPE_CODE (val_type) == TYPE_CODE_REF)
 	    res_val = value_cast (lookup_lvalue_reference_type (base_class_type),
 	                          tmp);
+	  else if (TYPE_CODE (val_type) == TYPE_CODE_RVALUE_REF)
+	    res_val = value_cast (lookup_rvalue_reference_type (base_class_type),
+	                          tmp);
 	  else
 	    res_val = value_cast (base_class_type, tmp);
 	}
@@ -1724,8 +1738,10 @@ reinterpret_cast operator."
   { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
   { "referenced_value", valpy_referenced_value, METH_NOARGS,
     "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
-  { "reference_value", valpy_reference_value, METH_NOARGS,
+  { "reference_value", valpy_lvalue_reference_value, METH_NOARGS,
     "Return a value of type TYPE_CODE_REF referencing this value." },
+  { "rvalue_reference_value", valpy_rvalue_reference_value, METH_NOARGS,
+    "Return a value of type TYPE_CODE_RVALUE_REF referencing this value." },
   { "const_value", valpy_const_value, METH_NOARGS,
     "Return a 'const' qualied version of the same value." },
   { "lazy_string", (PyCFunction) valpy_lazy_string,
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index d01488f..e061da2 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -464,9 +464,10 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
       if (!types_equal (obj_type, this_ptr))
 	obj = value_cast (this_ptr, obj);
     }
-  else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
+  else if (TYPE_IS_REFERENCE (obj_type))
     {
-      struct type *this_ref = lookup_lvalue_reference_type (this_type);
+      struct type *this_ref
+        = lookup_reference_type (this_type, TYPE_CODE (obj_type));
 
       if (!types_equal (obj_type, this_ref))
 	obj = value_cast (this_ref, obj);
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 09/11] Convert lvalue reference type check to general reference type check
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (8 preceding siblings ...)
  2017-03-10 20:10 ` [PATCH v6 05/11] Implement demangling for rvalue reference type names Keith Seitz
@ 2017-03-10 20:12 ` Keith Seitz
  2017-03-10 20:14 ` [PATCH v6 10/11] Add rvalue references to overloading resolution Keith Seitz
  2017-03-13 18:51 ` [PATCH v6 00/11] c++/14441: Rvalue reference support Pedro Alves
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:12 UTC (permalink / raw)
  To: gdb-patches

In almost all contexts (except for overload resolution rules and expression
semantics), lvalue and rvalue references are equivalent. That means that in all
but these cases we can replace a TYPE_CODE_REF check to a TYPE_IS_REFERENCE
check and, for switch statements, add a case label for a rvalue reference type
next to a case label for an lvalue reference type. This patch does exactly
that.

There are no changes to this patch from v5.

gdb/ChangeLog

	PR gdb/14441
	From Artemiy Volkov  <artemiyv@acm.org>
	* aarch64-tdep.c (aarch64_type_align)
	(aarch64_extract_return_value, aarch64_store_return_value): Change
	lvalue reference type checks to general reference type checks.
	* amd64-tdep.c (amd64_classify): Likewise.
	* amd64-windows-tdep.c (amd64_windows_passed_by_integer_register):
	Likewise.
	* arm-tdep.c (arm_type_align, arm_extract_return_value)
	(arm_store_return_value): Likewise.
	* ax-gdb.c (gen_fetch, gen_cast): Likewise.
	* c-typeprint.c (c_print_type): Likewise.
	* c-varobj.c (adjust_value_for_child_access, c_value_of_variable)
	(cplus_number_of_children, cplus_describe_child): Likewise.
	* compile/compile-c-symbols.c (generate_vla_size): Likewise.
	* completer.c (expression_completer): Likewise.
	* cp-support.c (make_symbol_overload_list_adl_namespace):
	Likewise.
	* darwin-nat-info.c (info_mach_region_command): Likewise.
	* dwarf2loc.c (entry_data_value_coerce_ref)
	(value_of_dwarf_reg_entry): Likewise.
	* eval.c (ptrmath_type_p, evaluate_subexp_standard)
	(evaluate_subexp_for_address, evaluate_subexp_for_sizeof):
	Likewise.
	* findvar.c (extract_typed_address, store_typed_address):
	Likewise.
	* gdbtypes.c (rank_one_type): Likewise.
	* hppa-tdep.c (hppa64_integral_or_pointer_p): Likewise.
	* infcall.c (value_arg_coerce): Likewise.
	* language.c (pointer_type): Likewise.
	* m32c-tdep.c (m32c_reg_arg_type, m32c_m16c_address_to_pointer):
	Likewise.
	* m88k-tdep.c (m88k_integral_or_pointer_p): Likewise.
	* mn10300-tdep.c (mn10300_type_align): Likewise.
	* msp430-tdep.c (msp430_push_dummy_call): Likewise.
	* ppc-sysv-tdep.c (do_ppc_sysv_return_value)
	(ppc64_sysv_abi_push_param, ppc64_sysv_abi_return_value):
	Likewise.
	* printcmd.c (print_formatted, x_command): Likewise.
	* python/py-type.c (typy_get_composite, typy_template_argument):
	Likewise.
	* python/py-value.c (valpy_referenced_value)
	(valpy_get_dynamic_type, value_has_field): Likewise.
	* s390-linux-tdep.c (s390_function_arg_integer): Likewise.
	* sparc-tdep.c (sparc_integral_or_pointer_p): Likewise.
	* sparc64-tdep.c (sparc64_integral_or_pointer_p): Likewise.
	* spu-tdep.c (spu_scalar_value_p): Likewise.
	* symtab.c (lookup_symbol_aux): Likewise.
	* typeprint.c (whatis_exp, print_type_scalar): Likewise.
	* valarith.c (binop_types_user_defined_p, unop_user_defined_p):
	Likewise.
	* valops.c (value_cast_pointers, value_cast)
	(value_reinterpret_cast, value_dynamic_cast, value_addr, typecmp)
	(value_struct_elt, value_struct_elt_bitpos)
	(value_find_oload_method_list, find_overload_match)
	(value_rtti_indirect_type): Likewise.
	* valprint.c (val_print_scalar_type_p, generic_val_print):
	Likewise.
	* value.c (value_actual_type, value_as_address, unpack_long)
	(pack_long, pack_unsigned_long, coerce_ref_if_computed)
	(coerce_ref): Likewise.
	* varobj.c (varobj_get_value_type): Likewise.
---
 gdb/ChangeLog                   | 65 +++++++++++++++++++++++++++++++++++++++++
 gdb/aarch64-tdep.c              |  5 ++--
 gdb/amd64-tdep.c                |  2 +-
 gdb/amd64-windows-tdep.c        |  1 +
 gdb/arm-tdep.c                  |  5 ++--
 gdb/ax-gdb.c                    |  2 ++
 gdb/c-varobj.c                  | 10 +++----
 gdb/compile/compile-c-symbols.c |  2 +-
 gdb/completer.c                 |  3 +-
 gdb/cp-support.c                |  2 +-
 gdb/darwin-nat-info.c           |  2 +-
 gdb/dwarf2loc.c                 |  4 +--
 gdb/eval.c                      | 14 ++++-----
 gdb/findvar.c                   |  6 ++--
 gdb/gdbtypes.c                  |  5 ++--
 gdb/hppa-tdep.c                 |  1 +
 gdb/infcall.c                   |  3 +-
 gdb/language.c                  |  3 +-
 gdb/m32c-tdep.c                 |  8 ++---
 gdb/m88k-tdep.c                 |  1 +
 gdb/mn10300-tdep.c              |  1 +
 gdb/msp430-tdep.c               |  2 +-
 gdb/ppc-sysv-tdep.c             |  7 ++---
 gdb/printcmd.c                  |  2 +-
 gdb/python/py-type.c            |  5 ++--
 gdb/python/py-value.c           |  6 ++--
 gdb/s390-linux-tdep.c           |  2 +-
 gdb/sparc-tdep.c                |  1 +
 gdb/sparc64-tdep.c              |  1 +
 gdb/spu-tdep.c                  |  1 +
 gdb/symtab.c                    |  3 +-
 gdb/typeprint.c                 |  4 +--
 gdb/valarith.c                  |  6 ++--
 gdb/valops.c                    | 45 +++++++++++++---------------
 gdb/valprint.c                  |  5 ++--
 gdb/value.c                     | 12 ++++----
 gdb/varobj.c                    |  2 +-
 37 files changed, 158 insertions(+), 91 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b7dd758..ee3de5c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,70 @@
 2017-MM-DD  Keith Seitz  <keiths@redhat.com>
 
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
+	* aarch64-tdep.c (aarch64_type_align)
+	(aarch64_extract_return_value, aarch64_store_return_value): Change
+	lvalue reference type checks to general reference type checks.
+	* amd64-tdep.c (amd64_classify): Likewise.
+	* amd64-windows-tdep.c (amd64_windows_passed_by_integer_register):
+	Likewise.
+	* arm-tdep.c (arm_type_align, arm_extract_return_value)
+	(arm_store_return_value): Likewise.
+	* ax-gdb.c (gen_fetch, gen_cast): Likewise.
+	* c-typeprint.c (c_print_type): Likewise.
+	* c-varobj.c (adjust_value_for_child_access, c_value_of_variable)
+	(cplus_number_of_children, cplus_describe_child): Likewise.
+	* compile/compile-c-symbols.c (generate_vla_size): Likewise.
+	* completer.c (expression_completer): Likewise.
+	* cp-support.c (make_symbol_overload_list_adl_namespace):
+	Likewise.
+	* darwin-nat-info.c (info_mach_region_command): Likewise.
+	* dwarf2loc.c (entry_data_value_coerce_ref)
+	(value_of_dwarf_reg_entry): Likewise.
+	* eval.c (ptrmath_type_p, evaluate_subexp_standard)
+	(evaluate_subexp_for_address, evaluate_subexp_for_sizeof):
+	Likewise.
+	* findvar.c (extract_typed_address, store_typed_address):
+	Likewise.
+	* gdbtypes.c (rank_one_type): Likewise.
+	* hppa-tdep.c (hppa64_integral_or_pointer_p): Likewise.
+	* infcall.c (value_arg_coerce): Likewise.
+	* language.c (pointer_type): Likewise.
+	* m32c-tdep.c (m32c_reg_arg_type, m32c_m16c_address_to_pointer):
+	Likewise.
+	* m88k-tdep.c (m88k_integral_or_pointer_p): Likewise.
+	* mn10300-tdep.c (mn10300_type_align): Likewise.
+	* msp430-tdep.c (msp430_push_dummy_call): Likewise.
+	* ppc-sysv-tdep.c (do_ppc_sysv_return_value)
+	(ppc64_sysv_abi_push_param, ppc64_sysv_abi_return_value):
+	Likewise.
+	* printcmd.c (print_formatted, x_command): Likewise.
+	* python/py-type.c (typy_get_composite, typy_template_argument):
+	Likewise.
+	* python/py-value.c (valpy_referenced_value)
+	(valpy_get_dynamic_type, value_has_field): Likewise.
+	* s390-linux-tdep.c (s390_function_arg_integer): Likewise.
+	* sparc-tdep.c (sparc_integral_or_pointer_p): Likewise.
+	* sparc64-tdep.c (sparc64_integral_or_pointer_p): Likewise.
+	* spu-tdep.c (spu_scalar_value_p): Likewise.
+	* symtab.c (lookup_symbol_aux): Likewise.
+	* typeprint.c (whatis_exp, print_type_scalar): Likewise.
+	* valarith.c (binop_types_user_defined_p, unop_user_defined_p):
+	Likewise.
+	* valops.c (value_cast_pointers, value_cast)
+	(value_reinterpret_cast, value_dynamic_cast, value_addr, typecmp)
+	(value_struct_elt, value_struct_elt_bitpos)
+	(value_find_oload_method_list, find_overload_match)
+	(value_rtti_indirect_type): Likewise.
+	* valprint.c (val_print_scalar_type_p, generic_val_print):
+	Likewise.
+	* value.c (value_actual_type, value_as_address, unpack_long)
+	(pack_long, pack_unsigned_long, coerce_ref_if_computed)
+	(coerce_ref): Likewise.
+	* varobj.c (varobj_get_value_type): Likewise.
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
 	* doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to
 	table of constants.
 
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 801c03d..e7d0844 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -1096,6 +1096,7 @@ aarch64_type_align (struct type *t)
     case TYPE_CODE_RANGE:
     case TYPE_CODE_BITSTRING:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_CHAR:
     case TYPE_CODE_BOOL:
       return TYPE_LENGTH (t);
@@ -1805,7 +1806,7 @@ aarch64_extract_return_value (struct type *type, struct regcache *regs,
 	   || TYPE_CODE (type) == TYPE_CODE_CHAR
 	   || TYPE_CODE (type) == TYPE_CODE_BOOL
 	   || TYPE_CODE (type) == TYPE_CODE_PTR
-	   || TYPE_CODE (type) == TYPE_CODE_REF
+	   || TYPE_IS_REFERENCE (type)
 	   || TYPE_CODE (type) == TYPE_CODE_ENUM)
     {
       /* If the the type is a plain integer, then the access is
@@ -1943,7 +1944,7 @@ aarch64_store_return_value (struct type *type, struct regcache *regs,
 	   || TYPE_CODE (type) == TYPE_CODE_CHAR
 	   || TYPE_CODE (type) == TYPE_CODE_BOOL
 	   || TYPE_CODE (type) == TYPE_CODE_PTR
-	   || TYPE_CODE (type) == TYPE_CODE_REF
+	   || TYPE_IS_REFERENCE (type)
 	   || TYPE_CODE (type) == TYPE_CODE_ENUM)
     {
       if (TYPE_LENGTH (type) <= X_REGISTER_SIZE)
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 98710fe..9ff7dfc 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -679,7 +679,7 @@ amd64_classify (struct type *type, enum amd64_reg_class theclass[2])
   if ((code == TYPE_CODE_INT || code == TYPE_CODE_ENUM
        || code == TYPE_CODE_BOOL || code == TYPE_CODE_RANGE
        || code == TYPE_CODE_CHAR
-       || code == TYPE_CODE_PTR || code == TYPE_CODE_REF)
+       || code == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type))
       && (len == 1 || len == 2 || len == 4 || len == 8))
     theclass[0] = AMD64_INTEGER;
 
diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index 73844a1..f1acdb9 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -56,6 +56,7 @@ amd64_windows_passed_by_integer_register (struct type *type)
       case TYPE_CODE_CHAR:
       case TYPE_CODE_PTR:
       case TYPE_CODE_REF:
+      case TYPE_CODE_RVALUE_REF:
       case TYPE_CODE_STRUCT:
       case TYPE_CODE_UNION:
 	return (TYPE_LENGTH (type) == 1
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 3aee722..a0ea2fe 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -3387,6 +3387,7 @@ arm_type_align (struct type *t)
     case TYPE_CODE_SET:
     case TYPE_CODE_RANGE:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_CHAR:
     case TYPE_CODE_BOOL:
       return TYPE_LENGTH (t);
@@ -7983,7 +7984,7 @@ arm_extract_return_value (struct type *type, struct regcache *regs,
 	   || TYPE_CODE (type) == TYPE_CODE_CHAR
 	   || TYPE_CODE (type) == TYPE_CODE_BOOL
 	   || TYPE_CODE (type) == TYPE_CODE_PTR
-	   || TYPE_CODE (type) == TYPE_CODE_REF
+	   || TYPE_IS_REFERENCE (type)
 	   || TYPE_CODE (type) == TYPE_CODE_ENUM)
     {
       /* If the type is a plain integer, then the access is
@@ -8188,7 +8189,7 @@ arm_store_return_value (struct type *type, struct regcache *regs,
 	   || TYPE_CODE (type) == TYPE_CODE_CHAR
 	   || TYPE_CODE (type) == TYPE_CODE_BOOL
 	   || TYPE_CODE (type) == TYPE_CODE_PTR
-	   || TYPE_CODE (type) == TYPE_CODE_REF
+	   || TYPE_IS_REFERENCE (type)
 	   || TYPE_CODE (type) == TYPE_CODE_ENUM)
     {
       if (TYPE_LENGTH (type) <= 4)
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 3587b5d..01099f5 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -491,6 +491,7 @@ gen_fetch (struct agent_expr *ax, struct type *type)
     {
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_ENUM:
     case TYPE_CODE_INT:
     case TYPE_CODE_CHAR:
@@ -1000,6 +1001,7 @@ gen_cast (struct agent_expr *ax, struct axs_value *value, struct type *type)
     {
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       /* It's implementation-defined, and I'll bet this is what GCC
          does.  */
       break;
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index 01d52ce..a5793e5 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -78,7 +78,7 @@ adjust_value_for_child_access (struct value **value,
      to us, is already supposed to be
      reference-stripped.  */
 
-  gdb_assert (TYPE_CODE (*type) != TYPE_CODE_REF);
+  gdb_assert (!TYPE_IS_REFERENCE (*type));
 
   /* Pointers to structures are treated just like
      structures when accessing children.  Don't
@@ -488,7 +488,7 @@ c_value_of_variable (const struct varobj *var,
   struct type *type = get_type (var);
 
   /* Strip top-level references.  */
-  while (TYPE_CODE (type) == TYPE_CODE_REF)
+  while (TYPE_IS_REFERENCE (type))
     type = check_typedef (TYPE_TARGET_TYPE (type));
 
   switch (TYPE_CODE (type))
@@ -580,7 +580,7 @@ cplus_number_of_children (const struct varobj *var)
       if (opts.objectprint)
         {
           value = var->value;
-          lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
+          lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
 				|| TYPE_CODE (var->type) == TYPE_CODE_PTR);
         }
       adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
@@ -617,7 +617,7 @@ cplus_number_of_children (const struct varobj *var)
 	  const struct varobj *parent = var->parent;
 
 	  value = parent->value;
-	  lookup_actual_type = (TYPE_CODE (parent->type) == TYPE_CODE_REF
+	  lookup_actual_type = (TYPE_IS_REFERENCE (parent->type)
 				|| TYPE_CODE (parent->type) == TYPE_CODE_PTR);
         }
       adjust_value_for_child_access (&value, &type, NULL, lookup_actual_type);
@@ -722,7 +722,7 @@ cplus_describe_child (const struct varobj *parent, int index,
 
   var = (CPLUS_FAKE_CHILD (parent)) ? parent->parent : parent;
   if (opts.objectprint)
-    lookup_actual_type = (TYPE_CODE (var->type) == TYPE_CODE_REF
+    lookup_actual_type = (TYPE_IS_REFERENCE (var->type)
 			  || TYPE_CODE (var->type) == TYPE_CODE_PTR);
   value = var->value;
   type = varobj_get_value_type (var);
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 9282cfc..15e1d6d 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -593,7 +593,7 @@ generate_vla_size (struct compile_c_instance *compiler,
 {
   type = check_typedef (type);
 
-  if (TYPE_CODE (type) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (type))
     type = check_typedef (TYPE_TARGET_TYPE (type));
 
   switch (TYPE_CODE (type))
diff --git a/gdb/completer.c b/gdb/completer.c
index c22800f..45adc62 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -611,8 +611,7 @@ expression_completer (struct cmd_list_element *ignore,
       for (;;)
 	{
 	  type = check_typedef (type);
-	  if (TYPE_CODE (type) != TYPE_CODE_PTR
-	      && TYPE_CODE (type) != TYPE_CODE_REF)
+	  if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
 	    break;
 	  type = TYPE_TARGET_TYPE (type);
 	}
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index b1b96c8..5704466 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1242,7 +1242,7 @@ make_symbol_overload_list_adl_namespace (struct type *type,
   int i, prefix_len;
 
   while (TYPE_CODE (type) == TYPE_CODE_PTR
-	 || TYPE_CODE (type) == TYPE_CODE_REF
+	 || TYPE_IS_REFERENCE (type)
          || TYPE_CODE (type) == TYPE_CODE_ARRAY
          || TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
     {
diff --git a/gdb/darwin-nat-info.c b/gdb/darwin-nat-info.c
index 1c54a44..91bc5b3 100644
--- a/gdb/darwin-nat-info.c
+++ b/gdb/darwin-nat-info.c
@@ -731,7 +731,7 @@ info_mach_region_command (char *exp, int from_tty)
 
   expression_up expr = parse_expression (exp);
   val = evaluate_expression (expr.get ());
-  if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (value_type (val)))
     {
       val = value_ind (val);
     }
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 4393c1f..9b21d67 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -1347,7 +1347,7 @@ entry_data_value_coerce_ref (const struct value *value)
   struct type *checked_type = check_typedef (value_type (value));
   struct value *target_val;
 
-  if (TYPE_CODE (checked_type) != TYPE_CODE_REF)
+  if (!TYPE_IS_REFERENCE (checked_type))
     return NULL;
 
   target_val = (struct value *) value_computed_closure (value);
@@ -1422,7 +1422,7 @@ value_of_dwarf_reg_entry (struct type *type, struct frame_info *frame,
      TYPE_CODE_REF with non-entry data value would give current value - not the
      entry value.  */
 
-  if (TYPE_CODE (checked_type) != TYPE_CODE_REF
+  if (!TYPE_IS_REFERENCE (checked_type)
       || TYPE_TARGET_TYPE (checked_type) == NULL)
     return outer_val;
 
diff --git a/gdb/eval.c b/gdb/eval.c
index 61d8d19..2a39774 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -620,7 +620,7 @@ static int
 ptrmath_type_p (const struct language_defn *lang, struct type *type)
 {
   type = check_typedef (type);
-  if (TYPE_CODE (type) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (type))
     type = TYPE_TARGET_TYPE (type);
 
   switch (TYPE_CODE (type))
@@ -2491,7 +2491,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	{
 	  type = check_typedef (value_type (arg1));
 	  if (TYPE_CODE (type) == TYPE_CODE_PTR
-	      || TYPE_CODE (type) == TYPE_CODE_REF
+	      || TYPE_IS_REFERENCE (type)
 	  /* In C you can dereference an array to get the 1st elt.  */
 	      || TYPE_CODE (type) == TYPE_CODE_ARRAY
 	    )
@@ -2769,7 +2769,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	    {
 	      struct type *type = value_type (result);
 
-	      if (TYPE_CODE (check_typedef (type)) != TYPE_CODE_REF)
+	      if (!TYPE_IS_REFERENCE (type))
 		{
 		  type = lookup_lvalue_reference_type (type);
 		  result = allocate_value (type);
@@ -2872,7 +2872,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
 
       /* C++: The "address" of a reference should yield the address
        * of the object pointed to.  Let value_addr() deal with it.  */
-      if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
+      if (TYPE_IS_REFERENCE (SYMBOL_TYPE (var)))
 	goto default_case;
 
       (*pos) += 4;
@@ -2911,7 +2911,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
 	{
 	  struct type *type = check_typedef (value_type (x));
 
-	  if (TYPE_CODE (type) == TYPE_CODE_REF)
+	  if (TYPE_IS_REFERENCE (type))
 	    return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
 			       not_lval);
 	  else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
@@ -3001,7 +3001,7 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
       type = check_typedef (value_type (val));
       if (TYPE_CODE (type) != TYPE_CODE_PTR
-	  && TYPE_CODE (type) != TYPE_CODE_REF
+	  && !TYPE_IS_REFERENCE (type)
 	  && TYPE_CODE (type) != TYPE_CODE_ARRAY)
 	error (_("Attempt to take contents of a non-pointer value."));
       type = TYPE_TARGET_TYPE (type);
@@ -3073,7 +3073,7 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
      the size of the referenced type."  */
   type = check_typedef (type);
   if (exp->language_defn->la_language == language_cplus
-      && TYPE_CODE (type) == TYPE_CODE_REF)
+      && (TYPE_IS_REFERENCE (type)))
     type = check_typedef (TYPE_TARGET_TYPE (type));
   return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
 }
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 80c709a..ed4d5c1 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -169,8 +169,7 @@ extract_long_unsigned_integer (const gdb_byte *addr, int orig_len,
 CORE_ADDR
 extract_typed_address (const gdb_byte *buf, struct type *type)
 {
-  if (TYPE_CODE (type) != TYPE_CODE_PTR
-      && TYPE_CODE (type) != TYPE_CODE_REF)
+  if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
     internal_error (__FILE__, __LINE__,
 		    _("extract_typed_address: "
 		    "type is not a pointer or reference"));
@@ -242,8 +241,7 @@ store_unsigned_integer (gdb_byte *addr, int len,
 void
 store_typed_address (gdb_byte *buf, struct type *type, CORE_ADDR addr)
 {
-  if (TYPE_CODE (type) != TYPE_CODE_PTR
-      && TYPE_CODE (type) != TYPE_CODE_REF)
+  if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
     internal_error (__FILE__, __LINE__,
 		    _("store_typed_address: "
 		    "type is not a pointer or reference"));
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 60cef68..defc00d 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3622,10 +3622,11 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
 
   /* See through references, since we can almost make non-references
      references.  */
-  if (TYPE_CODE (arg) == TYPE_CODE_REF)
+
+  if (TYPE_IS_REFERENCE (arg))
     return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
                        REFERENCE_CONVERSION_BADNESS));
-  if (TYPE_CODE (parm) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (parm))
     return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
                        REFERENCE_CONVERSION_BADNESS));
   if (overload_debug)
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index c0ac6ae..a5053c6 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -895,6 +895,7 @@ hppa64_integral_or_pointer_p (const struct type *type)
       }
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       return (TYPE_LENGTH (type) == 8);
     default:
       break;
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 713738e..38335a7 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -157,10 +157,11 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
   switch (TYPE_CODE (type))
     {
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       {
 	struct value *new_value;
 
-	if (TYPE_CODE (arg_type) == TYPE_CODE_REF)
+	if (TYPE_IS_REFERENCE (arg_type))
 	  return value_cast_pointers (type, arg, 0);
 
 	/* Cast the value to the reference's target type, and then
diff --git a/gdb/language.c b/gdb/language.c
index 31c5c59..119c07e 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -409,8 +409,7 @@ language_info (int quietly)
 int
 pointer_type (struct type *type)
 {
-  return TYPE_CODE (type) == TYPE_CODE_PTR ||
-    TYPE_CODE (type) == TYPE_CODE_REF;
+  return TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type);
 }
 
 \f
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index d08b263..7376372 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -2011,7 +2011,7 @@ m32c_reg_arg_type (struct type *type)
   return (code == TYPE_CODE_INT
 	  || code == TYPE_CODE_ENUM
 	  || code == TYPE_CODE_PTR
-	  || code == TYPE_CODE_REF
+	  || TYPE_IS_REFERENCE (type)
 	  || code == TYPE_CODE_BOOL
 	  || code == TYPE_CODE_CHAR);
 }
@@ -2433,8 +2433,7 @@ m32c_m16c_address_to_pointer (struct gdbarch *gdbarch,
 {
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   enum type_code target_code;
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_PTR ||
-	      TYPE_CODE (type) == TYPE_CODE_REF);
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type));
 
   target_code = TYPE_CODE (TYPE_TARGET_TYPE (type));
 
@@ -2513,8 +2512,7 @@ m32c_m16c_pointer_to_address (struct gdbarch *gdbarch,
   CORE_ADDR ptr;
   enum type_code target_code;
 
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_PTR ||
-	      TYPE_CODE (type) == TYPE_CODE_REF);
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type));
 
   ptr = extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order);
 
diff --git a/gdb/m88k-tdep.c b/gdb/m88k-tdep.c
index fb7cf8b..6ae9590 100644
--- a/gdb/m88k-tdep.c
+++ b/gdb/m88k-tdep.c
@@ -161,6 +161,7 @@ m88k_integral_or_pointer_p (const struct type *type)
       return 1;
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       {
 	/* Allow only 32-bit pointers.  */
 	return (TYPE_LENGTH (type) == 4);
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 5f5d5ca..38356e5 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -96,6 +96,7 @@ mn10300_type_align (struct type *type)
     case TYPE_CODE_FLT:
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       return TYPE_LENGTH (type);
 
     case TYPE_CODE_COMPLEX:
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 6297b58..75329df 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -760,7 +760,7 @@ msp430_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 
 		  if (code_model == MSP_LARGE_CODE_MODEL
 		      && (TYPE_CODE (arg_type) == TYPE_CODE_PTR
-		          || TYPE_CODE (arg_type) == TYPE_CODE_REF
+		          || TYPE_IS_REFERENCE (arg_type)
 			  || TYPE_CODE (arg_type) == TYPE_CODE_STRUCT
 			  || TYPE_CODE (arg_type) == TYPE_CODE_UNION))
 		    {
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index ecae636..c1778f2 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -806,7 +806,7 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *func_type,
 	    || TYPE_CODE (type) == TYPE_CODE_CHAR
 	    || TYPE_CODE (type) == TYPE_CODE_BOOL
 	    || TYPE_CODE (type) == TYPE_CODE_PTR
-	    || TYPE_CODE (type) == TYPE_CODE_REF
+	    || TYPE_IS_REFERENCE (type)
 	    || TYPE_CODE (type) == TYPE_CODE_ENUM)
 	   && TYPE_LENGTH (type) <= tdep->wordsize)
     {
@@ -1494,7 +1494,7 @@ ppc64_sysv_abi_push_param (struct gdbarch *gdbarch,
 	    || TYPE_CODE (type) == TYPE_CODE_BOOL
 	    || TYPE_CODE (type) == TYPE_CODE_CHAR
 	    || TYPE_CODE (type) == TYPE_CODE_PTR
-	    || TYPE_CODE (type) == TYPE_CODE_REF)
+	    || TYPE_IS_REFERENCE (type))
 	   && TYPE_LENGTH (type) <= tdep->wordsize)
     {
       ULONGEST word = 0;
@@ -2000,8 +2000,7 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct value *function,
     }
 
   /* All pointers live in r3.  */
-  if (TYPE_CODE (valtype) == TYPE_CODE_PTR
-      || TYPE_CODE (valtype) == TYPE_CODE_REF)
+  if (TYPE_CODE (valtype) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (valtype))
     {
       int regnum = tdep->ppc_gp0_regnum + 3;
 
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index dab4f53..e4a35a7 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1691,7 +1691,7 @@ x_command (char *exp, int from_tty)
       if (from_tty)
 	*exp = 0;
       val = evaluate_expression (expr.get ());
-      if (TYPE_CODE (value_type (val)) == TYPE_CODE_REF)
+      if (TYPE_IS_REFERENCE (value_type (val)))
 	val = coerce_ref (val);
       /* In rvalue contexts, such as this, functions are coerced into
          pointers to functions.  This makes "x/i main" work.  */
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index c063d2c..f071006 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -460,8 +460,7 @@ typy_get_composite (struct type *type)
 	}
       END_CATCH
 
-      if (TYPE_CODE (type) != TYPE_CODE_PTR
-	  && TYPE_CODE (type) != TYPE_CODE_REF)
+      if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
 	break;
       type = TYPE_TARGET_TYPE (type);
     }
@@ -921,7 +920,7 @@ typy_template_argument (PyObject *self, PyObject *args)
   TRY
     {
       type = check_typedef (type);
-      if (TYPE_CODE (type) == TYPE_CODE_REF)
+      if (TYPE_IS_REFERENCE (type))
 	type = check_typedef (TYPE_TARGET_TYPE (type));
     }
   CATCH (except, RETURN_MASK_ALL)
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index aacf628..693bc39 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -217,6 +217,7 @@ valpy_referenced_value (PyObject *self, PyObject *args)
           res_val = value_ind (self_val);
           break;
         case TYPE_CODE_REF:
+        case TYPE_CODE_RVALUE_REF:
           res_val = coerce_ref (self_val);
           break;
         default:
@@ -363,8 +364,7 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
       type = value_type (val);
       type = check_typedef (type);
 
-      if (((TYPE_CODE (type) == TYPE_CODE_PTR)
-	   || (TYPE_CODE (type) == TYPE_CODE_REF))
+      if (((TYPE_CODE (type) == TYPE_CODE_PTR) || TYPE_IS_REFERENCE (type))
 	  && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
 	{
 	  struct value *target;
@@ -994,7 +994,7 @@ enum valpy_opcode
 
 /* If TYPE is a reference, return the target; otherwise return TYPE.  */
 #define STRIP_REFERENCE(TYPE) \
-  ((TYPE_CODE (TYPE) == TYPE_CODE_REF) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
+  (TYPE_IS_REFERENCE (TYPE) ? (TYPE_TARGET_TYPE (TYPE)) : (TYPE))
 
 /* Helper for valpy_binop.  Returns a value object which is the result
    of applying the operation specified by OPCODE to the given
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index abc9438..6ffe802 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -3151,7 +3151,7 @@ s390_function_arg_integer (struct type *type)
       || code == TYPE_CODE_CHAR
       || code == TYPE_CODE_BOOL
       || code == TYPE_CODE_PTR
-      || code == TYPE_CODE_REF)
+      || TYPE_IS_REFERENCE (type))
     return 1;
 
   return ((code == TYPE_CODE_UNION || code == TYPE_CODE_STRUCT)
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index b605da7..d346aec 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -227,6 +227,7 @@ sparc_integral_or_pointer_p (const struct type *type)
       return (len == 1 || len == 2 || len == 4 || len == 8);
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       /* Allow either 32-bit or 64-bit pointers.  */
       return (len == 4 || len == 8);
     default:
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index 43beffb..fae41ef 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -68,6 +68,7 @@ sparc64_integral_or_pointer_p (const struct type *type)
       return 1;
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       {
 	int len = TYPE_LENGTH (type);
 	gdb_assert (len == 8);
diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
index 70d7f6f..cd8b64d 100644
--- a/gdb/spu-tdep.c
+++ b/gdb/spu-tdep.c
@@ -1339,6 +1339,7 @@ spu_scalar_value_p (struct type *type)
     case TYPE_CODE_BOOL:
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       return TYPE_LENGTH (type) <= 16;
 
     default:
diff --git a/gdb/symtab.c b/gdb/symtab.c
index c0fd0fd..cc2f400 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1989,8 +1989,7 @@ lookup_symbol_aux (const char *name, const struct block *block,
 	  /* I'm not really sure that type of this can ever
 	     be typedefed; just be safe.  */
 	  t = check_typedef (t);
-	  if (TYPE_CODE (t) == TYPE_CODE_PTR
-	      || TYPE_CODE (t) == TYPE_CODE_REF)
+	  if (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
 	    t = TYPE_TARGET_TYPE (t);
 
 	  if (TYPE_CODE (t) != TYPE_CODE_STRUCT
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index a22c6fb..fc687d3 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -453,8 +453,7 @@ whatis_exp (char *exp, int show)
   get_user_print_options (&opts);
   if (opts.objectprint)
     {
-      if (((TYPE_CODE (type) == TYPE_CODE_PTR)
-	   || (TYPE_CODE (type) == TYPE_CODE_REF))
+      if (((TYPE_CODE (type) == TYPE_CODE_PTR) || TYPE_IS_REFERENCE (type))
 	  && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
         real_type = value_rtti_indirect_type (val, &full, &top, &using_enc);
       else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
@@ -571,6 +570,7 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
     case TYPE_CODE_METHODPTR:
     case TYPE_CODE_METHOD:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_NAMESPACE:
       error (_("internal error: unhandled type in print_type_scalar"));
       break;
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 7298262..985233c 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -232,11 +232,11 @@ binop_types_user_defined_p (enum exp_opcode op,
     return 0;
 
   type1 = check_typedef (type1);
-  if (TYPE_CODE (type1) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (type1))
     type1 = check_typedef (TYPE_TARGET_TYPE (type1));
 
   type2 = check_typedef (type2);
-  if (TYPE_CODE (type2) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (type2))
     type2 = check_typedef (TYPE_TARGET_TYPE (type2));
 
   return (TYPE_CODE (type1) == TYPE_CODE_STRUCT
@@ -270,7 +270,7 @@ unop_user_defined_p (enum exp_opcode op, struct value *arg1)
   if (op == UNOP_ADDR)
     return 0;
   type1 = check_typedef (value_type (arg1));
-  if (TYPE_CODE (type1) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (type1))
     type1 = check_typedef (TYPE_TARGET_TYPE (type1));
   return TYPE_CODE (type1) == TYPE_CODE_STRUCT;
 }
diff --git a/gdb/valops.c b/gdb/valops.c
index 21f4008..93ae6cf 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -318,7 +318,7 @@ value_cast_pointers (struct type *type, struct value *arg2,
     {
       struct value *v2;
 
-      if (TYPE_CODE (type2) == TYPE_CODE_REF)
+      if (TYPE_IS_REFERENCE (type2))
 	v2 = coerce_ref (arg2);
       else
 	v2 = value_ind (arg2);
@@ -361,24 +361,20 @@ value_cast (struct type *type, struct value *arg2)
   if (value_type (arg2) == type)
     return arg2;
 
-  code1 = TYPE_CODE (check_typedef (type));
-
   /* Check if we are casting struct reference to struct reference.  */
-  if (code1 == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (check_typedef (type)))
     {
       /* We dereference type; then we recurse and finally
          we generate value of the given reference.  Nothing wrong with 
 	 that.  */
       struct type *t1 = check_typedef (type);
       struct type *dereftype = check_typedef (TYPE_TARGET_TYPE (t1));
-      struct value *val =  value_cast (dereftype, arg2);
+      struct value *val = value_cast (dereftype, arg2);
 
       return value_ref (val, TYPE_CODE (t1));
     }
 
-  code2 = TYPE_CODE (check_typedef (value_type (arg2)));
-
-  if (code2 == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (check_typedef (value_type (arg2))))
     /* We deref the value and then do the cast.  */
     return value_cast (type, coerce_ref (arg2)); 
 
@@ -389,7 +385,7 @@ value_cast (struct type *type, struct value *arg2)
 
   /* You can't cast to a reference type.  See value_cast_pointers
      instead.  */
-  gdb_assert (code1 != TYPE_CODE_REF);
+  gdb_assert (!TYPE_IS_REFERENCE (type));
 
   /* A cast to an undetermined-length array_type, such as 
      (TYPE [])OBJECT, is treated like a cast to (TYPE [N])OBJECT,
@@ -592,8 +588,8 @@ value_reinterpret_cast (struct type *type, struct value *arg)
   dest_type = type;
 
   /* If we are casting to a reference type, transform
-     reinterpret_cast<T&>(V) to *reinterpret_cast<T*>(&V).  */
-  if (TYPE_CODE (real_type) == TYPE_CODE_REF)
+     reinterpret_cast<T&[&]>(V) to *reinterpret_cast<T*>(&V).  */
+  if (TYPE_IS_REFERENCE (real_type))
     {
       is_ref = 1;
       arg = value_addr (arg);
@@ -733,10 +729,10 @@ value_dynamic_cast (struct type *type, struct value *arg)
   struct type *class_type, *rtti_type;
   struct value *result, *tem, *original_arg = arg;
   CORE_ADDR addr;
-  int is_ref = TYPE_CODE (resolved_type) == TYPE_CODE_REF;
+  int is_ref = TYPE_IS_REFERENCE (resolved_type);
 
   if (TYPE_CODE (resolved_type) != TYPE_CODE_PTR
-      && TYPE_CODE (resolved_type) != TYPE_CODE_REF)
+      && !TYPE_IS_REFERENCE (resolved_type))
     error (_("Argument to dynamic_cast must be a pointer or reference type"));
   if (TYPE_CODE (TYPE_TARGET_TYPE (resolved_type)) != TYPE_CODE_VOID
       && TYPE_CODE (TYPE_TARGET_TYPE (resolved_type)) != TYPE_CODE_STRUCT)
@@ -1478,7 +1474,7 @@ value_addr (struct value *arg1)
   struct value *arg2;
   struct type *type = check_typedef (value_type (arg1));
 
-  if (TYPE_CODE (type) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (type))
     {
       if (value_bits_synthetic_pointer (arg1, value_embedded_offset (arg1),
 	  TARGET_CHAR_BIT * TYPE_LENGTH (type)))
@@ -1744,7 +1740,7 @@ typecmp (int staticp, int varargs, int nargs,
       tt1 = check_typedef (t1[i].type);
       tt2 = check_typedef (value_type (t2[i]));
 
-      if (TYPE_CODE (tt1) == TYPE_CODE_REF
+      if (TYPE_IS_REFERENCE (tt1)
 	  /* We should be doing hairy argument matching, as below.  */
 	  && (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (tt1)))
 	      == TYPE_CODE (tt2)))
@@ -1762,14 +1758,13 @@ typecmp (int staticp, int varargs, int nargs,
 	 char *>, and properly access map["hello"], because the
 	 argument to [] will be a reference to a pointer to a char,
 	 and the argument will be a pointer to a char.  */
-      while (TYPE_CODE(tt1) == TYPE_CODE_REF
-	     || TYPE_CODE (tt1) == TYPE_CODE_PTR)
+      while (TYPE_IS_REFERENCE (tt1) || TYPE_CODE (tt1) == TYPE_CODE_PTR)
 	{
 	  tt1 = check_typedef( TYPE_TARGET_TYPE(tt1) );
 	}
       while (TYPE_CODE(tt2) == TYPE_CODE_ARRAY
 	     || TYPE_CODE(tt2) == TYPE_CODE_PTR
-	     || TYPE_CODE(tt2) == TYPE_CODE_REF)
+	     || TYPE_IS_REFERENCE (tt2))
 	{
 	  tt2 = check_typedef (TYPE_TARGET_TYPE(tt2));
 	}
@@ -2161,7 +2156,7 @@ value_struct_elt (struct value **argp, struct value **args,
 
   /* Follow pointers until we get to a non-pointer.  */
 
-  while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+  while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
     {
       *argp = value_ind (*argp);
       /* Don't coerce fn pointer to fn and then back again!  */
@@ -2248,7 +2243,7 @@ value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
 
   t = check_typedef (value_type (*argp));
 
-  while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+  while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
     {
       *argp = value_ind (*argp);
       if (TYPE_CODE (check_typedef (value_type (*argp))) != TYPE_CODE_FUNC)
@@ -2409,7 +2404,7 @@ value_find_oload_method_list (struct value **argp, const char *method,
   t = check_typedef (value_type (*argp));
 
   /* Code snarfed from value_struct_elt.  */
-  while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+  while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
     {
       *argp = value_ind (*argp);
       /* Don't coerce fn pointer to fn and then back again!  */
@@ -2818,7 +2813,7 @@ find_overload_match (struct value **args, int nargs,
 
       if (TYPE_CODE (temp_type) != TYPE_CODE_PTR
 	  && (TYPE_CODE (objtype) == TYPE_CODE_PTR
-	      || TYPE_CODE (objtype) == TYPE_CODE_REF))
+	      || TYPE_IS_REFERENCE (objtype)))
 	{
 	  temp = value_addr (temp);
 	}
@@ -3614,7 +3609,7 @@ value_rtti_indirect_type (struct value *v, int *full,
 
   type = value_type (v);
   type = check_typedef (type);
-  if (TYPE_CODE (type) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (type))
     target = coerce_ref (v);
   else if (TYPE_CODE (type) == TYPE_CODE_PTR)
     {
@@ -3647,8 +3642,8 @@ value_rtti_indirect_type (struct value *v, int *full,
       target_type = value_type (target);
       real_type = make_cv_type (TYPE_CONST (target_type),
 				TYPE_VOLATILE (target_type), real_type, NULL);
-      if (TYPE_CODE (type) == TYPE_CODE_REF)
-        real_type = lookup_lvalue_reference_type (real_type);
+      if (TYPE_IS_REFERENCE (type))
+        real_type = lookup_reference_type (real_type, TYPE_CODE (type));
       else if (TYPE_CODE (type) == TYPE_CODE_PTR)
         real_type = lookup_pointer_type (real_type);
       else
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 529f9a5..6937dab 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -281,7 +281,7 @@ int
 val_print_scalar_type_p (struct type *type)
 {
   type = check_typedef (type);
-  while (TYPE_CODE (type) == TYPE_CODE_REF)
+  while (TYPE_IS_REFERENCE (type))
     {
       type = TYPE_TARGET_TYPE (type);
       type = check_typedef (type);
@@ -536,7 +536,7 @@ get_value_addr_contents (struct value *deref_val)
     }
 }
 
-/* generic_val_print helper for TYPE_CODE_REF.  */
+/* generic_val_print helper for TYPE_CODE_{RVALUE_,}REF.  */
 
 static void
 generic_val_print_ref (struct type *type,
@@ -960,6 +960,7 @@ generic_val_print (struct type *type,
       break;
 
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       generic_val_print_ref (type, embedded_offset, stream, recurse,
 			     original_value, options);
       break;
diff --git a/gdb/value.c b/gdb/value.c
index 8c3b3f6..be01f0f 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1205,8 +1205,7 @@ value_actual_type (struct value *value, int resolve_simple_types,
     {
       /* If result's target type is TYPE_CODE_STRUCT, proceed to
 	 fetch its rtti type.  */
-      if ((TYPE_CODE (result) == TYPE_CODE_PTR
-	   || TYPE_CODE (result) == TYPE_CODE_REF)
+      if ((TYPE_CODE (result) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (result))
 	  && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
 	     == TYPE_CODE_STRUCT
 	  && !value_optimized_out (value))
@@ -2883,7 +2882,7 @@ value_as_address (struct value *val)
      ABI-specific code is a more reasonable place to handle it.  */
 
   if (TYPE_CODE (value_type (val)) != TYPE_CODE_PTR
-      && TYPE_CODE (value_type (val)) != TYPE_CODE_REF
+      && !TYPE_IS_REFERENCE (value_type (val))
       && gdbarch_integer_to_address_p (gdbarch))
     return gdbarch_integer_to_address (gdbarch, value_type (val),
 				       value_contents (val));
@@ -2940,6 +2939,7 @@ unpack_long (struct type *type, const gdb_byte *valaddr)
 
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
       /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
          whether we want this to be true eventually.  */
       return extract_typed_address (valaddr, type);
@@ -3546,6 +3546,7 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num)
       break;
 
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_PTR:
       store_typed_address (buf, type, (CORE_ADDR) num);
       break;
@@ -3582,6 +3583,7 @@ pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num)
       break;
 
     case TYPE_CODE_REF:
+    case TYPE_CODE_RVALUE_REF:
     case TYPE_CODE_PTR:
       store_typed_address (buf, type, (CORE_ADDR) num);
       break;
@@ -3812,7 +3814,7 @@ coerce_ref_if_computed (const struct value *arg)
 {
   const struct lval_funcs *funcs;
 
-  if (TYPE_CODE (check_typedef (value_type (arg))) != TYPE_CODE_REF)
+  if (!TYPE_IS_REFERENCE (check_typedef (value_type (arg))))
     return NULL;
 
   if (value_lval_const (arg) != lval_computed)
@@ -3854,7 +3856,7 @@ coerce_ref (struct value *arg)
   if (retval)
     return retval;
 
-  if (TYPE_CODE (value_type_arg_tmp) != TYPE_CODE_REF)
+  if (!TYPE_IS_REFERENCE (value_type_arg_tmp))
     return arg;
 
   enc_type = check_typedef (value_enclosing_type (arg));
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 173abf3..f5d1cbf 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -2136,7 +2136,7 @@ varobj_get_value_type (const struct varobj *var)
 
   type = check_typedef (type);
 
-  if (TYPE_CODE (type) == TYPE_CODE_REF)
+  if (TYPE_IS_REFERENCE (type))
     type = get_target_type (type);
 
   type = check_typedef (type);
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v6 10/11] Add rvalue references to overloading resolution
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (9 preceding siblings ...)
  2017-03-10 20:12 ` [PATCH v6 09/11] Convert lvalue reference type check to general reference type check Keith Seitz
@ 2017-03-10 20:14 ` Keith Seitz
  2017-03-13 18:51 ` [PATCH v6 00/11] c++/14441: Rvalue reference support Pedro Alves
  11 siblings, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-10 20:14 UTC (permalink / raw)
  To: gdb-patches

This patch introduces changes to rank_one_type() dealing with ranking an rvalue
reference type when selecting a best viable function from a set of candidate
functions. The 4 new added rules for rvalue references are:

1) An rvalue argument cannot be bound to a non-const lvalue reference parameter
and an lvalue argument cannot be bound to an rvalue reference parameter.
[C++11 13.3.3.1.4p3]

2) If a conversion to one type of reference is an identity conversion, and a
conversion to the second type of reference is a non-identity conversion, choose
the first type. [C++11 13.3.3.2p3]

3) An rvalue should be first tried to bind to an rvalue reference, and then to
an lvalue reference. [C++11 13.3.3.2p3]

4) An lvalue reference to a function gets higher priority than an rvalue
reference to a function. [C++11 13.3.3.2p3]

There are no changes to this patch from v5.

NOTE: This patch is not exactly correct.  See c++/15372 for tracking overload
resolution bugs.

gdb/ChangeLog

	PR gdb/14441
	From Artemiy Volkov  <artemiyv@acm.org>
	* gdbtypes.c (rank_one_type): Implement overloading
	resolution rules regarding rvalue references.
---
 gdb/ChangeLog  |  7 +++++++
 gdb/gdbtypes.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ee3de5c..338f412 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -2,6 +2,13 @@
 
 	PR gdb/14441
 	From Artemiy Volkov  <artemiyv@acm.org>
+	* gdbtypes.c (rank_one_type): Implement overloading
+	resolution rules regarding rvalue references.
+
+2017-MM-DD  Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	From Artemiy Volkov  <artemiyv@acm.org>
 	* aarch64-tdep.c (aarch64_type_align)
 	(aarch64_extract_return_value, aarch64_store_return_value): Change
 	lvalue reference type checks to general reference type checks.
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index defc00d..6f3aeab 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -58,6 +58,8 @@ const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0};
 const struct rank BOOL_CONVERSION_BADNESS = {3,0};
 const struct rank BASE_CONVERSION_BADNESS = {2,0};
 const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
+const struct rank LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS = {5,0};
+const struct rank DIFFERENT_REFERENCE_TYPE_BADNESS = {6,0};
 const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
 const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
 const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0};
@@ -3611,15 +3613,65 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
 {
   struct rank rank = {0,0};
 
-  if (types_equal (parm, arg))
-    return EXACT_MATCH_BADNESS;
-
   /* Resolve typedefs */
   if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
     parm = check_typedef (parm);
   if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
     arg = check_typedef (arg);
 
+  if (value != NULL)
+    {
+      /* An rvalue argument cannot be bound to a non-const lvalue
+         reference parameter...  */
+      if (VALUE_LVAL (value) == not_lval
+          && TYPE_CODE (parm) == TYPE_CODE_REF
+          && !TYPE_CONST (parm->main_type->target_type))
+        return INCOMPATIBLE_TYPE_BADNESS;
+
+      /* ... and an lvalue argument cannot be bound to an rvalue
+         reference parameter.  [C++ 13.3.3.1.4p3]  */
+      if (VALUE_LVAL (value) != not_lval
+          && TYPE_CODE (parm) == TYPE_CODE_RVALUE_REF)
+        return INCOMPATIBLE_TYPE_BADNESS;
+    }
+
+  if (types_equal (parm, arg))
+    return EXACT_MATCH_BADNESS;
+
+  /* An lvalue reference to a function should get higher priority than an
+     rvalue reference to a function.  */
+
+  if (value != NULL && TYPE_CODE (arg) == TYPE_CODE_RVALUE_REF
+      && TYPE_CODE (TYPE_TARGET_TYPE (arg)) == TYPE_CODE_FUNC)
+    {
+      return (sum_ranks (rank_one_type (parm,
+              lookup_pointer_type (TYPE_TARGET_TYPE (arg)), NULL),
+              DIFFERENT_REFERENCE_TYPE_BADNESS));
+    }
+
+  /* If a conversion to one type of reference is an identity conversion, and a
+     conversion to the second type of reference is a non-identity conversion,
+     choose the first type.  */
+
+  if (value != NULL && TYPE_IS_REFERENCE (parm) && TYPE_IS_REFERENCE (arg)
+     && TYPE_CODE (parm) != TYPE_CODE (arg))
+    {
+      return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm),
+              TYPE_TARGET_TYPE (arg), NULL), DIFFERENT_REFERENCE_TYPE_BADNESS));
+    }
+
+  /* An rvalue should be first tried to bind to an rvalue reference, and then to
+     an lvalue reference.  */
+
+  if (value != NULL && TYPE_CODE (parm) == TYPE_CODE_REF
+      && VALUE_LVAL (value) == not_lval)
+    {
+      if (TYPE_IS_REFERENCE (arg))
+	arg = TYPE_TARGET_TYPE (arg);
+      return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
+			 LVALUE_REFERENCE_TO_RVALUE_BINDING_BADNESS));
+    }
+
   /* See through references, since we can almost make non-references
      references.  */
 
-- 
2.1.0

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-10 20:05 ` [PATCH v6 11/11] Add rvalue reference tests and NEWS entry Keith Seitz
@ 2017-03-10 22:02   ` Eli Zaretskii
  2017-03-14 18:14     ` Keith Seitz
  2017-03-17 17:06     ` Keith Seitz
  2017-03-13 18:52   ` Pedro Alves
  2017-04-04 11:10   ` Yao Qi
  2 siblings, 2 replies; 25+ messages in thread
From: Eli Zaretskii @ 2017-03-10 22:02 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches

> From: Keith Seitz <keiths@redhat.com>
> Date: Fri, 10 Mar 2017 12:04:46 -0800
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index cf58595..edbe41f 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -7,9 +7,12 @@
>    added by the Memory Protection Keys for Userspace feature which will be
>    available in future Intel CPUs.
>  
> +* GDB now supports C++11 ravlue references.
                            ^^^^^^
A typo.

(I think it would be nice to have this described in the manual as
well.)

Thanks.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/)
  2017-03-10 20:10 ` [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/) Keith Seitz
@ 2017-03-10 22:04   ` Eli Zaretskii
  2017-03-14 18:14     ` Keith Seitz
  2017-03-17 17:06     ` Keith Seitz
  0 siblings, 2 replies; 25+ messages in thread
From: Eli Zaretskii @ 2017-03-10 22:04 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches

> From: Keith Seitz <keiths@redhat.com>
> Date: Fri, 10 Mar 2017 12:04:43 -0800
> 
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index c3ea203..d463afe 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -1162,6 +1162,10 @@ A pointer-to-member.
>  @item gdb.TYPE_CODE_REF
>  A reference type.
>  
> +@vindex TYPE_CODE_RVALUE_REF
> +@item gdb.TYPE_CODE_RVALUE_REF
> +An rvalue reference type.

Thanks.  However, I'm not sure this is enough to explain to the reader
what this is about.  At the very least, the text should mention C++.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 00/11] c++/14441: Rvalue reference support
  2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
                   ` (10 preceding siblings ...)
  2017-03-10 20:14 ` [PATCH v6 10/11] Add rvalue references to overloading resolution Keith Seitz
@ 2017-03-13 18:51 ` Pedro Alves
  11 siblings, 0 replies; 25+ messages in thread
From: Pedro Alves @ 2017-03-13 18:51 UTC (permalink / raw)
  To: Keith Seitz, gdb-patches

On 03/10/2017 08:04 PM, Keith Seitz wrote:
> This patch series was submitted in June, 2016, and the original author does
> not have the time to see this through. Given that we would like this in the
> 8.0 release, I have contacted the orginal author, who is allowing me to
> champion his patch on his behalf.
> 
> When this series was last reviewed, revisions were requested in patches 8
> and 11. I have highlighted in those patches what I have changed over the last
> submitted patch version (v5).

Thanks so much for this Keith.

I'll point out a few nits to patch #11, but otherwise the
series is OK.

Before committing, please address a couple procedural issues.

> +2017-MM-DD  Keith Seitz  <keiths@redhat.com>
> +
> +	PR gdb/14441
> +	From Artemiy Volkov  <artemiyv@acm.org>

As explained in:

 https://www.gnu.org/prep/standards/standards.html#Style-of-Change-Logs

Since the patch is unchanged, this should be written as:

2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>

	PR gdb/14441

Likewise in the other patches, of course.

Likewise, the git commit "Author" should be preserved when
it makes sense.  For the patches that are largely unchanged
from Artemiy's original versions, we should make sure that
our git history preserves his authorship.

When changes were done to the patches to fix things, to
apply modernization, etc., add your name as another author
for the patch, like:

YYYY-MM-DD  Hacker 1  <hacker2@foo.com>
	    Hacker 2  <hacker2@bar.com>

For example, in patch #8, the ChangeLog entry for
the manual should be "squashed", and then both names
should appear as above, instead of keeping the "who did what"
parts separated.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-10 20:05 ` [PATCH v6 11/11] Add rvalue reference tests and NEWS entry Keith Seitz
  2017-03-10 22:02   ` Eli Zaretskii
@ 2017-03-13 18:52   ` Pedro Alves
  2017-03-14 18:15     ` Keith Seitz
  2017-04-04 11:10   ` Yao Qi
  2 siblings, 1 reply; 25+ messages in thread
From: Pedro Alves @ 2017-03-13 18:52 UTC (permalink / raw)
  To: Keith Seitz, gdb-patches

On 03/10/2017 08:04 PM, Keith Seitz wrote:
> This patch adds tests for the initial rvalue reference support patchset.  All
> of the new tests are practically mirrored regular references tests and, except
> for the demangler ones, are introduced in new files, which are set to be
> compiled with -std=gnu++11.  Tested are printing of rvalue reference types and
> values, rvalue reference parameters in function overloading, demangling of
> function names containing rvalue reference parameters, casts to rvalue
> reference types, application of the sizeof operator to rvalue reference types
> and values, and support for rvalue references within the gdb python module.
> 
> Changes since v5:
> o Added NEWS entries
> o Rewrote rvalue-ref-overload.{cc,exp}
> o Updated all tests to current coding standard
> o Added missing copyright headers, maintaining dates from copied files
> o KFAIL failing overload resolution tests

Thanks!

A few nits below.  With these addressed, this is good to me.

> 
> gdb/ChnageLog
> 
> 	* NEWS: Mention support for ravlue references in GDB and python.

Typo, "ravlue".

> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,6 +1,11 @@
>  2017-MM-DD  Keith Seitz  <keiths@redhat.com>
>  
>  	PR gdb/14441
> +	* NEWS: Mention support for ravlue references in GDB and python.

Again.

> +
> +2017-MM-DD  Keith Seitz  <keiths@redhat.com>
> +
> +	PR gdb/14441
>  	From Artemiy Volkov  <artemiyv@acm.org>
>  	* gdbtypes.c (rank_one_type): Implement overloading
>  	resolution rules regarding rvalue references.

> diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp b/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
> new file mode 100644
> index 0000000..7ae4ef0
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
> @@ -0,0 +1,76 @@
> +# Copyright 2002-2017 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/>.
> +
> +# This file is part of the gdb testsuite
> +
> +# C++11 rvalue reference type casting tests, based on gdb.cp/casts.exp.
> +
> +if {[skip_cplus_tests]} { continue }
> +
> +standard_testfile .cc
> +
> +if {[get_compiler_info "c++"]} {
> +    return -1
> +}
> +
> +if {[prepare_for_testing $testfile.exp $testfile $srcfile \
> +    {debug c++ additional_flags="-std=gnu++11"}]} {
> +    return -1
> +}
> +
> +if {![runto_main]} {
> +    untested "couldn't run to main"
> +    return -1
> +}
> +
> +# Prevent symbol on address 0x0 being printed.
> +gdb_test_no_output "set print symbol off"
> +
> +set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}]
> +gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\."

Please add an explicit test message in order to avoid it changing
if/when $line changes.

> +
> +gdb_test "continue" "Breakpoint .* at .*$srcfile:$line.*"
> +
> +# Check upcasting.
> +gdb_test "print (A &&) br" ".* = .A &&.* {a = 42}" \
> +    "cast derived class rvalue reference to base class rvalue reference"
> +
> +# Check downcasting.
> +gdb_test "print (B &&) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
> +    "cast base class rvalue reference to derived class rvalue reference"
> +
> +# Check compiler casting
> +
> +set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+"
> +
> +gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
> +    [concat "let compiler cast base class rvalue reference to derived " \
> +	 "class rvalue reference"]

Is there a special reason for using concat here?  I'd think a
continuation would do:

	"let compiler cast base class rvalue reference to derived\
	 class rvalue reference"

TCL replaces continuation+newline+spaces/tabs with a single whitespace:
 http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M24

> +
> +gdb_test "print static_cast<A &&> (*b)" " = \\(A \\&\\&\\) @$hex: {a = 42}" \
> +    "static_cast to rvalue reference type"
> +
> +gdb_test "print reinterpret_cast<A &&> (*b)" \
> +    " = \\(A \\&\\&\\) @$hex: {a = 42}" \
> +    "reinterpret_cast to rvalue reference type"
> +
> +gdb_test "print dynamic_cast<Alpha &&> (derived)" \
> +    [format " = \\(Alpha \\&\\&\\) @%s: {.* = %s( <vtable for Derived.*>)?}" \
> +	 $nonzero_hex $nonzero_hex] \
> +    "dynamic_cast simple upcast to rvalue reference"
> +
> +gdb_test "print dynamic_cast<VirtuallyDerived &&> (*ad)" \
> +    "dynamic_cast failed" \
> +    "dynamic_cast to rvalue reference to non-existing base"


> new file mode 100644
> index 0000000..7ffb344
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/rvalue-ref-params.exp
> @@ -0,0 +1,64 @@
> +# Copyright 2006-2017 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/>.
> +
> +# Tests for rvalue reference parameters of types and their subtypes in GDB,
> +# based on gdb.cp/ref-params.exp.
> +
> +#
> +# test running programs
> +#
> +
> +if {[skip_cplus_tests]} { continue }
> +
> +standard_testfile .cc
> +
> +if {[prepare_for_testing $testfile.exp $testfile $srcfile \
> +    {debug c++ additional_flags="-std=gnu++11"}] == 1} {
> +    return -1
> +}
> +
> +proc gdb_start_again {text} {
> +    global binfile
> +    global srcfile
> +
> +    clean_restart $binfile
> +
> +    runto ${srcfile}:[gdb_get_line_number $text]

Should probably be wrapped with with_test_prefix to avoid
duplicate messages from within clean_restart / runto,
in case they fail.

> +}
> +
> +gdb_start_again "marker1 here"
> +gdb_test "print f1(static_cast<Child&&>(Q))" ".* = 40.*" \
> +    "print value of f1 on (Child&&) in main"
> +
> +gdb_start_again "marker1 here"
> +gdb_test "print f2(static_cast<Child&&>(Q))" ".* = 40.*" \
> +    "print value of f2 on (Child&&) in main"
> +
> +gdb_start_again "marker2 here"
> +gdb_test "print C" ".*id = 42.*" "print value of Child&& in f2"
> +
> +setup_kfail "c++/15372" "*-*-*"
> +gdb_test "print f1 (static_cast<Child&&> (C))" ".* = 42.*" \
> +    "print value of f1 on Child&& in f2"
> +
> +gdb_start_again "marker3 here"
> +gdb_test "print R" ".*id = 41.*" "print value of Parent&& in f1"
> +
> +gdb_start_again "breakpoint MQ here"
> +gdb_test "print f1(static_cast<MultiChild&&>(MQ))" ".* = 53"
> +gdb_start_again "breakpoint MQ here"
> +gdb_test "print mf1(static_cast<MultiChild&&>(MQ))" ".* = 106"
> +gdb_start_again "breakpoint MQ here"
> +gdb_test "print mf2(static_cast<MultiChild&&>(MQ))" ".* = 106"


> new file mode 100644
> index 0000000..62a665d
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/rvalue-ref-types.cc
> @@ -0,0 +1,79 @@
> +/* This test script is part of GDB, the GNU debugger.
> +
> +   Copyright 1999-2017 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/>.  */
> +
> +/* Tests for reference types with short type variables in GDB, based on
> +   gdb.cp/ref-types.cc.  */
> +
> +#include <utility>
> +
> +int main2 ();
> +
> +void
> +marker1 ()
> +{
> +}
> +
> +int
> +main ()
> +{
> +  short t = -1;
> +  short *pt;
> +  short &&rrt = std::move (t);
> +  pt = &rrt;
> +
> +  short *&&rrpt = std::move (pt);
> +  short at[4];
> +  at[0] = 0;
> +  at[1] = 1;
> +  at[2] = 2;
> +  at[3] = 3;
> +
> +  short (&&rrat)[4] = std::move( at);
> +
> +    marker1();
> +
> +    main2();
> +
> +    return 0;

Indentation of these 3 statements above is odd.

> diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-types.exp b/gdb/testsuite/gdb.cp/rvalue-ref-types.exp
> new file mode 100644
> index 0000000..9067b3b
> --- /dev/null
> +++ b/gdb/testsuite/gdb.cp/rvalue-ref-types.exp
> @@ -0,0 +1,165 @@
> +# Copyright 1999-2017 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/>.
> +
> +# Tests for reference types with short type variables in GDB, based on
> +# gdb.cp/ref-types.exp.
> +


> +#
> +# test running programs
> +#

Eh, we still have that string blindly copied all over
the place.  Please don't add another copy.  :-)

> +
> +proc gdb_start_again {} {
> +    global srcdir
> +    global subdir
> +    global binfile
> +    global gdb_prompt
> +    global decimal
> +
> +    gdb_start
> +    gdb_reinitialize_dir $srcdir/$subdir
> +    gdb_load ${binfile}
> +
> +    #
> +    # set it up at a breakpoint so we can play with the variable values
> +    #
> +    if {![runto_main]} {
> +	perror "couldn't run to breakpoint"
> +	continue
> +    }
> +
> +    if {![runto 'marker1']} {
> +	perror "couldn't run to marker1"
> +	continue
> +    }
> +
> +    gdb_test "up" ".*main.*" "up from marker1 2"
> +}

Same comment about with_test_prefix.  Actually, can we just
remove the "eof" handling below making this procedure
unnecessary?  (I know this is copied from the other file.)

> +
> +
> +gdb_test_multiple "print rrt" "print value of rrt" {
> +    -re ".\[0-9\]* = \\(short( int)? &&\\) @$hex: -1.*$gdb_prompt $" {
> +        pass "print value of rrt"
> +    }
> +    eof { fail "print rrt ($gdb dumped core) (fixme)" ; gdb_start_again ; }
> +}


Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-10 22:02   ` Eli Zaretskii
@ 2017-03-14 18:14     ` Keith Seitz
  2017-03-17 17:06     ` Keith Seitz
  1 sibling, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-14 18:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

On 03/10/2017 02:02 PM, Eli Zaretskii wrote:
>> From: Keith Seitz <keiths@redhat.com>
>> Date: Fri, 10 Mar 2017 12:04:46 -0800
>>
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index cf58595..edbe41f 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -7,9 +7,12 @@
>>    added by the Memory Protection Keys for Userspace feature which will be
>>    available in future Intel CPUs.
>>  
>> +* GDB now supports C++11 ravlue references.
>                             ^^^^^^
> A typo.

Good catch. Fixed.

> (I think it would be nice to have this described in the manual as
> well.)

I've searched through the manual for a suitable place to mention this,
the only bit of doc/gdb.texinfo that talks specifically about C++
references is the "reference declarations" in the C++ Expressions node.
I've added a bit explaining that GDB understands both lvalue and rvalue
references.

Let me know if you would like anything further, and thank you for the
quick review!

[I've trimmed down the patch to just the documentation parts. If you
would like to see the full patch, please see my reply to Pedro's message
on this patch.]

Keith

> commit 25826f564b480af57a1da01c0f76c4b61034485e
> Author: Artemiy Volkov <artemiyv@acm.org>
> Date:   Wed Jan 25 10:33:56 2017 -0800
> 
>     Add rvalue reference tests and docs
>     
>     This patch adds tests for the initial rvalue reference support patchset.  All
>     of the new tests are practically mirrored regular references tests and, except
>     for the demangler ones, are introduced in new files, which are set to be
>     compiled with -std=gnu++11.  Tested are printing of rvalue reference types and
>     values, rvalue reference parameters in function overloading, demangling of
>     function names containing rvalue reference parameters, casts to rvalue
>     reference types, application of the sizeof operator to rvalue reference types
>     and values, and support for rvalue references within the gdb python module.
>     
>     gdb/ChnageLog
>     
>     	PR gdb/14441
>     	* NEWS: Mention support for rvalue references in GDB and python.
>     	* doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
>     	supports both lvalue and rvalue references.
>     
[snip]
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 544f192..7876b47 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,6 +1,13 @@
>  2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
>  
>  	PR gdb/14441
> +	* NEWS: Mention support for rvalue references in GDB and python.
> +	* doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
> +	supports both lvalue and rvalue references.
> +
> +2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
> +
> +	PR gdb/14441
>  	* gdbtypes.c (rank_one_type): Implement overloading
>  	resolution rules regarding rvalue references.
>  
> diff --git a/gdb/NEWS b/gdb/NEWS
> index cf58595..4fade30 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -7,9 +7,12 @@
>    added by the Memory Protection Keys for Userspace feature which will be
>    available in future Intel CPUs.
>  
> +* GDB now supports C++11 rvalue references.
> +
>  * Python Scripting
>  
>    ** New functions to start, stop and access a running btrace recording.
> +  ** Rvalue references are now supported in gdb.Type.
>  
>  * GDB now supports recording and replaying rdrand and rdseed Intel 64
>    instructions.
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 5cf0f97..581ddae 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -14827,9 +14827,9 @@ see @ref{Completion, ,Command Completion}.
>  
>  @cindex reference declarations
>  @item
> -@value{GDBN} understands variables declared as C@t{++} references; you can use
> -them in expressions just as you do in C@t{++} source---they are automatically
> -dereferenced.
> +@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
> +references; you can use them in expressions just as you do in C@t{++}
> +source---they are automatically dereferenced.
>  

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/)
  2017-03-10 22:04   ` Eli Zaretskii
@ 2017-03-14 18:14     ` Keith Seitz
  2017-03-17 17:06     ` Keith Seitz
  1 sibling, 0 replies; 25+ messages in thread
From: Keith Seitz @ 2017-03-14 18:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

On 03/10/2017 02:04 PM, Eli Zaretskii wrote:
>> From: Keith Seitz <keiths@redhat.com>
>> Date: Fri, 10 Mar 2017 12:04:43 -0800
>>
>> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
>> index c3ea203..d463afe 100644
>> --- a/gdb/doc/python.texi
>> +++ b/gdb/doc/python.texi
>> @@ -1162,6 +1162,10 @@ A pointer-to-member.
>>  @item gdb.TYPE_CODE_REF
>>  A reference type.
>>  
>> +@vindex TYPE_CODE_RVALUE_REF
>> +@item gdb.TYPE_CODE_RVALUE_REF
>> +An rvalue reference type.
> 
> Thanks.  However, I'm not sure this is enough to explain to the reader
> what this is about.  At the very least, the text should mention C++.
> 

I've added that this is a C++11 feature. Updated patch below.

Thanks again!

Keith

> commit 731f0b2600518fce3ec1a94a9a53483bb29f3be3
> Author: Artemiy Volkov <artemiyv@acm.org>
> Date:   Tue Mar 7 15:05:51 2017 -0800
> 
>     Support rvalue references in the gdb python module (includes doc/)
>     
>     This patch adds the ability to inspect rvalue reference types and values using
>     the gdb python module. This is achieved by creating two wrappers for
>     valpy_reference_value(), using the ReferenceExplorer class to handle the
>     objects of rvalue reference types and placing necessary checks for a
>     TYPE_CODE_RVALUE_REF type code next to the checks for a TYPE_CODE_REF type
>     code.
>     
>     gdb/ChangeLog
>     
>     	PR gdb/14441
>     	* doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to
>     	table of constants.
>     	* python/lib/gdb/command/explore.py: Support exploring values
>     	of rvalue reference types.
>     	* python/lib/gdb/types.py: Implement get_basic_type() for
>     	rvalue reference types.
>     	* python/py-type.c (pyty_codes) <TYPE_CODE_RVALUE_REF>: New
>     	constant.
>     	* python/py-value.c (valpy_getitem): Add an rvalue reference
>     	check.
>     	(valpy_reference_value): Add new parameter "refcode".
>     	(valpy_lvalue_reference_value, valpy_rvalue_reference_value):
>     	New wrappers for valpy_reference_value().
>     	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
>     	(gdbpy_invoke_xmethod): Likewise.
> 
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 9670b14..20ca925 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,6 +1,25 @@
>  2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
>  
>  	PR gdb/14441
> +	* doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to
> +	table of constants.
> +	* python/lib/gdb/command/explore.py: Support exploring values
> +	of rvalue reference types.
> +	* python/lib/gdb/types.py: Implement get_basic_type() for
> +	rvalue reference types.
> +	* python/py-type.c (pyty_codes) <TYPE_CODE_RVALUE_REF>: New
> +	constant.
> +	* python/py-value.c (valpy_getitem): Add an rvalue reference
> +	check.
> +	(valpy_reference_value): Add new parameter "refcode".
> +	(valpy_lvalue_reference_value, valpy_rvalue_reference_value):
> +	New wrappers for valpy_reference_value().
> +	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
> +	(gdbpy_invoke_xmethod): Likewise.
> +
> +2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
> +
> +	PR gdb/14441
>  	* dwarf2read.c (process_die, read_type_die_1): Handle the
>  	DW_TAG_rvalue_reference_type DIE.
>  	(read_tag_reference_type): Add new parameter "refcode".
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index c3ea203..15ff2a2 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -1162,6 +1162,10 @@ A pointer-to-member.
>  @item gdb.TYPE_CODE_REF
>  A reference type.
>  
> +@vindex TYPE_CODE_RVALUE_REF
> +@item gdb.TYPE_CODE_RVALUE_REF
> +A C@t{++}11 rvalue reference type.
> +
>  @vindex TYPE_CODE_CHAR
>  @item gdb.TYPE_CODE_CHAR
>  A character type.
> diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py
> index b2878b9..4eb2e24 100644
> --- a/gdb/python/lib/gdb/command/explore.py
> +++ b/gdb/python/lib/gdb/command/explore.py
> @@ -132,6 +132,7 @@ class Explorer(object):
>              gdb.TYPE_CODE_UNION : CompoundExplorer,
>              gdb.TYPE_CODE_PTR : PointerExplorer,
>              gdb.TYPE_CODE_REF : ReferenceExplorer,
> +            gdb.TYPE_CODE_RVALUE_REF : ReferenceExplorer,
>              gdb.TYPE_CODE_TYPEDEF : TypedefExplorer,
>              gdb.TYPE_CODE_ARRAY : ArrayExplorer
>          }
> @@ -318,7 +319,6 @@ class ReferenceExplorer(object):
>          Explorer.explore_type(name, target_type, is_child)
>          return False
>  
> -
>  class ArrayExplorer(object):
>      """Internal class used to explore arrays."""
>  
> diff --git a/gdb/python/lib/gdb/types.py b/gdb/python/lib/gdb/types.py
> index 799a07d..26a5027 100644
> --- a/gdb/python/lib/gdb/types.py
> +++ b/gdb/python/lib/gdb/types.py
> @@ -31,8 +31,10 @@ def get_basic_type(type_):
>      """
>  
>      while (type_.code == gdb.TYPE_CODE_REF or
> +           type_.code == gdb.TYPE_CODE_RVALUE_REF or
>             type_.code == gdb.TYPE_CODE_TYPEDEF):
> -        if type_.code == gdb.TYPE_CODE_REF:
> +        if (type_.code == gdb.TYPE_CODE_REF or
> +            type_.code == gdb.TYPE_CODE_RVALUE_REF):
>              type_ = type_.target()
>          else:
>              type_ = type_.strip_typedefs()
> diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
> index 0249cbb..c063d2c 100644
> --- a/gdb/python/py-type.c
> +++ b/gdb/python/py-type.c
> @@ -106,6 +106,7 @@ static struct pyty_code pyty_codes[] =
>    ENTRY (TYPE_CODE_METHODPTR),
>    ENTRY (TYPE_CODE_MEMBERPTR),
>    ENTRY (TYPE_CODE_REF),
> +  ENTRY (TYPE_CODE_RVALUE_REF),
>    ENTRY (TYPE_CODE_CHAR),
>    ENTRY (TYPE_CODE_BOOL),
>    ENTRY (TYPE_CODE_COMPLEX),
> diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
> index c0199ea..aacf628 100644
> --- a/gdb/python/py-value.c
> +++ b/gdb/python/py-value.c
> @@ -238,7 +238,7 @@ valpy_referenced_value (PyObject *self, PyObject *args)
>  /* Return a value which is a reference to the value.  */
>  
>  static PyObject *
> -valpy_reference_value (PyObject *self, PyObject *args)
> +valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode)
>  {
>    PyObject *result = NULL;
>  
> @@ -248,7 +248,7 @@ valpy_reference_value (PyObject *self, PyObject *args)
>        scoped_value_mark free_values;
>  
>        self_val = ((value_object *) self)->value;
> -      result = value_to_value_object (value_ref (self_val, TYPE_CODE_REF));
> +      result = value_to_value_object (value_ref (self_val, refcode));
>      }
>    CATCH (except, RETURN_MASK_ALL)
>      {
> @@ -259,6 +259,18 @@ valpy_reference_value (PyObject *self, PyObject *args)
>    return result;
>  }
>  
> +static PyObject *
> +valpy_lvalue_reference_value (PyObject *self, PyObject *args)
> +{
> +  return valpy_reference_value (self, args, TYPE_CODE_REF);
> +}
> +
> +static PyObject *
> +valpy_rvalue_reference_value (PyObject *self, PyObject *args)
> +{
> +  return valpy_reference_value (self, args, TYPE_CODE_RVALUE_REF);
> +}
> +
>  /* Return a "const" qualified version of the value.  */
>  
>  static PyObject *
> @@ -585,8 +597,7 @@ value_has_field (struct value *v, PyObject *field)
>      {
>        val_type = value_type (v);
>        val_type = check_typedef (val_type);
> -      if (TYPE_CODE (val_type) == TYPE_CODE_REF
> -	  || TYPE_CODE (val_type) == TYPE_CODE_PTR)
> +      if (TYPE_IS_REFERENCE (val_type) || TYPE_CODE (val_type) == TYPE_CODE_PTR)
>        val_type = check_typedef (TYPE_TARGET_TYPE (val_type));
>  
>        type_code = TYPE_CODE (val_type);
> @@ -743,6 +754,9 @@ valpy_getitem (PyObject *self, PyObject *key)
>  	  else if (TYPE_CODE (val_type) == TYPE_CODE_REF)
>  	    res_val = value_cast (lookup_lvalue_reference_type (base_class_type),
>  	                          tmp);
> +	  else if (TYPE_CODE (val_type) == TYPE_CODE_RVALUE_REF)
> +	    res_val = value_cast (lookup_rvalue_reference_type (base_class_type),
> +	                          tmp);
>  	  else
>  	    res_val = value_cast (base_class_type, tmp);
>  	}
> @@ -1724,8 +1738,10 @@ reinterpret_cast operator."
>    { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
>    { "referenced_value", valpy_referenced_value, METH_NOARGS,
>      "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
> -  { "reference_value", valpy_reference_value, METH_NOARGS,
> +  { "reference_value", valpy_lvalue_reference_value, METH_NOARGS,
>      "Return a value of type TYPE_CODE_REF referencing this value." },
> +  { "rvalue_reference_value", valpy_rvalue_reference_value, METH_NOARGS,
> +    "Return a value of type TYPE_CODE_RVALUE_REF referencing this value." },
>    { "const_value", valpy_const_value, METH_NOARGS,
>      "Return a 'const' qualied version of the same value." },
>    { "lazy_string", (PyCFunction) valpy_lazy_string,
> diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
> index d01488f..e061da2 100644
> --- a/gdb/python/py-xmethods.c
> +++ b/gdb/python/py-xmethods.c
> @@ -464,9 +464,10 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
>        if (!types_equal (obj_type, this_ptr))
>  	obj = value_cast (this_ptr, obj);
>      }
> -  else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
> +  else if (TYPE_IS_REFERENCE (obj_type))
>      {
> -      struct type *this_ref = lookup_lvalue_reference_type (this_type);
> +      struct type *this_ref
> +        = lookup_reference_type (this_type, TYPE_CODE (obj_type));
>  
>        if (!types_equal (obj_type, this_ref))
>  	obj = value_cast (this_ref, obj);

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-13 18:52   ` Pedro Alves
@ 2017-03-14 18:15     ` Keith Seitz
  2017-03-14 18:39       ` Pedro Alves
  0 siblings, 1 reply; 25+ messages in thread
From: Keith Seitz @ 2017-03-14 18:15 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1714 bytes --]

On 03/13/2017 11:52 AM, Pedro Alves wrote:
> 
> Typo, "ravlue".
> 

All corrected.

>> +set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}]
>> +gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\."
> 
> Please add an explicit test message in order to avoid it changing
> if/when $line changes.

Fixed.

> Is there a special reason for using concat here?  I'd think a
> continuation would do:
> 
> 	"let compiler cast base class rvalue reference to derived\
> 	 class rvalue reference"
> 
> TCL replaces continuation+newline+spaces/tabs with a single whitespace:
>  http://www.tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M24
> 

Ha. I'm such an old dog! [And learned/was reminded of a new trick...] Fixed.

>> +
>> +#
>> +# test running programs
>> +#

I've removed the above comment from all the rvalue-*.exp tests. They
don't actually serve to clarify anything anyway.

>> +proc gdb_start_again {text} {
>> +    global binfile
>> +    global srcfile
>> +
>> +    clean_restart $binfile
>> +
>> +    runto ${srcfile}:[gdb_get_line_number $text]
> 
> Should probably be wrapped with with_test_prefix to avoid
> duplicate messages from within clean_restart / runto,
> in case they fail.

Fixed.

>> +  short (&&rrat)[4] = std::move( at);
>> +
>> +    marker1();
>> +
>> +    main2();
>> +
>> +    return 0;
> 
> Indentation of these 3 statements above is odd.
> 

Yup. Fixed.

> 
> Same comment about with_test_prefix.  Actually, can we just
> remove the "eof" handling below making this procedure
> unnecessary?  (I know this is copied from the other file.)
> 

Indeed. I've replaced the gdb_test_multiple with the simpler gdb_test
and removed the gdb_start_again procedure.

Revision attached.

Keith

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: add-rvalue-tests-and-doc.patch --]
[-- Type: text/x-patch; name="add-rvalue-tests-and-doc.patch", Size: 37982 bytes --]

commit 25826f564b480af57a1da01c0f76c4b61034485e
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Wed Jan 25 10:33:56 2017 -0800

    Add rvalue reference tests and docs
    
    This patch adds tests for the initial rvalue reference support patchset.  All
    of the new tests are practically mirrored regular references tests and, except
    for the demangler ones, are introduced in new files, which are set to be
    compiled with -std=gnu++11.  Tested are printing of rvalue reference types and
    values, rvalue reference parameters in function overloading, demangling of
    function names containing rvalue reference parameters, casts to rvalue
    reference types, application of the sizeof operator to rvalue reference types
    and values, and support for rvalue references within the gdb python module.
    
    gdb/ChnageLog
    
    	PR gdb/14441
    	* NEWS: Mention support for rvalue references in GDB and python.
    	* doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
    	supports both lvalue and rvalue references.
    
    gdb/testsuite/ChangeLog
    
    	PR gdb/14441
    	* gdb.cp/demangle.exp: Add rvalue reference tests.
    	* gdb.cp/rvalue-ref-casts.cc: New file.
    	* gdb.cp/rvalue-ref-casts.exp: New file.
    	* gdb.cp/rvalue-ref-overload.cc: New file.
    	* gdb.cp/rvalue-ref-overload.exp: New file.
    	* gdb.cp/rvalue-ref-params.cc: New file.
    	* gdb.cp/rvalue-ref-params.exp: New file.
    	* gdb.cp/rvalue-ref-sizeof.cc: New file.
    	* gdb.cp/rvalue-ref-sizeof.exp: New file.
    	* gdb.cp/rvalue-ref-types.cc: New file.
    	* gdb.cp/rvalue-ref-types.exp: New file.
    	* gdb.python/py-rvalue-ref-value-cc.cc: New file.
    	* gdb.python/py-rvalue-ref-value-cc.exp: New file.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 544f192..7876b47 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,6 +1,13 @@
 2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
 
 	PR gdb/14441
+	* NEWS: Mention support for rvalue references in GDB and python.
+	* doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
+	supports both lvalue and rvalue references.
+
+2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
+
+	PR gdb/14441
 	* gdbtypes.c (rank_one_type): Implement overloading
 	resolution rules regarding rvalue references.
 
diff --git a/gdb/NEWS b/gdb/NEWS
index cf58595..4fade30 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -7,9 +7,12 @@
   added by the Memory Protection Keys for Userspace feature which will be
   available in future Intel CPUs.
 
+* GDB now supports C++11 rvalue references.
+
 * Python Scripting
 
   ** New functions to start, stop and access a running btrace recording.
+  ** Rvalue references are now supported in gdb.Type.
 
 * GDB now supports recording and replaying rdrand and rdseed Intel 64
   instructions.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 5cf0f97..581ddae 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -14827,9 +14827,9 @@ see @ref{Completion, ,Command Completion}.
 
 @cindex reference declarations
 @item
-@value{GDBN} understands variables declared as C@t{++} references; you can use
-them in expressions just as you do in C@t{++} source---they are automatically
-dereferenced.
+@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
+references; you can use them in expressions just as you do in C@t{++}
+source---they are automatically dereferenced.
 
 In the parameter list shown when @value{GDBN} displays a frame, the values of
 reference variables are not displayed (unlike other variables); this
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 0718d76..fb41311 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,21 @@
+2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
+	    Keith Seitz  <keiths@redhat.com>
+
+	PR gdb/14441
+	* gdb.cp/demangle.exp: Add rvalue reference tests.
+	* gdb.cp/rvalue-ref-casts.cc: New file.
+	* gdb.cp/rvalue-ref-casts.exp: New file.
+	* gdb.cp/rvalue-ref-overload.cc: New file.
+	* gdb.cp/rvalue-ref-overload.exp: New file.
+	* gdb.cp/rvalue-ref-params.cc: New file.
+	* gdb.cp/rvalue-ref-params.exp: New file.
+	* gdb.cp/rvalue-ref-sizeof.cc: New file.
+	* gdb.cp/rvalue-ref-sizeof.exp: New file.
+	* gdb.cp/rvalue-ref-types.cc: New file.
+	* gdb.cp/rvalue-ref-types.exp: New file.
+	* gdb.python/py-rvalue-ref-value-cc.cc: New file.
+	* gdb.python/py-rvalue-ref-value-cc.exp: New file.
+
 2017-03-10  Keith Seitz  <keiths@redhat.com>
 
 	PR c++/8128
diff --git a/gdb/testsuite/gdb.cp/demangle.exp b/gdb/testsuite/gdb.cp/demangle.exp
index 0ecf95d..fe51c55 100644
--- a/gdb/testsuite/gdb.cp/demangle.exp
+++ b/gdb/testsuite/gdb.cp/demangle.exp
@@ -70,7 +70,9 @@ proc test_demangling_core {tester test result} {
     }
 
     if {[string compare $style $current_demangling_style]} {
-	set_demangling_style $style
+	with_test_prefix $test {
+	    set_demangling_style $style
+	}
     }
 
     $tester "demangle $name" $result $test
@@ -521,6 +523,44 @@ proc test_gnu_style_demangling {} {
     test_demangling_exact "gnu: foo__I_200_" "foo(int512_t)"
     test_demangling_exact "gnu: foo__I_200" "Can't demangle \"foo__I_200\""
 
+    # Rvalue reference tests
+    test_demangling_exact "gnu-v3: _ZN9ArrowLine19ArrowheadIntersectsEP9ArrowheadO6BoxObjP7Graphic" "ArrowLine::ArrowheadIntersects(Arrowhead*, BoxObj&&, Graphic*)"
+    test_demangling "gnu-v3: _Z13BitPatterntoaOK10BitPatternccc" \
+	"BitPatterntoa\[(\]+(const BitPattern|BitPattern const)&&, char, char, char\[)\]+"
+    test_demangling_exact "gnu-v3: _ZN8TextCode14CoreConstDeclsEO7ostream" "TextCode::CoreConstDecls(ostream&&)"
+    test_demangling "gnu-v3: _Z31DrawDestinationTransformedImageP7_XImageiiS0_iimjiijmmP4_XGCOK13ivTransformeriiii" \
+	"DrawDestinationTransformedImage\[(\]+_XImage\[*\]+, int, int, _XImage\[*\]+, int, int, unsigned long, unsigned int, int, int, unsigned int, unsigned long, unsigned long, _XGC\[*\]+, (const ivTransformer|ivTransformer const)&&, int, int, int, int\[)\]+"
+    test_demangling_exact "gnu-v3: _ZN11RelateManip6EffectEO7ivEvent" "RelateManip::Effect(ivEvent&&)"
+    test_demangling_exact "gnu-v3: _ZN20DisplayList_IteratorC4EO11DisplayList" "DisplayList_Iterator::DisplayList_Iterator(DisplayList&&)"
+    test_demangling_exact "gnu-v3: _ZN3fooC4EOS_" "foo::foo(foo&&)"
+    test_demangling_exact "gnu-v3: _ZN3fooC4EiOS_iS0_iS0_" "foo::foo(int, foo&&, int, foo&&, int, foo&&)"
+    test_demangling "gnu-v3: _ZN7ivWorldC2EPKcOiPPcPK12ivOptionDescPK14ivPropertyData" \
+	"ivWorld::ivWorld\[(\]+(const char|char const)\[*\]+, int&&, char\[*\]+\[*\]+, (const ivOptionDesc|ivOptionDesc const)\[*\]+, (const ivPropertyData|ivPropertyData const)\[*\]+\[)\]+"
+    test_demangling "gnu-v3: _Z3argOK7Complex" \
+	"arg\[(\]+(const Complex|Complex const)&&\[)\]+"
+    test_demangling "gnu-v3: _ZNK9BitString8containsEOK10BitPattern" \
+	"BitString::contains\[(\]+(const BitPattern|BitPattern const)&&\[)\]+ const"
+    test_demangling "gnu-v3: _ZNK9BitString8containsEOK12BitSubStringi" \
+	"BitString::contains\[(\]+(const BitSubString|BitSubString const)&&, int\[)\]+ const"
+    test_demangling "gnu-v3: _ZNK9BitString8containsEOKS_" \
+	"BitString::contains\[(\]+(const BitString|BitString const)&&\[)\]+ const"
+    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE3PixC4EOKS2_" \
+	"List<VHDLEntity>::Pix::Pix(List<VHDLEntity>::Pix const&&)"
+    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC2EOKS0_PS2_" \
+	"List<VHDLEntity>::element::element(VHDLEntity const&&, List<VHDLEntity>::element*)"
+    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC4EOKS2_" \
+	"List<VHDLEntity>::element::element(List<VHDLEntity>::element const&&)"
+    test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityEclEOKNS1_3PixE" \
+	"List<VHDLEntity>::operator()(List<VHDLEntity>::Pix const&&) const"
+    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityEC4EOKS1_" \
+	"List<VHDLEntity>::List(List<VHDLEntity> const&&)"
+    test_demangling_exact "gnu-v3: _ZN4PixXI11VHDLLibrary14VHDLLibraryRep4ListI10VHDLEntityEEC2EOKS5_" \
+	"PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> >::PixX(PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> > const&&)"
+    test_demangling_exact "gnu-v3: _ZNK11VHDLLibrary5nextEEO4PixXIS_14VHDLLibraryRep4ListI10VHDLEntityEE" \
+	"VHDLLibrary::nextE(PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> >&&) const"
+    test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityE4nextEONS1_3PixE" \
+	"List<VHDLEntity>::next(List<VHDLEntity>::Pix&&) const"
+
     ## Buffer overrun.  Should make GDB crash.  Woo hoo!
     test_demangling_exact "gnu: foo__I_4000000000000000000000000000000000000000000000000000000000000000000000000" "Can't demangle \"foo__I_4000000000000000000000000000000000000000000000000000000000000000000000000\""
 
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc b/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc
new file mode 100644
index 0000000..1f81fe0
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-casts.cc
@@ -0,0 +1,75 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2002-2017 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/>.  */
+
+/* Rvalue references casting tests, based on casts.cc.  */
+
+#include <utility>
+
+struct A
+{
+  int a;
+  A (int aa): a (aa) {}
+};
+
+struct B: public A
+{
+  int b;
+  B (int aa, int bb): A (aa), b (bb) {}
+};
+
+
+struct Alpha
+{
+  virtual void x () { }
+};
+
+struct Gamma
+{
+};
+
+struct Derived : public Alpha
+{
+};
+
+struct VirtuallyDerived : public virtual Alpha
+{
+};
+
+struct DoublyDerived : public VirtuallyDerived,
+		       public virtual Alpha,
+		       public Gamma
+{
+};
+
+int
+main (int argc, char **argv)
+{
+  A *a = new B (42, 1729);
+  B *b = (B *) a;
+  A &ar = *b;
+  B &br = (B&)ar;
+  A &&arr = std::move (A (42));
+  B &&brr = std::move (B (42, 1729));
+
+  Derived derived;
+  DoublyDerived doublyderived;
+
+  Alpha *ad = &derived;
+  Alpha *add = &doublyderived;
+
+  return 0;  /* breakpoint spot: rvalue-ref-casts.exp: 1 */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp b/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
new file mode 100644
index 0000000..f3a794c
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-casts.exp
@@ -0,0 +1,77 @@
+# Copyright 2002-2017 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/>.
+
+# This file is part of the gdb testsuite
+
+# C++11 rvalue reference type casting tests, based on gdb.cp/casts.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[get_compiler_info "c++"]} {
+    return -1
+}
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}]} {
+    return -1
+}
+
+if {![runto_main]} {
+    untested "couldn't run to main"
+    return -1
+}
+
+# Prevent symbol on address 0x0 being printed.
+gdb_test_no_output "set print symbol off"
+
+set line [gdb_get_line_number {rvalue-ref-casts.exp: 1}]
+gdb_test "break $line" "Breakpoint.*at.* file .*$srcfile, line $line\\." \
+    "break at test location"
+
+gdb_test "continue" "Breakpoint .* at .*$srcfile:$line.*"
+
+# Check upcasting.
+gdb_test "print (A &&) br" ".* = .A &&.* {a = 42}" \
+    "cast derived class rvalue reference to base class rvalue reference"
+
+# Check downcasting.
+gdb_test "print (B &&) ar" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
+    "cast base class rvalue reference to derived class rvalue reference"
+
+# Check compiler casting
+
+set nonzero_hex "0x\[0-9A-Fa-f\]\[0-9A-Fa-f\]+"
+
+gdb_test "print br" ".* = .B.* {<A> = {a = 42}, b = 1729}" \
+    "let compiler cast base class rvalue reference to derived\
+    class rvalue reference"
+
+gdb_test "print static_cast<A &&> (*b)" " = \\(A \\&\\&\\) @$hex: {a = 42}" \
+    "static_cast to rvalue reference type"
+
+gdb_test "print reinterpret_cast<A &&> (*b)" \
+    " = \\(A \\&\\&\\) @$hex: {a = 42}" \
+    "reinterpret_cast to rvalue reference type"
+
+gdb_test "print dynamic_cast<Alpha &&> (derived)" \
+    " = \\(Alpha \\&\\&\\) @$nonzero_hex: {.* = ${nonzero_hex}(\
+    <vtable for Derived.*>)?}" \
+    "dynamic_cast simple upcast to rvalue reference"
+
+gdb_test "print dynamic_cast<VirtuallyDerived &&> (*ad)" \
+    "dynamic_cast failed" \
+    "dynamic_cast to rvalue reference to non-existing base"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc b/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
new file mode 100644
index 0000000..c12eb03
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-overload.cc
@@ -0,0 +1,86 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 1998-2017 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/>.  */
+
+/* Rvalue references overload tests for GDB, based on overload.cc.  */
+
+#include <stddef.h>
+#include <utility>
+
+class foo;
+
+typedef foo &foo_lval_ref;
+typedef foo &&foo_rval_ref;
+
+class foo
+{
+public:
+  foo ();
+  foo (foo_lval_ref);
+  foo (foo_rval_ref);
+  ~foo ();
+
+  int overload1arg (foo_lval_ref);
+  int overload1arg (foo_rval_ref);
+};
+
+void
+marker1 ()
+{
+}
+
+static int
+f (int &x)
+{
+  return 1;
+}
+
+static int
+f (const int &x)
+{
+  return 2;
+}
+
+static int
+f (int &&x)
+{
+  return 3;
+}
+
+int
+main ()
+{
+  foo foo_rr_instance1;
+  foo arg;
+  int i = 0;
+  const int ci = 0;
+
+  // result = 1 + 2 + 3 + 3 = 9
+  int result = f (i) + f (ci) + f (0) + f (std::move (i));
+
+  marker1 (); // marker1-returns-here
+  return result;
+}
+
+foo::foo  ()                       {}
+foo::foo  (foo_lval_ref afoo)      {}
+foo::foo  (foo_rval_ref afoo)      {}
+foo::~foo ()                       {}
+
+/* Some functions to test overloading by varying one argument type. */
+
+int foo::overload1arg (foo_lval_ref arg)           { return 1; }
+int foo::overload1arg (foo_rval_ref arg)           { return 2; }
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp b/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp
new file mode 100644
index 0000000..e729209
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-overload.exp
@@ -0,0 +1,69 @@
+# Copyright 1998-2017 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/>.
+
+# This file is part of the gdb testsuite
+
+# Tests for overloaded member functions with rvalue reference parameters,
+# based on gdb.cp/overload.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+load_lib "cp-support.exp"
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}]} {
+    return -1
+}
+
+# Set it up at a breakpoint so we can play with the variable values.
+
+if {![runto 'marker1']} {
+    untested "couldn't run to marker1"
+    return -1
+}
+
+# Prevent symbol on address 0x0 being printed.
+gdb_test_no_output "set print symbol off"
+gdb_test "up" ".*main.*" "up from marker1"
+
+# Print the monster class type.
+cp_test_ptype_class "foo_rr_instance1" "" "class" "foo" \
+    {
+	{ method public "foo(void);" }
+	{ method public "foo(foo_lval_ref);" }
+	{ method public "foo(foo_rval_ref);" }
+	{ method public "~foo();" }
+	{ method public "int overload1arg(foo_lval_ref);" }
+	{ method public "int overload1arg(foo_rval_ref);" }
+    }
+
+gdb_test "print foo_rr_instance1.overload1arg(arg)" \
+    "\\$\[0-9\]+ = 1" \
+    "print call overloaded func foo & arg"
+
+gdb_test "print foo_rr_instance1.overload1arg(static_cast<foo&&>(arg))" \
+    "\\$\[0-9\]+ = 2" \
+    "print call overloaded func foo && arg"
+
+# Test lvalue vs rvalue function overloads
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f (i)" "= 1" "lvalue reference overload"
+
+gdb_test "print f (ci)" "= 2" "lvalue reference to const overload"
+
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f (3)" "= 3" "rvalue reference overload"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-params.cc b/gdb/testsuite/gdb.cp/rvalue-ref-params.cc
new file mode 100644
index 0000000..59f459b
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-params.cc
@@ -0,0 +1,83 @@
+/* This test script is part of GDB, the GNU debugger.
+
+   Copyright 2006-2017 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/>.  */
+
+/* Rvalue reference parameter tests, based on ref-params.cc.  */
+
+#include <utility>
+
+struct Parent
+{
+  Parent (int id0) : id (id0) { }
+  int id;
+};
+
+struct Child : public Parent
+{
+  Child (int id0) : Parent (id0) { }
+};
+
+int
+f1 (Parent &&R)
+{
+  return R.id;			/* Set breakpoint marker3 here.  */
+}
+
+int
+f2 (Child &&C)
+{
+  return f1 (std::move (C));                 /* Set breakpoint marker2 here.  */
+}
+
+struct OtherParent
+{
+  OtherParent (int other_id0) : other_id (other_id0) { }
+  int other_id;
+};
+
+struct MultiChild : public Parent, OtherParent
+{
+  MultiChild (int id0) : Parent (id0), OtherParent (id0 * 2) { }
+};
+
+int
+mf1 (OtherParent &&R)
+{
+  return R.other_id;
+}
+
+int
+mf2 (MultiChild &&C)
+{
+  return mf1 (std::move (C));
+}
+
+int
+main ()
+{
+  Child Q(40);
+  Child &QR = Q;
+
+  /* Set breakpoint marker1 here.  */
+
+  f1 (Child (41));
+  f2 (Child (42));
+
+  MultiChild MQ (53);
+  MultiChild &MQR = MQ;
+
+  mf2 (std::move (MQ));			/* Set breakpoint MQ here.  */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-params.exp b/gdb/testsuite/gdb.cp/rvalue-ref-params.exp
new file mode 100644
index 0000000..303b447
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-params.exp
@@ -0,0 +1,69 @@
+# Copyright 2006-2017 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/>.
+
+# Tests for rvalue reference parameters of types and their subtypes in GDB,
+# based on gdb.cp/ref-params.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}] == 1} {
+    return -1
+}
+
+proc gdb_start_again {text prefix} {
+    global binfile
+    global srcfile
+
+    with_test_prefix $prefix {
+	clean_restart $binfile
+
+	runto ${srcfile}:[gdb_get_line_number $text]
+    }
+}
+
+set t "print value of f1 on (Child&&) in main"
+gdb_start_again "marker1 here" $t
+gdb_test "print f1(static_cast<Child&&>(Q))" ".* = 40.*" $t
+
+set t "print value of f2 on (Child&&) in main" 
+gdb_start_again "marker1 here" $t
+gdb_test "print f2(static_cast<Child&&>(Q))" ".* = 40.*" $t
+
+set t "print value of Child&& in f2"
+gdb_start_again "marker2 here" $t
+gdb_test "print C" ".*id = 42.*" $t
+
+setup_kfail "c++/15372" "*-*-*"
+gdb_test "print f1 (static_cast<Child&&> (C))" ".* = 42.*" \
+    "print value of f1 on Child&& in f2"
+
+set t "print value of Parent&& in f1"
+gdb_start_again "marker3 here" $t
+gdb_test "print R" ".*id = 41.*" $t
+
+set t "print f1(static_cast<MultiChild&&>(MQ))"
+gdb_start_again "breakpoint MQ here" $t
+gdb_test $t ".* = 53"
+
+set t "print mf1(static_cast<MultiChild&&>(MQ))"
+gdb_start_again "breakpoint MQ here" $t
+gdb_test $t ".* = 106"
+
+set t "print mf2(static_cast<MultiChild&&>(MQ))"
+gdb_start_again "breakpoint MQ here" $t
+gdb_test $t ".* = 106"
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc
new file mode 100644
index 0000000..ab42c67
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.cc
@@ -0,0 +1,75 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2014-2017 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/>.  */
+
+/* Sizeof tests for rvalue references, based on cpsizeof.cc.  */
+
+#include <utility>
+
+struct Class
+{
+  int a;
+  char b;
+  long c;
+
+  Class () : a (1), b ('2'), c (3) { }
+};
+
+union Union
+{
+  Class *kp;
+  char a;
+  int b;
+  long c;
+};
+
+enum Enum { A, B, C, D };
+
+typedef unsigned char a4[4];
+typedef unsigned char a8[8];
+typedef unsigned char a12[12];
+typedef Class c4[4];
+typedef Union u8[8];
+typedef Enum e12[12];
+
+#define T(N)					\
+  N N ## obj;					\
+  N&& N ## _rref = std::move (N ## obj);        \
+  N* N ## p = &(N ## obj);			\
+  N*&& N ## p_rref = std::move (N ## p);        \
+  int size_ ## N = sizeof (N ## _rref);		\
+  int size_ ## N ## p = sizeof (N ## p_rref);	\
+
+int
+main ()
+{
+  T (char);
+  T (int);
+  T (long);
+  T (float);
+  T (double);
+  T (a4);
+  T (a8);
+  T (a12);
+  T (Class);
+  T (Union);
+  T (Enum);
+  T (c4);
+  T (u8);
+  T (e12);
+
+  return 0; /* break here */
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp
new file mode 100644
index 0000000..c6c2d21
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-sizeof.exp
@@ -0,0 +1,43 @@
+# Copyright 2014-2017 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/>.
+
+# sizeof() tests with rvalue reference parameter types, based on
+# gdb.cp/cpsizeof.exp.
+
+standard_testfile .cc
+
+if {[skip_cplus_tests]} { continue }
+
+if {[prepare_for_testing ${testfile}.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}] } {
+     return -1
+}
+
+if {![runto_main]} {
+    perror "could not run to main"
+    continue
+}
+
+gdb_breakpoint [gdb_get_line_number "break here"]
+gdb_continue_to_breakpoint "break here"
+
+# Compare sizeof from the compiler and gdb.  Do this once with the actual
+# type name and once with a reference variable.
+foreach v {char int long float double a4 a8 a12 Class Union Enum c4 u8 e12} {
+    gdb_test "print size_$v == sizeof (${v}&&)" "= true"
+    gdb_test "print size_$v == sizeof (${v}_rref)" "= true"
+    gdb_test "print size_${v}p == sizeof (${v}*&&)" "= true"
+    gdb_test "print size_${v}p == sizeof (${v}p_rref)" "= true"
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-types.cc b/gdb/testsuite/gdb.cp/rvalue-ref-types.cc
new file mode 100644
index 0000000..bd8865c
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-types.cc
@@ -0,0 +1,79 @@
+/* This test script is part of GDB, the GNU debugger.
+
+   Copyright 1999-2017 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/>.  */
+
+/* Tests for reference types with short type variables in GDB, based on
+   gdb.cp/ref-types.cc.  */
+
+#include <utility>
+
+int main2 ();
+
+void
+marker1 ()
+{
+}
+
+int
+main ()
+{
+  short t = -1;
+  short *pt;
+  short &&rrt = std::move (t);
+  pt = &rrt;
+
+  short *&&rrpt = std::move (pt);
+  short at[4];
+  at[0] = 0;
+  at[1] = 1;
+  at[2] = 2;
+  at[3] = 3;
+
+  short (&&rrat)[4] = std::move( at);
+
+  marker1();
+
+  main2();
+
+  return 0;
+}
+
+int
+f ()
+{
+  int f1;
+  f1 = 1;
+  return f1;
+}
+
+int
+main2 ()
+{
+  char &&rrC = 'A';
+  unsigned char &&rrUC = 21;
+  short &&rrS = -14;
+  unsigned short &&rrUS = 7;
+  int &&rrI = 102;
+  unsigned int &&rrUI = 1002;
+  long &&rrL = -234;
+  unsigned long &&rrUL = 234;
+  float &&rrF = 1.25E10;
+  double &&rrD = -1.375E-123;
+
+  f ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/rvalue-ref-types.exp b/gdb/testsuite/gdb.cp/rvalue-ref-types.exp
new file mode 100644
index 0000000..61be9d0
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/rvalue-ref-types.exp
@@ -0,0 +1,128 @@
+# Copyright 1999-2017 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/>.
+
+# Tests for reference types with short type variables in GDB, based on
+# gdb.cp/ref-types.exp.
+
+if { [skip_cplus_tests] } { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=gnu++11"}]} {
+    return -1
+}
+
+#
+# Set it up at a breakpoint so we can play with the variable values.
+#
+if {![runto_main]} {
+    untested "couldn't run to breakpoint"
+    return -1
+}
+
+if {![runto 'marker1']} {
+    untested "couldn't run to marker1"
+    return -1
+}
+
+gdb_test "up" ".*main.*" "up from marker1 1"
+
+gdb_test "print rrt" " = \\(short( int)? &&\\) @$hex: -1" "print value of rrt" 
+
+gdb_test "ptype rrt" "type = short( int)? &&" "ptype rrt"
+
+gdb_test "print *rrpt" ".$decimal = -1" "print value of *rrpt"
+
+# gdb had a bug about dereferencing a pointer type
+# that would lead to wrong results
+# if we try to examine memory at pointer value.
+
+gdb_test "x /hd rrpt" "$hex:\[ \t\]*-1" "examine value at rrpt"
+
+gdb_test "ptype rrpt" "type = short( int)? \\*&&" "ptype rrpt"
+
+gdb_test "print rrat\[0\]" ".$decimal = 0" "print value of rrat\[0\]"
+
+gdb_test "ptype rrat" "type = short( int)? \\\(&&\\\)\\\[4\\\]" "ptype rrat"
+
+gdb_test "print rrat\[1\]" ".$decimal = 1" "print value of rrat\[1\]"
+gdb_test "print rrat\[2\]" ".$decimal = 2" "print value of rrat\[2\]"
+gdb_test "print rrat\[3\]" ".$decimal = 3" "print value of rrat\[3\]"
+
+
+if {![runto 'f']} then {
+    perror "couldn't run to f"
+    continue
+}
+
+gdb_test "up" ".main2.*" "up from f"
+
+gdb_test "ptype rrC" "type = char &&"
+
+gdb_test "ptype rrUC" "type = unsigned char &&"
+
+gdb_test "ptype rrS" "type = short( int)? &&" "ptype rrS"
+
+gdb_test "ptype rrUS" "type = unsigned short( int)? &&" "ptype rrUS"
+
+gdb_test "ptype rrI" "type = int &&"
+
+gdb_test "ptype rrUI" "type = unsigned int &&"
+
+gdb_test "ptype rrL" "type = long( int)? &&" "ptype rrL"
+
+gdb_test "ptype rrUL" "type = unsigned long( int)? &&" "ptype rrUL"
+
+gdb_test "ptype rrF" "type = float &&"
+
+gdb_test "ptype rrD" "type = double &&"
+
+gdb_test "print rrC" "$decimal = \\(char &&\\) @$hex: 65 \'A\'" \
+    "print value of rrC"
+
+gdb_test "print rrUC" \
+    "$decimal = \\(unsigned char &&\\) @$hex: 21 \'.025\'" \
+    "print value of rrUC"
+
+gdb_test "print rrS" "$decimal = \\(short( int)? &&\\) @$hex: -14" \
+                  "print value of rrS"
+
+gdb_test "print rrUS" \
+         "$decimal = \\(unsigned short( int)? &&\\) @$hex: 7" \
+         "print value of rrUS"
+
+gdb_test "print rrI" "$decimal = \\(int &&\\) @$hex: 102" \
+       "print value of rrI"
+
+gdb_test "print rrUI" \
+    "$decimal = \\(unsigned int &&\\) @$hex: 1002" \
+        "print value of rrUI"
+
+gdb_test "print rrL" \
+       "$decimal = \\(long( int)? &&\\) @$hex: -234" \
+         "print value of rrL"
+
+gdb_test "print rrUL" \
+    "$decimal = \\((unsigned long|long unsigned int)? &&\\) @$hex: 234" \
+    "print value of rrUL"
+
+gdb_test "print rrF" \
+    "$decimal = \\(float &&\\) @$hex: 1.2${decimal}e\\+0?10.*" \
+    "print value of rrF"
+
+gdb_test "print rrD" \
+    "$decimal = \\(double &&\\) @$hex: -1.375e-123.*" \
+    "print value of rrD"
diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc
new file mode 100644
index 0000000..8943be1
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.cc
@@ -0,0 +1,59 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2012-2017 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/>.  */
+
+/* Test rvalue references in python.  Based on py-value-cc.cc.  */
+
+#include <utility>
+
+class A
+{
+public:
+  int operator+ (const int a1);
+
+ public:
+  int a;
+};
+
+int
+A::operator+ (const int a1)
+{
+  return a + a1;
+}
+
+class B : public A
+{
+ public:
+  char a;
+};
+
+typedef int *int_ptr;
+
+int
+main ()
+{
+  int val = 10;
+  int &&int_rref = std::move (val);
+  int_ptr ptr = &val;
+  int_ptr &&int_ptr_rref = std::move (ptr);
+
+  B b;
+  b.a = 'b';
+  (&b)->A::a = 100;
+  B &&b_rref = std::move (b);
+
+  return 0; /* Break here.  */
+}
diff --git a/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp
new file mode 100644
index 0000000..dde5a94
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-rvalue-ref-value-cc.exp
@@ -0,0 +1,57 @@
+# Copyright (C) 2012-2017 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/>.
+
+# This file is part of the GDB testsuite.  It tests the mechanism
+# exposing rvalue reference values to Python.  It is based on
+# gdb.python/py-value-cc.exp.
+
+if {[skip_cplus_tests]} { continue }
+
+standard_testfile .cc
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile \
+    {debug c++ additional_flags="-std=c++11"}]} {
+    return -1
+}
+
+# Skip all tests if Python scripting is not enabled.
+if {[skip_python_tests]} { continue }
+
+if {![runto_main]} {
+    untested "couldn't run to main"
+   return -1
+}
+
+gdb_breakpoint [gdb_get_line_number "Break here."]
+gdb_continue_to_breakpoint "Break here" ".*Break here.*"
+
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").type))" "int &&"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").referenced_value().type))" "int"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_rref\").referenced_value()))" "10"
+
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").dereference().type))" "int"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().type))" "int_ptr"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().dereference()))" "10"
+gdb_test "python print (str(gdb.parse_and_eval(\"int_ptr_rref\").referenced_value().referenced_value()))" "10"
+
+gdb_test_no_output "python b = gdb.parse_and_eval('b')" "init b"
+gdb_test_no_output "python b_rref = gdb.parse_and_eval('b_rref')" "init b_rref"
+gdb_test_no_output "python b_fields = b.type.fields()" "init b_fields"
+
+gdb_test "python print(b_rref\[b_fields\[1\]\])" "98 'b'" "b_rref.a via field"
+gdb_test "python print(b_rref\[b_fields\[0\]\].type.target())" "A" \
+  "type of b_rref's base class via field"
+gdb_test "python print(b_rref\[b_fields\[0\]\]\['a'\])" "100" \
+  "b_rref.A::a via field"

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-14 18:15     ` Keith Seitz
@ 2017-03-14 18:39       ` Pedro Alves
  0 siblings, 0 replies; 25+ messages in thread
From: Pedro Alves @ 2017-03-14 18:39 UTC (permalink / raw)
  To: Keith Seitz, gdb-patches

On 03/14/2017 06:15 PM, Keith Seitz wrote:

> Revision attached.

LGTM.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-10 22:02   ` Eli Zaretskii
  2017-03-14 18:14     ` Keith Seitz
@ 2017-03-17 17:06     ` Keith Seitz
  2017-03-17 18:51       ` Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Keith Seitz @ 2017-03-17 17:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Pedro asked me to resend/ping this since we'd like to have this for 8.0, and my last response had the patch oddly quoted. I apologize for that.

Keith

On 03/10/2017 02:02 PM, Eli Zaretskii wrote:
>> From: Keith Seitz <keiths@redhat.com>
>> Date: Fri, 10 Mar 2017 12:04:46 -0800
>>
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index cf58595..edbe41f 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -7,9 +7,12 @@
>>    added by the Memory Protection Keys for Userspace feature which will be
>>    available in future Intel CPUs.
>>  
>> +* GDB now supports C++11 ravlue references.
>                             ^^^^^^
> A typo.

Good catch. Fixed.

> (I think it would be nice to have this described in the manual as
> well.)

I've searched through the manual for a suitable place to mention this,
the only bit of doc/gdb.texinfo that talks specifically about C++
references is the "reference declarations" in the C++ Expressions node.
I've added a bit explaining that GDB understands both lvalue and rvalue
references.

Let me know if you would like anything further, and thank you for the
quick review!

[I've trimmed down the patch to just the documentation parts. If you
would like to see the full patch, please see my reply to Pedro's message
on this patch.]

Keith

commit 25826f564b480af57a1da01c0f76c4b61034485e
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Wed Jan 25 10:33:56 2017 -0800

    Add rvalue reference tests and docs
    
    This patch adds tests for the initial rvalue reference support patchset.  All
    of the new tests are practically mirrored regular references tests and, except
    for the demangler ones, are introduced in new files, which are set to be
    compiled with -std=gnu++11.  Tested are printing of rvalue reference types and
    values, rvalue reference parameters in function overloading, demangling of
    function names containing rvalue reference parameters, casts to rvalue
    reference types, application of the sizeof operator to rvalue reference types
    and values, and support for rvalue references within the gdb python module.
    
    gdb/ChnageLog
    
    	PR gdb/14441
    	* NEWS: Mention support for rvalue references in GDB and python.
    	* doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
    	supports both lvalue and rvalue references.
    
[snip]
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 544f192..7876b47 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,6 +1,13 @@
 2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
 
 	PR gdb/14441
+	* NEWS: Mention support for rvalue references in GDB and python.
+	* doc/gdb.texinfo (C Plus Plus Expressions): Mention that GDB
+	supports both lvalue and rvalue references.
+
+2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
+
+	PR gdb/14441
 	* gdbtypes.c (rank_one_type): Implement overloading
 	resolution rules regarding rvalue references.
 
diff --git a/gdb/NEWS b/gdb/NEWS
index cf58595..4fade30 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -7,9 +7,12 @@
   added by the Memory Protection Keys for Userspace feature which will be
   available in future Intel CPUs.
 
+* GDB now supports C++11 rvalue references.
+
 * Python Scripting
 
   ** New functions to start, stop and access a running btrace recording.
+  ** Rvalue references are now supported in gdb.Type.
 
 * GDB now supports recording and replaying rdrand and rdseed Intel 64
   instructions.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 5cf0f97..581ddae 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -14827,9 +14827,9 @@ see @ref{Completion, ,Command Completion}.
 
 @cindex reference declarations
 @item
-@value{GDBN} understands variables declared as C@t{++} references; you can use
-them in expressions just as you do in C@t{++} source---they are automatically
-dereferenced.
+@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
+references; you can use them in expressions just as you do in C@t{++}
+source---they are automatically dereferenced.
 

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/)
  2017-03-10 22:04   ` Eli Zaretskii
  2017-03-14 18:14     ` Keith Seitz
@ 2017-03-17 17:06     ` Keith Seitz
  2017-03-17 18:51       ` Eli Zaretskii
  1 sibling, 1 reply; 25+ messages in thread
From: Keith Seitz @ 2017-03-17 17:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Likewise, pinging this updated patch for 8.0.

Keith

On 03/10/2017 02:04 PM, Eli Zaretskii wrote:
>> From: Keith Seitz <keiths@redhat.com>
>> Date: Fri, 10 Mar 2017 12:04:43 -0800
>>
>> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
>> index c3ea203..d463afe 100644
>> --- a/gdb/doc/python.texi
>> +++ b/gdb/doc/python.texi
>> @@ -1162,6 +1162,10 @@ A pointer-to-member.
>>  @item gdb.TYPE_CODE_REF
>>  A reference type.
>>  
>> +@vindex TYPE_CODE_RVALUE_REF
>> +@item gdb.TYPE_CODE_RVALUE_REF
>> +An rvalue reference type.
> 
> Thanks.  However, I'm not sure this is enough to explain to the reader
> what this is about.  At the very least, the text should mention C++.
> 

I've added that this is a C++11 feature. Updated patch below.

Thanks again!

Keith

commit 731f0b2600518fce3ec1a94a9a53483bb29f3be3
Author: Artemiy Volkov <artemiyv@acm.org>
Date:   Tue Mar 7 15:05:51 2017 -0800

    Support rvalue references in the gdb python module (includes doc/)
    
    This patch adds the ability to inspect rvalue reference types and values using
    the gdb python module. This is achieved by creating two wrappers for
    valpy_reference_value(), using the ReferenceExplorer class to handle the
    objects of rvalue reference types and placing necessary checks for a
    TYPE_CODE_RVALUE_REF type code next to the checks for a TYPE_CODE_REF type
    code.
    
    gdb/ChangeLog
    
    	PR gdb/14441
    	* doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to
    	table of constants.
    	* python/lib/gdb/command/explore.py: Support exploring values
    	of rvalue reference types.
    	* python/lib/gdb/types.py: Implement get_basic_type() for
    	rvalue reference types.
    	* python/py-type.c (pyty_codes) <TYPE_CODE_RVALUE_REF>: New
    	constant.
    	* python/py-value.c (valpy_getitem): Add an rvalue reference
    	check.
    	(valpy_reference_value): Add new parameter "refcode".
    	(valpy_lvalue_reference_value, valpy_rvalue_reference_value):
    	New wrappers for valpy_reference_value().
    	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
    	(gdbpy_invoke_xmethod): Likewise.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9670b14..20ca925 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,6 +1,25 @@
 2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
 
 	PR gdb/14441
+	* doc/python.texi (Types in Python): Add TYPE_CODE_RVALUE_REF to
+	table of constants.
+	* python/lib/gdb/command/explore.py: Support exploring values
+	of rvalue reference types.
+	* python/lib/gdb/types.py: Implement get_basic_type() for
+	rvalue reference types.
+	* python/py-type.c (pyty_codes) <TYPE_CODE_RVALUE_REF>: New
+	constant.
+	* python/py-value.c (valpy_getitem): Add an rvalue reference
+	check.
+	(valpy_reference_value): Add new parameter "refcode".
+	(valpy_lvalue_reference_value, valpy_rvalue_reference_value):
+	New wrappers for valpy_reference_value().
+	* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
+	(gdbpy_invoke_xmethod): Likewise.
+
+2017-MM-DD  Artemiy Volkov  <artemiyv@acm.org>
+
+	PR gdb/14441
 	* dwarf2read.c (process_die, read_type_die_1): Handle the
 	DW_TAG_rvalue_reference_type DIE.
 	(read_tag_reference_type): Add new parameter "refcode".
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index c3ea203..15ff2a2 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -1162,6 +1162,10 @@ A pointer-to-member.
 @item gdb.TYPE_CODE_REF
 A reference type.
 
+@vindex TYPE_CODE_RVALUE_REF
+@item gdb.TYPE_CODE_RVALUE_REF
+A C@t{++}11 rvalue reference type.
+
 @vindex TYPE_CODE_CHAR
 @item gdb.TYPE_CODE_CHAR
 A character type.
diff --git a/gdb/python/lib/gdb/command/explore.py b/gdb/python/lib/gdb/command/explore.py
index b2878b9..4eb2e24 100644
--- a/gdb/python/lib/gdb/command/explore.py
+++ b/gdb/python/lib/gdb/command/explore.py
@@ -132,6 +132,7 @@ class Explorer(object):
             gdb.TYPE_CODE_UNION : CompoundExplorer,
             gdb.TYPE_CODE_PTR : PointerExplorer,
             gdb.TYPE_CODE_REF : ReferenceExplorer,
+            gdb.TYPE_CODE_RVALUE_REF : ReferenceExplorer,
             gdb.TYPE_CODE_TYPEDEF : TypedefExplorer,
             gdb.TYPE_CODE_ARRAY : ArrayExplorer
         }
@@ -318,7 +319,6 @@ class ReferenceExplorer(object):
         Explorer.explore_type(name, target_type, is_child)
         return False
 
-
 class ArrayExplorer(object):
     """Internal class used to explore arrays."""
 
diff --git a/gdb/python/lib/gdb/types.py b/gdb/python/lib/gdb/types.py
index 799a07d..26a5027 100644
--- a/gdb/python/lib/gdb/types.py
+++ b/gdb/python/lib/gdb/types.py
@@ -31,8 +31,10 @@ def get_basic_type(type_):
     """
 
     while (type_.code == gdb.TYPE_CODE_REF or
+           type_.code == gdb.TYPE_CODE_RVALUE_REF or
            type_.code == gdb.TYPE_CODE_TYPEDEF):
-        if type_.code == gdb.TYPE_CODE_REF:
+        if (type_.code == gdb.TYPE_CODE_REF or
+            type_.code == gdb.TYPE_CODE_RVALUE_REF):
             type_ = type_.target()
         else:
             type_ = type_.strip_typedefs()
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 0249cbb..c063d2c 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -106,6 +106,7 @@ static struct pyty_code pyty_codes[] =
   ENTRY (TYPE_CODE_METHODPTR),
   ENTRY (TYPE_CODE_MEMBERPTR),
   ENTRY (TYPE_CODE_REF),
+  ENTRY (TYPE_CODE_RVALUE_REF),
   ENTRY (TYPE_CODE_CHAR),
   ENTRY (TYPE_CODE_BOOL),
   ENTRY (TYPE_CODE_COMPLEX),
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index c0199ea..aacf628 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -238,7 +238,7 @@ valpy_referenced_value (PyObject *self, PyObject *args)
 /* Return a value which is a reference to the value.  */
 
 static PyObject *
-valpy_reference_value (PyObject *self, PyObject *args)
+valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode)
 {
   PyObject *result = NULL;
 
@@ -248,7 +248,7 @@ valpy_reference_value (PyObject *self, PyObject *args)
       scoped_value_mark free_values;
 
       self_val = ((value_object *) self)->value;
-      result = value_to_value_object (value_ref (self_val, TYPE_CODE_REF));
+      result = value_to_value_object (value_ref (self_val, refcode));
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -259,6 +259,18 @@ valpy_reference_value (PyObject *self, PyObject *args)
   return result;
 }
 
+static PyObject *
+valpy_lvalue_reference_value (PyObject *self, PyObject *args)
+{
+  return valpy_reference_value (self, args, TYPE_CODE_REF);
+}
+
+static PyObject *
+valpy_rvalue_reference_value (PyObject *self, PyObject *args)
+{
+  return valpy_reference_value (self, args, TYPE_CODE_RVALUE_REF);
+}
+
 /* Return a "const" qualified version of the value.  */
 
 static PyObject *
@@ -585,8 +597,7 @@ value_has_field (struct value *v, PyObject *field)
     {
       val_type = value_type (v);
       val_type = check_typedef (val_type);
-      if (TYPE_CODE (val_type) == TYPE_CODE_REF
-	  || TYPE_CODE (val_type) == TYPE_CODE_PTR)
+      if (TYPE_IS_REFERENCE (val_type) || TYPE_CODE (val_type) == TYPE_CODE_PTR)
       val_type = check_typedef (TYPE_TARGET_TYPE (val_type));
 
       type_code = TYPE_CODE (val_type);
@@ -743,6 +754,9 @@ valpy_getitem (PyObject *self, PyObject *key)
 	  else if (TYPE_CODE (val_type) == TYPE_CODE_REF)
 	    res_val = value_cast (lookup_lvalue_reference_type (base_class_type),
 	                          tmp);
+	  else if (TYPE_CODE (val_type) == TYPE_CODE_RVALUE_REF)
+	    res_val = value_cast (lookup_rvalue_reference_type (base_class_type),
+	                          tmp);
 	  else
 	    res_val = value_cast (base_class_type, tmp);
 	}
@@ -1724,8 +1738,10 @@ reinterpret_cast operator."
   { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
   { "referenced_value", valpy_referenced_value, METH_NOARGS,
     "Return the value referenced by a TYPE_CODE_REF or TYPE_CODE_PTR value." },
-  { "reference_value", valpy_reference_value, METH_NOARGS,
+  { "reference_value", valpy_lvalue_reference_value, METH_NOARGS,
     "Return a value of type TYPE_CODE_REF referencing this value." },
+  { "rvalue_reference_value", valpy_rvalue_reference_value, METH_NOARGS,
+    "Return a value of type TYPE_CODE_RVALUE_REF referencing this value." },
   { "const_value", valpy_const_value, METH_NOARGS,
     "Return a 'const' qualied version of the same value." },
   { "lazy_string", (PyCFunction) valpy_lazy_string,
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index d01488f..e061da2 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -464,9 +464,10 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
       if (!types_equal (obj_type, this_ptr))
 	obj = value_cast (this_ptr, obj);
     }
-  else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
+  else if (TYPE_IS_REFERENCE (obj_type))
     {
-      struct type *this_ref = lookup_lvalue_reference_type (this_type);
+      struct type *this_ref
+        = lookup_reference_type (this_type, TYPE_CODE (obj_type));
 
       if (!types_equal (obj_type, this_ref))
 	obj = value_cast (this_ref, obj);

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/)
  2017-03-17 17:06     ` Keith Seitz
@ 2017-03-17 18:51       ` Eli Zaretskii
  0 siblings, 0 replies; 25+ messages in thread
From: Eli Zaretskii @ 2017-03-17 18:51 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches

> From: Keith Seitz <keiths@redhat.com>
> Cc: gdb-patches@sourceware.org
> Date: Fri, 17 Mar 2017 10:06:40 -0700
> 
> Likewise, pinging this updated patch for 8.0.

OK.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-17 17:06     ` Keith Seitz
@ 2017-03-17 18:51       ` Eli Zaretskii
  0 siblings, 0 replies; 25+ messages in thread
From: Eli Zaretskii @ 2017-03-17 18:51 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches

> From: Keith Seitz <keiths@redhat.com>
> Cc: gdb-patches@sourceware.org
> Date: Fri, 17 Mar 2017 10:06:34 -0700
> 
> Pedro asked me to resend/ping this since we'd like to have this for 8.0, and my last response had the patch oddly quoted. I apologize for that.

This is OK.

Thanks.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v6 11/11] Add rvalue reference tests and NEWS entry
  2017-03-10 20:05 ` [PATCH v6 11/11] Add rvalue reference tests and NEWS entry Keith Seitz
  2017-03-10 22:02   ` Eli Zaretskii
  2017-03-13 18:52   ` Pedro Alves
@ 2017-04-04 11:10   ` Yao Qi
  2 siblings, 0 replies; 25+ messages in thread
From: Yao Qi @ 2017-04-04 11:10 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches

Keith Seitz <keiths@redhat.com> writes:

Hi Keith,
> +# Test lvalue vs rvalue function overloads
> +setup_kfail "c++/15372" "*-*-*"
> +gdb_test "print f (i)" "= 1" "lvalue reference overload"
> +

I got KPASS and FAIL in this test.  On x86_64-linux (g++ 5.4.0)

print f (i)^M
$3 = 1^M
(gdb) KPASS: gdb.cp/rvalue-ref-overload.exp: lvalue reference overload
(PRMS c++/15372)

> +gdb_test "print f (ci)" "= 2" "lvalue reference to const overload"
> +

print f (ci)^M
Attempt to take address of value not located in memory.^M
(gdb) FAIL: gdb.cp/rvalue-ref-overload.exp: lvalue reference to const overload

> +setup_kfail "c++/15372" "*-*-*"
> +gdb_test "print f (3)" "= 3" "rvalue reference overload"

They also exist in the test result on aarch64-linux and s390x-linux,
https://gdb-build.sergiodj.net/builders/RHEL-s390x-m64/builds/3700/steps/test%20gdb/logs/stdio
https://gdb-build.sergiodj.net/builders/Ubuntu-AArch64-m64/builds/1666/steps/test%20gdb/logs/stdio

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2017-04-04 11:10 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-10 20:04 [PATCH v6 00/11] c++/14441: Rvalue reference support Keith Seitz
2017-03-10 20:04 ` [PATCH v6 01/11] Add definitions for rvalue reference types Keith Seitz
2017-03-10 20:05 ` [PATCH v6 02/11] Change {lookup,make}_reference_type API Keith Seitz
2017-03-10 20:05 ` [PATCH v6 03/11] Add ability to return rvalue reference values from value_ref Keith Seitz
2017-03-10 20:05 ` [PATCH v6 11/11] Add rvalue reference tests and NEWS entry Keith Seitz
2017-03-10 22:02   ` Eli Zaretskii
2017-03-14 18:14     ` Keith Seitz
2017-03-17 17:06     ` Keith Seitz
2017-03-17 18:51       ` Eli Zaretskii
2017-03-13 18:52   ` Pedro Alves
2017-03-14 18:15     ` Keith Seitz
2017-03-14 18:39       ` Pedro Alves
2017-04-04 11:10   ` Yao Qi
2017-03-10 20:10 ` [PATCH v6 07/11] Support DW_TAG_rvalue_reference type Keith Seitz
2017-03-10 20:10 ` [PATCH v6 06/11] Implement printing of rvalue reference types and values Keith Seitz
2017-03-10 20:10 ` [PATCH v6 04/11] Support rvalue reference type in parser Keith Seitz
2017-03-10 20:10 ` [PATCH v6 08/11] Support rvalue references in the gdb python module (includes doc/) Keith Seitz
2017-03-10 22:04   ` Eli Zaretskii
2017-03-14 18:14     ` Keith Seitz
2017-03-17 17:06     ` Keith Seitz
2017-03-17 18:51       ` Eli Zaretskii
2017-03-10 20:10 ` [PATCH v6 05/11] Implement demangling for rvalue reference type names Keith Seitz
2017-03-10 20:12 ` [PATCH v6 09/11] Convert lvalue reference type check to general reference type check Keith Seitz
2017-03-10 20:14 ` [PATCH v6 10/11] Add rvalue references to overloading resolution Keith Seitz
2017-03-13 18:51 ` [PATCH v6 00/11] c++/14441: Rvalue reference support Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).