Hi Bill, Could you pull this into the 3.4 release?
Tom Stellard also wants it: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20131118/093809.h tml Thanks, Joey -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Joey Gouly Sent: 21 November 2013 17:09 To: [email protected] Subject: r195367 - Fix a crash in EmitStoreThroughExtVectorComponentLValue for vectors of odd sizes. Author: joey Date: Thu Nov 21 11:09:05 2013 New Revision: 195367 URL: http://llvm.org/viewvc/llvm-project?rev=195367&view=rev Log: Fix a crash in EmitStoreThroughExtVectorComponentLValue for vectors of odd sizes. In OpenCL a vector of 3 elements, acts like a vector of four elements. So for a vector of size 3 the '.hi' and '.odd' accessors, would access the elements {2, 3} and {1, 3} respectively. However, in EmitStoreThroughExtVectorComponentLValue we are still operating on a vector of size 3, so we should only access {2} and {1}. We do this by checking the last element to be accessed, and ignore it if it is out-of-bounds. EmitLoadOfExtVectorElementLValue doesn't have a similar problem, because it does a direct shufflevector with undef, so an out-of-bounds access just gives an undef value. Patch by Anastasia Stulova! Added: cfe/trunk/test/CodeGenOpenCL/vector_odd.cl Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=195 367&r1=195366&r2=195367&view=diff ============================================================================ == --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Nov 21 11:09:05 2013 @@ -1553,6 +1553,12 @@ void CodeGenFunction::EmitStoreThroughEx 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 array will be one past the size of the vector. + // Ignore the last element here, if it is greater than the 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); Added: cfe/trunk/test/CodeGenOpenCL/vector_odd.cl URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/vector_odd. cl?rev=195367&view=auto ============================================================================ == --- cfe/trunk/test/CodeGenOpenCL/vector_odd.cl (added) +++ cfe/trunk/test/CodeGenOpenCL/vector_odd.cl Thu Nov 21 11:09:05 2013 @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 %s -O0 -emit-llvm -o - | FileCheck %s + +typedef unsigned char __attribute__((ext_vector_type(3))) uchar3; + +//CHECK: {{%.*}} = shufflevector <3 x i8> {{%.*}}, <3 x i8> <i8 1, i8 1, i8 undef>, <3 x i32> <i32 0, i32 3, i32 2> + +kernel void test_odd_vector1 (uchar3 lhs) +{ + lhs.odd = 1; +} + +//CHECK: {{%.*}} = shufflevector <3 x i8> {{%.*}}, <3 x i8> <i8 2, i8 2, i8 undef>, <3 x i32> <i32 0, i32 1, i32 3> + +kernel void test_odd_vector2 (uchar3 lhs) +{ + lhs.hi = 2; +} _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
