<div>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.</div>

<div> </div>
<div>First, some background on the problem.</div>
<div> </div>
<div>Basically, the following produced an "cannot initialize a vector element of type '(type)'" error:</div>
<div><font size="2"></font> </div>
<div><font size="2">vector </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">char</font></font><font size="2"> v1 = (vector </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">char</font></font><font size="2">)((vector </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">int</font></font><font size="2">)(1, 2, 3, 4));</font></div>

<div><font size="2"></font> </div>
<div><font size="2">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 <a href="http://www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf">http://www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf</a>, section 2.5.2, where it actually discusses this case.)</font></div>

<div> </div>
<div>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.</div>
<div> </div>
<div>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?</div>

<div> </div>
<div>Here a sample of the AST produced from this:</div>
<div> </div>
<div>vector int v1 = (vector int)(1, 2, 3, 4);<br>vector char v2 = (vector char)((vector int)(1, 2, 3, 4));<br></div>
<div>From: clang -cc1 -triple=powerpc-apple-darwin8 -faltivec -D__ALTIVEC_H -ast-dump vecliteralcast1.c >vecliteralcast1.txt 2>&1</div>
<div> </div>
<div>(The -D__ALTIVEC_H argument disables the altivec.h header implicitly included.)</div>
<div> </div>
<div>The output:</div>
<div> </div>
<div>typedef char *__builtin_va_list;<br>__vector int v1 = (CompoundLiteralExpr 0x2e7b0f8 <vecliteralcast1.c:1:17, col:28> '__vector int'<br>  (InitListExpr 0x2e7b188 <col:17, col:28> '__vector int'<br>
    (IntegerLiteral 0x2e51730 <col:30> 'int' 1)<br>    (IntegerLiteral 0x2e4f068 <col:33> 'int' 2)<br>    (IntegerLiteral 0x2e4f0c0 <col:36> 'int' 3)<br>    (IntegerLiteral 0x2e7aff0 <col:39> 'int' 4)))<br>
;<br>__vector char v2 = (CStyleCastExpr 0x2e7b748 <vecliteralcast1.c:2:18, col:56> '__vector char' <BitCast><br>  (ParenExpr 0x2e7b700 <col:31, col:56> '__vector int'<br>    (CompoundLiteralExpr 0x2e7b580 <col:32, col:43> '__vector int'<br>
      (InitListExpr 0x2e7b610 <col:32, col:43> '__vector int'<br>        (IntegerLiteral 0x2e7b330 <col:45> 'int' 1)<br>        (IntegerLiteral 0x2e7b388 <col:48> 'int' 2)<br>        (IntegerLiteral 0x2e7b3e0 <col:51> 'int' 3)<br>
        (IntegerLiteral 0x2e7b438 <col:54> 'int' 4)))))<br>;<br></div>
<div>Thanks.</div>
<div> </div>
<div>-John<br clear="all"><br>-- <br>John Thompson<br><a href="mailto:John.Thompson.JTSoftware@gmail.com" target="_blank">John.Thompson.JTSoftware@gmail.com</a><br><br></div>