Merge branch 'maint'
authorSven Verdoolaege <sven.verdoolaege@gmail.com>
Thu, 17 May 2018 14:05:45 +0000 (17 16:05 +0200)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Thu, 17 May 2018 14:05:45 +0000 (17 16:05 +0200)
1  2 
isl_multi_templ.c
isl_test.c

@@@ -232,9 -214,33 +232,33 @@@ __isl_give EL *FN(FN(MULTI(BASE),get),B
        if (pos < 0 || pos >= multi->n)
                isl_die(ctx, isl_error_invalid,
                        "index out of bounds", return NULL);
 -      return FN(EL,copy)(multi->p[pos]);
 +      return FN(EL,copy)(multi->u.p[pos]);
  }
  
 -      FN(EL,free)(multi->p[pos]);
 -      multi->p[pos] = el;
+ /* Set the element at position "pos" of "multi" to "el",
+  * where the position may be empty if "multi" has only a single reference.
+  */
+ static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore)(
+       __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
+ {
+       multi = FN(MULTI(BASE),cow)(multi);
+       if (!multi || !el)
+               goto error;
+       if (pos < 0 || pos >= multi->n)
+               isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
+                       "index out of bounds", goto error);
++      FN(EL,free)(multi->u.p[pos]);
++      multi->u.p[pos] = el;
+       return multi;
+ error:
+       FN(MULTI(BASE),free)(multi);
+       FN(EL,free)(el);
+       return NULL;
+ }
  __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),set),BASE)(
        __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el)
  {
diff --cc isl_test.c
@@@ -7202,64 -5837,43 +7202,101 @@@ static int test_align_parameters_1(isl_
        return 0;
  }
  
+ /* Check the isl_multi_*_from_*_list operation in case inputs
+  * have unaligned parameters.
+  * In particular, older versions of isl would simply fail
+  * (without printing any error message).
+  */
+ static isl_stat test_align_parameters_2(isl_ctx *ctx)
+ {
+       isl_space *space;
+       isl_map *map;
+       isl_aff *aff;
+       isl_multi_aff *ma;
+       map = isl_map_read_from_str(ctx, "{ A[] -> M[x] }");
+       space = isl_map_get_space(map);
+       isl_map_free(map);
+       aff = isl_aff_read_from_str(ctx, "[N] -> { A[] -> [N] }");
+       ma = isl_multi_aff_from_aff_list(space, isl_aff_list_from_aff(aff));
+       isl_multi_aff_free(ma);
+       if (!ma)
+               return isl_stat_error;
+       return isl_stat_ok;
+ }
+ /* Perform basic parameter alignment tests.
+  */
+ static int test_align_parameters(isl_ctx *ctx)
+ {
+       if (test_align_parameters_1(ctx) < 0)
+               return -1;
+       if (test_align_parameters_2(ctx) < 0)
+               return -1;
+       return 0;
+ }
 +/* Check that isl_*_drop_unused_params actually drops the unused parameters
 + * by comparing the result using isl_*_plain_is_equal.
 + * Note that this assumes that isl_*_plain_is_equal does not consider
 + * objects that only differ by unused parameters to be equal.
 + */
 +int test_drop_unused_parameters(isl_ctx *ctx)
 +{
 +      const char *str_with, *str_without;
 +      isl_basic_set *bset1, *bset2;
 +      isl_set *set1, *set2;
 +      isl_pw_aff *pwa1, *pwa2;
 +      int equal;
 +
 +      str_with = "[n, m, o] -> { [m] }";
 +      str_without = "[m] -> { [m] }";
 +
 +      bset1 = isl_basic_set_read_from_str(ctx, str_with);
 +      bset2 = isl_basic_set_read_from_str(ctx, str_without);
 +      bset1 = isl_basic_set_drop_unused_params(bset1);
 +      equal = isl_basic_set_plain_is_equal(bset1, bset2);
 +      isl_basic_set_free(bset1);
 +      isl_basic_set_free(bset2);
 +
 +      if (equal < 0)
 +              return -1;
 +      if (!equal)
 +              isl_die(ctx, isl_error_unknown,
 +                      "result not as expected", return -1);
 +
 +      set1 = isl_set_read_from_str(ctx, str_with);
 +      set2 = isl_set_read_from_str(ctx, str_without);
 +      set1 = isl_set_drop_unused_params(set1);
 +      equal = isl_set_plain_is_equal(set1, set2);
 +      isl_set_free(set1);
 +      isl_set_free(set2);
 +
 +      if (equal < 0)
 +              return -1;
 +      if (!equal)
 +              isl_die(ctx, isl_error_unknown,
 +                      "result not as expected", return -1);
 +
 +      pwa1 = isl_pw_aff_read_from_str(ctx, str_with);
 +      pwa2 = isl_pw_aff_read_from_str(ctx, str_without);
 +      pwa1 = isl_pw_aff_drop_unused_params(pwa1);
 +      equal = isl_pw_aff_plain_is_equal(pwa1, pwa2);
 +      isl_pw_aff_free(pwa1);
 +      isl_pw_aff_free(pwa2);
 +
 +      if (equal < 0)
 +              return -1;
 +      if (!equal)
 +              isl_die(ctx, isl_error_unknown,
 +                      "result not as expected", return -1);
 +
 +      return 0;
 +}
 +
  static int test_list(isl_ctx *ctx)
  {
        isl_id *a, *b, *c, *d, *id;