Skip to content

Commit 84d73e7

Browse files
certikanutosh491
authored andcommitted
Only use ptr_loads = 0 if it is an argument
The solution in this commit should be simplified.
1 parent 73953d6 commit 84d73e7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,27 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
12471247
int64_t ptr_loads_copy = ptr_loads;
12481248
for( size_t i = 0; i < x.n_args; i++ ) {
12491249
if (ASR::is_a<ASR::CPtr_t>(*ASRUtils::expr_type(x.m_args[i]))) {
1250-
ptr_loads = 0;
1250+
bool is_argument = false;
1251+
ASR::expr_t *var = x.m_args[i];
1252+
if (is_a<ASR::Var_t>(*var)) {
1253+
ASR::symbol_t *var_sym = ASR::down_cast<ASR::Var_t>(var)
1254+
->m_v;
1255+
if (is_a<ASR::Variable_t>(*var_sym)) {
1256+
ASR::Variable_t *v = down_cast<ASR::Variable_t>(var_sym);
1257+
if (v->m_intent == intent_local ||
1258+
v->m_intent == intent_return_var ||
1259+
!v->m_intent) {
1260+
is_argument = false;
1261+
} else {
1262+
is_argument = true;
1263+
}
1264+
}
1265+
}
1266+
if (is_argument) {
1267+
ptr_loads = 0;
1268+
} else {
1269+
ptr_loads = 1;
1270+
}
12511271
} else {
12521272
ptr_loads = 1;
12531273
}

0 commit comments

Comments
 (0)