tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] VLAs broken on mob branch


From: Pip Cet
Subject: [Tinycc-devel] VLAs broken on mob branch
Date: Fri, 24 Apr 2015 09:07:14 +0000

Hi,
as far as I can tell, VLAs are currently broken. If you apply this
patch to the source code (adding a useless VLA to the TCC code
itself), make test dies with a segmentation fault (on x86-64, Linux):

diff --git a/x86_64-gen.c b/x86_64-gen.c
index d837a1d..593dd91 100644
--- a/x86_64-gen.c
+++ b/x86_64-gen.c
@@ -1186,6 +1186,7 @@ void gfunc_call(int nb_args)
     int size, align, r, args_size, stack_adjust, run_start, run_end,
i, reg_count;
     int nb_reg_args = 0;
     int nb_sse_args = 0;
+    int offsets[nb_args*nb_args+1];
     int sse_reg, gen_reg;

     /* calculate the number of integer/float register arguments */

I've tried fixing it. So far all I have is a patch that appears to
make the problem go away, but that I don't fully understand. If anyone
who actually understands the VLA code could have a look, that would be
very much appreciated. I include the patch mostly for reasons of
completeness, since it's probably very different from any actual fix:

diff --git a/tccgen.c b/tccgen.c
index 103c955..afd610e 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -3479,7 +3479,7 @@ static void post_type(CType *type, AttributeDef *ad)

             vla_runtime_type_size(type, &align);
             gen_op('*');
-            vset(&int_type, VT_LOCAL|VT_LVAL, loc);
+            vset(&int_type, VT_LOCAL|VT_LVAL, n);
             vswap();
             vstore();
         }
@@ -4804,7 +4804,7 @@ static void block(int *bsym, int *csym, int
*case_sym, int *def_sym,
         gsym_addr(b, d);
     } else if (tok == '{') {
         Sym *llabel;
-        int block_vla_sp_loc, *saved_vla_sp_loc, saved_vla_flags;
+        int block_vla_sp_loc, *saved_vla_sp_loc, saved_vla_flags,
*orig_vla_sp_loc;

         next();
         /* record local declaration stack position */
@@ -4817,7 +4817,8 @@ static void block(int *bsym, int *csym, int
*case_sym, int *def_sym,
         /* save VLA state */
         block_vla_sp_loc = *(saved_vla_sp_loc = vla_sp_loc);
         if (saved_vla_sp_loc != &vla_sp_root_loc)
-          vla_sp_loc = &block_vla_sp_loc;
+            vla_sp_loc = &block_vla_sp_loc;
+        orig_vla_sp_loc = vla_sp_loc;

         saved_vla_flags = vla_flags;
         vla_flags |= VLA_NEED_NEW_FRAME;
@@ -4873,10 +4874,10 @@ static void block(int *bsym, int *csym, int
*case_sym, int *def_sym,
         /* Pop VLA frames and restore stack pointer if required */
         if (saved_vla_sp_loc != &vla_sp_root_loc)
             *saved_vla_sp_loc = block_vla_sp_loc;
-        if (vla_sp_loc != (saved_vla_sp_loc == &vla_sp_root_loc ?
&vla_sp_root_loc : &block_vla_sp_loc)) {
-            vla_sp_loc = saved_vla_sp_loc;
-            gen_vla_sp_restore(*vla_sp_loc);
+        if (vla_sp_loc != orig_vla_sp_loc) {
+            gen_vla_sp_restore(*saved_vla_sp_loc);
         }
+        vla_sp_loc = saved_vla_sp_loc;
         vla_flags = (vla_flags & ~VLA_SCOPE_FLAGS) | (saved_vla_flags
& VLA_SCOPE_FLAGS);

         next();
@@ -5458,6 +5459,7 @@ static void decl_initializer(CType *type,
Section *sec, unsigned long c,

         vla_runtime_type_size(type, &a);
         gen_vla_alloc(type, a);
+        vla_sp_save();
         vset(type, VT_LOCAL|VT_LVAL, c);
         vswap();
         vstore();

Attachment tcc-break-vlas.diff is the change that causes the segfault;
attachment tcc-notafix.diff is the half-understood patch that "fixes"
things.

Attachment: tcc-break-vlas.diff
Description: Text document

Attachment: tcc-notafix.diff
Description: Text document


reply via email to

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