[cfe-dev] r46343 - Are vector compound literals constant?
Nate Begeman
nbegeman at apple.com
Fri Jan 25 11:56:00 PST 2008
On Jan 25, 2008, at 11:29 AM, Eli Friedman wrote:
> This commit needs more discission; the changes to
> GenerateAggregateInit are basically correct, but I'm not sure about
> the changes to GenerateConstantExpr and isConstantExpr.
Neither am I, but it resulted in the behavior i was looking. I'm fine
with eventually putting this under the control of something like
LaxVectorConversions.
> I think the semantics that were implemented are something like "If a
> vector compound literal lvalue is converted to the value stored in the
> compound literal (ref C99 section 6.3.2.1), and all the values
> contained in the compound literal are constant expressions, the
> compound literal is a constant expression."
>
> This would mean, that, for example,
> float4 foo = *&(float4){ 1.0, 2.0, 3.0, 4.0 };
> is an error,
> float4 bar = (const float4){ 1.0, 2.0, 3.0, 4.0 };
> is legal,
> and
> float4 bar = (const float4){ 1.0, 2.0, 3.0, 4.0 } + (const float4){
> 1.0, 2.0, 3.0, 4.0 };
> is also legal. This is consistent with the implementation. Note that
> this significantly different from what gcc implements; it considers
> the first legal and the second two illegal.
That is basically what I was shooting for. Personally, I don't really
know what gcc implements with regard to vectors, but I suppose someone
will want to be compatible with it :)
> That said, the change wasn't implemented completely correctly; clang
> now lets through the following, for example:
> int a(float s) {
> static float4 bar = (float4){s,s,s,s};
> }
Patches welcome!
Nate
More information about the cfe-dev
mailing list