[rfc][07/37] Eliminate builtin_type_ macros: Use expression arch for size_t type

uweigand
2008-08-31T17:52:17Z

[-- Attachment #1: diff-type-sizeof --]
[-- Type: text/plain, Size: 2187 bytes --]

Hello,

evaluate_subexp_for_sizeof simply uses "builtin_type_int" as the type
of its result. This should really be a platform-specific "size_t" type.
The following patch at least uses the proper gdbarch; at some later
point we can add a "size_t" as gdbarch property.

Bye,
Ulrich

ChangeLog:

* eval.c (evaluate_subexp_for_sizeof): Use builtin_int type of
the expression architecture instead of builtin_type_int as the
sizeof return type.

Index: gdb-head/gdb/eval.c
===================================================================
--- gdb-head.orig/gdb/eval.c
+++ gdb-head/gdb/eval.c
@@ -2335,6 +2335,8 @@ evaluate_subexp_with_coercion (struct ex
static struct value *
evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
{
+ /* FIXME: This should size_t. */
+ struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
enum exp_opcode op;
int pc;
struct type *type;
@@ -2358,24 +2360,22 @@ evaluate_subexp_for_sizeof (struct expre
&& TYPE_CODE (type) != TYPE_CODE_ARRAY)
error (_("Attempt to take contents of a non-pointer value."));
type = check_typedef (TYPE_TARGET_TYPE (type));
- return value_from_longest (builtin_type_int, (LONGEST)
- TYPE_LENGTH (type));
+ return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));

case UNOP_MEMVAL:
(*pos) += 3;
type = check_typedef (exp->elts[pc + 1].type);
- return value_from_longest (builtin_type_int,
- (LONGEST) TYPE_LENGTH (type));
+ return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));

case OP_VAR_VALUE:
(*pos) += 4;
type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
return
- value_from_longest (builtin_type_int, (LONGEST) TYPE_LENGTH (type));
+ value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));

default:
val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
- return value_from_longest (builtin_type_int,
+ return value_from_longest (size_type,
(LONGEST) TYPE_LENGTH (value_type (val)));
}
}