From c36dbb62f747907aa543ce2a8dedfd4a00f1abea Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 4 Apr 2024 19:51:31 +0530 Subject: [PATCH] Introducing basic_free_stack_if_not_null --- src/libasr/pass/replace_symbolic.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index 6e4aa5a7d2..64bb2dabb3 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -148,6 +148,19 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor func_body; + func_body.reserve(al, 1); + func_body.push_back(al, basic_free_stack(loc, x)); + ASR::ttype_t *CPtr_type = ASRUtils::TYPE(ASR::make_CPtr_t(al, loc)); + ASR::ttype_t *Logical_type = ASRUtils::TYPE(ASR::make_Logical_t(al, loc, 4)); + ASR::expr_t* null = ASRUtils::EXPR(ASR::make_PointerNullConstant_t(al, loc, CPtr_type)); + ASR::expr_t* cond = ASRUtils::EXPR(ASR::make_CPtrCompare_t(al, loc, x, ASR::cmpopType::NotEq, + null, Logical_type, nullptr)); + return ASRUtils::STMT(ASR::make_If_t(al, loc, cond, + func_body.p, func_body.size(), nullptr, 0)); + } + ASR::expr_t *basic_new_heap(const Location& loc) { ASR::symbol_t* basic_new_heap_sym = create_bindc_function(loc, "basic_new_heap", {}, ASRUtils::TYPE((ASR::make_CPtr_t(al, loc)))); @@ -324,7 +337,7 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor