The size of char

To figure out the size of data varaibles for my backend, I tries this code
stolen from X86 backend:

    const TargetData& TD = m_tm.getTargetData();
    unsigned size = TD.getTypeSize(initializer->getType());

However, the getTypeInfo function in TargetData.cpp contains this:

   case Type::VoidTyID:
   case Type::BoolTyID:
   case Type::UByteTyID:
   case Type::SByteTyID: Size = 1; Alignment = TD->getByteAlignment();
         return;

The problem is that my target can't address bytes -- the memory interface
itself specifies word addresses. For that reason, I'd like to allocate 4-byte
(word) blocks even for bools/chars/ubytes and so on. That's exactly what the
standard compiler does, btw.

So, what am I to do, except for copy-pasting the function and adjusting sizes?

- Volodya

The code in TargetData is correct. A byte in LLVM is always 8 bits, a
short is always 16 bits, etc. The only first-class type that changes size
are pointers. If C chars are supposed to compile to 32-bit on your
platform, the LLVM code for a C char would be using int's, not chars. To
support shorts or bytes, you will probably have to emit shift and masking
operations to do it (assuming that your have a byte-granularity address
space).

If you are compiling a C program on your target that uses a char and you
are getting an LLVM sbyte, then it's a bug in the C front-end that you are
using.

-Chris