shithub: mc

Download patch

ref: ce9623eb0bebca8f485f9a49276b23a0feff677b
parent: a9e728b098491d2976801a4e8a668c453688cac4
author: Ori Bernstein <[email protected]>
date: Thu Oct 10 10:18:38 EDT 2013

Duplicate types from imports resolve to the same one now.

    This fixes compiler crashes that come when checking the ID of
    types fails.

--- a/parse/use.c
+++ b/parse/use.c
@@ -581,12 +581,28 @@
 static void fixmappings(Stab *st)
 {
     size_t i;
+    Type *t, *old;
 
     for (i = 0; i < ntypefixdest; i++) {
-        *typefixdest[i] = htget(tidmap, (void*)typefixid[i]);
+        t = htget(tidmap, (void*)typefixid[i]);
+        if (t->type == Tyname && !t->issynth) {
+            old = gettype(st, t->name);
+            if (old)
+                t = old;
+        }
+        *typefixdest[i] = t;
         if (!*typefixdest[i])
             die("Couldn't find type %d\n", (int)typefixid[i]);
     }
+    /* check for duplicate type names */
+    for (i = 0; i < ntypefixdest; i++) {
+        t = htget(tidmap, (void*)typefixid[i]);
+        if (t->type != Tyname || t->issynth)
+            continue;
+        old = gettype(st, t->name);
+        if (old && !tyeq(t, old))
+            fatal(-1, "Duplicate definition of type %s", tystr(old));
+    }
     lfree(&typefixdest, &ntypefixdest);
     lfree(&typefixid, &ntypefixid);
 }
@@ -639,10 +655,10 @@
                 t = tyunpickle(f);
                 htput(tidmap, (void*)tid, t);
                 /* fix up types */
-                if (t->type == Tyname)
-                    if (!gettype(s, t->name))
+                if (t->type == Tyname) {
+                    if (!gettype(s, t->name) && !t->issynth)
                         puttype(s, t->name, t);
-                if (t->type == Tyunion)  {
+                } else if (t->type == Tyunion)  {
                     for (i = 0; i < t->nmemb; i++)
                         if (!t->udecls[i]->synth)
                             putucon(s, t->udecls[i]);