@@ -1239,7 +1239,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
1239
1239
return ;
1240
1240
}
1241
1241
der_type_name = " " ;
1242
+ uint64_t ptr_loads_copy = ptr_loads;
1243
+ ptr_loads = ptr_loads_copy - ASR::is_a<ASR::Pointer_t>(*ASRUtils::expr_type (x.m_v ));
1242
1244
this ->visit_expr (*x.m_v );
1245
+ ptr_loads = ptr_loads_copy;
1243
1246
ASR::Variable_t* member = down_cast<ASR::Variable_t>(symbol_get_past_external (x.m_m ));
1244
1247
std::string member_name = std::string (member->m_name );
1245
1248
LFORTRAN_ASSERT (der_type_name.size () != 0 );
@@ -1608,15 +1611,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
1608
1611
}
1609
1612
case (ASR::ttypeType::Pointer) : {
1610
1613
ASR::ttype_t *t2 = ASR::down_cast<ASR::Pointer_t>(asr_type)->m_type ;
1611
- switch (t2->type ) {
1612
- case (ASR::ttypeType::Derived) : {
1613
- throw CodeGenError (" Pointers for Derived type not implemented yet in conversion." );
1614
- }
1615
- default :
1616
- llvm_type = get_type_from_ttype_t (t2, m_storage, is_array_type,
1614
+ llvm_type = get_type_from_ttype_t (t2, m_storage, is_array_type,
1617
1615
is_malloc_array_type, m_dims, n_dims, a_kind);
1618
- llvm_type = llvm_type->getPointerTo ();
1619
- }
1616
+ llvm_type = llvm_type->getPointerTo ();
1620
1617
break ;
1621
1618
}
1622
1619
case (ASR::ttypeType::List) : {
@@ -2654,9 +2651,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
2654
2651
2655
2652
void visit_CPtrToPointer (const ASR::CPtrToPointer_t& x) {
2656
2653
ASR::expr_t *cptr = x.m_cptr , *fptr = x.m_ptr , *shape = x.m_shape ;
2654
+ int reduce_loads = 0 ;
2655
+ if ( ASR::is_a<ASR::Var_t>(*cptr) ) {
2656
+ ASR::Variable_t* cptr_var = ASRUtils::EXPR2VAR (cptr);
2657
+ reduce_loads = cptr_var->m_intent == ASRUtils::intent_in;
2658
+ }
2657
2659
if ( ASRUtils::is_array (ASRUtils::expr_type (fptr)) ) {
2658
2660
uint64_t ptr_loads_copy = ptr_loads;
2659
- ptr_loads = 1 ;
2661
+ ptr_loads = 1 - reduce_loads ;
2660
2662
this ->visit_expr (*cptr);
2661
2663
llvm::Value* llvm_cptr = tmp;
2662
2664
ptr_loads = 0 ;
@@ -2706,7 +2708,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
2706
2708
}
2707
2709
} else {
2708
2710
uint64_t ptr_loads_copy = ptr_loads;
2709
- ptr_loads = 1 ;
2711
+ ptr_loads = 1 - reduce_loads ;
2710
2712
this ->visit_expr (*cptr);
2711
2713
llvm::Value* llvm_cptr = tmp;
2712
2714
ptr_loads = 0 ;
@@ -3689,13 +3691,17 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
3689
3691
switch (t2->type ) {
3690
3692
case ASR::ttypeType::Integer:
3691
3693
case ASR::ttypeType::Real:
3692
- case ASR::ttypeType::Complex: {
3694
+ case ASR::ttypeType::Complex:
3695
+ case ASR::ttypeType::Derived: {
3696
+ if ( t2->type == ASR::ttypeType::Derived ) {
3697
+ ASR::Derived_t* d = ASR::down_cast<ASR::Derived_t>(t2);
3698
+ der_type_name = ASRUtils::symbol_name (d->m_derived_type );
3699
+ }
3693
3700
fetch_ptr (x);
3694
3701
break ;
3695
3702
}
3696
3703
case ASR::ttypeType::Character:
3697
- case ASR::ttypeType::Logical:
3698
- case ASR::ttypeType::Derived: {
3704
+ case ASR::ttypeType::Logical: {
3699
3705
break ;
3700
3706
}
3701
3707
default :
@@ -4080,7 +4086,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
4080
4086
std::vector<std::string> fmt;
4081
4087
for (size_t i=0 ; i<x.n_values ; i++) {
4082
4088
uint64_t ptr_loads_copy = ptr_loads;
4083
- ptr_loads = 1 ;
4089
+ int reduce_loads = 0 ;
4090
+ if ( ASR::is_a<ASR::Var_t>(*x.m_values [i]) ) {
4091
+ ASR::Variable_t* cptr_var = ASRUtils::EXPR2VAR (x.m_values [i]);
4092
+ reduce_loads = cptr_var->m_intent == ASRUtils::intent_in;
4093
+ }
4094
+ ptr_loads = 1 - reduce_loads;
4084
4095
this ->visit_expr_wrapper (x.m_values [i], true );
4085
4096
ptr_loads = ptr_loads_copy;
4086
4097
ASR::expr_t *v = x.m_values [i];
@@ -4235,11 +4246,13 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
4235
4246
template <typename T>
4236
4247
inline void set_func_subrout_params (T* func_subrout, ASR::abiType& x_abi,
4237
4248
std::uint32_t & m_h, ASR::Variable_t*& orig_arg,
4238
- std::string& orig_arg_name, size_t arg_idx) {
4249
+ std::string& orig_arg_name, ASR::intentType& arg_intent,
4250
+ size_t arg_idx) {
4239
4251
m_h = get_hash ((ASR::asr_t *)func_subrout);
4240
4252
orig_arg = EXPR2VAR (func_subrout->m_args [arg_idx]);
4241
4253
orig_arg_name = orig_arg->m_name ;
4242
4254
x_abi = func_subrout->m_abi ;
4255
+ arg_intent = orig_arg->m_intent ;
4243
4256
}
4244
4257
4245
4258
@@ -4255,6 +4268,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
4255
4268
ASR::Subroutine_t* sub = down_cast<ASR::Subroutine_t>(func_subrout);
4256
4269
x_abi = sub->m_abi ;
4257
4270
}
4271
+ // TODO: Below if check is dead. Remove.
4258
4272
if ( x_abi == ASR::abiType::Intrinsic ) {
4259
4273
if ( name == " lbound" || name == " ubound" ) {
4260
4274
ASR::Variable_t *arg = EXPR2VAR (x.m_args [0 ].m_value );
@@ -4283,23 +4297,24 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
4283
4297
tmp = llvm_symtab[h];
4284
4298
func_subrout = symbol_get_past_external (x.m_name );
4285
4299
x_abi = (ASR::abiType) 0 ;
4300
+ ASR::intentType orig_arg_intent = ASR::intentType::Unspecified;
4286
4301
std::uint32_t m_h;
4287
4302
ASR::Variable_t *orig_arg = nullptr ;
4288
4303
std::string orig_arg_name = " " ;
4289
4304
if ( func_subrout->type == ASR::symbolType::Function ) {
4290
4305
ASR::Function_t* func = down_cast<ASR::Function_t>(func_subrout);
4291
- set_func_subrout_params (func, x_abi, m_h, orig_arg, orig_arg_name, i);
4306
+ set_func_subrout_params (func, x_abi, m_h, orig_arg, orig_arg_name, orig_arg_intent, i);
4292
4307
} else if ( func_subrout->type == ASR::symbolType::Subroutine ) {
4293
4308
ASR::Subroutine_t* sub = down_cast<ASR::Subroutine_t>(func_subrout);
4294
- set_func_subrout_params (sub, x_abi, m_h, orig_arg, orig_arg_name, i);
4309
+ set_func_subrout_params (sub, x_abi, m_h, orig_arg, orig_arg_name, orig_arg_intent, i);
4295
4310
} else if ( func_subrout->type == ASR::symbolType::ClassProcedure ) {
4296
4311
ASR::ClassProcedure_t* clss_proc = ASR::down_cast<ASR::ClassProcedure_t>(func_subrout);
4297
4312
if ( clss_proc->m_proc ->type == ASR::symbolType::Subroutine ) {
4298
4313
ASR::Subroutine_t* sub = down_cast<ASR::Subroutine_t>(clss_proc->m_proc );
4299
- set_func_subrout_params (sub, x_abi, m_h, orig_arg, orig_arg_name, i);
4314
+ set_func_subrout_params (sub, x_abi, m_h, orig_arg, orig_arg_name, orig_arg_intent, i);
4300
4315
} else if ( clss_proc->m_proc ->type == ASR::symbolType::Function ) {
4301
4316
ASR::Function_t* func = down_cast<ASR::Function_t>(clss_proc->m_proc );
4302
- set_func_subrout_params (func, x_abi, m_h, orig_arg, orig_arg_name, i);
4317
+ set_func_subrout_params (func, x_abi, m_h, orig_arg, orig_arg_name, orig_arg_intent, i);
4303
4318
}
4304
4319
} else {
4305
4320
LFORTRAN_ASSERT (false )
0 commit comments