[cfe-commits] [REVIEW] - Altivec vector literal casting problem - need feedback - AST/Sema

John Thompson john.thompson.jtsoftware at gmail.com
Fri Jun 25 18:15:07 PDT 2010

Actually, I'm not trying to build a vector from a subvector, I'm trying to
cast a vector literal from one vector type to another.  But that's a good
point that I didn't think of, checking the type of the parenthesized
expression to see if it's a vector type.  I'll look into that next week.

Also, regarding my problem with altivec.h, I was just going to ask the
following question:

Though the ALTIVECPIM.pdf doc says: "A vector literal is written as a
parenthesized vector type followed by a parenthesized set of constant
expressions."  I.e. (vector unsigned int)(1, 2, 3, 4)
However, should a non-constant expression like this be supported?:

int a = 1;
(vector unsigned int)(1 + a, 2 + a, 3 + a, 4 + a)

My PS3 gcc doesn't like it, but do any other compilers support this?  Or
more importantly, should Clang/LLVM support it?

On Fri, Jun 25, 2010 at 5:21 PM, John McCall <rjmccall at apple.com> wrote:

>   On Jun 25, 2010, at 4:48 PM, John Thompson wrote:
> I have the first pass at a fix for bug 6895, which I also reported.
> However, because of possible problems in altivec.h that are being looked
> into, it's not quite ready for prime time.  However, I'm hoping for some
> preliminary feedback to see if I'm on the right track.
> First, some background on the problem.
> Basically, the following produced an "cannot initialize a vector element of
> type '(type)'" error:
> vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
> This was because the outer paren expression was trying to make a vector
> literal out of the inner, instead of making it a cast.  (See the original
> AltiVec standard at
> http://www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf,
> section 2.5.2, where it actually discusses this case.)
> After straining my brain to figure out where the fix should go (I think it
> should be ActOnCastOfParenListExpr), this patch is what I came up with.
> Because I needed some way to determine if the initializers were arithmetic
> constants or not, I added a function to Expr, isArithmeticConstantExpr,
> which calls a static function of the same name, which I hacked up from a
> copy of the CheckICE function used by the isIntegerConstantExpression
> function.  (Is this plagerism?).  I'm not sure if it's exactly right,
> complete, or is overkill, but it seems to work for the few cases I've
> tried.  Is it reasonable to put it in Expr, or should it just be a static
> function in the one file I use it in?
> Is there a reason why the fix can't be "the operand is of vector type and
> therefore this is a vector cast and not a vector literal"?  I thought
> building vectors from subvectors was an OpenCL-ism not supported in AltiVec.
> John.

John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100625/e2a5b068/attachment.html>

More information about the cfe-commits mailing list