public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: tromey@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  tromey/operator-new-delete: more constructor handling in overloading
Date: Tue, 21 May 2013 20:53:00 -0000	[thread overview]
Message-ID: <20130521205323.25967.qmail@sourceware.org> (raw)

The branch, tromey/operator-new-delete has been updated
       via  1dccec2e16dd71b398326fba7e01ad4672f5f766 (commit)
       via  031161b2515c175349a1e928017d412d6e27bf3a (commit)
       via  0d0ea1921e5482d54a2ab68c87cb757cff738645 (commit)
      from  822f1dafa18a9471407ff6faa3da8bdbb0b101c5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 1dccec2e16dd71b398326fba7e01ad4672f5f766
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue May 21 14:52:30 2013 -0600

    more constructor handling in overloading
    
    this changes the overloading code to know not to recurse into
    subclasses when searching for a constructor.  we already did this, but
    were missing a spot

commit 031161b2515c175349a1e928017d412d6e27bf3a
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue May 21 14:51:34 2013 -0600

    interoperability fixes
    
    this tests the case where an object is allocated by gdb
    but then deleted by the c++ runtime
    
    This still fails because we aren't invoking constructors
    properly.

commit 0d0ea1921e5482d54a2ab68c87cb757cff738645
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue May 21 13:56:08 2013 -0600

    more updates to the notes

-----------------------------------------------------------------------

Summary of changes:
 README.archer                |   11 +++++++-
 gdb/testsuite/gdb.cp/new.cc  |   59 +++++++++++++++++++++++++++++++++--------
 gdb/testsuite/gdb.cp/new.exp |   34 +++++++++++++++++++++++-
 gdb/valops.c                 |   17 ++++++++----
 4 files changed, 101 insertions(+), 20 deletions(-)

First 500 lines of diff:
diff --git a/README.archer b/README.archer
index 383a852..e5ca05c 100644
--- a/README.archer
+++ b/README.archer
@@ -3,6 +3,7 @@ This branch adds support for "new" and "delete"; PR c++/10050.
 It is incomplete:
 
 * it doesn't ensure it is calling the in-charge constructor
+
 * it doesn't ensure it is calling the complete object destructor
   (These required a GCC fix, see the PR.)
        look for 'D0Ev' at the end
@@ -31,4 +32,12 @@ It is incomplete:
 
 * operator delete with extra args
 
-* need tests for 'new' in gdb but delete from C++
+* constructors can have in_charge and VTT artificial arguments
+  we need to supply these before overload resolution, so it
+  will do the right thing
+  however, the type of at least the VTT argument seems weird in DWARF
+  I saw a plain:
+
+   <1><24d>: Abbrev Number: 16 (DW_TAG_const_type)
+
+  ... with no children, using the F18 g++
diff --git a/gdb/testsuite/gdb.cp/new.cc b/gdb/testsuite/gdb.cp/new.cc
index 99fa5f5..2688d72 100644
--- a/gdb/testsuite/gdb.cp/new.cc
+++ b/gdb/testsuite/gdb.cp/new.cc
@@ -11,12 +11,12 @@ enum what_operator
     WHATOP_GLOBAL = 2,
     WHATOP_HASOPS = 4,
     WHATOP_DERIVED = 8,
-    WHATOP_BASE = 16,
+    WHATOP_BASE = 0x10,
 
-    WHATOP_ARRAY = 32,
-    WHATOP_DELETE = 64,
-    WHATOP_PLACEMENT = 128,
-    WHATOP_ARGS = 256
+    WHATOP_ARRAY = 0x20,
+    WHATOP_DELETE = 0x40,
+    WHATOP_PLACEMENT = 0x80,
+    WHATOP_ARGS = 0x100
   };
 
 int whatop = WHATOP_INVALID;
@@ -131,6 +131,12 @@ struct Base
     free (ptr);
   }
 
+  void operator delete[] (void *ptr)
+  {
+    whatop = WHATOP_BASE | WHATOP_DELETE | WHATOP_ARRAY;
+    free (ptr);
+  }
+
   Base()
   {
   }
@@ -149,6 +155,12 @@ struct DerivedFromBase : public Base
     free (ptr);
   }
 
+  void operator delete[] (void *ptr)
+  {
+    whatop = WHATOP_DERIVED | WHATOP_DELETE | WHATOP_ARRAY;
+    free (ptr);
+  }
+
   ~DerivedFromBase()
   {
     ++dcount;
@@ -179,15 +191,38 @@ struct VDerived2 : public VDerived, public virtual Base
   }
 };
 
+template<typename T>
+void call_delete (T *ptr)
+{
+  delete ptr;
+}
+
+template<typename T>
+void call_deletev (T *ptr)
+{
+  delete[] ptr;
+}
+
+template<typename T>
+void
+keep_stuff_helper ()
+{
+  call_delete (new T);
+  call_deletev (new T[5]);
+}
+
 int keep_stuff ()
 {
-  delete new HasOps;
-  delete[] new HasOps[5];
-  delete (Base *) new DerivedFromBase;
-  delete new Base;
-  delete new VDerived;
-  delete new VDerived2;
-  delete new Simple;
+  keep_stuff_helper<int> ();
+  keep_stuff_helper<HasOps> ();
+  keep_stuff_helper<Base> ();
+  keep_stuff_helper<VDerived> ();
+  keep_stuff_helper<VDerived2> ();
+  keep_stuff_helper<Simple> ();
+  keep_stuff_helper<DerivedFromBase> ();
+
+  call_delete ((Base *) new DerivedFromBase);
+  call_deletev ((Base *) new DerivedFromBase[5]);
 }
 
 int main ()
diff --git a/gdb/testsuite/gdb.cp/new.exp b/gdb/testsuite/gdb.cp/new.exp
index 41125a2..e44970a 100644
--- a/gdb/testsuite/gdb.cp/new.exp
+++ b/gdb/testsuite/gdb.cp/new.exp
@@ -34,6 +34,9 @@ gdb_continue_to_breakpoint Stop
 
 proc check_op {name value {dcount ""}} {
     with_test_prefix $name {
+	# Handy for debugging.
+	gdb_test "print/x whatop" " = 0x.*"
+
 	gdb_test "print whatop == ($value)" " = true" "check settings"
 
 	if {$dcount != ""} {
@@ -154,7 +157,8 @@ check_op "::delete HasOps" {WHATOP_GLOBAL | WHATOP_DELETE}
 gdb_test "print delete\[\] \$hasops_array" " = void"
 check_op "delete HasOps array" {WHATOP_HASOPS | WHATOP_DELETE | WHATOP_ARRAY}
 
-# Interoperability with the real C++ runtime.
+# Interoperability with the real C++ runtime: create an object in the
+# inferior delete it from gdb.
 gdb_test "print delete ip" " = void"
 check_op "delete int from c++" {WHATOP_GLOBAL | WHATOP_DELETE}
 
@@ -172,3 +176,31 @@ check_op "delete Simple array from c++" \
 gdb_test "print delete b" " = void"
 check_op "delete Derived from c++ via base pointer" \
     {WHATOP_BASE | WHATOP_DELETE}
+
+# Interoperability with the real C++ runtime: create an object in gdb
+# inferior delete it in the inferior.
+foreach {type what multiplier} {
+    int WHATOP_GLOBAL 0
+    HasOps WHATOP_HASOPS 0
+    DerivedFromBase WHATOP_DERIVED 2
+    Base WHATOP_BASE 1
+    VDerived WHATOP_BASE 2
+    VDerived2 WHATOP_BASE 3
+} {
+    set what "$what | WHATOP_DELETE"
+
+    set x_dcount [expr "$multiplier * 1"]
+    set x_dcountv [expr "$multiplier * 5"]
+
+    gdb_test "print call_delete<${type}>(new ${type})" " = void"
+    check_op "call_delete for new $type" $what $x_dcount
+
+    gdb_test "print call_deletev<${type}>(new ${type}\[5\])" " = void"
+    check_op "call_deletev for new $type\[5\]" "$what | WHATOP_ARRAY" $x_dcountv
+}
+
+# Type tests with "set print object on"
+
+gdb_test_no_output "set print object on"
+gdb_test "print new VDerived" " = \\(VDerived \\*\\) $hex"
+gdb_test "print new VDerived\[5\]" " = \\(VDerived \\*\\) $hex"
diff --git a/gdb/valops.c b/gdb/valops.c
index 42ea8f2..a32b3c9 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -103,7 +103,7 @@ static struct value *cast_into_complex (struct type *, struct value *);
 
 static struct fn_field *find_method_list (struct value **, const char *,
 					  int, struct type *, int *,
-					  struct type **, int *);
+					  struct type **, int *, int);
 
 void _initialize_valops (void);
 
@@ -2455,7 +2455,7 @@ value_struct_elt (struct value **argp, struct value **args,
 static struct fn_field *
 find_method_list (struct value **argp, const char *method,
 		  int offset, struct type *type, int *num_fns,
-		  struct type **basetype, int *boffset)
+		  struct type **basetype, int *boffset, int is_constructor)
 {
   int i;
   struct fn_field *f;
@@ -2485,6 +2485,9 @@ find_method_list (struct value **argp, const char *method,
 	}
     }
 
+  if (is_constructor)
+    return NULL;
+
   /* Not found in object, check in base subobjects.  */
   for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
     {
@@ -2504,7 +2507,7 @@ find_method_list (struct value **argp, const char *method,
 	}
       f = find_method_list (argp, method, base_offset + offset,
 			    TYPE_BASECLASS (type, i), num_fns, 
-			    basetype, boffset);
+			    basetype, boffset, is_constructor);
       if (f)
 	return f;
     }
@@ -2524,7 +2527,8 @@ find_method_list (struct value **argp, const char *method,
 static struct fn_field *
 value_find_oload_method_list (struct value **argp, const char *method,
 			      int offset, int *num_fns, 
-			      struct type **basetype, int *boffset)
+			      struct type **basetype, int *boffset,
+			      int is_constructor)
 {
   struct type *t;
 
@@ -2546,7 +2550,7 @@ value_find_oload_method_list (struct value **argp, const char *method,
 	     "value that is not a struct or union"));
 
   return find_method_list (argp, method, 0, t, num_fns, 
-			   basetype, boffset);
+			   basetype, boffset, is_constructor);
 }
 
 /* Given an array of arguments (ARGS) (which includes an
@@ -2660,7 +2664,8 @@ find_overload_match (struct value **args, int nargs,
       /* Retrieve the list of methods with the name NAME.  */
       fns_ptr = value_find_oload_method_list (&temp, name, 
 					      0, &num_fns, 
-					      &basetype, &boffset);
+					      &basetype, &boffset,
+					      is_constructor);
       /* If this is a method only search, and no methods were found
          the search has faild.  */
       if (method == METHOD && (!fns_ptr || !num_fns))


hooks/post-receive
--
Repository for Project Archer.


             reply	other threads:[~2013-05-21 20:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-21 20:53 tromey [this message]
2013-08-14 18:41 tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130521205323.25967.qmail@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=archer-commits@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).