Martin O'Riordan
2013-Oct-02 13:23 UTC
[LLVMdev] [CLang] Comparing vector types - invalid error and proposed fix
I was investigating an error diagnostic in the following test example: typedef signed char char16 __attribute__((ext_vector_type(16))); void test( char16 srcA, char16 srcB, char16 *dst) { *dst = ( srcA == srcB ); } which produces the message: mismatch.c:5:10: error: assigning to 'char16' from incompatible type 'char __attribute__((ext_vector_type(16)))' *dst = ( srcA == srcB ); ^ ~~~~~~~~~~~~~~~~ 1 error generated. There appear to be two things going on here. The first is the notion of compatible types which are not supported by GCC/CLang for vector extensions, even in the trivial case where 'signed char' == 'char' (in C). The second thing is that the result of a comparison between two vectors is supposed to result in the a 'signed' integer vector result. 'char' is always troublesome, though in C++ it is a discrete type. I made the following change in my copy (clang-3.3) that I think is a correct and valid change: File: tools/clang/lib/Sema/SemaChecking.cpp Function: Sema::GetSignedVectorType() Replace the fragment: if (TypeSize == Context.getTypeSize(Context.CharTy)) return Context.getExtVectorType(Context.CharTy, VTy->getNumElements()); ^^^^^^ with: if (TypeSize == Context.getTypeSize(Context.CharTy)) return Context.getExtVectorType(Context.SignedCharTy, VTy->getNumElements()); ^^^^^^^^^^^^ I would like to propose this as a fix for a future release of CLang. Thanks, Martin O'Riordan - Movidius Ltd.
Reasonably Related Threads
- [LLVMdev] [CLang] Comparing vector types - invalid error and proposed fix
- [LLVMdev] [CLang] Comparing vector types - invalid error and proposed fix
- Unsigned int displaying as negative
- Is there a way to correlate operation to machine instruction?
- Unsigned int displaying as negative