This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [rfc] Use LONGEST instead of value for index arithmetic
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: drow at false dot org (Daniel Jacobowitz)
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 26 Jun 2009 18:50:04 +0200 (CEST)
- Subject: Re: [rfc] Use LONGEST instead of value for index arithmetic
Daniel Jacobowitz wrote:
> On Fri, Jun 26, 2009 at 05:49:07PM +0200, Ulrich Weigand wrote:
> > Hello,
> >
> > this patch implements the change I mentioned recently: use LONGEST instead
> > of struct value to represent array indexes (and similarly the integer
> > operands to pointer arithmetic). This has the advantage that index
> > computations can be performed in host instead of target arithmetic,
> > and not just eliminates a bunch of references to global built-in types,
> > but makes both implementation and users of the value_subscript and
> > pointer arithmetic routines quite a bit simpler.
>
> Looks good to me. I noticed you're removing several error calls; do
> those garbage cases still produce some error message? I guess they
> must be untested :-(
All error messages should be preserved by my changes, but I admit this
isn't quite obvious. For example, in the "pointer + not-integer" case,
the following error used to be emitted by value_ptradd:
- if (!is_integral_type (value_type (arg2)))
- error (_("Argument to arithmetic operation not a number or boolean."));
With the patch applied, due to those eval.c changes:
- else if (ptrmath_type_p (value_type (arg1)))
- return value_ptradd (arg1, arg2);
- else if (ptrmath_type_p (value_type (arg2)))
- return value_ptradd (arg2, arg1);
+ else if (ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ return value_ptradd (arg1, value_as_long (arg2));
+ else if (ptrmath_type_p (value_type (arg2))
+ && is_integral_type (value_type (arg1)))
+ return value_ptradd (arg2, value_as_long (arg1));
else
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
control will fall through to the default value_binop code, and *this*
will now issue the error message:
if ((TYPE_CODE (type1) != TYPE_CODE_FLT
&& TYPE_CODE (type1) != TYPE_CODE_DECFLOAT
&& !is_integral_type (type1))
|| (TYPE_CODE (type2) != TYPE_CODE_FLT
&& TYPE_CODE (type2) != TYPE_CODE_DECFLOAT
&& !is_integral_type (type2)))
error (_("Argument to arithmetic operation not a number or boolean."));
(Note that when I originally introduced value_ptradd I duplicated this
message in the first place.)
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com