From 3bdf2bbd3e87625fb26815d48e36fc7fb3656aca Mon Sep 17 00:00:00 2001
From: Ken Werner <ken.werner@de.ibm.com>
Date: Fri, 8 Oct 2010 16:50:55 +0000
Subject: 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.

---
 gdb/valops.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

(limited to 'gdb/valops.c')

diff --git a/gdb/valops.c b/gdb/valops.c
index 13c83ffc474..fe4576ec8ae 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -421,7 +421,8 @@ value_cast (struct type *type, struct value *arg2)
     }
 
   if (current_language->c_style_arrays
-      && TYPE_CODE (type2) == TYPE_CODE_ARRAY)
+      && TYPE_CODE (type2) == TYPE_CODE_ARRAY
+      && !TYPE_VECTOR (type2))
     arg2 = value_coerce_array (arg2);
 
   if (TYPE_CODE (type2) == TYPE_CODE_FUNC)
@@ -537,6 +538,26 @@ value_cast (struct type *type, struct value *arg2)
 	 minus one, instead of biasing the normal case.  */
       return value_from_longest (type, -1);
     }
+  else if (code1 == TYPE_CODE_ARRAY && TYPE_VECTOR (type) && scalar)
+    {
+      /* Widen the scalar to a vector.  */
+      struct type *eltype;
+      struct value *val;
+      int i, n;
+
+      eltype = check_typedef (TYPE_TARGET_TYPE (type));
+      arg2 = value_cast (eltype, arg2);
+      val = allocate_value (type);
+      n = TYPE_LENGTH (type) / TYPE_LENGTH (eltype);
+
+      for (i = 0; i < n; i++)
+	{
+	  /* Duplicate the contents of arg2 into the destination vector.  */
+	  memcpy (value_contents_writeable (val) + (i * TYPE_LENGTH (eltype)),
+		  value_contents_all (arg2), TYPE_LENGTH (eltype));
+	}
+      return val;
+    }
   else if (TYPE_LENGTH (type) == TYPE_LENGTH (type2))
     {
       if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
-- 
cgit v1.2.1