diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index abc0fc1c0b..54c685a853 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -309,7 +309,7 @@ RUN(NAME data_08 LABELS gfortran llvmImplicit) RUN(NAME data_09 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc c llvm17) RUN(NAME data_10 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME data_11 LABELS gfortran llvmImplicit) -# RUN(NAME data_12 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran llvm17) +RUN(NAME data_12 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran llvm17) RUN(NAME minmax_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc wasm c fortran llvm17) RUN(NAME arithmetic_if_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc c llvm17) # arithmetic tests use goto @@ -505,7 +505,7 @@ RUN(NAME arrays_52 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME global_allocatable_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME global_allocatable_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME global_array_pointer_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -# RUN(NAME global_array_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) +RUN(NAME global_array_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME pointer_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME pointer_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -991,7 +991,7 @@ RUN(NAME modules_53 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME modules_54 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME modules_55 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME modules_56 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc NOFAST llvm17) -# RUN(NAME modules_57 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) +RUN(NAME modules_57 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) # RUN(NAME modules_58 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRAFILES modules_58_module.f90) RUN(NAME operator_overloading_05_module3 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17 EXTRAFILES operator_overloading_05_module1.f90 operator_overloading_05_module2.f90) @@ -1269,7 +1269,7 @@ RUN(NAME string_27 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME string_28 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME string_29 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) COMPILE(NAME string_30 COMPILERS gfortran llvm llvm_wasm llvm_wasm_emcc fortran llvm17) -# RUN(NAME string_31 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) +RUN(NAME string_31 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME string_32 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_33 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) RUN(NAME string_34 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvm17) diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 025608d4e1..e4b43633ee 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -1598,11 +1598,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::Var_t *v = ASR::down_cast(object); v2 = ASR::down_cast(v->m_v); } - if( v2->m_storage == ASR::storage_typeType::Parameter ) { - v2->m_value = ASRUtils::EXPR(tmp); - } else { - v2->m_value = nullptr; - } + v2->m_value = ASRUtils::EXPR(tmp); v2->m_symbolic_value = ASRUtils::EXPR(tmp); SetChar var_deps_vec; var_deps_vec.reserve(al, 1); @@ -1685,11 +1681,7 @@ class CommonVisitor : public AST::BaseVisitor { if (ASR::is_a(*object)) { ASR::StructInstanceMember_t *mem = ASR::down_cast(object); ASR::Variable_t* v2 = ASR::down_cast(ASRUtils::symbol_get_past_external(mem->m_m)); - if( v2->m_storage == ASR::storage_typeType::Parameter ) { - v2->m_value = expression_value; - } else { - v2->m_value = nullptr; - } + v2->m_value = expression_value; v2->m_symbolic_value = expression_value; SetChar var_deps_vec; var_deps_vec.reserve(al, 1); @@ -1707,11 +1699,7 @@ class CommonVisitor : public AST::BaseVisitor { // y / 2 / ASR::Var_t *v = ASR::down_cast(object); ASR::Variable_t *v2 = ASR::down_cast(v->m_v); - if( v2->m_storage == ASR::storage_typeType::Parameter ) { - v2->m_value = expression_value; - } else { - v2->m_value = nullptr; - } + v2->m_value = expression_value; v2->m_symbolic_value = expression_value; SetChar var_deps_vec; var_deps_vec.reserve(al, 1); @@ -3281,9 +3269,6 @@ class CommonVisitor : public AST::BaseVisitor { } if( std::find(excluded_from_symtab.begin(), excluded_from_symtab.end(), sym) == excluded_from_symtab.end() ) { if ( !is_implicitly_declared && !is_external) { - if( storage_type != ASR::storage_typeType::Parameter ) { - value = nullptr; - } SetChar variable_dependencies_vec; variable_dependencies_vec.reserve(al, 1); ASRUtils::collect_variable_dependencies(al, variable_dependencies_vec, type, init_expr, value); diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 2e75aa8340..080d075385 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -4126,9 +4126,6 @@ static inline ASR::asr_t* make_Variable_t_util( ASR::intentType a_intent, ASR::expr_t* a_symbolic_value, ASR::expr_t* a_value, ASR::storage_typeType a_storage, ASR::ttype_t* a_type, ASR::symbol_t* a_type_declaration, ASR::abiType a_abi, ASR::accessType a_access, ASR::presenceType a_presence, bool a_value_attr) { - if( a_storage != ASR::storage_typeType::Parameter ) { - a_value = nullptr; - } return ASR::make_Variable_t(al, a_loc, a_parent_symtab, a_name, a_dependencies, n_dependencies, a_intent, a_symbolic_value, a_value, a_storage, a_type, a_type_declaration, a_abi, a_access, a_presence, a_value_attr); diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index 38d34978c4..83d2ae3ef9 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -673,8 +673,8 @@ class VerifyVisitor : public BaseWalkVisitor // For now restrict this check only to variables which are present // inside symbols which have a body. if( x.m_storage != ASR::storage_typeType::Parameter ) { - require(x.m_value == nullptr, - "Only parameter variables can have non-NULL value attribute." ) + // require(x.m_value == nullptr, + // "Only parameter variables can have non-NULL value attribute." ) require( (x.m_symbolic_value != nullptr && (ASRUtils::is_value_constant(x.m_symbolic_value) || ASRUtils::is_value_constant(ASRUtils::expr_value(x.m_symbolic_value))) ) || diff --git a/src/libasr/pass/simplifier.cpp b/src/libasr/pass/simplifier.cpp index caeaa62d6a..3ed354f452 100644 --- a/src/libasr/pass/simplifier.cpp +++ b/src/libasr/pass/simplifier.cpp @@ -1729,13 +1729,25 @@ class TransformVariableInitialiser: } Vec& result_vec = symtab2decls[current_scope]; ASR::expr_t* target = ASRUtils::EXPR(ASR::make_Var_t(al, loc, &(xx.base))); - exprs_with_target[xx.m_symbolic_value] = std::make_pair(target, targetType::OriginalTarget); + + // if `m_value` is present, then use that for converting it into + // assignment/association below, otherwise use `m_symbolic_value` + // for the same. As `m_value` is usually more "simplified" than + // `m_symbolic_value` + ASR::expr_t* value = nullptr; + if (xx.m_value) { + value = xx.m_value; + } else { + value = xx.m_symbolic_value; + } + + exprs_with_target[value] = std::make_pair(target, targetType::OriginalTarget); if (ASRUtils::is_pointer(x.m_type)) { result_vec.push_back(al, ASRUtils::STMT(ASR::make_Associate_t( - al, loc, target, xx.m_symbolic_value))); + al, loc, target, value))); } else { result_vec.push_back(al, ASRUtils::STMT(make_Assignment_t_util( - al, loc, target, xx.m_symbolic_value, nullptr, exprs_with_target))); + al, loc, target, value, nullptr, exprs_with_target))); } xx.m_symbolic_value = nullptr; xx.m_value = nullptr;