Hello,

I would like to submit a patch that fixes the crash in clang at code
generation phase. This problem appears when a store into .hi or .odd of a
vector of odd size is performed that cause an assertion to happen due to out
of bound element access in SmallVector.

The patch file contains the fix and a test program that cause the crash.

Please review them and let me know if ok to check it in.

Thanks,
Anastasia

diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 221d132..2814e91 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1553,6 +1553,12 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
       for (unsigned i = 0; i != NumDstElts; ++i)
         Mask.push_back(Builder.getInt32(i));
 
+      // When the vector size is odd and .odd or .hi is used, the last element
+      // of the Elts constant will be one past the size of the vector. 
+      // Ignore the last element here, if it is outside of mask size.
+      if (getAccessedFieldNo(NumSrcElts-1, Elts) == Mask.size())
+        NumSrcElts--;
+
       // modify when what gets shuffled in
       for (unsigned i = 0; i != NumSrcElts; ++i)
         Mask[getAccessedFieldNo(i, Elts)] = Builder.getInt32(i+NumDstElts);
diff --git a/test/SemaOpenCL/vector_odd.cl b/test/SemaOpenCL/vector_odd.cl
new file mode 100644
index 0000000..2d33628
--- /dev/null
+++ b/test/SemaOpenCL/vector_odd.cl
@@ -0,0 +1,14 @@
+// RUN: %clang -c %s 
+// expected-no-diagnostics
+
+typedef unsigned char __attribute__((ext_vector_type(3))) uchar3;
+
+kernel void test_odd_vector1 (uchar3 lhs_lvalue)
+{
+	lhs_lvalue.odd = 1;
+}
+
+kernel void test_odd_vector2 (uchar3 lhs_lvalue)
+{
+	lhs_lvalue.hi = 2;
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to