scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit fbd4dc3ffdc99ec1ea9c3eb5af6340e8824ab310
parent 97fb8811816aa9e4f7a9eced1ec231016a4cba6c
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 16 Feb 2017 10:07:16 -0800

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

Diffstat:
Mcc1/types.c | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git 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;