[hackers] [scc] [cc1] Fix definition of union types || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 27 Sep 2016 17:07:54 +0200 (CEST)

commit dd69378b91c35a62d9e2960fbad9ae11e4a06ec4
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Sep 27 17:04:49 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Sep 27 17:04:49 2016 +0200

    [cc1] Fix definition of union types
    
    The size of unions was always wrong (and 0). This patch
    also fixes the offset of fields in unions, which must
    be 0 always.

diff --git a/cc1/types.c b/cc1/types.c
index f4fa6f9..44deac6 100644
--- a/cc1/types.c
+++ b/cc1/types.c
_AT_@ -176,7 +176,7 @@ typesize(Type *tp)
 {
         Symbol **sp;
         Type *aux;
- unsigned long size;
+ unsigned long size, offset;
         int align, a;
         TINT n;
 
_AT_@ -200,10 +200,10 @@ typesize(Type *tp)
                  * field, and the size of a struct is the sum
                  * of the size of every field plus padding bits.
                  */
- align = size = 0;
+ offset = align = size = 0;
                 n = tp->n.elem;
                 for (sp = tp->p.fields; n--; ++sp) {
- (*sp)->u.i = size;
+ (*sp)->u.i = offset;
                         aux = (*sp)->type;
                         a = aux->align;
                         if (a > align)
_AT_@ -212,8 +212,9 @@ typesize(Type *tp)
                                 if (--a != 0)
                                         size += (size + a) & ~a;
                                 size += aux->size;
+ offset = size;
                         } else {
- if (tp->size > size)
+ if ((*sp)->type->size > size)
                                         size = aux->size;
                         }
                 }
Received on Tue Sep 27 2016 - 17:07:54 CEST

This archive was generated by hypermail 2.3.0 : Tue Sep 27 2016 - 17:12:15 CEST