fix: support string section in character array with transfer
fixes: https://github.com/lfortran/lfortran/issues/8178
CI fails.
Getting this failure now.
Post job cleanup.
Will use pre-installed micromamba at C:\Users\runneradmin\micromamba-bin\micromamba.EXE
Deinitialize micromamba for bash
C:\Users\runneradmin\micromamba-bin\micromamba.EXE shell deinit -s bash -r C:\Users\runneradmin\micromamba --log-level warning --rc-file D:\a\_temp\setup-micromamba\.condarc
Resetting RC file "C:\\Users\\runneradmin\\.bash_profile"
Deleting config for root prefix
Clearing mamba executable environment variable
Removing the following in your "C:\\Users\\runneradmin\\.bash_profile" file
# >>> mamba initialize >>>
...
# <<< mamba initialize <<<
Removing environment lf from auto-activate bash ...
Error: Could not find micromamba activate lf in C:\Users\runneradmin\.bash_profile
Let's merge this after I fix them.
Thanks for handling this. trasnfer is for sure in bad need of intense refactor, as we're extremely hard wiring things.
For the issue mentioned here, I tested this minor fix on my side and it works. If the fix propsed here is fixing more cases , so let's push on it instead
diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp
index 59c3b5ee1..d2eae41bd 100644
--- a/src/libasr/codegen/asr_to_llvm.cpp
+++ b/src/libasr/codegen/asr_to_llvm.cpp
@@ -10254,9 +10254,16 @@ public:
return;
}
llvm::Value* source{};
- this->visit_expr_load_wrapper(x.m_source,
- ASRUtils::is_character(*expr_type(x.m_source)) ? 0 : ptr_loads,
- true);
+ int64_t p_load = 0 ;
+ if(ASRUtils::is_character(*expr_type(x.m_source))){
+ const bool source_is_descriptor_array_= ASR::is_a<ASR::Array_t>(*ASRUtils::type_get_past_allocatable_pointer(expr_type(x.m_source)))
+ && ASRUtils::extract_physical_type(expr_type(x.m_source)) == ASR::DescriptorArray;
+ p_load = source_is_descriptor_array_? 1 : 0;
+ } else {
+ p_load = ptr_loads;
+ }
+
+ this->visit_expr_load_wrapper(x.m_source, p_load, true);
source = tmp;
llvm::Type* source_type = llvm_utils->get_type_from_ttype_t_util(x.m_source, ASRUtils::expr_type(x.m_source), module.get());
llvm::Value* source_ptr;
@@ -10292,9 +10299,11 @@ public:
switch(ASRUtils::type_get_past_allocatable_pointer(expr_type(x.m_mold))->type){
case(ASR::String) : {
llvm::Value* str;
- { // Create String Based On PhysicalType + Setup
+ { // Create String Based On PhysicalType + Setup (Use mold's length)
str = llvm_utils->create_string(ASRUtils::get_string_type(x.m_mold), "bit_cast_expr_return");
- setup_string(str, ASRUtils::expr_type(x.m_mold));
+ llvm::Value* str_data_len /* i64* */ = llvm_utils->get_string_length(ASRUtils::get_string_type(x.m_mold), str, true);
+ llvm::Value* mold_length = get_string_length(x.m_mold);
+ builder->CreateStore(mold_length, str_data_len);
}
{ // Cast Ptr + Store In String
What is the plan here --- are we going with the approach in this PR, or another approach?
@certik We got the issue resolved #8885. The approach here is attempting to cover more cases as I think.
Perfect, let's make it a Draft then.