From 937726fe716b8f552fa7793f0c315097b053d68c Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sat, 7 Oct 2023 18:41:27 +0530 Subject: [PATCH] Also support constant variables in floordiv --- src/libasr/pass/intrinsic_function_registry.h | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 4f861ebb8e..5e852be01b 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -1980,6 +1980,8 @@ namespace FloorDiv { x.base.base.loc, diagnostics); ASR::ttype_t *type1 = ASRUtils::expr_type(x.m_args[0]); ASR::ttype_t *type2 = ASRUtils::expr_type(x.m_args[1]); + type1 = ASRUtils::type_get_past_const(type1); + type2 = ASRUtils::type_get_past_const(type2); ASRUtils::require_impl((is_integer(*type1) && is_integer(*type2)) || (is_unsigned_integer(*type1) && is_unsigned_integer(*type2)) || (is_real(*type1) && is_real(*type2)) || @@ -1990,14 +1992,18 @@ namespace FloorDiv { static ASR::expr_t *eval_FloorDiv(Allocator &al, const Location &loc, ASR::ttype_t* t1, Vec &args) { - bool is_real1 = is_real(*ASRUtils::expr_type(args[0])); - bool is_real2 = is_real(*ASRUtils::expr_type(args[1])); - bool is_int1 = is_integer(*ASRUtils::expr_type(args[0])); - bool is_int2 = is_integer(*ASRUtils::expr_type(args[1])); - bool is_unsigned_int1 = is_unsigned_integer(*ASRUtils::expr_type(args[0])); - bool is_unsigned_int2 = is_unsigned_integer(*ASRUtils::expr_type(args[1])); - bool is_logical1 = is_logical(*ASRUtils::expr_type(args[0])); - bool is_logical2 = is_logical(*ASRUtils::expr_type(args[1])); + ASR::ttype_t *type1 = ASRUtils::expr_type(args[0]); + ASR::ttype_t *type2 = ASRUtils::expr_type(args[1]); + type1 = ASRUtils::type_get_past_const(type1); + type2 = ASRUtils::type_get_past_const(type2); + bool is_real1 = is_real(*type1); + bool is_real2 = is_real(*type2); + bool is_int1 = is_integer(*type1); + bool is_int2 = is_integer(*type2); + bool is_unsigned_int1 = is_unsigned_integer(*type1); + bool is_unsigned_int2 = is_unsigned_integer(*type2); + bool is_logical1 = is_logical(*type1); + bool is_logical2 = is_logical(*type2); if (is_int1 && is_int2) { int64_t a = ASR::down_cast(args[0])->m_n; @@ -2032,6 +2038,8 @@ namespace FloorDiv { } ASR::ttype_t *type1 = ASRUtils::expr_type(args[0]); ASR::ttype_t *type2 = ASRUtils::expr_type(args[1]); + type1 = ASRUtils::type_get_past_const(type1); + type2 = ASRUtils::type_get_past_const(type2); if (!((ASRUtils::is_integer(*type1) && ASRUtils::is_integer(*type2)) || (ASRUtils::is_unsigned_integer(*type1) && ASRUtils::is_unsigned_integer(*type2)) || (ASRUtils::is_real(*type1) && ASRUtils::is_real(*type2)) ||