bernstein_coefficients_cell: handle NULL poly
[platform/upstream/isl.git] / isl_bernstein.c
index c022930..7358b71 100644 (file)
  * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
  */
 
-#include <isl_set.h>
-#include <isl_seq.h>
+#include <isl_ctx_private.h>
+#include <isl_map_private.h>
+#include <isl/set.h>
+#include <isl/seq.h>
 #include <isl_morph.h>
 #include <isl_factorization.h>
 #include <isl_vertices_private.h>
@@ -91,7 +93,7 @@ error:
  */
 static int is_tight(int *k, int n, int d, isl_cell *cell)
 {
-       int i, j;
+       int i;
 
        for (i = 0; i < n; ++i) {
                int v;
@@ -251,12 +253,20 @@ static int bernstein_coefficients_cell(__isl_take isl_cell *cell, void *user)
        isl_qpolynomial **subs;
        isl_pw_qpolynomial_fold *pwf;
        isl_set *dom;
+       isl_ctx *ctx;
+
+       if (!poly)
+               goto error;
 
        nvar = isl_qpolynomial_dim(poly, isl_dim_set) - 1;
        n_vertices = cell->n_vertices;
 
-       subs = isl_alloc_array(data->poly->dim->ctx, isl_qpolynomial *,
-                               1 + nvar);
+       ctx = isl_qpolynomial_get_ctx(poly);
+       if (n_vertices > nvar + 1 && ctx->opt->bernstein_triangulate)
+               return isl_cell_foreach_simplex(cell,
+                                           &bernstein_coefficients_cell, user);
+
+       subs = isl_alloc_array(ctx, isl_qpolynomial *, 1 + nvar);
        if (!subs)
                goto error;