# HG changeset patch # User Rob Landley # Date 1178140687 14400 # Node ID 98a68386c5a6675b7ceebbc6274028fa97a65c49 # Parent 04d9a1c05f94cb7aee9c96b28a42240bd837750e Support casting pointer to short or _Bool (grischka-2005-09-25 bugfix 6.1). This patch was originally posted in grischka's 2005-09-25 email as a "required fix" 6 (subfix 6.1) to compile gcc 2.95. It was tweaked by David A. Wheeler to merge the test case into the standard tcc test suite, and the test case now uses the correct formats %hd and %hhd (not %d). diff -r 04d9a1c05f94 -r 98a68386c5a6 tcc.c --- a/tcc.c Tue May 01 17:26:50 2007 -0400 +++ b/tcc.c Wed May 02 17:18:07 2007 -0400 @@ -5125,6 +5125,10 @@ gen_op(TOK_NE); } else if ((dbt & VT_BTYPE) == VT_BYTE || (dbt & VT_BTYPE) == VT_SHORT) { + if (sbt == VT_PTR) { + vtop->type.t = VT_INT; + warning("nonportable conversion from pointer to char/short"); + } force_charshort_cast(dbt); } else if ((dbt & VT_BTYPE) == VT_INT) { /* scalar to int */ diff -r 04d9a1c05f94 -r 98a68386c5a6 tests/tcctest.c --- a/tests/tcctest.c Tue May 01 17:26:50 2007 -0400 +++ b/tests/tcctest.c Wed May 02 17:18:07 2007 -0400 @@ -1107,6 +1107,16 @@ d = (char)b; printf("((unsigned)(char)0x%08x) = 0x%08x\n", b, d); + /* Try casting pointer to short or _Bool (grishka case_6.1). This + * is lossy, so tcc will print a warning. This capability is needed + * to compile gcc 2.95 as well as other programs. */ + { + void *p = (void *) 3; + printf("Expect 3 1 -> %hd %hhd\n", + (short) p, (_Bool) p); /* Expect warning */ + } + + /* test implicit int casting for array accesses */ c = 0; tab[1] = 2;