[cfe-dev] [PATCH] [OpenCL] Conversions for ternary operations between scalar and vector
Sahasrabuddhe, Sameer
sameer.sahasrabuddhe at amd.com
Thu Dec 4 23:22:55 PST 2014
On 12/4/2014 9:38 PM, Colin Riddell wrote:
> Working with the OpenCL 1.2 CTS I discovered one of the tests fails
> with the tip revision of clang. Firstly, I wonder if anyone else
> working with OpenCL has came across an assertion like this:
>
> Type.cpp:841: clang::Type::ScalarTypeKind
> clang::Type::getScalarTypeKind() const: Assertion `isScalarType()'
> failed.
>
> As far as I can tell, non scalar values are trying to be implicitly
> casted where vector types should be allowed to be arithmetically
> converted to the element type used by the vector operand as well.
I can see the crash too. The problem is that the call to
checkConditionalConvertScalarsToVectors() has already implicitly casted
LHS and RHS to the same vector type as CondTy, but the subsequent code
still assumes scalar types. But I am confused about this conversion. The
OpenCL 1.2 spec says on page 220 that "The second and third expressions
can be any type, as long their types match, or there is a conversion ...
<snip>". It further says that the type of the entire expression is
derived from the second and third expression, and nowhere does it
mention the type of the first expression. Then what is the type of the
following expression?
float2 = char2 ? float2 : float2
I actually get an error for this: "error: initializing 'float2' (vector
of 2 'float' values) with an expression of incompatible type 'char2'
(vector of 2 'char' values)". It seems Clang decided that the ternary
expression has type char2. But from my understanding of the spec, the
type should be float2.
How about the following? Are they valid, and what is their return type?
char2 ? int : float
char2 ? int : unsigned
float2 ? char : unsigned
Sameer.
More information about the cfe-dev
mailing list