summaryrefslogtreecommitdiff
path: root/gdb/valarith.c
diff options
context:
space:
mode:
authorkwerner <kwerner>2010-10-08 16:50:51 +0000
committerkwerner <kwerner>2010-10-08 16:50:51 +0000
commit8be941b9ba9ef001a45aed2349dd0cc619a2024f (patch)
tree95f8a44c557fe4660c7ba380bb6d564ccc305b1b /gdb/valarith.c
parentd01f999fb76e39c651b8cc9ec0e9a54ce204041f (diff)
downloadgdb-8be941b9ba9ef001a45aed2349dd0cc619a2024f.tar.gz
gdb:
* valops.c (value_cast): Handle vector types. * valarith.c (value_binop): Widen scalar to vector if appropriate. gdb/testsuite: * gdb.base/gnu_vector.c (ia, ib, fa, fb): New variables. * gdb.base/gnu_vector.exp: Add tests for scalar to vector widening.
Diffstat (limited to 'gdb/valarith.c')
-rw-r--r--gdb/valarith.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/gdb/valarith.c b/gdb/valarith.c
index d75fdd2b530..554c4ff3a29 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -1435,14 +1435,34 @@ vector_binop (struct value *val1, struct value *val2, enum exp_opcode op)
struct value *
value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
{
+ struct value *val;
struct type *type1 = check_typedef (value_type (arg1));
struct type *type2 = check_typedef (value_type (arg2));
-
- if ((TYPE_CODE (type1) == TYPE_CODE_ARRAY && TYPE_VECTOR (type1))
- || (TYPE_CODE (type2) == TYPE_CODE_ARRAY && TYPE_VECTOR (type2)))
- return vector_binop (arg1, arg2, op);
+ int t1_is_vec = (TYPE_CODE (type1) == TYPE_CODE_ARRAY
+ && TYPE_VECTOR (type1));
+ int t2_is_vec = (TYPE_CODE (type2) == TYPE_CODE_ARRAY
+ && TYPE_VECTOR (type2));
+
+ if (!t1_is_vec && !t2_is_vec)
+ val = scalar_binop (arg1, arg2, op);
+ else if (t1_is_vec && t2_is_vec)
+ val = vector_binop (arg1, arg2, op);
else
- return scalar_binop (arg1, arg2, op);
+ {
+ /* Widen the scalar operand to a vector. */
+ struct value **v = t1_is_vec ? &arg2 : &arg1;
+ struct type *t = t1_is_vec ? type2 : type1;
+
+ if (TYPE_CODE (t) != TYPE_CODE_FLT
+ && TYPE_CODE (t) != TYPE_CODE_DECFLOAT
+ && !is_integral_type (t))
+ error (_("Argument to operation not a number or boolean."));
+
+ *v = value_cast (t1_is_vec ? type1 : type2, *v);
+ val = vector_binop (arg1, arg2, op);
+ }
+
+ return val;
}
/* Simulate the C operator ! -- return 1 if ARG1 contains zero. */