[PING^2] Fix dynamic_cast operator

Message ID CAGyQ6gx3cwryWYumhSTs3GfXQqbQvSFt6QEas1aZVanXs2QXhg@mail.gmail.com
State Not applicable
Headers

Commit Message

Siva Chandra Reddy April 28, 2014, 2:13 p.m. UTC
  Original post: https://sourceware.org/ml/gdb-patches/2014-04/msg00089.html

ChangeLog:
2014-04-28  Siva Chandra Reddy  <sivachandra@google.com>

         * valops.c (value_dynamic_cast): Fix mixup between rtti_type
         and resolved_type.

         testsuite/
         * gdb.cp/casts.exp: Adjust expected result for few tests.
  

Comments

Doug Evans April 29, 2014, 8:16 p.m. UTC | #1
On Mon, Apr 28, 2014 at 7:13 AM, Siva Chandra <sivachandra@google.com> wrote:
> Original post: https://sourceware.org/ml/gdb-patches/2014-04/msg00089.html
>
> ChangeLog:
> 2014-04-28  Siva Chandra Reddy  <sivachandra@google.com>
>
>          * valops.c (value_dynamic_cast): Fix mixup between rtti_type
>          and resolved_type.
>
>          testsuite/
>          * gdb.cp/casts.exp: Adjust expected result for few tests.

Hi.
fyi, I've been deferring commenting on this patch as I think the
original author of dynamic_cast support can do a better job.  Tom can
get to it whenever he's able.  Just letting you know I haven't set
aside time to.
  
Siva Chandra Reddy Sept. 23, 2014, 2:47 p.m. UTC | #2
On Mon, Apr 28, 2014 at 7:13 AM, Siva Chandra <sivachandra@google.com> wrote:
> Original post: https://sourceware.org/ml/gdb-patches/2014-04/msg00089.html
>
> ChangeLog:
> 2014-04-28  Siva Chandra Reddy  <sivachandra@google.com>
>
>          * valops.c (value_dynamic_cast): Fix mixup between rtti_type
>          and resolved_type.
>
>          testsuite/
>          * gdb.cp/casts.exp: Adjust expected result for few tests.

Ping.

I have seen some patches around dynamic values recently and hence
trying to bubble this up.
  

Patch

diff --git a/gdb/testsuite/gdb.cp/casts.exp b/gdb/testsuite/gdb.cp/casts.exp
index 9122450..dd848db 100644
--- a/gdb/testsuite/gdb.cp/casts.exp
+++ b/gdb/testsuite/gdb.cp/casts.exp
@@ -151,8 +151,7 @@  gdb_test "print dynamic_cast<Alpha &> (derived)" \
     "dynamic_cast simple upcast to reference"
 
 gdb_test "print dynamic_cast<Derived *> (ad)" \
-    " = \\(Derived \\*\\) ${nonzero_hex}( <vtable for Derived.*>)?" \
-    "dynamic_cast simple downcast"
+    " = \\(Derived \\*\\) ${nonzero_hex}" "dynamic_cast simple downcast"
 
 gdb_test "print dynamic_cast<VirtuallyDerived *> (add)" \
     " = \\(VirtuallyDerived \\*\\) $nonzero_hex" \
@@ -167,8 +166,7 @@  gdb_test "print dynamic_cast<VirtuallyDerived &> (*ad)" \
     "dynamic_cast to reference to non-existing base"
 
 gdb_test "print dynamic_cast<DoublyDerived *> (add)" \
-    " = \\(DoublyDerived \\*\\) ${nonzero_hex}( <vtable for DoublyDerived.*>)?" \
-    "dynamic_cast unique downcast"
+    " = \\(DoublyDerived \\*\\) ${nonzero_hex}" "dynamic_cast unique downcast"
 
 gdb_test "print dynamic_cast<Gamma *> (add)" \
     " = \\(Gamma \\*\\) $nonzero_hex" \
diff --git a/gdb/valops.c b/gdb/valops.c
index 7f2d5f0..b68c4e1 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -801,14 +801,14 @@  value_dynamic_cast (struct type *type, struct value *arg)
       && TYPE_CODE (TYPE_TARGET_TYPE (resolved_type)) == TYPE_CODE_VOID)
     return value_at_lazy (type, addr);
 
-  tem = value_at (type, addr);
-  type = value_type (tem);
+  tem = value_at (rtti_type, addr);
 
   /* The first dynamic check specified in 5.2.7.  */
   if (is_public_ancestor (arg_type, TYPE_TARGET_TYPE (resolved_type)))
     {
       if (class_types_same_p (rtti_type, TYPE_TARGET_TYPE (resolved_type)))
-	return tem;
+	return value_from_pointer (type, addr);
+
       result = NULL;
       if (dynamic_cast_check_1 (TYPE_TARGET_TYPE (resolved_type),
 				value_contents_for_printing (tem),