[LLVMdev] [CLang] Comparing vector types - invalid error and proposed fix

Martin O'Riordan Martin.ORiordan at movidius.com
Wed Oct 2 06:25:31 PDT 2013


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.





More information about the llvm-dev mailing list