From 783cc13e5b1747fb7d728dad34b757f49d6ee853 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 16 Feb 2015 10:35:51 +0100 Subject: [PATCH] isl_ast_expr_is_equal: properly handle expressions with arguments Due to a spurious "return 0" introduced in fdcc255 (add isl_ast_expr_is_equal, Wed Jun 5 14:21:53 2013 +0200), expressions with arguments would never be considered equal. Detected by a scan_build on Polly. Signed-off-by: Sven Verdoolaege --- isl_ast.c | 1 - isl_test.c | 14 +++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/isl_ast.c b/isl_ast.c index 97199fc2..19b5d8f0 100644 --- a/isl_ast.c +++ b/isl_ast.c @@ -351,7 +351,6 @@ int isl_ast_expr_is_equal(__isl_keep isl_ast_expr *expr1, int equal; equal = isl_ast_expr_is_equal(expr1->u.op.args[i], expr2->u.op.args[i]); - return 0; if (equal < 0 || !equal) return equal; } diff --git a/isl_test.c b/isl_test.c index e73c1b7f..2e78ff7d 100644 --- a/isl_test.c +++ b/isl_test.c @@ -4361,25 +4361,33 @@ static int test_pullback(isl_ctx *ctx) return 0; } -/* Check that negation is printed correctly. +/* Check that negation is printed correctly and that equal expressions + * are correctly identified. */ static int test_ast(isl_ctx *ctx) { isl_ast_expr *expr, *expr1, *expr2, *expr3; char *str; - int ok; + int ok, equal; expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL)); expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL)); expr = isl_ast_expr_add(expr1, expr2); + expr2 = isl_ast_expr_copy(expr); expr = isl_ast_expr_neg(expr); + expr2 = isl_ast_expr_neg(expr2); + equal = isl_ast_expr_is_equal(expr, expr2); str = isl_ast_expr_to_str(expr); ok = str ? !strcmp(str, "-(A + B)") : -1; free(str); isl_ast_expr_free(expr); + isl_ast_expr_free(expr2); - if (ok < 0) + if (ok < 0 || equal < 0) return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, + "equal expressions not considered equal", return -1); if (!ok) isl_die(ctx, isl_error_unknown, "isl_ast_expr printed incorrectly", return -1); -- 2.11.4.GIT