changeset 434:98a68386c5a6

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).
author Rob Landley <rob@landley.net>
date Wed, 02 May 2007 17:18:07 -0400
parents 04d9a1c05f94
children f16b04be31b6
files tcc.c tests/tcctest.c
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 */
--- 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;