[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.

Hi Martin,

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 right place to discuss clang issues is cfe-dev@cs.uiuc.edu.

Having said that, in C/C++, char, signed char, and unsigned char are three distinct types, so I don’t think your proposed fix below is correct.

Thanks Mark, hadn't spotted the CLang distribution list.

  MartinO