Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Ken Werner <ken@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org, Joel Brobecker <brobecker@adacore.com>
Subject: [patch] fix pre-/post- in-/decrement
Date: Fri, 01 Oct 2010 17:45:00 -0000	[thread overview]
Message-ID: <201010011945.27883.ken@linux.vnet.ibm.com> (raw)
In-Reply-To: <20100930185634.GC6213@adacore.com>

[-- Attachment #1: Type: Text/Plain, Size: 659 bytes --]

On Thursday, September 30, 2010 8:56:34 pm Joel Brobecker wrote:
> Would you mind if we treated this as a separate patch, on top of
> the current patch? I'd also like to add a test that verifies this,
> hopefully not involving vector types.

The attached patch prevents the pre-/post- in-/decrement operators from 
returning  lvalues.  The following gdb command for example should not assign a 
value to the result of the post increment operation but throw an error:
  print i++ = 3;
I've added a few tests to the testsuite. Please let me know if there is a 
better place to put them.
Tested on i686-*-linux-gnu with no regressions. OK to apply?

Thanks
-ken

[-- Attachment #2: pre_post_in_decrement.patch --]
[-- Type: text/x-patch, Size: 3685 bytes --]

ChangeLog:

2010-10-01  Ken Werner  <ken.werner@de.ibm.com>

	* eval.c evaluate_subexp_standard) <UNOP_PREINCREMENT,
	UNOP_PREDECREMENT> Set VALUE_LVAL of the result to not_lval.
	<UNOP_POSTINCREMENT, UNOP_POSTDECREMENT>: Copy arg1 to prevent
	returning a lvalue.

testsuite/ChangeLog:

2010-10-01  Ken Werner  <ken.werner@de.ibm.com>

	* gdb.base/exprs.exp: Add tests for pre-/post- in-/decrement operators.


Index: gdb/eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.139
diff -p -u -r1.139 eval.c
--- gdb/eval.c	11 Aug 2010 16:48:26 -0000	1.139
+++ gdb/eval.c	1 Oct 2010 17:31:16 -0000
@@ -2702,7 +2702,10 @@ evaluate_subexp_standard (struct type *e
 	      arg2 = value_binop (tmp, arg2, BINOP_ADD);
 	    }
 
-	  return value_assign (arg1, arg2);
+	  /* Prevent to return a lvalue.  */
+	  arg3 = value_assign (arg1, arg2);
+	  VALUE_LVAL (arg3) = not_lval;
+	  return arg3;
 	}
 
     case UNOP_PREDECREMENT:
@@ -2726,7 +2729,10 @@ evaluate_subexp_standard (struct type *e
 	      arg2 = value_binop (tmp, arg2, BINOP_SUB);
 	    }
 
-	  return value_assign (arg1, arg2);
+	  /* Prevent to return a lvalue.  */
+	  arg3 = value_assign (arg1, arg2);
+	  VALUE_LVAL (arg3) = not_lval;
+	  return arg3;
 	}
 
     case UNOP_POSTINCREMENT:
@@ -2739,7 +2745,14 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
-	  if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
+	  type = value_type (arg1);
+	  arg3 = allocate_value (type);
+
+	  /* Copy the value to prevent to return a lvalue.  */
+	  memcpy (value_contents_raw (arg3), value_contents (arg1),
+		  TYPE_LENGTH (type));
+
+	  if (ptrmath_type_p (exp->language_defn, type))
 	    arg2 = value_ptradd (arg1, 1);
 	  else
 	    {
@@ -2751,7 +2764,7 @@ evaluate_subexp_standard (struct type *e
 	    }
 
 	  value_assign (arg1, arg2);
-	  return arg1;
+	  return arg3;
 	}
 
     case UNOP_POSTDECREMENT:
@@ -2764,7 +2777,14 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
-	  if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
+	  type = value_type (arg1);
+	  arg3 = allocate_value (type);
+
+	  /* Copy the value to prevent to return a lvalue.  */
+	  memcpy (value_contents_raw (arg3), value_contents (arg1),
+		  TYPE_LENGTH (type));
+
+	  if (ptrmath_type_p (exp->language_defn, type))
 	    arg2 = value_ptradd (arg1, -1);
 	  else
 	    {
@@ -2776,7 +2796,7 @@ evaluate_subexp_standard (struct type *e
 	    }
 
 	  value_assign (arg1, arg2);
-	  return arg1;
+	  return arg3;
 	}
 
     case OP_THIS:
Index: gdb/testsuite/gdb.base/exprs.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/exprs.exp,v
retrieving revision 1.19
diff -p -u -r1.19 exprs.exp
--- gdb/testsuite/gdb.base/exprs.exp	10 Jun 2010 19:48:19 -0000	1.19
+++ gdb/testsuite/gdb.base/exprs.exp	1 Oct 2010 17:31:16 -0000
@@ -253,3 +253,14 @@ gdb_test "set output-radix 8" ".*"
 test_expr "print red" "\\$\[0-9\]* = red"
 test_expr "print/d red" "\\$\[0-9\]* = 0"
 gdb_test "set output-radix 10" ".*"
+
+# Pre-/post in-/decrement tests.
+gdb_test "set variable v_int = 1" ""
+gdb_test "print v_int++" "\\$\[0-9\]* = 1"
+gdb_test "print ++v_int" "\\$\[0-9\]* = 3"
+gdb_test "print v_int--" "\\$\[0-9\]* = 3"
+gdb_test "print --v_int" "\\$\[0-9\]* = 1"
+gdb_test "print v_int++ = 5" "Left operand of assignment is not an lvalue."
+gdb_test "print ++v_int = 5" "Left operand of assignment is not an lvalue."
+gdb_test "print v_int-- = 5" "Left operand of assignment is not an lvalue."
+gdb_test "print --v_int = 5" "Left operand of assignment is not an lvalue."

  parent reply	other threads:[~2010-10-01 17:45 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-17 12:58 [patch] GNU vector unop support Ken Werner
2010-09-28 16:04 ` Ken Werner
     [not found] ` <20100930185634.GC6213@adacore.com>
2010-10-01 17:45   ` Ken Werner [this message]
2010-10-04 13:01     ` [patch] fix pre-/post- in-/decrement Ulrich Weigand
2010-10-04 19:47       ` Ken Werner
2010-10-04 20:45         ` Daniel Jacobowitz
2010-10-04 21:58           ` Ulrich Weigand
2010-10-04 22:59             ` Daniel Jacobowitz
2010-10-04 23:25               ` Ulrich Weigand
2010-10-05  1:17                 ` Daniel Jacobowitz
2010-10-05 13:28                   ` Ulrich Weigand
2010-10-05 13:42                     ` Daniel Jacobowitz
2010-10-06 18:59                       ` [rfc] Fix value_assign return value (Re: [patch] fix pre-/post- in-/decrement) Ulrich Weigand
2010-10-26 13:42                         ` Daniel Jacobowitz
2010-12-01 16:51                           ` Ulrich Weigand
2010-10-06 20:55                       ` [patch] fix pre-/post- in-/decrement Vladimir Prus
2010-10-07 12:38         ` Ken Werner
2010-10-12 23:00           ` Tom Tromey
2010-10-13  8:45             ` Andreas Schwab
2010-10-13  9:23             ` Ken Werner
2010-10-13 16:07               ` Daniel Jacobowitz
2010-10-13 19:01               ` Tom Tromey
2010-10-19  7:38                 ` Ken Werner
2010-11-02  8:23                   ` Ken Werner
2010-11-02 20:31                   ` Tom Tromey
2010-11-03 13:52                     ` Ken Werner
2010-10-04 20:52   ` [patch] GNU vector unop support Ken Werner
2010-10-06 23:27     ` Joel Brobecker
2010-10-07 16:23       ` Ken Werner
2010-11-03 14:07       ` Ken Werner

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=201010011945.27883.ken@linux.vnet.ibm.com \
    --to=ken@linux.vnet.ibm.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@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