nir: fix nir_shader_clone() and nir_sweep()
authorTimothy Arceri <timothy.arceri@collabora.com>
Wed, 2 Nov 2016 22:18:19 +0000 (09:18 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Wed, 2 Nov 2016 23:39:13 +0000 (10:39 +1100)
These were broken in e1af20f18a8 when the info field in nir_shader was
turned into a pointer.

Clone was copying the pointer rather than the data and nir_sweep was
cleaning up shader_info rather than claiming it.

Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/nir/nir_clone.c
src/compiler/nir/nir_sweep.c

index f23fabc70158f2dd287b1fb321343a7c0f1d5394..4f7bdd969697435f4acb00199872ca1affd4a164 100644 (file)
@@ -710,7 +710,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
    clone_reg_list(&state, &ns->registers, &s->registers);
    ns->reg_alloc = s->reg_alloc;
 
-   ns->info = s->info;
+   *ns->info = *s->info;
    ns->info->name = ralloc_strdup(ns, ns->info->name);
    if (ns->info->label)
       ns->info->label = ralloc_strdup(ns, ns->info->label);
index faf696d6decd663eaaa5d8d3e1a3b5a005acaa0c..e6ae298dd3604835f9f42376df58449e8aef6f11 100644 (file)
@@ -150,9 +150,17 @@ nir_sweep(nir_shader *nir)
 {
    void *rubbish = ralloc_context(NULL);
 
+   /* The shader may not own shader_info so check first */
+   bool steal_info = false;
+   if (nir == ralloc_parent(nir->info))
+      steal_info = true;
+
    /* First, move ownership of all the memory to a temporary context; assume dead. */
    ralloc_adopt(rubbish, nir);
 
+   if (steal_info)
+      ralloc_steal(nir, nir->info);
+
    ralloc_steal(nir, (char *)nir->info->name);
    if (nir->info->label)
       ralloc_steal(nir, (char *)nir->info->label);