[oi-dev] -funsigned-char breaks int8_t (and possibly more system headers)

C Bergström cbergstrom at pathscale.com
Sat Aug 13 20:14:55 UTC 2016


I'm playing around with clang self hosting and hit this. My system is
not updated and apologies if this is already fixed.

I can probably get a test case which shows this breaks gcc as well.
-------------
llvm/include/llvm/CodeGen/MachineValueType.h:34:35: error: enumerator
value evaluates to -1, which
      cannot be narrowed to type 'int8_t' (aka 'char') [-Wc++11-narrowing]
      INVALID_SIMPLE_VALUE_TYPE = -1,
                                  ^
1 error generated.

Turns out we're building be with -funsigned-char. However, system
header <sys/isa_defs.h> unconditionally defines _CHAR_IS_SIGNED which
indicates that 'char' is signed (while we make it unsigned!) which in
turn makes <sys/int_types.h> (used for <stdint.h>) define int8_t using
plain 'char' (which turns out unsigned).

Solaris doc:

 * _CHAR_IS_UNSIGNED / _CHAR_IS_SIGNED:
 * The C Compiler implements objects of type `char' as `unsigned' or
 * `signed' respectively. This is really an implementation choice of
 * the compiler writer, but it is specified in the ABI and tends to
 * be uniform across compilers for an instruction set architecture.
 * Hence, it has the properties of a processor characteristic.




More information about the oi-dev mailing list