commit fbd4dc3ffdc99ec1ea9c3eb5af6340e8824ab310
Author:     Michael Forney <[email protected]>
AuthorDate: Thu Feb 16 10:07:16 2017 -0800
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Thu Feb 16 20:51:13 2017 +0100

    [cc1] Fix eqtype for structs and unions with the same number of fields

diff --git a/cc1/types.c b/cc1/types.c
index a367d0b..ed20f23 100644
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -351,6 +351,7 @@ eqtype(Type *tp1, Type *tp2, int equiv)
 {
        TINT n;
        Type **p1, **p2;
+       Symbol **s1, **s2;
 
        if (tp1 == tp2)
                return 1;
@@ -362,6 +363,20 @@ eqtype(Type *tp1, Type *tp2, int equiv)
        switch (tp1->op) {
        case UNION:
        case STRUCT:
+               if (tp1->letter != tp2->letter)
+                       return 0;
+               if (tp1->tag->name || tp2->tag->name)
+                       return tp1->tag == tp2->tag;
+               if (tp1->n.elem != tp2->n.elem)
+                       return 0;
+               s1 = tp1->p.fields, s2 = tp2->p.fields;
+               for (n = tp1->n.elem; n > 0; --n, ++s1, ++s2) {
+                       if (strcmp((*s1)->name, (*s2)->name))
+                               return 0;
+                       if (!eqtype((*s1)->type, (*s2)->type, equiv))
+                               return 0;
+               }
+               return 1;
        case FTN:
                if (tp1->n.elem != tp2->n.elem)
                        return 0;

Reply via email to