> On Mar 21, 2016, at 10:23 PM, Gao, Liming <[email protected]> wrote:
>
> Andrew:
> Thanks for your point. I verify this change with VS2015 and GCC49 on IA32
> arch. There is no warning report. So, I think the compiler option is not
> required for all tool chains and all archs. But, this is not true for CLANG.
> It may not be true for ARM. So, I suggest we add option -funsigned-char for
> every tool chain and every arch to ensure char is unsigned. For VS tool
> chain, /J (Default char Type Is unsigned) option. can be used. And, we also
> update CHAR8 definition with unsigned char to clearly follow UEFI spec.
>
Liming,
It looks like clang warns if you assume a string literal has a specific sign.
The -funsigned-char flag does not change this behavior.
~/work/Compiler>cat string.c
unsigned char *a = "a test";
signed char *b = "b test";
char *c = "c test";
~/work/Compiler>clang string.c -S -funsigned-char
string.c:2:16: warning: initializing 'unsigned char *' with an expression of
type 'char [7]' converts between pointers to integer
types with different sign [-Wpointer-sign]
unsigned char *a = "a test";
^ ~~~~~~~~
string.c:3:16: warning: initializing 'signed char *' with an expression of type
'char [7]' converts between pointers to integer types
with different sign [-Wpointer-sign]
signed char *b = "b test";
^ ~~~~~~~~
2 warnings generated.
~/work/Compiler>clang string.c -S
string.c:2:16: warning: initializing 'unsigned char *' with an expression of
type 'char [7]' converts between pointers to integer
types with different sign [-Wpointer-sign]
unsigned char *a = "a test";
^ ~~~~~~~~
string.c:3:16: warning: initializing 'signed char *' with an expression of type
'char [7]' converts between pointers to integer types
with different sign [-Wpointer-sign]
signed char *b = "b test";
^ ~~~~~~~~
2 warnings generated.
~/work/Compiler>
It looks like clang's -Wpointer-sign will warn if you write code that assumes
the sign of string literals. I assume this is to enforce portability. It looks
like you need to cast between char * and (signed char *or unsigned char *) to
make the compiler happy.
If we try to force CHAR8 to be signed or unsigned explicitly (type unsigned
char), then we will have to cast all string literals to (CHAR8 *)
~/work/Compiler>cat string.c
unsigned char *a = (unsigned char *)"a test";
signed char *b = (signed char *)"b test";
char *c = "c test";
~/work/Compiler>clang string.c -S -funsigned-char
~/work/Compiler>clang string.c -S
I think this is why CHAR8 is defined as a char in all the processor bindings.
Thanks,
Andrew Fish
> Thanks
> Liming
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel