[cfe-dev] Question about conditional operator with vector type
Eli Friedman
eli.friedman at gmail.com
Thu Aug 29 14:37:51 PDT 2013
On Thu, Aug 29, 2013 at 10:13 AM, JinGu Kang <jingu at codeplay.com> wrote:
> Hi all,
>
> My colleague 'Alistair' tested a simple code and found a error. The
> simplified code and error message are as following:
>
> Source code:
> typedef char char16 __attribute__((ext_vector_**type(16)));
>
> int main(void) {
> char16 valA;
> char valB;
> char valC;
> char16 destVal = valC ? valA : valB;
> }
>
> Error message:
> error: can't convert between vector values of different size ('char16' and
> 'int')
> char16 destVal = valC ? valA : valB;
> ^ ~~~~ ~~~~
>
> This error message comes from "CheckVectorOperands()" function in
> "CheckConditionalOperands()" function because "UsualArithmeticConversions(
> **LHS, RHS)" function is executed before "CheckVectorOperands()" function
> and "UsualArithmeticConversions(**LHS, RHS)" function changes RHS as
> follows:
> GDB output of original RHS:
> DeclRefExpr 0xc4b3050 'char' lvalue Var 0xc4b2f50 'valB' 'char'
>
> GDB output of changed RHS:
> ImplicitCastExpr 0xc4b30a8 'int' <IntegralCast>
> `-ImplicitCastExpr 0xc4b3098 'char' <LValueToRValue>
> `-DeclRefExpr 0xc4b3050 'char' lvalue Var 0xc4b2f50 'valB' 'char'
>
> So, the error message is generated between 'char16' and 'int'. I am
> wondering whether this error is correct or not. I have checked other
> checking functions executes "CheckVectorOperands()" function before
> "UsualArithmeticConversions(**LHS, RHS)" function such as
> "CheckSubtractionOperands()", "CheckAdditionOperands()" functions and
> etc... Could someone let me know about this error? I have attached a simple
> patch to fix it on the assumption that it is not correct.
>
>
The patch is in the right direction; the call to UsualArithmeticConversions
should come after the call to CheckVectorOperands.
Shouldn't the UsualArithmeticConversions call come after the
checkConditionalConvertScalarsToVectors check? Not completely sure here
(the rules aren't really clear, and clang's implementation of the check in
question isn't consistent with any interpretation of the OpenCL standard).
If you're going to go the route of updating CondTy, LHSTy, and RHSTy
whenever the expressions change, please make sure they stay consistently
up-to-date throughout the function.
-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130829/98db6743/attachment.html>
More information about the cfe-dev
mailing list