From a5c8ebf3997b0b0453899184c1ecfeec89ef1d4c Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 6 Nov 2014 12:25:09 +0100 Subject: [PATCH] gpu: properly handle dereferencing of pointers to struct Code for handling this case was added in 89cf296 (add support for arrays of structs, Mon Aug 12 23:14:50 2013 +0200), but it was incomplete, causing it to fail to properly detect member accesses. Adjust dereference to use the same detection mechanism that is used in gpu_local_array_info_linearize_index. Reported-by: Michael Kruse Signed-off-by: Sven Verdoolaege --- gpu.c | 14 ++++++++++---- tests/struct2.c | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tests/struct2.c diff --git a/gpu.c b/gpu.c index 1f605bd..7f849ac 100644 --- a/gpu.c +++ b/gpu.c @@ -3836,18 +3836,24 @@ static __isl_give isl_multi_pw_aff *transform_index( static __isl_give isl_ast_expr *dereference(__isl_take isl_ast_expr *expr) { isl_ctx *ctx; - isl_ast_expr *res; + isl_ast_expr *arg0, *res; isl_ast_expr_list *list; - if (isl_ast_expr_get_op_type(expr) == isl_ast_op_member) { + arg0 = isl_ast_expr_get_op_arg(expr, 0); + if (!arg0) + return isl_ast_expr_free(expr); + if (isl_ast_expr_get_type(arg0) == isl_ast_expr_op && + isl_ast_expr_get_op_type(arg0) == isl_ast_op_member) { isl_ast_expr *arg; - arg = isl_ast_expr_get_op_arg(expr, 0); + arg = isl_ast_expr_get_op_arg(arg0, 0); arg = dereference(arg); - expr = isl_ast_expr_set_op_arg(expr, 0, arg); + arg0 = isl_ast_expr_set_op_arg(arg0, 0, arg); + expr = isl_ast_expr_set_op_arg(expr, 0, arg0); return expr; } + isl_ast_expr_free(arg0); ctx = isl_ast_expr_get_ctx(expr); res = isl_ast_expr_from_val(isl_val_zero(ctx)); diff --git a/tests/struct2.c b/tests/struct2.c new file mode 100644 index 0000000..d7d6a9f --- /dev/null +++ b/tests/struct2.c @@ -0,0 +1,21 @@ +#include + +struct s { + int a; +}; + +int main() +{ + struct s a, b[10]; + +#pragma scop + a.a = 42; + for (int i = 0; i < 10; ++i) + b[i].a = a.a; +#pragma endscop + for (int i = 0; i < 10; ++i) + if (b[i].a != 42) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} -- 2.11.4.GIT