[LLVMdev] The size of char

Chris Lattner sabre at nondot.org
Sat Jun 19 12:43:01 PDT 2004


On Sat, 19 Jun 2004, Vladimir Prus wrote:
> 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?

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

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




More information about the llvm-dev mailing list