OpenCL C: Widths of the integer scalar data types

Hi,

One of the differences between OpenCL C and ISO C99 is that
OpenCL C defines fixed widths for its integer scalar data
types while in ISO C99 they are platform dependent.

In the practical targets of today, this is a problem only with the
long int data type which, e.g., for x86_32 is 32 bits and for
x86_64 is 64 bits of width.

It seems Clang doesn't yet detect the basic scalar data types of
OpenCL C (compiling code with, e.g., ulong or ushort fails) but
strictly relies on the C data types which assumes the implementation
should resort to typedef/macro trickery to get the correct
width type names imported to the OpenCL C kernels.

I think that the data types of OpenCL C should be recognized in Clang
when it compiles OpenCL C code. As their widths are dictated by
the standard, it should generate the fixed width integer datatypes of
the LLVM IR when it encounters an integer data type, right?

I can implement this but as I'm not very familiar with the Clang
code base, I'd appreciate any pointers on where to start poking.

Hi,

Could this be implemented by poking only the following parts of
Clang?

* ASTContext::InitBuiltinTypes()

In case the current language is OpenCL (LangOpts.OpenCL),
init the integer types as fixed width (and fixed alignment) types.

Might need to define new BuiltinTypes for (U)Int32 etc.

For now it's enough to ensure the 'long' is defined to a 64 bit
type in the target. For starters, it could check if the LongLong of
the target is 64 bits and use that (if Long is not 64 bits).
'long long' of OpenCL is reserved for 128 bit types (6.1.4).

* ASTContext::getTypeInfo.

Detect the fixed-width OCL types here. Return the widths and the
alignment which are dictated by the standard.

After ensuring in Clang that correct fixed width integer types
are used in OpenCL C compilation, one can use typedefs for uint,
ulong, ushort and uchar (like we do currently in pocl). This would
avoid the need to touch the Lex/Parse to support these types.