isl_basic_map_curry: add missing isl_basic_map_cow
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 27 Feb 2013 13:42:44 +0000 (14:42 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 28 Feb 2013 16:11:59 +0000 (17:11 +0100)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_map.c
isl_test.c

index 51a8600..085bbb4 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -10389,6 +10389,9 @@ __isl_give isl_basic_map *isl_basic_map_curry(__isl_take isl_basic_map *bmap)
        if (!isl_basic_map_can_curry(bmap))
                isl_die(bmap->ctx, isl_error_invalid,
                        "basic map cannot be curried", goto error);
+       bmap = isl_basic_map_cow(bmap);
+       if (!bmap)
+               return NULL;
        bmap->dim = isl_space_curry(bmap->dim);
        if (!bmap->dim)
                goto error;
index 82fa8d2..8f03ddb 100644 (file)
@@ -3303,6 +3303,31 @@ static int test_conversion(isl_ctx *ctx)
        return 0;
 }
 
+/* Check that isl_basic_map_curry does not modify input.
+ */
+static int test_curry(isl_ctx *ctx)
+{
+       const char *str;
+       isl_basic_map *bmap1, *bmap2;
+       int equal;
+
+       str = "{ [A[] -> B[]] -> C[] }";
+       bmap1 = isl_basic_map_read_from_str(ctx, str);
+       bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
+       equal = isl_basic_map_is_equal(bmap1, bmap2);
+       isl_basic_map_free(bmap1);
+       isl_basic_map_free(bmap2);
+
+       if (equal < 0)
+               return -1;
+       if (equal)
+               isl_die(ctx, isl_error_unknown,
+                       "curried map should not be equal to original",
+                       return -1);
+
+       return 0;
+}
+
 struct {
        const char *set;
        const char *ma;
@@ -3783,6 +3808,7 @@ struct {
        const char *name;
        int (*fn)(isl_ctx *ctx);
 } tests [] = {
+       { "curry", &test_curry },
        { "piecewise multi affine expressions", &test_pw_multi_aff },
        { "conversion", &test_conversion },
        { "list", &test_list },