tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] 4 bugfixes for Rob Landley's revision 470


From: Joshua Phillips
Subject: [Tinycc-devel] 4 bugfixes for Rob Landley's revision 470
Date: Wed, 05 Sep 2007 21:28:57 +0100
User-agent: Icedove 1.5.0.12 (X11/20070607)

I have made some fixes to tcc that may be useful...

Fixed variable-length array in struct:
    struct foo {
       int a;
       void *b[];
    };
    sizeof(struct foo) is now 4 instead of 0.

Added opcode definition for 8-bit sign-extended immediates in 16/32-bit
arithmetic
not really a fix (hence not counted as one of the four), but I was a bit
frustrated when asm ("addl $4,%esp") produced the long, 6-byte opcode. I
fixed this to use the shorter opcode where possible.

Fix backslash parsing between a false #if/ifdef..#endif
    as described in http://www.landley.net/code/tinycc/bugs/preprocessor.c

Fix bug when casting between integer pointers of different sizes
    as described in http://www.landley.net/code/tinycc/bugs/gildabah.c

Fix dereferences used in inline assembly output
    as described in http://www.landley.net/code/tinycc/bugs/asm.c

I have tested these changes, and "make test" still works 100%.
I have the changes under Mercurial (repository cloned from
landley.net), which I'd prefer to use, for now I've attached a diff
with all the changes to revision 470.


diff -r 44036032a50a -r fa40073359fe i386/i386-asm.h
--- a/i386/i386-asm.h   Wed Sep 05 00:06:26 2007 -0500
+++ b/i386/i386-asm.h   Wed Sep 05 20:46:18 2007 +0100
@@ -154,6 +154,7 @@ ALT(DEF_ASM_OP2(lgs, 0x0fb5, 0, OPC_MODR
      /* arith */
 ALT(DEF_ASM_OP2(addb, 0x00, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_REG, 
OPT_EA | OPT_REG)) /* XXX: use D bit ? */
 ALT(DEF_ASM_OP2(addb, 0x02, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_EA | 
OPT_REG, OPT_REG))
+ALT(DEF_ASM_OP2(addb, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WL, OPT_IM8S, 
OPT_EA | OPT_REG))
 ALT(DEF_ASM_OP2(addb, 0x04, 0, OPC_ARITH | OPC_BWL, OPT_IM, OPT_EAX))
 ALT(DEF_ASM_OP2(addb, 0x80, 0, OPC_ARITH | OPC_MODRM | OPC_BWL, OPT_IM, OPT_EA 
| OPT_REG))
 ALT(DEF_ASM_OP2(addw, 0x83, 0, OPC_ARITH | OPC_MODRM | OPC_WL, OPT_IM8S, 
OPT_EA | OPT_REG))
diff -r 44036032a50a -r fa40073359fe tcc.c
--- a/tcc.c     Wed Sep 05 00:06:26 2007 -0500
+++ b/tcc.c     Wed Sep 05 20:46:18 2007 +0100
@@ -1100,6 +1100,24 @@ static void handle_stray(void)
     }
 }
 
+/* handle '\[\r]\n' silently */
+static void handle_stray_noerror(void)
+{
+    while (ch == '\\'){
+        inp();
+        if (ch == '\n'){
+            file->line_num++;
+            inp();
+        } else if (ch == '\r'){
+            inp();
+            if (ch == '\n'){
+                file->line_num++;
+                inp();
+            }
+        }
+    }
+}
+
 /* skip the stray and handle the \\n case. Output an error if
    incorrect char after the stray */
 static int handle_stray1(uint8_t *p)
@@ -1379,7 +1397,7 @@ void preprocess_skip(void)
             } else if (c == '\\') {
                 /* XXX: incorrect: should not give an error */
                 ch = file->buf_ptr[0];
-                handle_stray();
+                handle_stray_noerror();
             }
             p = file->buf_ptr;
             goto redo_no_start;
@@ -5137,6 +5155,10 @@ static void gen_cast(CType *type)
                the lvalue already contains the real type size (see
                VT_LVAL_xxx constants) */
         }
+    } else if ((dbt & VT_BTYPE) == VT_PTR && !(vtop->r & VT_LVAL)){
+        /* if we are casting between pointer types,
+           we must update the VT_LVAL_xxx size */
+        vtop->r = (vtop->r & ~VT_LVAL_TYPE) | (lvalue_type(type->ref->type.t) 
& VT_LVAL_TYPE);
     }
     vtop->type = *type;
 }
@@ -5851,7 +5873,8 @@ static void struct_decl(CType *type, int
                             if (a == TOK_STRUCT) {
                                 c = (c + align - 1) & -align;
                                 offset = c;
-                                c += size;
+                                if (size > 0)
+                                    c += size;
                             } else {
                                 offset = 0;
                                 if (size > c)
diff -r 44036032a50a -r fa40073359fe tccasm.c
--- a/tccasm.c  Wed Sep 05 00:06:26 2007 -0500
+++ b/tccasm.c  Wed Sep 05 20:46:18 2007 +0100
@@ -806,7 +806,7 @@ static void subst_asm_operands(ASMOperan
             sv = *op->vt;
             if (op->reg >= 0) {
                 sv.r = op->reg;
-                if ((op->vt->r & VT_VALMASK) == VT_LLOCAL)
+                if ((op->vt->r & VT_VALMASK) == VT_LLOCAL && op->is_memory)
                     sv.r |= VT_LVAL;
             }
             subst_asm_operand(out_str, &sv, modifier);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]