This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFC: fix cast to void


This patch fixes a bug I noticed while debugging another problem.

In some cases a cast to void will fail like so:

    (gdb) p (void) v_int_pointer 
    Attempt to dereference a generic pointer.

The problem is that the check for cast-to-void comes after the
lval_memory case.

Fixed as appended.  New test included.
Built & regtested on x86-64 Fedora 16.

Tom

2012-11-28  Tom Tromey  <tromey@redhat.com>

	* valops.c (value_cast): Move TYPE_CODE_VOID case earlier.

2012-11-28  Tom Tromey  <tromey@redhat.com>

	* gdb.base/exprs.exp: Add test for cast to void.

diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp
index c6a07fa..37a4ac6 100644
--- a/gdb/testsuite/gdb.base/exprs.exp
+++ b/gdb/testsuite/gdb.base/exprs.exp
@@ -270,3 +270,6 @@ gdb_test {print v_int_array_init[1]@1} { = \{20\}}
 # gdb's {} extension
 gdb_test_no_output "set variable v_short_array\[0\] = 42"
 gdb_test "print {short} v_short_array" "$decimal = 42"
+
+# Regression test for cast to void.
+gdb_test "print (void) v_int_pointer" " = void"
diff --git a/gdb/valops.c b/gdb/valops.c
index 924b56d..38a9960 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -580,12 +580,12 @@ value_cast (struct type *type, struct value *arg2)
       set_value_pointed_to_offset (arg2, 0);	/* pai: chk_val */
       return arg2;
     }
-  else if (VALUE_LVAL (arg2) == lval_memory)
-    return value_at_lazy (type, value_address (arg2));
   else if (code1 == TYPE_CODE_VOID)
     {
       return value_zero (type, not_lval);
     }
+  else if (VALUE_LVAL (arg2) == lval_memory)
+    return value_at_lazy (type, value_address (arg2));
   else
     {
       error (_("Invalid cast."));


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]