changeset 401:2707893d0c57

Fix from David Heine for tcc typecast sign extension bug. For details, see http://lists.gnu.org/archive/html/tinycc-devel/2005-01/msg00013.html
author landley@driftwood
date Sun, 08 Oct 2006 12:24:42 -0400
parents afda44bbf76b
children 7e9800049711
files tcc.c tcctest.c
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tcc.c	Sun Oct 08 01:13:34 2006 -0400
+++ b/tcc.c	Sun Oct 08 12:24:42 2006 -0400
@@ -5754,6 +5754,11 @@
         bits = 32 - bits;
         vpushi(bits);
         gen_op(TOK_SHL);
+        /* result must be signed or the SAR is converted to an SHL
+           This was not the case when "t" was a signed short
+           and the last value on the stack was an unsigned int
+        */
+        vtop->type.t &= (~VT_UNSIGNED);
         vpushi(bits);
         gen_op(TOK_SAR);
     }
--- a/tcctest.c	Sun Oct 08 01:13:34 2006 -0400
+++ b/tcctest.c	Sun Oct 08 12:24:42 2006 -0400
@@ -1066,6 +1066,8 @@
     int a;
     char c;
     char tab[10];
+    unsigned b,c;
+    short s;
 
     printf("cast_test:\n");
     a = 0xfffff;
@@ -1089,6 +1091,14 @@
     
     printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c), sizeof((int)c));
 
+    /* test cast from unsigned to signed short to int */
+    b = 0xf000;
+    d = (short)b;
+    printf("((unsigned)(short)0x%08x) = 0x%08x\n", b, d);
+    b = 0xf0f0;
+    d = (char)b;
+    printf("((unsigned)(char)0x%08x) = 0x%08x\n", b, d);
+
     /* test implicit int casting for array accesses */
     c = 0;
     tab[1] = 2;