@@ -323,7 +323,6 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
323
323
func_body.from_pointer_n_copy (al, xx.m_body , xx.n_body );
324
324
325
325
for (ASR::symbol_t * symbol : symbolic_vars_to_free) {
326
- if (symbolic_vars_to_omit.find (symbol) != symbolic_vars_to_omit.end ()) continue ;
327
326
func_body.push_back (al, basic_free_stack (x.base .base .loc ,
328
327
ASRUtils::EXPR (ASR::make_Var_t (al, x.base .base .loc , symbol))));
329
328
}
@@ -352,7 +351,7 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
352
351
353
352
ASR::ttype_t *CPtr_type = ASRUtils::TYPE (ASR::make_CPtr_t (al, xx.base .base .loc ));
354
353
xx.m_type = CPtr_type;
355
- if (var_name != " _lpython_return_variable " && xx.m_intent != ASR::intentType::Out ) {
354
+ if (xx.m_intent == ASR::intentType::Local ) {
356
355
symbolic_vars_to_free.insert (ASR::down_cast<ASR::symbol_t >((ASR::asr_t *)&xx));
357
356
}
358
357
if (xx.m_intent == ASR::intentType::In){
@@ -524,7 +523,8 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
524
523
void visit_Assignment (const ASR::Assignment_t &x) {
525
524
if (ASR::is_a<ASR::Var_t>(*x.m_value ) && ASR::is_a<ASR::CPtr_t>(*ASRUtils::expr_type (x.m_value ))) {
526
525
ASR::symbol_t *v = ASR::down_cast<ASR::Var_t>(x.m_value )->m_v ;
527
- if (symbolic_vars_to_free.find (v) == symbolic_vars_to_free.end ()) return ;
526
+ if ((symbolic_vars_to_free.find (v) == symbolic_vars_to_free.end ()) &&
527
+ (symbolic_vars_to_omit.find (v) == symbolic_vars_to_omit.end ())) return ;
528
528
ASR::symbol_t * var_sym = ASR::down_cast<ASR::Var_t>(x.m_value )->m_v ;
529
529
pass_result.push_back (al, basic_assign (x.base .base .loc , x.m_target ,
530
530
ASRUtils::EXPR (ASR::make_Var_t (al, x.base .base .loc , var_sym))));
@@ -784,7 +784,8 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
784
784
ASR::expr_t * val = x.m_values [i];
785
785
if (ASR::is_a<ASR::Var_t>(*val) && ASR::is_a<ASR::CPtr_t>(*ASRUtils::expr_type (val))) {
786
786
ASR::symbol_t *v = ASR::down_cast<ASR::Var_t>(val)->m_v ;
787
- if (symbolic_vars_to_free.find (v) == symbolic_vars_to_free.end ()) return ;
787
+ if ((symbolic_vars_to_free.find (v) == symbolic_vars_to_free.end ()) &&
788
+ (symbolic_vars_to_omit.find (v) == symbolic_vars_to_omit.end ())) return ;
788
789
print_tmp.push_back (basic_str (x.base .base .loc , val));
789
790
} else if (ASR::is_a<ASR::IntrinsicScalarFunction_t>(*val)) {
790
791
ASR::IntrinsicScalarFunction_t* intrinsic_func = ASR::down_cast<ASR::IntrinsicScalarFunction_t>(val);
@@ -1007,14 +1008,12 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
1007
1008
}
1008
1009
1009
1010
void visit_Return (const ASR::Return_t &x) {
1011
+ // freeing out variables
1010
1012
if (!symbolic_vars_to_free.empty ()){
1011
1013
for (ASR::symbol_t * symbol : symbolic_vars_to_free) {
1012
- if (symbolic_vars_to_omit.find (symbol) != symbolic_vars_to_omit.end ()) continue ;
1013
- // freeing out variables
1014
1014
pass_result.push_back (al, basic_free_stack (x.base .base .loc ,
1015
1015
ASRUtils::EXPR (ASR::make_Var_t (al, x.base .base .loc , symbol))));
1016
1016
}
1017
- symbolic_vars_to_free.clear ();
1018
1017
pass_result.push_back (al, ASRUtils::STMT (ASR::make_Return_t (al, x.base .base .loc )));
1019
1018
}
1020
1019
}
0 commit comments