From f1c4b97e0e36bf489cf5b77c744ea1996985e565 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 7 Aug 2025 02:39:52 +0530 Subject: [PATCH 001/119] enh: check type-inheritance as part of type-checking for `ASR::StructType_t` Signed-off-by: Saurabh Kumar --- .../semantics/asr_implicit_cast_rules.h | 13 +- src/lfortran/semantics/ast_body_visitor.cpp | 38 ++--- src/lfortran/semantics/ast_common_visitor.h | 81 +++++---- .../semantics/ast_symboltable_visitor.cpp | 8 +- src/libasr/asr_builder.h | 31 ++-- src/libasr/asr_utils.cpp | 38 +++-- src/libasr/asr_utils.h | 161 +++++++++++------- src/libasr/asr_verify.cpp | 2 +- src/libasr/casting_utils.cpp | 13 +- src/libasr/codegen/asr_to_llvm.cpp | 7 +- src/libasr/pass/instantiate_template.cpp | 104 +---------- src/libasr/pass/instantiate_template.h | 7 +- .../pass/intrinsic_array_function_registry.h | 17 +- src/libasr/pass/intrinsic_functions.h | 24 +-- src/libasr/pass/pass_utils.cpp | 15 +- 15 files changed, 263 insertions(+), 296 deletions(-) diff --git a/src/lfortran/semantics/asr_implicit_cast_rules.h b/src/lfortran/semantics/asr_implicit_cast_rules.h index 7fa773580f3..6deda3b25fa 100644 --- a/src/lfortran/semantics/asr_implicit_cast_rules.h +++ b/src/lfortran/semantics/asr_implicit_cast_rules.h @@ -111,9 +111,16 @@ class ImplicitCastRules { ASR::expr_t **convert_can, ASR::ttype_t *source_type, ASR::ttype_t *dest_type, diag::Diagnostics &diag) { - if( ASRUtils::types_equal(source_type, dest_type, true) ) { - return; - } + if ((ASR::is_a(*ASRUtils::extract_type(source_type)) + || ASR::is_a(*ASRUtils::extract_type(dest_type))) + || ((ASR::is_a(*ASRUtils::extract_type(source_type)) + || ASR::is_a(*ASRUtils::extract_type(dest_type))))) { + // No casting supported currently for `StructType` and `FunctionType` + return; + } + if (ASRUtils::types_equal(source_type, dest_type, nullptr, nullptr, true)) { + return; + } ASR::ttype_t *source_type2 = ASRUtils::type_get_past_array( ASRUtils::type_get_past_pointer(source_type)); diff --git a/src/lfortran/semantics/ast_body_visitor.cpp b/src/lfortran/semantics/ast_body_visitor.cpp index 26890259ffb..3257d6732b5 100644 --- a/src/lfortran/semantics/ast_body_visitor.cpp +++ b/src/lfortran/semantics/ast_body_visitor.cpp @@ -1393,7 +1393,7 @@ class BodyVisitor : public CommonVisitor { if (ASRUtils::is_derived_type_similar(target_struct, value_struct)) { tmp = ASRUtils::make_Associate_t_util(al, x.base.base.loc, target, value); } - } else if (ASRUtils::types_equal(target_type, value_type)) { + } else if (ASRUtils::types_equal(target_type, value_type, target, value)) { tmp = ASRUtils::make_Associate_t_util(al, x.base.base.loc, target, value); } } @@ -1636,7 +1636,7 @@ class BodyVisitor : public CommonVisitor { for (size_t i = 0; i < alloc_args_vec.size(); i++) { if ( alloc_args_vec[i].n_dims == 0 ) { ASR::ttype_t* a_type = ASRUtils::type_get_past_allocatable(ASRUtils::expr_type(alloc_args_vec[i].m_a)); - if ( ASRUtils::check_equal_type(mold_type, a_type) ) { + if ( ASRUtils::check_equal_type(mold_type, a_type, mold, alloc_args_vec[i].m_a) ) { if (ASRUtils::is_array(mold_type)) { if (ASR::is_a(*mold_type) && ASR::down_cast(mold_type)->m_dims[0].m_length != nullptr) { ASR::Array_t* mold_array_type = ASR::down_cast(mold_type); @@ -1725,8 +1725,7 @@ class BodyVisitor : public CommonVisitor { } ASR::ttype_t* source_type = ASRUtils::expr_type(source); ASR::ttype_t* var_type = ASRUtils::expr_type(alloc_args_vec.p[i].m_a); - if (!ASRUtils::check_equal_type(source_type, var_type) - && !ASRUtils::check_class_assignment_compatibility(alloc_args_vec.p[i].m_a, source)) { + if (!ASRUtils::check_equal_type(source_type, var_type, source, alloc_args_vec.p[i].m_a)) { std::string source_type_str = ASRUtils::type_to_str_fortran(source_type); std::string var_type_str = ASRUtils::type_to_str_fortran(var_type); diag.add(Diagnostic( @@ -3125,7 +3124,7 @@ class BodyVisitor : public CommonVisitor { ImplicitCastRules::set_converted_value(al, x.base.base.loc, &value, ASRUtils::expr_type(value),ASRUtils::expr_type(to_return), diag); if (!ASRUtils::check_equal_type(ASRUtils::expr_type(to_return), - ASRUtils::expr_type(value))) { + ASRUtils::expr_type(value), to_return, value)) { std::string ltype = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(to_return)); std::string rtype = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(value)); diag.semantic_error_label( @@ -3396,7 +3395,7 @@ class BodyVisitor : public CommonVisitor { target->type == ASR::exprType::ArraySection || target->type == ASR::exprType::StructInstanceMember || target->type == ASR::exprType::UnionInstanceMember) && - !ASRUtils::check_equal_type(target_type, value_type)) { + !ASRUtils::check_equal_type(target_type, value_type, target, value)) { if (value->type == ASR::exprType::ArrayConstant) { ASR::ArrayConstant_t *ac = ASR::down_cast(value); int size = ASRUtils::get_fixed_size_of_array(ac->m_type); @@ -3447,14 +3446,15 @@ class BodyVisitor : public CommonVisitor { } } } - if (!ASRUtils::check_equal_type(ASRUtils::expr_type(target), ASRUtils::expr_type(value)) && - !ASRUtils::check_class_assignment_compatibility(target, value)) { + if (!ASRUtils::check_equal_type(ASRUtils::expr_type(target), + ASRUtils::expr_type(value), target, value)) { std::string ltype = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(target)); std::string rtype = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(value)); if(value->type == ASR::exprType::ArrayConstant) { ASR::ArrayConstant_t *ac = ASR::down_cast(value); for (size_t i = 0; i < (size_t) ASRUtils::get_fixed_size_of_array(ac->m_type); i++) { - if(!ASRUtils::check_equal_type(ASRUtils::expr_type(ASRUtils::fetch_ArrayConstant_value(al, ac, i)), ASRUtils::expr_type(target))) { + ASR::expr_t* arr_const_val = ASRUtils::fetch_ArrayConstant_value(al, ac, i); + if(!ASRUtils::check_equal_type(ASRUtils::expr_type(arr_const_val), ASRUtils::expr_type(target), arr_const_val, target)) { diag.semantic_error_label( "Type mismatch in assignment, the types must be compatible", {target->base.loc, value->base.loc}, @@ -3464,7 +3464,7 @@ class BodyVisitor : public CommonVisitor { } } LCOMPILERS_ASSERT(ASRUtils::is_array(ac->m_type)); - if(!ASRUtils::check_equal_type(ac->m_type, ASRUtils::expr_type(target))) { + if(!ASRUtils::check_equal_type(ac->m_type, ASRUtils::expr_type(target), value, target)) { diag.semantic_error_label( "Type mismatch in assignment, the types must be compatible", {target->base.loc, value->base.loc}, @@ -3475,7 +3475,7 @@ class BodyVisitor : public CommonVisitor { } else if(value->type == ASR::exprType::ArrayConstructor) { ASR::ArrayConstructor_t *ac = ASR::down_cast(value); for (size_t i = 0; i < ac->n_args; i++) { - if(!ASRUtils::check_equal_type(ASRUtils::expr_type(ac->m_args[i]), ASRUtils::expr_type(target))) { + if(!ASRUtils::check_equal_type(ASRUtils::expr_type(ac->m_args[i]), ASRUtils::expr_type(target), ac->m_args[i], target)) { diag.semantic_error_label( "Type mismatch in assignment, the types must be compatible", {target->base.loc, value->base.loc}, @@ -3485,7 +3485,7 @@ class BodyVisitor : public CommonVisitor { } } LCOMPILERS_ASSERT(ASRUtils::is_array(ac->m_type)); - if(!ASRUtils::check_equal_type(ac->m_type, ASRUtils::expr_type(target))) { + if(!ASRUtils::check_equal_type(ac->m_type, ASRUtils::expr_type(target), value, target)) { diag.semantic_error_label( "Type mismatch in assignment, the types must be compatible", {target->base.loc, value->base.loc}, @@ -3663,7 +3663,7 @@ class BodyVisitor : public CommonVisitor { ASR::List_t *list_type = ASR::down_cast(ASRUtils::expr_type(args[0])); ASR::ttype_t *arg_type = ASRUtils::expr_type(args[1]); ASR::ttype_t *contained_type = ASRUtils::get_contained_type((ASR::ttype_t *)list_type); - if (!ASRUtils::check_equal_type(contained_type, arg_type)) { + if (!ASRUtils::check_equal_type(contained_type, arg_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(arg_type); diag.add(Diagnostic( @@ -3689,7 +3689,7 @@ class BodyVisitor : public CommonVisitor { ASR::ttype_t *contained_type = ASRUtils::get_contained_type(ASRUtils::expr_type(args[0])); - if (!ASRUtils::check_equal_type(contained_type, ASRUtils::expr_type(args[2]))) { + if (!ASRUtils::check_equal_type(contained_type, ASRUtils::expr_type(args[2]), nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(args[2])); diag.add(Diagnostic( @@ -3721,7 +3721,7 @@ class BodyVisitor : public CommonVisitor { ASR::ttype_t *contained_type = ASRUtils::get_contained_type(ASRUtils::expr_type(args[0])); - if (!ASRUtils::check_equal_type(contained_type, ASRUtils::expr_type(args[1]))) { + if (!ASRUtils::check_equal_type(contained_type, ASRUtils::expr_type(args[1]), nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(args[2])); diag.add(Diagnostic( @@ -3760,7 +3760,7 @@ class BodyVisitor : public CommonVisitor { ASR::Set_t *set_type = ASR::down_cast(ASRUtils::expr_type(args[0])); ASR::ttype_t *arg_type = ASRUtils::expr_type(args[1]); ASR::ttype_t *contained_type = ASRUtils::get_contained_type((ASR::ttype_t *)set_type); - if (!ASRUtils::check_equal_type(contained_type, arg_type)) { + if (!ASRUtils::check_equal_type(contained_type, arg_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(arg_type); diag.add(Diagnostic( @@ -3782,7 +3782,7 @@ class BodyVisitor : public CommonVisitor { ASR::ttype_t *arg_type = ASRUtils::expr_type(args[2]); ASR::ttype_t *contained_type = ASRUtils::get_contained_type((ASR::ttype_t *)list_type); - if (!ASRUtils::check_equal_type(contained_type, arg_type)) { + if (!ASRUtils::check_equal_type(contained_type, arg_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(arg_type); diag.add(Diagnostic( @@ -3812,7 +3812,7 @@ class BodyVisitor : public CommonVisitor { ASR::ttype_t *dict_key_type = dict_type->m_key_type; ASR::ttype_t *dict_value_type = dict_type->m_value_type; - if (!ASRUtils::check_equal_type(dict_key_type, key_type)) { + if (!ASRUtils::check_equal_type(dict_key_type, key_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(dict_key_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(key_type); diag.add(Diagnostic( @@ -3824,7 +3824,7 @@ class BodyVisitor : public CommonVisitor { throw SemanticAbort(); } - if (!ASRUtils::check_equal_type(dict_value_type, value_type)) { + if (!ASRUtils::check_equal_type(dict_value_type, value_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(dict_value_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(value_type); diag.add(Diagnostic( diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 5ea59bc91c2..49cdf3b62ba 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -751,7 +751,7 @@ inline static void visit_Compare(Allocator &al, const AST::Compare_t &x, if( overloaded == nullptr ) { if (!ASRUtils::check_equal_type(ASRUtils::expr_type(left), - ASRUtils::expr_type(right))) { + ASRUtils::expr_type(right), left, right)) { diag.add(diag::Diagnostic( "Operands of comparison operator are of different types", Level::Error, Stage::Semantic, { @@ -912,7 +912,7 @@ inline static void visit_BoolOp(Allocator &al, const AST::BoolOp_t &x, ASR::ttype_t *right_type = ASRUtils::type_get_past_allocatable(ASRUtils::expr_type(right)); LCOMPILERS_ASSERT( - ASRUtils::check_equal_type(ASRUtils::expr_type(left), ASRUtils::expr_type(right))); + ASRUtils::check_equal_type(ASRUtils::expr_type(left), ASRUtils::expr_type(right), left, right)); ASR::expr_t *value = nullptr; ASR::expr_t* left_expr_value = ASRUtils::expr_value(left); @@ -2231,7 +2231,7 @@ class CommonVisitor : public AST::BaseVisitor { this->visit_expr(*a->m_value[curr_value++]); ASR::expr_t* value = ASRUtils::EXPR(tmp); current_variable_type_ = temp_current_variable_type_; - if (!ASRUtils::types_equal(ASRUtils::expr_type(value), array_type->m_type)) { + if (!ASRUtils::types_equal(ASRUtils::expr_type(value), array_type->m_type, value, object)) { diag.add(Diagnostic( "Type mismatch during data initialization", Level::Error, Stage::Semantic, { @@ -2282,7 +2282,7 @@ class CommonVisitor : public AST::BaseVisitor { } this->visit_expr(*a->m_value[j]); ASR::expr_t* value = ASRUtils::EXPR(tmp); - if (!ASRUtils::types_equal(ASRUtils::expr_type(value), array_type->m_type)) { + if (!ASRUtils::types_equal(ASRUtils::expr_type(value), array_type->m_type, value, object)) { diag.add(Diagnostic( "Type mismatch during data initialization", Level::Error, Stage::Semantic, { @@ -2795,18 +2795,21 @@ class CommonVisitor : public AST::BaseVisitor { } else { var__ = ASRUtils::EXPR2VAR(ASRUtils::EXPR(tmp)); } - if (!ASRUtils::check_equal_type(var_->m_type, var__->m_type)) { - diag.add(Diagnostic( - "The order of variables in common block must be same in all programs", - Level::Error, Stage::Semantic, { - Label("",{x.base.base.loc}) - })); - throw SemanticAbort(); - } else { - uint64_t hash = get_hash((ASR::asr_t*) var__); + if (!ASRUtils::check_equal_type(var_->m_type, + var__->m_type, + ASRUtils::get_expr_from_sym(al, &var_->base), + ASRUtils::get_expr_from_sym(al, &var__->base))) { + diag.add(Diagnostic( + "The order of variables in common block must be same in all programs", + Level::Error, + Stage::Semantic, + { Label("", { x.base.base.loc }) })); + throw SemanticAbort(); + } else { + uint64_t hash = get_hash((ASR::asr_t*) var__); common_variables_hash[hash] = common_block_struct_sym; - } - if (ASRUtils::is_array(var_->m_type) && ASR::is_a(*expr)) { + } + if (ASRUtils::is_array(var_->m_type) && ASR::is_a(*expr)) { /* Update type of original symbol case: @@ -5719,7 +5722,7 @@ class CommonVisitor : public AST::BaseVisitor { type = determine_type(x.base.base.loc, sym, x.m_vartype, false, false, dims, nullptr, type_declaration, ASR::abiType::Source); if (ASR::is_a(*type)) { - std::string derived_type_name = "ASRUtils::symbol_name(ASR::down_cast(type)->m_derived_type)"; // TODO: fix this regression + std::string derived_type_name = ASRUtils::symbol_name(type_declaration); diag.add(Diagnostic( "Invalid syntax of derived type for array constructor", Level::Error, Stage::Semantic, { @@ -5763,9 +5766,6 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t* extracted_type { type ? ASRUtils::extract_type(type) : nullptr }; size_t n_elements = 0; for (size_t i=0; ivisit_expr(*x.m_args[0]); - static ASR::expr_t* first_element = ASRUtils::EXPR(tmp); - this->visit_expr(*x.m_args[i]); ASR::expr_t *expr = ASRUtils::EXPR(tmp); @@ -5789,15 +5789,13 @@ class CommonVisitor : public AST::BaseVisitor { } else if (is_type_spec_ommitted) { // as the "type-spec" is omitted, each element should be the same type ASR::ttype_t* extracted_new_type = ASRUtils::extract_type(expr_type); - if (!ASRUtils::check_equal_type(extracted_new_type, extracted_type) - && (!ASRUtils::check_class_assignment_compatibility(first_element, expr) - || !ASRUtils::check_class_assignment_compatibility(expr, first_element))) { + if (!ASRUtils::check_equal_type(extracted_new_type, extracted_type, expr, expr)) { diag.add(Diagnostic("Element in `" + ASRUtils::type_to_str_with_type(extracted_type) + "` array constructor is `" + ASRUtils::type_to_str_with_type(extracted_new_type) + "`", Level::Error, Stage::Semantic, {Label("",{expr->base.loc})})); throw SemanticAbort(); } - } else if (!ASRUtils::check_equal_type(expr_type, type)) { + } else if (!ASRUtils::check_equal_type(expr_type, type, expr, expr)) { ImplicitCastRules::set_converted_value(al, expr->base.loc, &expr, expr_type, type, diag); } @@ -6501,7 +6499,7 @@ class CommonVisitor : public AST::BaseVisitor { } } - if(!ASRUtils::check_equal_type(arg_type,orig_arg_type) && + if(!ASRUtils::check_equal_type(arg_type,orig_arg_type, arg, func->m_args[i]) && !ASRUtils::check_class_assignment_compatibility(func->m_args[i], arg)){ std::string arg_str = ASRUtils::type_to_str_fortran(arg_type); std::string orig_arg_str = ASRUtils::type_to_str_fortran(orig_arg_type); @@ -7715,7 +7713,7 @@ class CommonVisitor : public AST::BaseVisitor { } else if (ASR::is_a(*ASRUtils::expr_type(args[0]))) { ASR::Dict_t* dict_type = ASR::down_cast(ASRUtils::expr_type(args[0])); ASR::ttype_t* key_type = dict_type->m_key_type; - if (!ASRUtils::check_equal_type(ASRUtils::expr_type(args[1]), key_type)) { + if (!ASRUtils::check_equal_type(ASRUtils::expr_type(args[1]), key_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(key_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(args[1])); diag.add(Diagnostic( @@ -7825,7 +7823,7 @@ class CommonVisitor : public AST::BaseVisitor { } else if (ASR::is_a(*ASRUtils::expr_type(args[0]))) { ASR::Dict_t* dict_type = ASR::down_cast(ASRUtils::expr_type(args[0])); ASR::ttype_t* key_type = dict_type->m_key_type; - if (!ASRUtils::check_equal_type(ASRUtils::expr_type(args[1]), key_type)) { + if (!ASRUtils::check_equal_type(ASRUtils::expr_type(args[1]), key_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(key_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(args[1])); diag.add(Diagnostic( @@ -7874,7 +7872,7 @@ class CommonVisitor : public AST::BaseVisitor { right = ASRUtils::EXPR(tmp); right_type = ASRUtils::get_contained_type(ASRUtils::expr_type(right)); - if (!ASRUtils::check_equal_type(list_el_type, right_type)) { + if (!ASRUtils::check_equal_type(list_el_type, right_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(list_el_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(right_type); diag.add(Diagnostic( @@ -7949,7 +7947,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t* left_type = ASRUtils::expr_type(left), *right_type = ASRUtils::expr_type(right); - if (!ASRUtils::check_equal_type(left_type, right_type)){ + if (!ASRUtils::check_equal_type(left_type, right_type, left, right)) { std::string left_type_str = ASRUtils::type_to_str_python(left_type); std::string right_type_str = ASRUtils::type_to_str_python(right_type); diag.add(Diagnostic( @@ -8001,7 +7999,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t *arg_type = ASRUtils::expr_type(arg); - if (contained_type && !ASRUtils::check_equal_type(contained_type, arg_type)) { + if (contained_type && !ASRUtils::check_equal_type(contained_type, arg_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(arg_type); diag.add(Diagnostic( @@ -8040,7 +8038,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t *arg_type = ASRUtils::expr_type(arg); - if (contained_type && !ASRUtils::check_equal_type(contained_type, arg_type)) { + if (contained_type && !ASRUtils::check_equal_type(contained_type, arg_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(arg_type); diag.add(Diagnostic( @@ -8085,7 +8083,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t *arg_type = ASRUtils::expr_type(arg); - if (contained_type && !ASRUtils::check_equal_type(contained_type, arg_type)) { + if (contained_type && !ASRUtils::check_equal_type(contained_type, arg_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(arg_type); diag.add(Diagnostic( @@ -8147,7 +8145,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t *arg_type = ASRUtils::expr_type(arg); - if (contained_type && !ASRUtils::check_equal_type(contained_type, arg_type)) { + if (contained_type && !ASRUtils::check_equal_type(contained_type, arg_type, nullptr, nullptr)) { std::string contained_type_str = ASRUtils::type_to_str_fortran(contained_type); std::string arg_type_str = ASRUtils::type_to_str_fortran(arg_type); diag.add(Diagnostic( @@ -9298,7 +9296,7 @@ class CommonVisitor : public AST::BaseVisitor { if( type == nullptr ) { type = type_; } else { - if (!unique_type || !ASRUtils::types_equal(type_, type)) { + if (!unique_type || !ASRUtils::types_equal(type_, type, expr, expr)) { unique_type = false; } } @@ -9513,7 +9511,7 @@ class CommonVisitor : public AST::BaseVisitor { if( type == nullptr ) { type = type_; } else { - if (!unique_type || !ASRUtils::types_equal(type_, type)) { + if (!unique_type || !ASRUtils::types_equal(type_, type, expr, expr)) { unique_type = false; } } @@ -9619,7 +9617,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t* n_type = ASRUtils::expr_type(n); ASR::ttype_t* w_type = ASRUtils::expr_type(w); - if (!ASRUtils::check_equal_type(n_type, w_type)) { + if (!ASRUtils::check_equal_type(n_type, w_type, nullptr, nullptr)) { if (ASRUtils::is_integer(*n_type) && ASRUtils::is_integer(*w_type)) { w = ASRUtils::EXPR(ASR::make_Cast_t(al, loc, w, ASR::cast_kindType::IntegerToInteger, n_type, nullptr)); } @@ -9973,7 +9971,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t *dest_type = ASRUtils::expr_type(dest); ASR::ttype_t *source_type = ASRUtils::expr_type(source); - if (!ASRUtils::check_equal_type(dest_type, source_type)) { + if (!ASRUtils::check_equal_type(dest_type, source_type, dest, source)) { std::string dtype = ASRUtils::type_to_str_fortran(dest_type); std::string stype = ASRUtils::type_to_str_fortran(source_type); diag.add(Diagnostic( @@ -10311,7 +10309,7 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::is_integer(*right_type)) { // Don't Check. } else if (!ASRUtils::check_equal_type(ASRUtils::expr_type(left), - ASRUtils::expr_type(right)) && overloaded == nullptr) { + ASRUtils::expr_type(right), left, right) && overloaded == nullptr) { std::string ltype = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(left)); std::string rtype = ASRUtils::type_to_str_fortran(ASRUtils::expr_type(right)); diag.add(Diagnostic( @@ -10496,7 +10494,8 @@ class CommonVisitor : public AST::BaseVisitor { // Handling local variables passed as instantiate's arguments ASR::symbol_t *arg_sym = current_scope->resolve_symbol(arg); ASR::ttype_t *arg_type = ASRUtils::symbol_type(arg_sym); - if (!ASRUtils::check_equal_type(arg_type, param_type)) { + if (!ASRUtils::check_equal_type(arg_type, param_type, ASRUtils::get_expr_from_sym( + al, arg_sym), ASRUtils::get_expr_from_sym(al, param_sym))) { diag.add(Diagnostic("The type of " + arg + " does not match the type of " + param, Level::Error, Stage::Semantic, {Label("", {loc})})); throw SemanticAbort(); @@ -10616,7 +10615,7 @@ class CommonVisitor : public AST::BaseVisitor { source_type, dest_type, diag); return_type = ASRUtils::duplicate_type(al, ftype); value = ASRUtils::EXPR(ASRUtils::make_Binop_util(al, loc, binop, left, right, dest_type)); - if (!ASRUtils::check_equal_type(dest_type, return_type)) { + if (!ASRUtils::check_equal_type(dest_type, return_type, f->m_args[1], f->m_return_var)) { diag.add(Diagnostic("Unapplicable types for intrinsic operator " + op_name, Level::Error, Stage::Semantic, {Label("", {loc})})); throw SemanticAbort(); @@ -10782,11 +10781,11 @@ class CommonVisitor : public AST::BaseVisitor { ASR::Function_t* func = ASR::down_cast(proc); if ((is_binary && func->n_args != 2) || (!is_binary && func->n_args != 1)) continue; - bool args_match = ASRUtils::check_equal_type(ASRUtils::expr_type(func->m_args[0]), left_type); + bool args_match = ASRUtils::check_equal_type(ASRUtils::expr_type(func->m_args[0]), left_type, func->m_args[0], first_operand); if (is_binary) { args_match = args_match && ASRUtils::check_equal_type(ASRUtils::expr_type(func->m_args[1]), - right_type); + right_type, func->m_args[1], second_operand); } if (!args_match) continue; diff --git a/src/lfortran/semantics/ast_symboltable_visitor.cpp b/src/lfortran/semantics/ast_symboltable_visitor.cpp index 4de9b6ae698..dd413c8e480 100644 --- a/src/lfortran/semantics/ast_symboltable_visitor.cpp +++ b/src/lfortran/semantics/ast_symboltable_visitor.cpp @@ -1739,7 +1739,8 @@ class SymbolTableVisitor : public CommonVisitor { if (ASRUtils::get_FunctionType(f2)->m_abi == ASR::abiType::ExternalUndefined || // TODO: Throw error when interface definition and implementation signatures are different ASRUtils::get_FunctionType(f2)->m_deftype == ASR::deftypeType::Interface) { - if (!ASRUtils::types_equal(f2->m_function_signature, func->m_function_signature)) { + if (!ASRUtils::types_equal(f2->m_function_signature, func->m_function_signature, + ASRUtils::get_expr_from_sym(al, f1), ASRUtils::get_expr_from_sym(al, func_sym))) { diag.add(diag::Diagnostic( "Argument(s) or return type mismatch in interface and implementation", diag::Level::Error, diag::Stage::Semantic, { @@ -3951,7 +3952,8 @@ class SymbolTableVisitor : public CommonVisitor { // Handling local variables passed as instantiate's arguments ASR::symbol_t *arg_sym = current_scope->resolve_symbol(arg); ASR::ttype_t *arg_type = ASRUtils::symbol_type(arg_sym); - if (!ASRUtils::check_equal_type(arg_type, param_type)) { + if (!ASRUtils::check_equal_type(arg_type, param_type, ASRUtils::get_expr_from_sym( + al, arg_sym), ASRUtils::get_expr_from_sym(al, param_sym))) { diag.add(diag::Diagnostic( "The type of " + arg + " does not match the type of " + param, diag::Level::Error, diag::Stage::Semantic, { @@ -4102,7 +4104,7 @@ class SymbolTableVisitor : public CommonVisitor { source_type, dest_type, diag); return_type = ASRUtils::duplicate_type(al, ftype); value = ASRUtils::EXPR(ASRUtils::make_Binop_util(al, x.base.base.loc, binop, left, right, dest_type)); - if (!ASRUtils::check_equal_type(dest_type, return_type)) { + if (!ASRUtils::check_equal_type(dest_type, return_type, f->m_args[1], f->m_return_var)) { diag.add(diag::Diagnostic( "Unapplicable types for intrinsic operator " + op_name, diag::Level::Error, diag::Stage::Semantic, { diff --git a/src/libasr/asr_builder.h b/src/libasr/asr_builder.h index 0e588469215..7681c8afcb1 100644 --- a/src/libasr/asr_builder.h +++ b/src/libasr/asr_builder.h @@ -477,7 +477,7 @@ class ASRBuilder { } ASR::expr_t *And(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { @@ -496,7 +496,7 @@ class ASRBuilder { } ASR::expr_t *Or(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { @@ -515,7 +515,7 @@ class ASRBuilder { } ASR::expr_t *Xor(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { @@ -551,7 +551,7 @@ class ASRBuilder { } ASR::expr_t *Add(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { @@ -580,7 +580,7 @@ class ASRBuilder { } ASR::expr_t *Sub(ASR::expr_t *left, ASR::expr_t *right, ASR::expr_t* value = nullptr) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { @@ -605,7 +605,7 @@ class ASRBuilder { } ASR::expr_t *Mul(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { @@ -644,7 +644,7 @@ class ASRBuilder { } ASR::expr_t *Div(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { @@ -669,7 +669,7 @@ class ASRBuilder { } ASR::expr_t *Pow(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { @@ -735,7 +735,7 @@ class ASRBuilder { // Compare ----------------------------------------------------------------- ASR::expr_t *Gt(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); switch(type->type){ case ASR::ttypeType::Integer: { @@ -759,7 +759,7 @@ class ASRBuilder { } ASR::expr_t *Lt(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right),left, right)); ASR::ttype_t *type = expr_type(left); switch(type->type){ case ASR::ttypeType::Integer: { @@ -783,7 +783,7 @@ class ASRBuilder { } ASR::expr_t *GtE(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); switch(type->type){ case ASR::ttypeType::Integer: { @@ -807,7 +807,7 @@ class ASRBuilder { } ASR::expr_t *LtE(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); switch(type->type){ case ASR::ttypeType::Integer: { @@ -831,7 +831,7 @@ class ASRBuilder { } ASR::expr_t *Eq(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); switch(type->type){ case ASR::ttypeType::Integer: { @@ -858,7 +858,7 @@ class ASRBuilder { } ASR::expr_t *NotEq(ASR::expr_t *left, ASR::expr_t *right) { - LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right))); + LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); ASR::ttype_t *type = expr_type(left); switch(type->type){ case ASR::ttypeType::Integer: { @@ -981,8 +981,7 @@ class ASRBuilder { } ASR::stmt_t *Assignment(ASR::expr_t *lhs, ASR::expr_t *rhs) { - LCOMPILERS_ASSERT_MSG(check_equal_type(expr_type(lhs), expr_type(rhs)) || - check_class_assignment_compatibility(lhs, rhs), + LCOMPILERS_ASSERT_MSG(check_equal_type(expr_type(lhs), expr_type(rhs), lhs, rhs), type_to_str_python(expr_type(lhs)) + ", " + type_to_str_python(expr_type(rhs))); return STMT(ASRUtils::make_Assignment_t_util(al, loc, lhs, rhs, nullptr, false)); } diff --git a/src/libasr/asr_utils.cpp b/src/libasr/asr_utils.cpp index 182460151a5..75564351589 100644 --- a/src/libasr/asr_utils.cpp +++ b/src/libasr/asr_utils.cpp @@ -158,12 +158,17 @@ ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression) } case ASR::exprType::StructInstanceMember: { ASR::StructInstanceMember_t* struct_instance_member = ASR::down_cast(expression); - ASR::symbol_t* member_sym = ASRUtils::symbol_get_past_external(struct_instance_member->m_m); - if (ASR::is_a(*member_sym)) { - return member_sym; + if (ASR::is_a(*ASRUtils::symbol_get_past_external(struct_instance_member->m_m))) { + // Special case: Can have `StructInstanceMember` like `var%member` where `member` is + // parent struct of the struct used to declare `var`. + // Please see assignment `c%parent_t = p` in + // `integration_tests/derived_types_73.f90` for an example. + return ASRUtils::symbol_get_past_external(struct_instance_member->m_m); + } else { + LCOMPILERS_ASSERT(ASR::is_a(*ASRUtils::symbol_get_past_external(struct_instance_member->m_m))); + ASR::Variable_t* var = ASR::down_cast(ASRUtils::symbol_get_past_external(struct_instance_member->m_m)); + return var->m_type_declaration; } - ASR::Variable_t* var = ASR::down_cast(member_sym); - return var->m_type_declaration; } case ASR::exprType::ArrayConstructor: { ASR::ArrayConstructor_t* array_constructor = ASR::down_cast(expression); @@ -565,7 +570,7 @@ const ASR::Function_t* get_function_from_expr(ASR::expr_t* expr) { if (!expr) { throw LCompilersException("Passed `ASR::expr_t expr` is nullptr."); } - if (!ASR::is_a(*ASRUtils::expr_type(expr))) { + if (!ASR::is_a(*ASRUtils::extract_type(ASRUtils::expr_type(expr)))) { throw LCompilersException("`ttype_t` of passed `ASR::expr_t expr` is not `ASR::exprType::FunctionType`."); } @@ -1229,10 +1234,8 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right, if( func->n_args == 2 ) { ASR::ttype_t* left_arg_type = ASRUtils::expr_type(func->m_args[0]); ASR::ttype_t* right_arg_type = ASRUtils::expr_type(func->m_args[1]); - if( (ASRUtils::check_equal_type(left_arg_type, left_type) && - ASRUtils::check_equal_type(right_arg_type, right_type)) - || (ASRUtils::check_class_assignment_compatibility(func->m_args[0], left) && - ASRUtils::check_class_assignment_compatibility(func->m_args[1], right)) ) { + if(ASRUtils::check_equal_type(left_arg_type, left_type, func->m_args[0], left) && + ASRUtils::check_equal_type(right_arg_type, right_type, func->m_args[1], right)) { found = true; Vec a_args; a_args.reserve(al, 2); @@ -1314,8 +1317,7 @@ void process_overloaded_unary_minus_function(ASR::symbol_t* proc, ASR::expr_t* o std::string matched_func_name = ""; if( func->n_args == 1 ) { ASR::ttype_t* operand_arg_type = ASRUtils::expr_type(func->m_args[0]); - if (ASRUtils::check_equal_type(operand_arg_type, operand_type) - || ASRUtils::check_class_assignment_compatibility(func->m_args[0], operand)) { + if (ASRUtils::check_equal_type(operand_arg_type, operand_type, func->m_args[0], operand)) { found = true; Vec a_args; a_args.reserve(al, 1); @@ -1507,8 +1509,8 @@ void process_overloaded_assignment_function(ASR::symbol_t* proc, ASR::expr_t* ta if( subrout->n_args == 2 ) { ASR::ttype_t* target_arg_type = ASRUtils::expr_type(subrout->m_args[0]); ASR::ttype_t* value_arg_type = ASRUtils::expr_type(subrout->m_args[1]); - if( ASRUtils::types_equal(target_arg_type, target_type) && - ASRUtils::types_equal(value_arg_type, value_type) ) { + if( ASRUtils::types_equal(target_arg_type, target_type, subrout->m_args[0], target) && + ASRUtils::types_equal(value_arg_type, value_type, subrout->m_args[1], value) ) { std::string arg0_name = ASRUtils::symbol_name(ASR::down_cast(subrout->m_args[0])->m_v); std::string arg1_name = ASRUtils::symbol_name(ASR::down_cast(subrout->m_args[1])->m_v); if( pass_arg != nullptr ) { @@ -1619,7 +1621,7 @@ void process_overloaded_read_write_function(std::string &read_write, ASR::symbol ASR::Function_t* subrout = ASR::down_cast(proc); std::string matched_subrout_name = ""; ASR::ttype_t* func_arg_type = ASRUtils::expr_type(subrout->m_args[0]); - if( ASRUtils::types_equal(func_arg_type, arg_type) ) { + if( ASRUtils::types_equal(func_arg_type, arg_type, subrout->m_args[0], args[0]) ) { std::string arg0_name = ASRUtils::symbol_name(ASR::down_cast(subrout->m_args[0])->m_v); if( pass_arg != nullptr ) { std::string pass_arg_str = std::string(pass_arg); @@ -2170,7 +2172,7 @@ bool argument_types_match(const Vec& args, } if (s1 && s2) { if (!ASRUtils::is_derived_type_similar(ASR::down_cast(s1), ASR::down_cast(s2))) return false; - } else if (!types_equal(arg1, arg2, !is_elemental)) { + } else if (!types_equal(arg1, arg2, args[i].m_value, sub.m_args[i], !ASRUtils::get_FunctionType(sub)->m_elemental)) { return false; } } else if (ASR::is_a(*sub_arg_sym)) { @@ -2178,7 +2180,9 @@ bool argument_types_match(const Vec& args, ASR::ttype_t *arg1 = ASRUtils::expr_type(args[i].m_value); ASR::ttype_t *arg2 = f->m_function_signature; - if (!types_equal(arg1, arg2, false)) { + Allocator al(512); + if (!types_equal(arg1, arg2, args[i].m_value, + ASRUtils::get_expr_from_sym(al, &f->base), false)) { return false; } } diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index f7e37a086e0..8f951ab1c04 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -69,7 +69,7 @@ ASR::asr_t* make_Binop_util(Allocator &al, const Location& loc, ASR::binopType b ASR::asr_t* make_Cmpop_util(Allocator &al, const Location& loc, ASR::cmpopType cmpop, ASR::expr_t* lexpr, ASR::expr_t* rexpr, ASR::ttype_t* ttype); -inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y, bool check_for_dimensions=false); +inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y, ASR::expr_t* x_expr, ASR::expr_t* y_expr, bool check_for_dimensions=false); static inline std::string type_to_str_python(const ASR::ttype_t *t, bool for_error_message=true); @@ -205,6 +205,25 @@ static inline ASR::FunctionType_t* get_FunctionType(ASR::symbol_t* x) { return func_type; } +static inline ASR::Function_t* get_function(ASR::symbol_t* x) +{ + ASR::symbol_t* a_name = ASRUtils::symbol_get_past_external(x); + + if (ASR::is_a(*a_name)) { + return ASR::down_cast(a_name); + } else if (ASR::is_a(*a_name)) { + return ASR::down_cast(ASRUtils::symbol_get_past_external( + ASR::down_cast(a_name)->m_type_declaration)); + } else if (ASR::is_a(*a_name)) { + return ASR::down_cast(ASRUtils::symbol_get_past_external( + ASR::down_cast(a_name)->m_proc)); + } else { + LCOMPILERS_ASSERT(false); + } + + return nullptr; +} + static inline const ASR::symbol_t *symbol_get_past_external(const ASR::symbol_t *f) { if (f->type == ASR::symbolType::ExternalSymbol) { @@ -425,9 +444,6 @@ static inline ASR::ttype_t* symbol_type(const ASR::symbol_t *f) return nullptr; } -// Recursively creates a Var node expression from a symbol. -// For Variable: returns Var node for the variable. -// For Function: resolves m_return_var, gets the variable, and returns Var node for it. static inline ASR::expr_t* get_expr_from_sym(Allocator& al, ASR::symbol_t* sym) { sym = ASRUtils::symbol_get_past_external(sym); switch (sym->type) { @@ -435,9 +451,7 @@ static inline ASR::expr_t* get_expr_from_sym(Allocator& al, ASR::symbol_t* sym) return ASRUtils::EXPR(ASR::make_Var_t(al, sym->base.loc, sym)); } case ASR::symbolType::Function: { - ASR::Function_t* fn = ASR::down_cast(sym); - ASR::Var_t* ret_var = ASR::down_cast(fn->m_return_var); - return get_expr_from_sym(al, ret_var->m_v); + return ASRUtils::EXPR(ASR::make_Var_t(al, sym->base.loc, sym)); } default: { throw LCompilersException("get_expr_from_sym: Only Variable and Function symbols are supported."); @@ -3732,7 +3746,7 @@ inline bool expr_equal(ASR::expr_t* x, ASR::expr_t* y) { case ASR::exprType::Var: { ASR::Var_t* var_x = ASR::down_cast(x); ASR::Var_t* var_y = ASR::down_cast(y); - return check_equal_type(expr_type(&var_x->base), expr_type(&var_y->base), true); + return check_equal_type(expr_type(&var_x->base), expr_type(&var_y->base), x, y, true); } case ASR::exprType::IntegerConstant: { ASR::IntegerConstant_t* intconst_x = ASR::down_cast(x); @@ -3792,7 +3806,7 @@ inline bool dimensions_compatible(ASR::dimension_t* dims_a, size_t n_dims_a, return (total_a == -1) || (total_b == -1) || (total_a >= total_b); } -inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, +inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, ASR::expr_t* a_expr, ASR::expr_t* b_expr, bool check_for_dimensions=false) { // TODO: If anyone of the input or argument is derived type then // add support for checking member wise types and do not compare @@ -3823,7 +3837,7 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, case (ASR::ttypeType::Array): { ASR::Array_t* a2 = ASR::down_cast(a); ASR::Array_t* b2 = ASR::down_cast(b); - if( !types_equal(a2->m_type, b2->m_type) ) { + if( !types_equal(a2->m_type, b2->m_type, a_expr, b_expr) ) { return false; } @@ -3877,17 +3891,16 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, case (ASR::ttypeType::List) : { ASR::List_t *a2 = ASR::down_cast(a); ASR::List_t *b2 = ASR::down_cast(b); - return types_equal(a2->m_type, b2->m_type); + return types_equal(a2->m_type, b2->m_type, a_expr, b_expr); } case (ASR::ttypeType::StructType) : { - ASR::StructType_t *st1 = ASR::down_cast(a); - ASR::StructType_t *st2 = ASR::down_cast(b); - - if (st1->n_data_member_types != st2->n_data_member_types) return false; - for (size_t i = 0; i < st1->n_data_member_types; i++) { - if (!types_equal(st1->m_data_member_types[i], st2->m_data_member_types[i])) { - return false; - } + ASR::Struct_t* x_struct = ASR::down_cast(ASRUtils::symbol_get_past_external( + ASRUtils::get_struct_sym_from_struct_expr(a_expr))); + ASR::Struct_t* y_struct = ASR::down_cast(ASRUtils::symbol_get_past_external( + ASRUtils::get_struct_sym_from_struct_expr(b_expr))); + + if (!is_derived_type_similar(x_struct, y_struct)) { + return false; } return true; @@ -3906,17 +3919,23 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, case ASR::ttypeType::FunctionType: { ASR::FunctionType_t* a2 = ASR::down_cast(a); ASR::FunctionType_t* b2 = ASR::down_cast(b); + + ASR::Function_t* left_func = const_cast(ASRUtils::get_function_from_expr(a_expr)); + ASR::Function_t* right_func = const_cast(ASRUtils::get_function_from_expr(b_expr)); + if( a2->n_arg_types != b2->n_arg_types || (a2->m_return_var_type != nullptr && b2->m_return_var_type == nullptr) || (a2->m_return_var_type == nullptr && b2->m_return_var_type != nullptr) ) { return false; } for( size_t i = 0; i < a2->n_arg_types; i++ ) { - if( !types_equal(a2->m_arg_types[i], b2->m_arg_types[i], true) ) { + if( !types_equal(a2->m_arg_types[i], b2->m_arg_types[i], left_func->m_args[i], + right_func->m_args[i], true) ) { return false; } } - if( !types_equal(a2->m_return_var_type, b2->m_return_var_type, true) ) { + if( !types_equal(a2->m_return_var_type, b2->m_return_var_type, left_func->m_return_var, + right_func->m_return_var, true) ) { return false; } return true; @@ -3928,8 +3947,9 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, } inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, - std::map> subs, + std::map> subs, ASR::expr_t* a_expr, ASR::expr_t* b_expr, bool check_for_dimensions=false) { + ASR::Struct_t* a_struct = nullptr; // TODO: If anyone of the input or argument is derived type then // add support for checking member wise types and do not compare // directly. From stdlib_string len(pattern) error @@ -3945,6 +3965,9 @@ inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, if (ASR::is_a(*a)) { ASR::TypeParameter_t* a_tp = ASR::down_cast(a); a = subs[a_tp->m_param].first; + if (ASR::is_a(*ASRUtils::extract_type(a))) { + a_struct = ASR::down_cast(ASRUtils::symbol_get_past_external(subs[a_tp->m_param].second)); + } } if (a->type == b->type) { // TODO: check dims @@ -3953,7 +3976,7 @@ inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, case (ASR::ttypeType::Array): { ASR::Array_t* a2 = ASR::down_cast(a); ASR::Array_t* b2 = ASR::down_cast(b); - if( !types_equal_with_substitution(a2->m_type, b2->m_type, subs) ) { + if( !types_equal_with_substitution(a2->m_type, b2->m_type, subs, a_expr, b_expr) ) { return false; } @@ -4007,17 +4030,21 @@ inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, case (ASR::ttypeType::List) : { ASR::List_t *a2 = ASR::down_cast(a); ASR::List_t *b2 = ASR::down_cast(b); - return types_equal_with_substitution(a2->m_type, b2->m_type, subs); - } - case (ASR::ttypeType::StructType) : { - ASR::StructType_t *st1 = ASR::down_cast(a); - ASR::StructType_t *st2 = ASR::down_cast(b); - - if (st1->n_data_member_types != st2->n_data_member_types) return false; - for (size_t i = 0; i < st1->n_data_member_types; i++) { - if (!types_equal(st1->m_data_member_types[i], st2->m_data_member_types[i])) { - return false; - } + return types_equal_with_substitution(a2->m_type, b2->m_type, subs, nullptr, nullptr); + } + case (ASR::ttypeType::StructType) : { + ASR::Struct_t* x_struct = nullptr; + if (a_struct) { + x_struct = a_struct; + } else { + x_struct = ASR::down_cast(ASRUtils::symbol_get_past_external( + ASRUtils::get_struct_sym_from_struct_expr(a_expr))); + } + ASR::Struct_t* y_struct = ASR::down_cast(ASRUtils::symbol_get_past_external( + ASRUtils::get_struct_sym_from_struct_expr(b_expr))); + + if (!is_derived_type_similar(x_struct, y_struct)) { + return false; } return true; @@ -4036,17 +4063,21 @@ inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, case ASR::ttypeType::FunctionType: { ASR::FunctionType_t* a2 = ASR::down_cast(a); ASR::FunctionType_t* b2 = ASR::down_cast(b); + + ASR::Function_t* left_func = const_cast(ASRUtils::get_function_from_expr(a_expr)); + ASR::Function_t* right_func = const_cast(ASRUtils::get_function_from_expr(b_expr)); + if( a2->n_arg_types != b2->n_arg_types || (a2->m_return_var_type != nullptr && b2->m_return_var_type == nullptr) || (a2->m_return_var_type == nullptr && b2->m_return_var_type != nullptr) ) { return false; } for( size_t i = 0; i < a2->n_arg_types; i++ ) { - if( !types_equal_with_substitution(a2->m_arg_types[i], b2->m_arg_types[i], subs, true) ) { + if( !types_equal_with_substitution(a2->m_arg_types[i], b2->m_arg_types[i], subs, left_func->m_args[i], right_func->m_args[i], true) ) { return false; } } - if( !types_equal_with_substitution(a2->m_return_var_type, b2->m_return_var_type, subs, true) ) { + if( !types_equal_with_substitution(a2->m_return_var_type, b2->m_return_var_type, subs, left_func->m_return_var, right_func->m_return_var, true) ) { return false; } return true; @@ -4057,7 +4088,7 @@ inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, return false; } -inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y, bool check_for_dimensions) { +inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y, ASR::expr_t* x_expr, ASR::expr_t* y_expr, bool check_for_dimensions) { ASR::ttype_t *x_underlying, *y_underlying; x_underlying = nullptr; y_underlying = nullptr; @@ -4078,33 +4109,33 @@ inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y, bool check_for_di if( y_underlying ) { y = y_underlying; } - return check_equal_type(x, y); + return check_equal_type(x, y, x_expr, y_expr); } if( ASR::is_a(*x) || ASR::is_a(*y) ) { x = ASRUtils::type_get_past_pointer(x); y = ASRUtils::type_get_past_pointer(y); - return check_equal_type(x, y); + return check_equal_type(x, y, x_expr, y_expr); } else if( ASR::is_a(*x) || ASR::is_a(*y) ) { x = ASRUtils::type_get_past_allocatable(x); y = ASRUtils::type_get_past_allocatable(y); - return check_equal_type(x, y); + return check_equal_type(x, y, x_expr, y_expr); } else if (ASR::is_a(*x) && ASR::is_a(*y)) { x = ASR::down_cast(x)->m_type; y = ASR::down_cast(y)->m_type; - return check_equal_type(x, y); + return check_equal_type(x, y, x_expr, y_expr); } else if (ASR::is_a(*x) && ASR::is_a(*y)) { x = ASR::down_cast(x)->m_type; y = ASR::down_cast(y)->m_type; - return check_equal_type(x, y); + return check_equal_type(x, y, x_expr, y_expr); } else if (ASR::is_a(*x) && ASR::is_a(*y)) { ASR::ttype_t *x_key_type = ASR::down_cast(x)->m_key_type; ASR::ttype_t *y_key_type = ASR::down_cast(y)->m_key_type; ASR::ttype_t *x_value_type = ASR::down_cast(x)->m_value_type; ASR::ttype_t *y_value_type = ASR::down_cast(y)->m_value_type; - return (check_equal_type(x_key_type, y_key_type) && - check_equal_type(x_value_type, y_value_type)); + return (check_equal_type(x_key_type, y_key_type, nullptr, nullptr) && + check_equal_type(x_value_type, y_value_type, nullptr, nullptr)); } else if (ASR::is_a(*x) && ASR::is_a(*y)) { ASR::Tuple_t *a = ASR::down_cast(x); ASR::Tuple_t *b = ASR::down_cast(y); @@ -4113,7 +4144,7 @@ inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y, bool check_for_di } bool result = true; for (size_t i=0; in_type; i++) { - result = result && check_equal_type(a->m_type[i], b->m_type[i]); + result = result && check_equal_type(a->m_type[i], b->m_type[i], nullptr, nullptr); if (!result) { return false; } @@ -4128,13 +4159,17 @@ inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y, bool check_for_di } else if (ASR::is_a(*x) && ASR::is_a(*y)) { ASR::FunctionType_t* left_ft = ASR::down_cast(x); ASR::FunctionType_t* right_ft = ASR::down_cast(y); + + ASR::Function_t* left_func = const_cast(ASRUtils::get_function_from_expr(x_expr)); + ASR::Function_t* right_func = const_cast(ASRUtils::get_function_from_expr(y_expr)); + if (left_ft->n_arg_types != right_ft->n_arg_types) { return false; } bool result; for (size_t i=0; in_arg_types; i++) { result = check_equal_type(left_ft->m_arg_types[i], - right_ft->m_arg_types[i]); + right_ft->m_arg_types[i], left_func->m_args[i], right_func->m_args[i]); if (!result) return false; } if (left_ft->m_return_var_type == nullptr && @@ -4143,12 +4178,12 @@ inline bool check_equal_type(ASR::ttype_t* x, ASR::ttype_t* y, bool check_for_di } else if (left_ft->m_return_var_type != nullptr && right_ft->m_return_var_type != nullptr) { return check_equal_type(left_ft->m_return_var_type, - right_ft->m_return_var_type); + right_ft->m_return_var_type, left_func->m_return_var, right_func->m_return_var); } return false; } - return types_equal(x, y, check_for_dimensions); + return types_equal(x, y, x_expr, y_expr, check_for_dimensions); } inline bool check_class_assignment_compatibility(ASR::expr_t* target, ASR::expr_t* value) { @@ -6192,17 +6227,8 @@ static inline void Call_t_body(Allocator& al, ASR::symbol_t* a_name, is_method = false; } ASR::FunctionType_t* func_type = get_FunctionType(a_name); - ASR::Function_t* func = nullptr; - - if (ASR::is_a(*a_name_)) { - func = ASR::down_cast(a_name_); - } else if (ASR::is_a(*a_name_)) { - func = ASR::down_cast(ASRUtils::symbol_get_past_external( - ASR::down_cast(a_name_)->m_type_declaration)); - } else if (ASR::is_a(*a_name_)) { - func = ASR::down_cast(ASRUtils::symbol_get_past_external( - ASR::down_cast(a_name_)->m_proc)); - } + ASR::Function_t* func = ASRUtils::get_function(a_name); + for( size_t i = 0; i < n_args; i++ ) { if( a_args[i].m_value == nullptr ) { continue; @@ -6227,7 +6253,19 @@ static inline void Call_t_body(Allocator& al, ASR::symbol_t* a_name, !(ASR::is_a(*ASRUtils::type_get_past_array(arg_type)) || ASR::is_a(*ASRUtils::type_get_past_array(orig_arg_type))) && a_dt == nullptr ) { - if (implicit_argument_casting && !ASRUtils::check_equal_type(arg_type, orig_arg_type)) { + // Pass actual argument expression to `check_equal_type()` if the expression is + // `ASR::FunctionParam_t`. + ASR::expr_t* arg_expr = arg; + ASR::expr_t* orig_arg_expr = func->m_args[i + is_method]; + if (ASR::is_a(*arg_expr)) { + ASR::FunctionParam_t* func_param = ASR::down_cast(arg_expr); + arg_expr = func->m_args[func_param->m_param_number]; + } + if (ASR::is_a(*orig_arg_expr)) { + ASR::FunctionParam_t* func_param = ASR::down_cast(orig_arg_expr); + orig_arg_expr = func->m_args[func_param->m_param_number]; + } + if (implicit_argument_casting && !ASRUtils::check_equal_type(arg_type, orig_arg_type, arg_expr, orig_arg_expr)) { if (ASR::is_a(*a_name_)) { // get current_scope SymbolTable* current_scope = nullptr; @@ -6331,8 +6369,7 @@ static inline void Call_t_body(Allocator& al, ASR::symbol_t* a_name, // not setup to return errors, so we need to refactor things. // For now we just do an assert. /*TODO: Remove this if check once intrinsic procedures are implemented correctly*/ - LCOMPILERS_ASSERT_MSG( ASRUtils::check_equal_type(arg_type, orig_arg_type) || - ASRUtils::check_class_assignment_compatibility(orig_arg, arg), + LCOMPILERS_ASSERT_MSG( ASRUtils::check_equal_type(arg_type, orig_arg_type, arg_expr, orig_arg_expr), "ASRUtils::check_equal_type(" + ASRUtils::get_type_code(arg_type) + ", " + ASRUtils::get_type_code(orig_arg_type) + ")"); } diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index 1d24349d197..4f1ebce862a 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -612,7 +612,7 @@ class VerifyVisitor : public BaseWalkVisitor "All members of EnumType must have their values to be set. " + std::string(itr_var->m_name) + " doesn't seem to follow this rule in " + std::string(x.m_name) + " EnumType."); - require(ASRUtils::check_equal_type(itr_var->m_type, common_type), + require(ASRUtils::check_equal_type(itr_var->m_type, common_type, nullptr, nullptr), "All members of EnumType must the same type. " + std::string(itr_var->m_name) + " doesn't seem to follow this rule in " + std::string(x.m_name) + " EnumType."); diff --git a/src/libasr/casting_utils.cpp b/src/libasr/casting_utils.cpp index 45ab7443046..15853701b19 100644 --- a/src/libasr/casting_utils.cpp +++ b/src/libasr/casting_utils.cpp @@ -60,7 +60,7 @@ namespace LCompilers::CastingUtil { ASR::ttype_t* right_type = ASRUtils::expr_type(right_expr); left_type = ASRUtils::type_get_past_pointer(left_type); right_type = ASRUtils::type_get_past_pointer(right_type); - if( ASRUtils::check_equal_type(left_type, right_type) || + if( ASRUtils::check_equal_type(left_type, right_type, left_expr, right_expr) || ASRUtils::is_character(*left_type) || ASRUtils::is_character(*right_type) ) { return 2; } @@ -133,7 +133,16 @@ namespace LCompilers::CastingUtil { } cast_kind = type_rules.at(cast_key); } - if( ASRUtils::check_equal_type(src, dest, true) ) { + if ((ASR::is_a(*ASRUtils::extract_type(src)) + || ASR::is_a(*ASRUtils::extract_type(dest))) + || ((ASR::is_a(*ASRUtils::extract_type(src)) + || ASR::is_a(*ASRUtils::extract_type(dest))))) { + // No casting supported currently for `StructType` and `FunctionType` + return expr; + } + // We do not cast from `StructTypeToStructType`, so no expression will be used in the + // below comparison, hence pass `nullptr`. + if (ASRUtils::check_equal_type(src, dest, nullptr, nullptr, true)) { return expr; } // TODO: Fix loc diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 969dd1164e6..6d51ceb9f3e 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -6510,7 +6510,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } if( ASRUtils::is_array(target_type) && ASRUtils::is_array(value_type) && - ASRUtils::check_equal_type(target_type, value_type) ) { + ASRUtils::check_equal_type(target_type, value_type, x.m_target, x.m_value) ) { bool data_only_copy = false; ASR::array_physical_typeType target_ptype = ASRUtils::extract_physical_type(target_type); ASR::array_physical_typeType value_ptype = ASRUtils::extract_physical_type(value_type); @@ -9039,7 +9039,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } llvm::Type* target_base_type = llvm_utils->get_type_from_ttype_t_util(const_cast(&x.base), ASRUtils::type_get_past_array(x.m_type), module.get()); llvm::Type* target_llvm_type = target_base_type->getPointerTo(); - if ( !ASRUtils::types_equal(ASRUtils::extract_type(ASRUtils::expr_type(x.m_source)), ASRUtils::extract_type(x.m_type), false) && + if ( !ASRUtils::types_equal(ASRUtils::extract_type(ASRUtils::expr_type(x.m_source)), ASRUtils::extract_type(x.m_type), + x.m_source, const_cast(&x.base), false) && !( ASR::is_a(*ASRUtils::extract_type(ASRUtils::expr_type(x.m_source))) && ASRUtils::is_integer(*ASRUtils::extract_type(x.m_type)) && ASR::down_cast(ASRUtils::extract_type(x.m_type))->m_kind == 1 ) /*Workaround (Refer to : `transfer_05`, `array_06_transfer`), scalar mold shold have scalar LHS*/ ) { tmp = llvm_utils->CreateLoad2(target_base_type, builder->CreateBitCast(source_ptr, target_llvm_type)); @@ -11650,7 +11651,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::ttype_t* expected_arg_type = ASRUtils::expr_type(expected_arg); ASR::ttype_t* passed_arg_type = ASRUtils::expr_type(passed_arg); if (ASR::is_a(*passed_arg)) { - if (!ASRUtils::types_equal(expected_arg_type, passed_arg_type, true)) { + if (!ASRUtils::types_equal(expected_arg_type, passed_arg_type, expected_arg, passed_arg, true)) { throw CodeGenError("Type mismatch in subroutine call, expected `" + ASRUtils::type_to_str_python(expected_arg_type) + "`, passed `" + ASRUtils::type_to_str_python(passed_arg_type) + "`", x.m_args[i].m_value->base.loc); } diff --git a/src/libasr/pass/instantiate_template.cpp b/src/libasr/pass/instantiate_template.cpp index 1907c3c5e34..395db85795c 100644 --- a/src/libasr/pass/instantiate_template.cpp +++ b/src/libasr/pass/instantiate_template.cpp @@ -777,7 +777,7 @@ ASR::symbol_t* rename_symbol(Allocator &al, return t.rename_symbol(sym); } -bool check_restriction(std::map> type_subs, +bool check_restriction(Allocator& al, std::map> type_subs, std::map &symbol_subs, ASR::Function_t *f, ASR::symbol_t *sym_arg) { std::string f_name = f->m_name; @@ -793,7 +793,7 @@ bool check_restriction(std::map(f_param); if (!ASRUtils::check_equal_type(type_subs[f_tp->m_param].first, - arg_param)) { + arg_param, ASRUtils::get_expr_from_sym(al, type_subs[f_tp->m_param].second), arg->m_args[i])) { return false; } } @@ -807,7 +807,8 @@ bool check_restriction(std::map(*f_ret)) { ASR::TypeParameter_t *return_tp = ASR::down_cast(f_ret); - if (!ASRUtils::check_equal_type(type_subs[return_tp->m_param].first, arg_ret)) { + if (!ASRUtils::check_equal_type(type_subs[return_tp->m_param].first, arg_ret, + ASRUtils::get_expr_from_sym(al, type_subs[return_tp->m_param].second), arg->m_return_var)) { return false; } } @@ -820,99 +821,6 @@ bool check_restriction(std::map type_subs, - std::map &symbol_subs, - ASR::Function_t *f, ASR::symbol_t *sym_arg, const Location &loc, - diag::Diagnostics &diagnostics) { - std::string f_name = f->m_name; - ASR::Function_t *arg = ASR::down_cast(ASRUtils::symbol_get_past_external(sym_arg)); - std::string arg_name = arg->m_name; - if (f->n_args != arg->n_args) { - std::string f_narg = std::to_string(f->n_args); - std::string arg_narg = std::to_string(arg->n_args); - diagnostics.add(diag::Diagnostic( - "Number of arguments mismatch, restriction expects a function with " + f_narg - + " parameters, but a function with " + arg_narg + " parameters is provided", - diag::Level::Error, diag::Stage::Semantic, { - diag::Label(arg_name + " has " + arg_narg + " parameters", - {loc, arg->base.base.loc}), - diag::Label(f_name + " has " + f_narg + " parameters", - {f->base.base.loc}) - } - )); - throw SemanticAbort(); - } - for (size_t i = 0; i < f->n_args; i++) { - ASR::ttype_t *f_param = ASRUtils::expr_type(f->m_args[i]); - ASR::ttype_t *arg_param = ASRUtils::expr_type(arg->m_args[i]); - if (ASR::is_a(*f_param)) { - ASR::TypeParameter_t *f_tp - = ASR::down_cast(f_param); - if (!ASRUtils::check_equal_type(type_subs[f_tp->m_param], - arg_param)) { - std::string rtype = ASRUtils::type_to_str_fortran(type_subs[f_tp->m_param]); - std::string rvar = ASRUtils::symbol_name( - ASR::down_cast(f->m_args[i])->m_v); - std::string atype = ASRUtils::type_to_str_fortran(arg_param); - std::string avar = ASRUtils::symbol_name( - ASR::down_cast(arg->m_args[i])->m_v); - diagnostics.add(diag::Diagnostic( - "Restriction type mismatch with provided function argument", - diag::Level::Error, diag::Stage::Semantic, { - diag::Label("", {loc}), - diag::Label("Restriction's parameter " + rvar + " of type " + rtype, - {f->m_args[i]->base.loc}), - diag::Label("Function's parameter " + avar + " of type " + atype, - {arg->m_args[i]->base.loc}) - } - )); - throw SemanticAbort(); - } - } - } - if (f->m_return_var) { - if (!arg->m_return_var) { - diagnostics.add(diag::Diagnostic( - "The restriction argument " + arg_name - + " should have a return value", - diag::Level::Error, diag::Stage::Semantic, { - diag::Label("", {loc})})); - throw SemanticAbort(); - } - ASR::ttype_t *f_ret = ASRUtils::expr_type(f->m_return_var); - ASR::ttype_t *arg_ret = ASRUtils::expr_type(arg->m_return_var); - if (ASR::is_a(*f_ret)) { - ASR::TypeParameter_t *return_tp - = ASR::down_cast(f_ret); - if (!ASRUtils::check_equal_type(type_subs[return_tp->m_param], arg_ret)) { - std::string rtype = ASRUtils::type_to_str_fortran(type_subs[return_tp->m_param]); - std::string atype = ASRUtils::type_to_str_fortran(arg_ret); - diagnostics.add(diag::Diagnostic( - "Restriction type mismatch with provided function argument", - diag::Level::Error, diag::Stage::Semantic, { - diag::Label("", {loc}), - diag::Label("Restriction's return type " + rtype, - {f->m_return_var->base.loc}), - diag::Label("Function's return type " + atype, - {arg->m_return_var->base.loc}) - } - )); - throw SemanticAbort(); - } - } - } else { - if (arg->m_return_var) { - diagnostics.add(diag::Diagnostic( - "The restriction argument " + arg_name - + " should not have a return value", - diag::Level::Error, diag::Stage::Semantic, { - diag::Label("", {loc})})); - throw SemanticAbort(); - } - } - symbol_subs[f_name] = sym_arg; -} - } // namespace LPython namespace LFortran { @@ -1926,7 +1834,7 @@ bool check_restriction(std::mapn_args; i++) { ASR::ttype_t *f_param = ASRUtils::expr_type(f->m_args[i]); ASR::ttype_t *arg_param = ASRUtils::expr_type(arg->m_args[i]); - if (!ASRUtils::types_equal_with_substitution(f_param, arg_param, type_subs)) { + if (!ASRUtils::types_equal_with_substitution(f_param, arg_param, type_subs, f->m_args[i], arg->m_args[i])) { if (report) { std::string rtype = ASRUtils::type_to_str_with_substitution(f_param, type_subs); std::string rvar = ASRUtils::symbol_name( @@ -1962,7 +1870,7 @@ bool check_restriction(std::mapm_return_var); ASR::ttype_t *arg_ret = ASRUtils::expr_type(arg->m_return_var); - if (!ASRUtils::types_equal_with_substitution(f_ret, arg_ret, type_subs)) { + if (!ASRUtils::types_equal_with_substitution(f_ret, arg_ret, type_subs, f->m_return_var, arg->m_return_var)) { if (report) { std::string rtype = ASRUtils::type_to_str_with_substitution(f_ret, type_subs); std::string atype = ASRUtils::type_to_str_fortran(arg_ret); diff --git a/src/libasr/pass/instantiate_template.h b/src/libasr/pass/instantiate_template.h index 87dea47aff9..08b5e94e41f 100644 --- a/src/libasr/pass/instantiate_template.h +++ b/src/libasr/pass/instantiate_template.h @@ -32,15 +32,10 @@ namespace LPython { SymbolTable *current_scope, std::string new_sym_name, ASR::symbol_t *sym); - bool check_restriction(std::map> type_subs, + bool check_restriction(Allocator& al, std::map> type_subs, std::map &symbol_subs, ASR::Function_t *f, ASR::symbol_t *sym_arg); - void report_check_restriction(std::map> type_subs, - std::map &symbol_subs, - ASR::Function_t *f, ASR::symbol_t *sym_arg, const Location &loc, - diag::Diagnostics &diagnostics); - } namespace LFortran { diff --git a/src/libasr/pass/intrinsic_array_function_registry.h b/src/libasr/pass/intrinsic_array_function_registry.h index 475cdc83e22..245c3a35c39 100644 --- a/src/libasr/pass/intrinsic_array_function_registry.h +++ b/src/libasr/pass/intrinsic_array_function_registry.h @@ -108,8 +108,9 @@ static inline void verify_array_int_real_cmplx(ASR::expr_t* array, ASR::ttype_t* int array_n_dims = ASRUtils::extract_n_dims_from_ttype(array_type); ASRUtils::require_impl(array_n_dims > 0, "Input to " + intrinsic_func_name + " intrinsic must always be an array", loc, diagnostics); + // `check_equal_type` will return `false` automatically for types that are not same, so pass `nullptr` for `expr` ASRUtils::require_impl(ASRUtils::check_equal_type( - return_type, array_type, false), + return_type, array_type, nullptr, nullptr, false), intrinsic_func_name + " intrinsic must return an output of the same type as input", loc, diagnostics); int return_n_dims = ASRUtils::extract_n_dims_from_ttype(return_type); ASRUtils::require_impl(return_n_dims == 0, @@ -128,8 +129,9 @@ static inline void verify_array_int_real(ASR::expr_t* array, ASR::ttype_t* retur int array_n_dims = ASRUtils::extract_n_dims_from_ttype(array_type); ASRUtils::require_impl(array_n_dims > 0, "Input to " + intrinsic_func_name + " intrinsic must always be an array", loc, diagnostics); + // `check_equal_type` will return `false` automatically for types that are not same, so pass `nullptr` for `expr` ASRUtils::require_impl(ASRUtils::check_equal_type( - return_type, array_type, false), + return_type, array_type, nullptr, nullptr, false), intrinsic_func_name + " intrinsic must return an output of the same type as input", loc, diagnostics); int return_n_dims = ASRUtils::extract_n_dims_from_ttype(return_type); ASRUtils::require_impl(return_n_dims == 0, @@ -152,8 +154,9 @@ static inline void verify_array_dim(ASR::expr_t* array, ASR::expr_t* dim, ASRUtils::require_impl(ASRUtils::is_integer(*ASRUtils::expr_type(dim)), "`dim` argument must be an integer", loc, diagnostics); + // `check_equal_type` will return `false` automatically for types that are not same, so pass `nullptr` for `expr` ASRUtils::require_impl(ASRUtils::check_equal_type( - return_type, array_type, false), + return_type, array_type, nullptr, nullptr, false), intrinsic_func_name + " intrinsic must return an output of the same type as input", loc, diagnostics); int return_n_dims = ASRUtils::extract_n_dims_from_ttype(return_type); ASRUtils::require_impl(array_n_dims == return_n_dims + 1, @@ -921,7 +924,7 @@ static inline ASR::expr_t* instantiate_ArrIntrinsic(Allocator &al, bool same_allocatable_type = (ASRUtils::is_allocatable(arg_type) == ASRUtils::is_allocatable(ASRUtils::expr_type(f->m_args[0]))); if (same_allocatable_type && ASRUtils::types_equal(ASRUtils::expr_type(f->m_args[0]), - arg_type) && orig_array_rank == rank) { + arg_type, f->m_args[0], new_args[0].m_value) && orig_array_rank == rank) { return builder.Call(s, new_args, return_type, nullptr); } else { new_func_name += std::to_string(i); @@ -2252,7 +2255,7 @@ namespace Eoshift { append_error(diag, "The argument `shift` in `eoshift` must be of type Integer", shift->base.loc); return nullptr; } - if( is_boundary_present && (!ASRUtils::check_equal_type(type_boundary, type_array))) { + if( is_boundary_present && (!ASRUtils::check_equal_type(type_boundary, type_array, boundary, array))) { append_error(diag, "'boundary' argument of 'eoshift' intrinsic must be a scalar of same type as array type", boundary->base.loc); return nullptr; } @@ -2649,7 +2652,7 @@ namespace IanyIall { bool same_allocatable_type = (ASRUtils::is_allocatable(arg_type) == ASRUtils::is_allocatable(ASRUtils::expr_type(f->m_args[0]))); if (same_allocatable_type && ASRUtils::types_equal(ASRUtils::expr_type(f->m_args[0]), - ASRUtils::expr_type(new_args[0].m_value), true) && orig_array_rank == rank) { + ASRUtils::expr_type(new_args[0].m_value), f->m_args[0], new_args[0].m_value, true) && orig_array_rank == rank) { return builder.Call(s, new_args, return_type, nullptr); } else { new_func_name += std::to_string(i); @@ -3005,7 +3008,7 @@ namespace AnyAll { bool same_allocatable_type = (ASRUtils::is_allocatable(arg_type) == ASRUtils::is_allocatable(ASRUtils::expr_type(f->m_args[0]))); if (same_allocatable_type && ASRUtils::types_equal(ASRUtils::expr_type(f->m_args[0]), - ASRUtils::expr_type(new_args[0].m_value), true) && orig_array_rank == rank) { + ASRUtils::expr_type(new_args[0].m_value), f->m_args[0], new_args[0].m_value, true) && orig_array_rank == rank) { return builder.Call(s, new_args, logical_return_type, nullptr); } else { new_func_name += std::to_string(i); diff --git a/src/libasr/pass/intrinsic_functions.h b/src/libasr/pass/intrinsic_functions.h index d9f4f39c351..4d99deee37f 100644 --- a/src/libasr/pass/intrinsic_functions.h +++ b/src/libasr/pass/intrinsic_functions.h @@ -392,7 +392,8 @@ static inline void verify_args(const ASR::IntrinsicElementalFunction_t& x, ASR::ttype_t* input_type = ASRUtils::expr_type(x.m_args[0]); ASR::ttype_t* output_type = x.m_type; - ASRUtils::require_impl(ASRUtils::check_equal_type(input_type, output_type, true), + ASRUtils::require_impl(ASRUtils::check_equal_type(input_type, output_type, x.m_args[0], + const_cast(&x.base), true), "The input and output type of elemental intrinsic, " + std::to_string(static_cast(x.m_intrinsic_id)) + " must exactly match, input type: " + @@ -766,7 +767,8 @@ namespace Abs { std::to_string(input_kind) + " output kind: " + std::to_string(output_kind), loc, diagnostics); } else { - ASRUtils::require_impl(ASRUtils::check_equal_type(input_type, output_type, true), + ASRUtils::require_impl(ASRUtils::check_equal_type(input_type, output_type, + x.m_args[0], const_cast(&x.base), true), "The input and output type of Abs intrinsic must exactly match, input type: " + input_type_str + " output type: " + output_type_str, loc, diagnostics); } @@ -5790,7 +5792,7 @@ static inline void verify_args(const ASR::IntrinsicElementalFunction_t& x, diag: x.base.base.loc, diagnostics); ASR::ttype_t* arg0_type = ASRUtils::expr_type(x.m_args[0]); ASRUtils::require_impl(ASR::is_a(*arg0_type) && - ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), ASRUtils::get_contained_type(arg0_type)), + ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), ASRUtils::get_contained_type(arg0_type), nullptr, nullptr), "First argument to list.index must be of list type and " "second argument must be of same type as list elemental type", x.base.base.loc, diagnostics); @@ -5826,7 +5828,7 @@ static inline ASR::asr_t* create_ListIndex(Allocator& al, const Location& loc, ASR::ttype_t *type = ASRUtils::expr_type(list_expr); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::expr_type(args[1]); - if (!ASRUtils::check_equal_type(ele_type, list_type)) { + if (!ASRUtils::check_equal_type(ele_type, list_type, nullptr, nullptr)) { std::string fnd = ASRUtils::get_type_code(ele_type); std::string org = ASRUtils::get_type_code(list_type); append_error(diag, @@ -5890,7 +5892,7 @@ static inline void verify_args(const ASR::IntrinsicElementalFunction_t& x, diag: break; } ASRUtils::require_impl(ASRUtils::check_equal_type(x.m_type, - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]))), + ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0])), nullptr, nullptr), "Return type of list.pop must be of same type as list's element type", x.base.base.loc, diagnostics); } @@ -5953,7 +5955,7 @@ static inline void verify_args(const ASR::IntrinsicElementalFunction_t& x, diag: x.base.base.loc, diagnostics); ASRUtils::require_impl(ASR::is_a(*x.m_type) && ASRUtils::check_equal_type(ASRUtils::get_contained_type(x.m_type), - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]), 0)), + ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]), 0), nullptr, nullptr), "Return type of dict.keys must be of list of dict key element type", x.base.base.loc, diagnostics); } @@ -6000,7 +6002,7 @@ static inline void verify_args(const ASR::IntrinsicElementalFunction_t& x, diag: x.base.base.loc, diagnostics); ASRUtils::require_impl(ASR::is_a(*x.m_type) && ASRUtils::check_equal_type(ASRUtils::get_contained_type(x.m_type), - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]), 1)), + ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]), 1), nullptr, nullptr), "Return type of dict.values must be of list of dict value element type", x.base.base.loc, diagnostics); } @@ -6046,7 +6048,7 @@ static inline void verify_args(const ASR::IntrinsicElementalFunction_t& x, diag: "First argument to set.add must be of set type", x.base.base.loc, diagnostics); ASRUtils::require_impl(ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]))), + ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0])), nullptr, nullptr), "Second argument to set.add must be of same type as set's element type", x.base.base.loc, diagnostics); ASRUtils::require_impl(x.m_type == nullptr, @@ -6068,7 +6070,7 @@ static inline ASR::asr_t* create_SetAdd(Allocator& al, const Location& loc, return nullptr; } if (!ASRUtils::check_equal_type(ASRUtils::expr_type(args[1]), - ASRUtils::get_contained_type(ASRUtils::expr_type(args[0])))) { + ASRUtils::get_contained_type(ASRUtils::expr_type(args[0])), nullptr, nullptr)) { append_error(diag, "Argument to set.add must be of same type as set's " "element type", loc); return nullptr; @@ -6097,7 +6099,7 @@ static inline void verify_args(const ASR::IntrinsicElementalFunction_t& x, diag: "First argument to set.remove must be of set type", x.base.base.loc, diagnostics); ASRUtils::require_impl(ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]))), + ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0])), nullptr, nullptr), "Second argument to set.remove must be of same type as set's element type", x.base.base.loc, diagnostics); ASRUtils::require_impl(x.m_type == nullptr, @@ -6119,7 +6121,7 @@ static inline ASR::asr_t* create_SetRemove(Allocator& al, const Location& loc, return nullptr; } if (!ASRUtils::check_equal_type(ASRUtils::expr_type(args[1]), - ASRUtils::get_contained_type(ASRUtils::expr_type(args[0])))) { + ASRUtils::get_contained_type(ASRUtils::expr_type(args[0])), nullptr, nullptr)) { append_error(diag, "Argument to set.remove must be of same type as set's " "element type", loc); return nullptr; diff --git a/src/libasr/pass/pass_utils.cpp b/src/libasr/pass/pass_utils.cpp index e9884ec6953..63804250484 100644 --- a/src/libasr/pass/pass_utils.cpp +++ b/src/libasr/pass/pass_utils.cpp @@ -343,7 +343,8 @@ namespace LCompilers { if( current_scope->get_symbol(str_name) == nullptr || !ASRUtils::check_equal_type( ASRUtils::symbol_type(current_scope->get_symbol(str_name)), - var_type, true + var_type, ASRUtils::get_expr_from_sym( + al, current_scope->get_symbol(str_name)), var, true ) ) { ASR::symbol_t* type_decl = nullptr; if ( var != nullptr ) { @@ -392,7 +393,7 @@ namespace LCompilers { ASR::symbol_t* idx_sym = current_scope->get_symbol(idx_var_name); if( ASR::is_a(*idx_sym) ) { ASR::Variable_t* idx_var = ASR::down_cast(idx_sym); - if( !(ASRUtils::check_equal_type(idx_var->m_type, int32_type) && + if( !(ASRUtils::check_equal_type(idx_var->m_type, int32_type, nullptr, nullptr) && idx_var->m_symbolic_value == nullptr) ) { idx_var_name = current_scope->get_unique_name(idx_var_name, false); } @@ -437,7 +438,7 @@ namespace LCompilers { ASR::symbol_t* idx_sym = current_scope->get_symbol(idx_var_name); if( ASR::is_a(*idx_sym) ) { ASR::Variable_t* idx_var = ASR::down_cast(idx_sym); - if( !(ASRUtils::check_equal_type(idx_var->m_type, int32_type) && + if( !(ASRUtils::check_equal_type(idx_var->m_type, int32_type, nullptr, nullptr) && idx_var->m_symbolic_value == nullptr) ) { idx_var_name = current_scope->get_unique_name(idx_var_name, false); } @@ -481,7 +482,7 @@ namespace LCompilers { ASR::symbol_t* idx_sym = current_scope->get_symbol(idx_var_name); if( ASR::is_a(*idx_sym) ) { ASR::Variable_t* idx_var = ASR::down_cast(idx_sym); - if( !(ASRUtils::check_equal_type(idx_var->m_type, int32_type) && + if( !(ASRUtils::check_equal_type(idx_var->m_type, int32_type, nullptr, nullptr) && idx_var->m_symbolic_value == nullptr) ) { idx_var_name = current_scope->get_unique_name(idx_var_name, false); } @@ -1488,7 +1489,7 @@ namespace LCompilers { ASR::expr_t* curr_init = ASRUtils::fetch_ArrayConstant_value(al, x, k); ASR::expr_t* res = PassUtils::create_array_ref(arr_var, idx_var, al, current_scope); - if( perform_cast && !ASRUtils::types_equal(ASRUtils::expr_type(curr_init), casted_type) ) { + if( perform_cast && !ASRUtils::types_equal(ASRUtils::expr_type(curr_init), casted_type, nullptr, nullptr) ) { curr_init = ASRUtils::EXPR(ASR::make_Cast_t( al, curr_init->base.loc, curr_init, cast_kind, casted_type, nullptr)); } @@ -1538,7 +1539,7 @@ namespace LCompilers { ASR::expr_t* curr_init = ASRUtils::fetch_ArrayConstant_value(al, x, k); ASR::expr_t* res = PassUtils::create_array_ref(arr_var, idx_vars, al, current_scope); - if( perform_cast && !ASRUtils::types_equal(ASRUtils::expr_type(curr_init), casted_type) ) { + if( perform_cast && !ASRUtils::types_equal(ASRUtils::expr_type(curr_init), casted_type, nullptr, nullptr) ) { curr_init = ASRUtils::EXPR(ASR::make_Cast_t( al, curr_init->base.loc, curr_init, cast_kind, casted_type, nullptr)); } @@ -1589,7 +1590,7 @@ namespace LCompilers { }, current_scope, result_vec); } else { ASR::expr_t* res = PassUtils::create_array_ref(arr_var, idx_var, al, current_scope); - if( perform_cast && !ASRUtils::types_equal(ASRUtils::expr_type(curr_init), casted_type) ) { + if( perform_cast && !ASRUtils::types_equal(ASRUtils::expr_type(curr_init), casted_type, nullptr, nullptr) ) { curr_init = ASRUtils::EXPR(ASR::make_Cast_t( al, curr_init->base.loc, curr_init, cast_kind, casted_type, nullptr)); } From 6f555c698ce9b238d9041da8264680e5f29c0141 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 7 Aug 2025 03:14:28 +0530 Subject: [PATCH 002/119] tests: update error reference Signed-off-by: Saurabh Kumar --- tests/reference/asr-continue_compilation_1-04b6d40.json | 2 +- tests/reference/asr-continue_compilation_1-04b6d40.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/reference/asr-continue_compilation_1-04b6d40.json b/tests/reference/asr-continue_compilation_1-04b6d40.json index 47c664993c2..d6a8ee67e2b 100644 --- a/tests/reference/asr-continue_compilation_1-04b6d40.json +++ b/tests/reference/asr-continue_compilation_1-04b6d40.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-continue_compilation_1-04b6d40.stderr", - "stderr_hash": "4bb4b609a78aa476292ce81879e2be7096a232f082ed499420042f0a", + "stderr_hash": "9ee0a8339530271d5d5de924e82d09c98d6b31347f02815cea0aa9dc", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/asr-continue_compilation_1-04b6d40.stderr b/tests/reference/asr-continue_compilation_1-04b6d40.stderr index e9599f59c0c..5a65d104e31 100644 --- a/tests/reference/asr-continue_compilation_1-04b6d40.stderr +++ b/tests/reference/asr-continue_compilation_1-04b6d40.stderr @@ -797,7 +797,7 @@ semantic error: Invalid syntax of derived type for array constructor --> tests/errors/continue_compilation_1.f90:342:12 | 342 | arr = [type(MyClass) :: v1, v2, v3] - | ^^^^^^^^^^^^^ help: use just the derived type name 'ASRUtils::symbol_name(ASR::down_cast(type)->m_derived_type)', without the keyword 'type' + | ^^^^^^^^^^^^^ help: use just the derived type name 'myclass', without the keyword 'type' semantic error: Class type `NonExistingType` is not defined --> tests/errors/continue_compilation_1.f90:344:11 From dc3623c07197895371042a0c65a9096143985338 Mon Sep 17 00:00:00 2001 From: Aditya Trivedi Date: Thu, 7 Aug 2025 15:55:43 +0530 Subject: [PATCH 003/119] chore: Change name of cpu_impl.h to cuda_cpu_runtime --- .github/workflows/Quick-Checks-CI.yml | 2 +- integration_tests/CMakeLists.txt | 4 ++-- src/libasr/codegen/asr_to_c.cpp | 2 +- src/libasr/runtime/{cpu_impl.c => cuda_cpu_runtime.c} | 2 +- src/libasr/runtime/{cpu_impl.h => cuda_cpu_runtime.h} | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) rename src/libasr/runtime/{cpu_impl.c => cuda_cpu_runtime.c} (99%) rename src/libasr/runtime/{cpu_impl.h => cuda_cpu_runtime.h} (94%) diff --git a/.github/workflows/Quick-Checks-CI.yml b/.github/workflows/Quick-Checks-CI.yml index 7ee82241192..f7cd993ee3b 100644 --- a/.github/workflows/Quick-Checks-CI.yml +++ b/.github/workflows/Quick-Checks-CI.yml @@ -301,7 +301,7 @@ jobs: cd integration_tests ./run_tests.py -b llvm_omp - - name: Test GFortran, Debug Build, Fortran, OpenMP, C/C++ backend, Upload Tarball, CPP Build, WASM - Test Target_Offload + - name: Test GFortran, Debug Build, Fortran, OpenMP, C/C++ backend, Upload Tarball, CPP Build, WASM - Test Target Offload shell: bash -e -l {0} if: contains(matrix.os, 'ubuntu') && contains(matrix.llvm-version, '11') run: | diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index ee1a242defb..0a6d25f4f1a 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -164,7 +164,7 @@ macro(RUN_UTIL RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_EXTRAFILES RUN_EXT ) add_executable(${name} ${CMAKE_SOURCE_DIR}/../src/libasr/runtime/lfortran_intrinsics.c - ${CMAKE_SOURCE_DIR}/../src/libasr/runtime/cpu_impl.c + ${CMAKE_SOURCE_DIR}/../src/libasr/runtime/cuda_cpu_runtime.c ${c_file} ) target_include_directories(${name} PUBLIC @@ -2501,8 +2501,8 @@ RUN(NAME openmp_66 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_67 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_68 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_69 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) -RUN(NAME openmp_72 LABELS target_offload) RUN(NAME openmp_71 LABELS target_offload) +RUN(NAME openmp_72 LABELS target_offload) RUN(NAME nullify_01 LABELS gfortran fortran llvm) RUN(NAME nullify_02 LABELS gfortran fortran llvm) diff --git a/src/libasr/codegen/asr_to_c.cpp b/src/libasr/codegen/asr_to_c.cpp index a2322ebc448..6961c2408f7 100644 --- a/src/libasr/codegen/asr_to_c.cpp +++ b/src/libasr/codegen/asr_to_c.cpp @@ -634,7 +634,7 @@ R"( #ifdef USE_GPU #include #else -#include"cpu_impl.h" +#include"cuda_cpu_runtime.h" #endif )"; } diff --git a/src/libasr/runtime/cpu_impl.c b/src/libasr/runtime/cuda_cpu_runtime.c similarity index 99% rename from src/libasr/runtime/cpu_impl.c rename to src/libasr/runtime/cuda_cpu_runtime.c index 7581a9320aa..b50cbadeaa6 100644 --- a/src/libasr/runtime/cpu_impl.c +++ b/src/libasr/runtime/cuda_cpu_runtime.c @@ -1,4 +1,4 @@ -#include "cpu_impl.h" +#include "cuda_cpu_runtime.h" // Thread-local storage for CUDA-like thread coordinates __thread uint3 threadIdx = {0, 0, 0}; diff --git a/src/libasr/runtime/cpu_impl.h b/src/libasr/runtime/cuda_cpu_runtime.h similarity index 94% rename from src/libasr/runtime/cpu_impl.h rename to src/libasr/runtime/cuda_cpu_runtime.h index f2b6d0769f6..0a9c42c368d 100644 --- a/src/libasr/runtime/cpu_impl.h +++ b/src/libasr/runtime/cuda_cpu_runtime.h @@ -1,5 +1,5 @@ -#ifndef CPU_IMPL_H -#define CPU_IMPL_H +#ifndef CUDA_CPU_RUNTIME_H +#define CUDA_CPU_RUNTIME_H #include #include @@ -64,4 +64,4 @@ typedef struct { void cpu_runtime_init(void); void cpu_runtime_cleanup(void); -#endif // CPU_IMPL_H +#endif // CUDA_CPU_RUNTIME_H From 41b4c418edf42bbb4329900bc252da9d9f55d2c2 Mon Sep 17 00:00:00 2001 From: Aditya Trivedi Date: Thu, 7 Aug 2025 17:20:15 +0530 Subject: [PATCH 004/119] TEST: Add --- integration_tests/openmp_73.f90 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 integration_tests/openmp_73.f90 diff --git a/integration_tests/openmp_73.f90 b/integration_tests/openmp_73.f90 new file mode 100644 index 00000000000..0f39f628098 --- /dev/null +++ b/integration_tests/openmp_73.f90 @@ -0,0 +1,27 @@ +! TEAMSDISTRIBUTE combined construct test +program openmp_73 + use omp_lib + implicit none +integer :: array(1000), i, j, sum=0 +array(1)=3 +!$omp teams distribute num_teams(2) thread_limit(5) +do i = 1, 1000, 100 + print*,omp_get_num_threads(), omp_get_max_threads() + !$omp parallel do + do j = i, min(i+99, 1000) + array(j) = j * 3 + end do + !$omp end parallel do +end do +!$omp end teams distribute + +! Sum of all elements +!$omp parallel do reduction(+:sum) +do i=1,1000 +sum=sum+array(i) +end do +!$omp end parallel do + +print*, sum +if(sum/=1501500) error stop +end program openmp_73 \ No newline at end of file From e4e55af860e87d4088421ba1538cbe30f6003b64 Mon Sep 17 00:00:00 2001 From: Aditya Trivedi Date: Thu, 7 Aug 2025 17:20:27 +0530 Subject: [PATCH 005/119] TEST: Register --- integration_tests/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 0a6d25f4f1a..a4d652d47bb 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2501,8 +2501,10 @@ RUN(NAME openmp_66 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_67 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_68 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_69 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) +RUN(NAME openmp_70 LABELS target_offload) RUN(NAME openmp_71 LABELS target_offload) RUN(NAME openmp_72 LABELS target_offload) +RUN(NAME openmp_73 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME nullify_01 LABELS gfortran fortran llvm) RUN(NAME nullify_02 LABELS gfortran fortran llvm) From a594642f762c8ff4045073bd450fe29897b21659 Mon Sep 17 00:00:00 2001 From: Aditya Trivedi Date: Thu, 7 Aug 2025 17:21:09 +0530 Subject: [PATCH 006/119] FEAT: Generate ASR for TEAMS DISTRIBUTE combined construct --- src/lfortran/parser/semantics.h | 3 ++- src/libasr/ASR.asdl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lfortran/parser/semantics.h b/src/lfortran/parser/semantics.h index 5cbd865e7f9..a60ca3e8150 100644 --- a/src/lfortran/parser/semantics.h +++ b/src/lfortran/parser/semantics.h @@ -1841,7 +1841,8 @@ static inline ast_t* OMP_PRAGMA2(Allocator &al, omp_stmt[i] == "sections" || omp_stmt[i] == "workshare" || omp_stmt[i] == "section" || - omp_stmt[i] == "parallel") { + omp_stmt[i] == "parallel" || + omp_stmt[i] == "distribute") { construct_name += " " + omp_stmt[i]; } else { m_clauses.push_back(al, EXPR(make_String_t(al, loc, diff --git a/src/libasr/ASR.asdl b/src/libasr/ASR.asdl index 4b6897e9ab1..8ae3838df77 100644 --- a/src/libasr/ASR.asdl +++ b/src/libasr/ASR.asdl @@ -250,7 +250,7 @@ arraybound = LBound | UBound arraystorage = RowMajor | ColMajor string_format_kind = FormatFortran | FormatC | FormatPythonPercent | FormatPythonFString | FormatPythonFormat -omp_region_type = Parallel | Do | ParallelDo | Sections | Section | ParallelSections | Critical | Atomic | Barrier | Single | Master | Task | Taskwait | Taskloop | Simd | Teams | Distribute | DistributeParallelDo | Target | TargetData +omp_region_type = Parallel | Do | ParallelDo | Sections | Section | ParallelSections | Critical | Atomic | Barrier | Single | Master | Task | Taskwait | Taskloop | Simd | Teams | Distribute | TeamsDistribute | DistributeParallelDo | Target | TargetData omp_clause = OMPPrivate(expr* vars) | OMPShared(expr* vars) From f364bbca2621b704f3fd2041306d68a090a4d20f Mon Sep 17 00:00:00 2001 From: Aditya Trivedi Date: Thu, 7 Aug 2025 17:21:44 +0530 Subject: [PATCH 007/119] FEAT: Implement TeamsDistribute combined construct --- src/lfortran/semantics/ast_body_visitor.cpp | 10 ++++++++++ src/libasr/pass/openmp.cpp | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/lfortran/semantics/ast_body_visitor.cpp b/src/lfortran/semantics/ast_body_visitor.cpp index 17fa01e62c2..a4f43d832fa 100644 --- a/src/lfortran/semantics/ast_body_visitor.cpp +++ b/src/lfortran/semantics/ast_body_visitor.cpp @@ -5545,6 +5545,8 @@ class BodyVisitor : public CommonVisitor { collect_omp_body(ASR::omp_region_typeType::Do); } else if (LCompilers::startswith(x.m_construct_name, "critical")) { collect_omp_body(ASR::omp_region_typeType::Critical); + } else if (LCompilers::startswith(x.m_construct_name, "teams distribute")) { + collect_omp_body(ASR::omp_region_typeType::TeamsDistribute); } else if (LCompilers::startswith(x.m_construct_name, "teams")) { collect_omp_body(ASR::omp_region_typeType::Teams); } else if (LCompilers::startswith(x.m_construct_name, "distribute parallel do")) { @@ -5701,6 +5703,14 @@ class BodyVisitor : public CommonVisitor { body.reserve(al, 0); omp_region_body.push_back(ASRUtils::STMT( ASR::make_OMPRegion_t(al, loc, ASR::omp_region_typeType::Distribute, clauses.p, clauses.n, body.p, body.n))); + } else if (to_lower(x.m_construct_name) == "teams distribute") { + pragma_nesting_level_2++; + Vec clauses; + clauses = get_clauses(x); + Vec body; + body.reserve(al, 0); + omp_region_body.push_back(ASRUtils::STMT( + ASR::make_OMPRegion_t(al, loc, ASR::omp_region_typeType::TeamsDistribute, clauses.p, clauses.n, body.p, body.n))); } else if (to_lower(x.m_construct_name) == "atomic") { pragma_nesting_level_2++; Vec clauses; diff --git a/src/libasr/pass/openmp.cpp b/src/libasr/pass/openmp.cpp index b40bef17247..d412a3850b2 100644 --- a/src/libasr/pass/openmp.cpp +++ b/src/libasr/pass/openmp.cpp @@ -2534,6 +2534,10 @@ class ParallelRegionVisitor : visit_OMPParallelSections(x); break; + case ASR::omp_region_typeType::TeamsDistribute: + visit_OMPTeamsDistribute(x); + break; + case ASR::omp_region_typeType::Single: case ASR::omp_region_typeType::Master: visit_OMPSingleThread(x); @@ -3699,8 +3703,14 @@ class ParallelRegionVisitor : } nested_lowered_body = body_copy; // Handle nested regions - if (x.m_region == ASR::omp_region_typeType::Teams) { - // Process body - could contain parallel, distribute, etc. + if (x.m_region == ASR::omp_region_typeType::TeamsDistribute) { + std::vector body_copy = nested_lowered_body; + visit_OMPDistribute(x); + for (size_t i=0; i Date: Thu, 7 Aug 2025 18:07:00 +0530 Subject: [PATCH 008/119] TEST: updaate Refs --- tests/reference/c_target_cuda-openmp_71-261df19.json | 2 +- tests/reference/c_target_cuda-openmp_71-261df19.stdout | 2 +- tests/reference/c_target_cuda-openmp_72-c617edf.json | 2 +- tests/reference/c_target_cuda-openmp_72-c617edf.stdout | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/reference/c_target_cuda-openmp_71-261df19.json b/tests/reference/c_target_cuda-openmp_71-261df19.json index 8ae11c7c80f..d97cfcb1c36 100644 --- a/tests/reference/c_target_cuda-openmp_71-261df19.json +++ b/tests/reference/c_target_cuda-openmp_71-261df19.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c_target_cuda-openmp_71-261df19.stdout", - "stdout_hash": "e748989aa162c1236e8b7254c93992bd167e8f59ad1206765870d778", + "stdout_hash": "27a8a74dbd12bcbf4bb8732cc3b2f367d8c4a5ca1a637e7294e41dba", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c_target_cuda-openmp_71-261df19.stdout b/tests/reference/c_target_cuda-openmp_71-261df19.stdout index 0a36422440e..7bb7b6c1b00 100644 --- a/tests/reference/c_target_cuda-openmp_71-261df19.stdout +++ b/tests/reference/c_target_cuda-openmp_71-261df19.stdout @@ -10,7 +10,7 @@ #ifdef USE_GPU #include #else -#include"cpu_impl.h" +#include"cuda_cpu_runtime.h" #endif struct dimension_descriptor diff --git a/tests/reference/c_target_cuda-openmp_72-c617edf.json b/tests/reference/c_target_cuda-openmp_72-c617edf.json index 9473c49c641..dc9436e148f 100644 --- a/tests/reference/c_target_cuda-openmp_72-c617edf.json +++ b/tests/reference/c_target_cuda-openmp_72-c617edf.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "c_target_cuda-openmp_72-c617edf.stdout", - "stdout_hash": "e748989aa162c1236e8b7254c93992bd167e8f59ad1206765870d778", + "stdout_hash": "27a8a74dbd12bcbf4bb8732cc3b2f367d8c4a5ca1a637e7294e41dba", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/c_target_cuda-openmp_72-c617edf.stdout b/tests/reference/c_target_cuda-openmp_72-c617edf.stdout index 0a36422440e..7bb7b6c1b00 100644 --- a/tests/reference/c_target_cuda-openmp_72-c617edf.stdout +++ b/tests/reference/c_target_cuda-openmp_72-c617edf.stdout @@ -10,7 +10,7 @@ #ifdef USE_GPU #include #else -#include"cpu_impl.h" +#include"cuda_cpu_runtime.h" #endif struct dimension_descriptor From bf57937e09c47920a23928f3d9b6cdb73b2a464e Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Thu, 7 Aug 2025 18:48:59 +0530 Subject: [PATCH 009/119] fix: store data member types in same order as declared --- integration_tests/CMakeLists.txt | 1 + integration_tests/nested_15.f90 | 24 ++++++++++++++++++++++++ src/libasr/codegen/asr_to_llvm.cpp | 7 ++++--- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 integration_tests/nested_15.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index ee1a242defb..da04ae12174 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1790,6 +1790,7 @@ RUN(NAME nested_11 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME nested_12 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME nested_13 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME nested_14 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME nested_15 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME nested_vars1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc wasm c) RUN(NAME nested_vars2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc wasm c) diff --git a/integration_tests/nested_15.f90 b/integration_tests/nested_15.f90 new file mode 100644 index 00000000000..c7e11f0bc29 --- /dev/null +++ b/integration_tests/nested_15.f90 @@ -0,0 +1,24 @@ +module nested_15_mod + type :: child + character(:), allocatable :: value + logical :: par = .true. + end type child +contains + + subroutine temp_sub(model) + type(child), intent(inout) :: model + call nested_sub() + contains + subroutine nested_sub() + if (.not. model%par) error stop + if (model%value /= "Hello") error stop + end subroutine + end subroutine +end module + +program nested_15 + use nested_15_mod + type(child) :: model + model%value = "Hello" + call temp_sub(model) +end program nested_15 \ No newline at end of file diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 6d9df2d872b..63cca392a33 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -3523,9 +3523,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (init_value == nullptr && x.m_type->type == ASR::ttypeType::StructType) { ASR::Struct_t* struct_sym = ASR::down_cast(ASRUtils::symbol_get_past_external(x.m_type_declaration)); std::vector field_values; - for (auto& member : struct_sym->m_symtab->get_scope()) { - ASR::symbol_t* sym = member.second; - if (!ASR::is_a(*sym)) + for (size_t i = 0; i < struct_sym->n_members; i++) { + std::string member_name = struct_sym->m_members[i]; + ASR::symbol_t* sym = struct_sym->m_symtab->get_symbol(member_name); + if (!sym || !ASR::is_a(*sym)) continue; ASR::Variable_t* var = ASR::down_cast(sym); if (var->m_value != nullptr) { From bbf5b87512cb970431474ed908951136cad13587 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 7 Aug 2025 20:30:34 +0530 Subject: [PATCH 010/119] fix: correct logic in handling `FunctionCall` and `OverloadedStringConcat` in `ASRUtils::get_struct_sym_from_struct_expr()` Signed-off-by: Saurabh Kumar --- src/libasr/asr_utils.cpp | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/libasr/asr_utils.cpp b/src/libasr/asr_utils.cpp index 75564351589..f938b7a184e 100644 --- a/src/libasr/asr_utils.cpp +++ b/src/libasr/asr_utils.cpp @@ -198,17 +198,8 @@ ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression) } case ASR::exprType::FunctionCall: { ASR::FunctionCall_t* func_call = ASR::down_cast(expression); - // `func_call->m_dt` will be non-null for Struct expressions - if ( func_call->m_dt != nullptr ){ - // If `func_call->m_dt` is not null, it means that the function call - // is returning a struct type. - return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(func_call->m_dt)); - } else if (ASR::is_a(*ASRUtils::symbol_get_past_external(func_call->m_name))) { - ASR::Function_t* func = ASR::down_cast(ASRUtils::symbol_get_past_external(func_call->m_name)); - return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(func->m_return_var)); - } else { - return nullptr; - } + ASR::Function_t* func = get_function(func_call->m_name); + return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(func->m_return_var)); } case ASR::exprType::StructConstant: { ASR::StructConstant_t* struct_constant = ASR::down_cast(expression); @@ -477,17 +468,7 @@ ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression) } case ASR::exprType::OverloadedStringConcat: { ASR::OverloadedStringConcat_t* overloaded_string_concat = ASR::down_cast(expression); - ASR::symbol_t* left_struct_sym = ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(overloaded_string_concat->m_left)); - ASR::symbol_t* right_struct_sym = ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(overloaded_string_concat->m_right)); - if (left_struct_sym != nullptr) { - return left_struct_sym; - } else if (right_struct_sym != nullptr) { - return right_struct_sym; - } else if ( overloaded_string_concat->m_value != nullptr ) { - return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(overloaded_string_concat->m_value)); - } else { - return nullptr; // If no struct symbol found in either side - } + return ASRUtils::get_struct_sym_from_struct_expr(overloaded_string_concat->m_overloaded); } case ASR::exprType::StringItem: { ASR::StringItem_t* string_item = ASR::down_cast(expression); From 8cd350959b2c363027d34fc14bd37a21122dbb02 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Thu, 7 Aug 2025 20:41:03 +0530 Subject: [PATCH 011/119] fix: check if arg_expr is non-null --- src/lfortran/semantics/ast_common_visitor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 9636caa334c..19361386c9f 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -6542,7 +6542,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::call_arg_t arg = args[i]; ASR::ttype_t* expected_arg_type = ASRUtils::duplicate_type(al, array_arg_idx[i]); ASR::expr_t* arg_expr = arg.m_value; - if (ASR::is_a(*arg_expr)) { + if (arg_expr && ASR::is_a(*arg_expr)) { ASR::ArrayItem_t* array_item = ASR::down_cast(arg_expr); ASR::expr_t* array_expr = array_item->m_v; LCOMPILERS_ASSERT(array_item->n_args > 0); From 74a0dd735ab4f03ffc9094d3e650013361d53292 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Thu, 7 Aug 2025 20:41:16 +0530 Subject: [PATCH 012/119] test: add and register test --- integration_tests/CMakeLists.txt | 2 ++ .../legacy_array_sections_07.f90 | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 integration_tests/legacy_array_sections_07.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index ee1a242defb..bdcb814bd1a 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2330,6 +2330,8 @@ RUN(NAME legacy_array_sections_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc RUN(NAME legacy_array_sections_04 LABELS gfortran llvm2 EXTRA_ARGS --implicit-interface --legacy-array-sections EXTRAFILES legacy_array_sections_04b.f90) RUN(NAME legacy_array_sections_05 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --legacy-array-sections) RUN(NAME legacy_array_sections_06 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --legacy-array-sections) +RUN(NAME legacy_array_sections_07 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --legacy-array-sections) + RUN(NAME cmake_minimal_test_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME char_array_initialization_declaration LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) diff --git a/integration_tests/legacy_array_sections_07.f90 b/integration_tests/legacy_array_sections_07.f90 new file mode 100644 index 00000000000..b1bf95b20c3 --- /dev/null +++ b/integration_tests/legacy_array_sections_07.f90 @@ -0,0 +1,29 @@ +module legacy_array_sections_07_module !! [order = polynomial degree + 1] + interface db1ink + module procedure :: db1ink_default + end interface + public :: db1ink + contains + pure subroutine db1ink_default(x) + implicit none + real(4), dimension(:), intent(in) :: x + call check_inputs(x=x) + end subroutine db1ink_default + pure subroutine check_inputs(x, y) + implicit none + real(4), dimension(:), intent(in), optional :: x, y + end subroutine check_inputs +end module legacy_array_sections_07_module +program legacy_array_sections_07 + use legacy_array_sections_07_module + implicit none + real :: x(5), y(2) + x = [1.0, 2.0, 3.0, 4.0, 5.0] + y = [6.0, 7.0] + call db1ink_default(x) + print *, x + if (any(x - [1.0, 2.0, 3.0, 4.0, 5.0] > 1e-6)) error stop + call check_inputs(x, y) + print *, y + if (any(y - [6.0, 7.0] > 1e-6)) error stop +end program legacy_array_sections_07 \ No newline at end of file From 19ceac2db764c9739dd2e19ed5dc02a5507cd878 Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Fri, 8 Aug 2025 00:17:03 +0530 Subject: [PATCH 013/119] fix: correctly create function call to class procedure --- src/lfortran/semantics/ast_common_visitor.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 19361386c9f..b2c923ac169 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -6297,10 +6297,14 @@ class CommonVisitor : public AST::BaseVisitor { } ASRUtils::insert_module_dependency(cp_s, al, current_module_dependencies); ASRUtils::insert_module_dependency(final_sym, al, current_module_dependencies); + Vec args_without_dt; args_without_dt.reserve(al, args.size() - 1); + for (size_t i = 1; i < args.size(); i++) { + args_without_dt.push_back(al, args[i]); + } ASRUtils::set_absent_optional_arguments_to_null(args, func, al); return ASRUtils::make_FunctionCall_t_util(al, loc, - cp_s, v, args.p, args.size(), type, - nullptr, nullptr); + cp_s, nullptr, args_without_dt.p, args_without_dt.size(), type, + nullptr, args[0].m_value); } else { if (ASRUtils::symbol_parent_symtab(final_sym)->get_counter() != current_scope->get_counter()) { ADD_ASR_DEPENDENCIES(current_scope, final_sym, current_function_dependencies); From bef1591c2ec839399c05bd1d5a1159374b1974b9 Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Fri, 8 Aug 2025 00:17:48 +0530 Subject: [PATCH 014/119] tests: add test and update reference tests --- integration_tests/CMakeLists.txt | 2 ++ integration_tests/procedure_22.f90 | 6 ++++ integration_tests/procedure_22_a.f90 | 29 +++++++++++++++++++ .../asr-dependency_test_01-280d5b3.json | 2 +- .../asr-dependency_test_01-280d5b3.stdout | 7 ++--- .../asr-derived_types_15-7fde02a.json | 2 +- .../asr-derived_types_15-7fde02a.stdout | 14 ++++----- .../asr-nested_struct_proc_01-3b9017b.json | 2 +- .../asr-nested_struct_proc_01-3b9017b.stdout | 17 +++++------ 9 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 integration_tests/procedure_22.f90 create mode 100644 integration_tests/procedure_22_a.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index bdcb814bd1a..b66d2570a62 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2172,6 +2172,8 @@ RUN(NAME procedure_18 LABELS gfortran llvm) RUN(NAME procedure_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME procedure_20 LABELS gfortran llvm) RUN(NAME procedure_21 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME procedure_22 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRAFILES procedure_22_a.f90) + RUN(NAME allocated_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocated_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) diff --git a/integration_tests/procedure_22.f90 b/integration_tests/procedure_22.f90 new file mode 100644 index 00000000000..f9e2883ebdf --- /dev/null +++ b/integration_tests/procedure_22.f90 @@ -0,0 +1,6 @@ +program procedure_22 + use procedure_22_mod_b + type(deps_t) :: temp_dpt + temp_dpt%str = "Hello " + if (func(temp_dpt) /= 5) error stop +end program \ No newline at end of file diff --git a/integration_tests/procedure_22_a.f90 b/integration_tests/procedure_22_a.f90 new file mode 100644 index 00000000000..b1cbc0e1049 --- /dev/null +++ b/integration_tests/procedure_22_a.f90 @@ -0,0 +1,29 @@ +module procedure_22_mod_a + implicit none + + type :: deps_t + character(:), allocatable :: str + contains + procedure :: find_string => find_by_name + generic :: find => find_string + end type deps_t + +contains + integer function find_by_name(self, name) + class(deps_t), intent(in) :: self + character(len=*), intent(in) :: name + find_by_name = len_trim(name) + end function find_by_name + +end module procedure_22_mod_a + + +module procedure_22_mod_b + use procedure_22_mod_a, only: deps_t +contains + function func(model) result(id) + class(deps_t), intent(in) :: model + integer :: id + id = model%find(model%str) + end function +end module procedure_22_mod_b \ No newline at end of file diff --git a/tests/reference/asr-dependency_test_01-280d5b3.json b/tests/reference/asr-dependency_test_01-280d5b3.json index fb02e12bf5b..95b1408b86b 100644 --- a/tests/reference/asr-dependency_test_01-280d5b3.json +++ b/tests/reference/asr-dependency_test_01-280d5b3.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-dependency_test_01-280d5b3.stdout", - "stdout_hash": "36db1e6b8c135af0c5dff7665813409c6d451e8d97906f8cb2b31077", + "stdout_hash": "976a7d92dfd08f99553e7c6765e3a2770e7a725c254c7cea6322d923", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-dependency_test_01-280d5b3.stdout b/tests/reference/asr-dependency_test_01-280d5b3.stdout index e66fffa5031..218d56e3c06 100644 --- a/tests/reference/asr-dependency_test_01-280d5b3.stdout +++ b/tests/reference/asr-dependency_test_01-280d5b3.stdout @@ -195,12 +195,11 @@ (Var 6 id) (FunctionCall 6 1_find_dependency - 5 find - [((Var 6 self)) - ((Var 6 dependency))] - (Integer 4) () + [((Var 6 dependency))] + (Integer 4) () + (Var 6 self) ) () .false. diff --git a/tests/reference/asr-derived_types_15-7fde02a.json b/tests/reference/asr-derived_types_15-7fde02a.json index 2d055527a42..ae0335a7cf2 100644 --- a/tests/reference/asr-derived_types_15-7fde02a.json +++ b/tests/reference/asr-derived_types_15-7fde02a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-derived_types_15-7fde02a.stdout", - "stdout_hash": "86b06740198b21c7cf47de944264df36b1fbcae4936ad8fbf4a77b71", + "stdout_hash": "2fb4e1d1a1553e72f33597248708bf3961b3dd20a9e4d7238ce7d33a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-derived_types_15-7fde02a.stdout b/tests/reference/asr-derived_types_15-7fde02a.stdout index b1386584534..0bf27bade0d 100644 --- a/tests/reference/asr-derived_types_15-7fde02a.stdout +++ b/tests/reference/asr-derived_types_15-7fde02a.stdout @@ -459,15 +459,14 @@ (RealCompare (FunctionCall 6 1_multiply - 3 compute - [((Var 6 type_1)) - ((RealConstant + () + [((RealConstant 5.000000 (Real 4) ))] (Real 4) () - () + (Var 6 type_1) ) NotEq (Cast @@ -492,12 +491,11 @@ (RealCompare (FunctionCall 6 1_sqrt_subtract - 3 compute - [((Var 6 type_1)) - ((IntegerConstant 2500 (Integer 4) Decimal))] - (Real 4) () + [((IntegerConstant 2500 (Integer 4) Decimal))] + (Real 4) () + (Var 6 type_1) ) NotEq (Cast diff --git a/tests/reference/asr-nested_struct_proc_01-3b9017b.json b/tests/reference/asr-nested_struct_proc_01-3b9017b.json index 4455c0d8454..2d6084b95a4 100644 --- a/tests/reference/asr-nested_struct_proc_01-3b9017b.json +++ b/tests/reference/asr-nested_struct_proc_01-3b9017b.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-nested_struct_proc_01-3b9017b.stdout", - "stdout_hash": "f6efd0934df35d5dc28d5ad7a02a42738d2338af173a3500b0abfc73", + "stdout_hash": "a3cc7adb3e15c9e0e1339ef68bd7a8e0a055e784076a457a457c3838", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-nested_struct_proc_01-3b9017b.stdout b/tests/reference/asr-nested_struct_proc_01-3b9017b.stdout index 93d225a1658..479455d862f 100644 --- a/tests/reference/asr-nested_struct_proc_01-3b9017b.stdout +++ b/tests/reference/asr-nested_struct_proc_01-3b9017b.stdout @@ -700,8 +700,14 @@ (Var 10 tmp) (FunctionCall 10 1_omap_i_at_rc - 7 at - [((StructInstanceMember + () + [((Var 10 key)) + ((Var 10 status))] + (Pointer + (Complex 4) + ) + () + (StructInstanceMember (Var 10 this) 10 1_integer32complex32orderedmap_map (StructType @@ -717,14 +723,7 @@ .false. ) () - )) - ((Var 10 key)) - ((Var 10 status))] - (Pointer - (Complex 4) ) - () - () ) ) (If From 9856e1d4b64e1623ae5f42e845b0dff7fd8d7236 Mon Sep 17 00:00:00 2001 From: swamishiju Date: Fri, 8 Aug 2025 00:56:46 +0530 Subject: [PATCH 015/119] Union ASR refactor (#7966) --- ci/parser.yy.patch | 14 ++-- grammar/AST.asdl | 8 +-- integration_tests/CMakeLists.txt | 53 ++++++++------- .../{lp_dict_test_01.f90 => dict_test_01.f90} | 0 ...lp_dict_test_01_.f90 => dict_test_01_.f90} | 0 ...lp_dict_test_02_.f90 => dict_test_02_.f90} | 0 ...lp_dict_test_03_.f90 => dict_test_03_.f90} | 0 ...lp_dict_test_04_.f90 => dict_test_04_.f90} | 0 ..._lists_test.f90 => list_of_lists_test.f90} | 0 ...uples_test.f90 => list_of_tuples_test.f90} | 0 .../{lp_list_test_01.f90 => list_test_01.f90} | 0 ...lp_list_test_01_.f90 => list_test_01_.f90} | 0 ...lp_list_test_02_.f90 => list_test_02_.f90} | 0 ...lp_list_test_03_.f90 => list_test_03_.f90} | 0 ...lp_list_test_04_.f90 => list_test_04_.f90} | 0 ...lp_list_test_06_.f90 => list_test_06_.f90} | 0 ...lp_list_test_08_.f90 => list_test_08_.f90} | 0 ...lp_list_test_09_.f90 => list_test_09_.f90} | 0 .../{lp_set_test_01.f90 => set_test_01.f90} | 0 ..._tuple_test_01_.f90 => tuple_test_01_.f90} | 0 ..._tuple_test_02_.f90 => tuple_test_02_.f90} | 0 ..._tuple_test_03_.f90 => tuple_test_03_.f90} | 0 ..._tuple_test_04_.f90 => tuple_test_04_.f90} | 0 ...est_concat_.f90 => tuple_test_concat_.f90} | 0 ...est_nested_.f90 => tuple_test_nested_.f90} | 0 ...lp_union_test_01.f90 => union_test_01.f90} | 0 ...lp_union_test_02.f90 => union_test_02.f90} | 0 integration_tests/union_test_03.f90 | 21 ++++++ src/lfortran/parser/parser.yy | 34 +++++----- src/lfortran/parser/semantics.h | 2 +- src/lfortran/parser/tokenizer.re | 12 ++-- src/lfortran/semantics/ast_common_visitor.h | 38 ++++++----- .../semantics/ast_symboltable_visitor.cpp | 37 +++++++--- src/libasr/ASR.asdl | 2 +- src/libasr/asr_utils.cpp | 62 +++++++++++++++++ src/libasr/asr_utils.h | 67 ++++++++++++------- src/libasr/asr_verify.cpp | 3 - src/libasr/codegen/asr_to_c.cpp | 3 +- src/libasr/codegen/asr_to_llvm.cpp | 3 +- src/libasr/codegen/llvm_utils.cpp | 18 +++-- src/libasr/codegen/llvm_utils.h | 3 - 41 files changed, 249 insertions(+), 131 deletions(-) rename integration_tests/{lp_dict_test_01.f90 => dict_test_01.f90} (100%) rename integration_tests/{lp_dict_test_01_.f90 => dict_test_01_.f90} (100%) rename integration_tests/{lp_dict_test_02_.f90 => dict_test_02_.f90} (100%) rename integration_tests/{lp_dict_test_03_.f90 => dict_test_03_.f90} (100%) rename integration_tests/{lp_dict_test_04_.f90 => dict_test_04_.f90} (100%) rename integration_tests/{lp_list_of_lists_test.f90 => list_of_lists_test.f90} (100%) rename integration_tests/{lp_list_of_tuples_test.f90 => list_of_tuples_test.f90} (100%) rename integration_tests/{lp_list_test_01.f90 => list_test_01.f90} (100%) rename integration_tests/{lp_list_test_01_.f90 => list_test_01_.f90} (100%) rename integration_tests/{lp_list_test_02_.f90 => list_test_02_.f90} (100%) rename integration_tests/{lp_list_test_03_.f90 => list_test_03_.f90} (100%) rename integration_tests/{lp_list_test_04_.f90 => list_test_04_.f90} (100%) rename integration_tests/{lp_list_test_06_.f90 => list_test_06_.f90} (100%) rename integration_tests/{lp_list_test_08_.f90 => list_test_08_.f90} (100%) rename integration_tests/{lp_list_test_09_.f90 => list_test_09_.f90} (100%) rename integration_tests/{lp_set_test_01.f90 => set_test_01.f90} (100%) rename integration_tests/{lp_tuple_test_01_.f90 => tuple_test_01_.f90} (100%) rename integration_tests/{lp_tuple_test_02_.f90 => tuple_test_02_.f90} (100%) rename integration_tests/{lp_tuple_test_03_.f90 => tuple_test_03_.f90} (100%) rename integration_tests/{lp_tuple_test_04_.f90 => tuple_test_04_.f90} (100%) rename integration_tests/{lp_tuple_test_concat_.f90 => tuple_test_concat_.f90} (100%) rename integration_tests/{lp_tuple_test_nested_.f90 => tuple_test_nested_.f90} (100%) rename integration_tests/{lp_union_test_01.f90 => union_test_01.f90} (100%) rename integration_tests/{lp_union_test_02.f90 => union_test_02.f90} (100%) create mode 100644 integration_tests/union_test_03.f90 diff --git a/ci/parser.yy.patch b/ci/parser.yy.patch index 28ee3c84ac4..f67da287836 100644 --- a/ci/parser.yy.patch +++ b/ci/parser.yy.patch @@ -1,8 +1,8 @@ diff --git a/src/lfortran/parser/parser.yy b/src/lfortran/parser/parser.yy -index 94c9668ac..32855e999 100644 +index 65e2c2b0e..6a153d2d4 100644 --- a/src/lfortran/parser/parser.yy +++ b/src/lfortran/parser/parser.yy -@@ -1395,9 +1395,7 @@ common_block_list_top +@@ -1405,9 +1405,7 @@ common_block_list_top ; common_block_list @@ -13,7 +13,7 @@ index 94c9668ac..32855e999 100644 ; common_block -@@ -2562,177 +2560,4 @@ id_opt +@@ -2572,177 +2570,4 @@ id_opt id : TK_NAME { $$ = SYMBOL($1, @$); } @@ -186,8 +186,8 @@ index 94c9668ac..32855e999 100644 - | KW_WHERE { $$ = SYMBOL($1, @$); } - | KW_WHILE { $$ = SYMBOL($1, @$); } - | KW_WRITE { $$ = SYMBOL($1, @$); } -- | KW_LF_LIST { $$ = SYMBOL($1, @$); } -- | KW_LF_SET { $$ = SYMBOL($1, @$); } -- | KW_LF_DICT { $$ = SYMBOL($1, @$); } -- | KW_LF_TUPLE { $$ = SYMBOL($1, @$); } +- | KW_LIST { $$ = SYMBOL($1, @$); } +- | KW_SET { $$ = SYMBOL($1, @$); } +- | KW_DICT { $$ = SYMBOL($1, @$); } +- | KW_TUPLE { $$ = SYMBOL($1, @$); } ; diff --git a/grammar/AST.asdl b/grammar/AST.asdl index c044d40d31c..fa2e215158a 100644 --- a/grammar/AST.asdl +++ b/grammar/AST.asdl @@ -339,10 +339,10 @@ decl_type | TypeProcedure | TypeReal | TypeType - | TypeLF_List - | TypeLF_Set - | TypeLF_Dict - | TypeLF_Tuple + | TypeList + | TypeSet + | TypeDict + | TypeTuple event_attribute = AttrStat(identifier variable) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index bdcb814bd1a..7b0d23b3022 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2585,37 +2585,38 @@ RUN(NAME formatted_read_01 LABELS gfortran llvm COPY_TO_BIN formatted_read_input # LFortran extensions (lists, dicts, etc.) -RUN(NAME lp_list_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_list_of_lists_test LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_set_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_dict_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -# RUN(NAME lp_list_of_tuples_test LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_of_lists_test LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME set_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME dict_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +# RUN(NAME list_of_tuples_test LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran # Completely ported tests -RUN(NAME lp_list_test_01_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_list_test_02_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_list_test_03_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_list_test_04_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_list_test_06_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_list_test_08_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_list_test_09_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran - -# RUN(NAME lp_tuple_test_01_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -# RUN(NAME lp_tuple_test_02_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -# RUN(NAME lp_tuple_test_03_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -# RUN(NAME lp_tuple_test_04_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -# RUN(NAME lp_tuple_test_concat_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -# RUN(NAME lp_tuple_test_nested_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran - -RUN(NAME lp_dict_test_01_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_dict_test_02_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -# RUN(NAME lp_dict_test_03_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_dict_test_04_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_test_01_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_test_02_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_test_03_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_test_04_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_test_06_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_test_08_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME list_test_09_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran + +# RUN(NAME tuple_test_01_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +# RUN(NAME tuple_test_02_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +# RUN(NAME tuple_test_03_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +# RUN(NAME tuple_test_04_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +# RUN(NAME tuple_test_concat_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +# RUN(NAME tuple_test_nested_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran + +RUN(NAME dict_test_01_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME dict_test_02_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +# RUN(NAME dict_test_03_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME dict_test_04_ LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran # LFortran extensions (union) -RUN(NAME lp_union_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME lp_union_test_02 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME union_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME union_test_02 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME union_test_03 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran # LFortran extensions (unsigned int) RUN(NAME test_unsigned LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran diff --git a/integration_tests/lp_dict_test_01.f90 b/integration_tests/dict_test_01.f90 similarity index 100% rename from integration_tests/lp_dict_test_01.f90 rename to integration_tests/dict_test_01.f90 diff --git a/integration_tests/lp_dict_test_01_.f90 b/integration_tests/dict_test_01_.f90 similarity index 100% rename from integration_tests/lp_dict_test_01_.f90 rename to integration_tests/dict_test_01_.f90 diff --git a/integration_tests/lp_dict_test_02_.f90 b/integration_tests/dict_test_02_.f90 similarity index 100% rename from integration_tests/lp_dict_test_02_.f90 rename to integration_tests/dict_test_02_.f90 diff --git a/integration_tests/lp_dict_test_03_.f90 b/integration_tests/dict_test_03_.f90 similarity index 100% rename from integration_tests/lp_dict_test_03_.f90 rename to integration_tests/dict_test_03_.f90 diff --git a/integration_tests/lp_dict_test_04_.f90 b/integration_tests/dict_test_04_.f90 similarity index 100% rename from integration_tests/lp_dict_test_04_.f90 rename to integration_tests/dict_test_04_.f90 diff --git a/integration_tests/lp_list_of_lists_test.f90 b/integration_tests/list_of_lists_test.f90 similarity index 100% rename from integration_tests/lp_list_of_lists_test.f90 rename to integration_tests/list_of_lists_test.f90 diff --git a/integration_tests/lp_list_of_tuples_test.f90 b/integration_tests/list_of_tuples_test.f90 similarity index 100% rename from integration_tests/lp_list_of_tuples_test.f90 rename to integration_tests/list_of_tuples_test.f90 diff --git a/integration_tests/lp_list_test_01.f90 b/integration_tests/list_test_01.f90 similarity index 100% rename from integration_tests/lp_list_test_01.f90 rename to integration_tests/list_test_01.f90 diff --git a/integration_tests/lp_list_test_01_.f90 b/integration_tests/list_test_01_.f90 similarity index 100% rename from integration_tests/lp_list_test_01_.f90 rename to integration_tests/list_test_01_.f90 diff --git a/integration_tests/lp_list_test_02_.f90 b/integration_tests/list_test_02_.f90 similarity index 100% rename from integration_tests/lp_list_test_02_.f90 rename to integration_tests/list_test_02_.f90 diff --git a/integration_tests/lp_list_test_03_.f90 b/integration_tests/list_test_03_.f90 similarity index 100% rename from integration_tests/lp_list_test_03_.f90 rename to integration_tests/list_test_03_.f90 diff --git a/integration_tests/lp_list_test_04_.f90 b/integration_tests/list_test_04_.f90 similarity index 100% rename from integration_tests/lp_list_test_04_.f90 rename to integration_tests/list_test_04_.f90 diff --git a/integration_tests/lp_list_test_06_.f90 b/integration_tests/list_test_06_.f90 similarity index 100% rename from integration_tests/lp_list_test_06_.f90 rename to integration_tests/list_test_06_.f90 diff --git a/integration_tests/lp_list_test_08_.f90 b/integration_tests/list_test_08_.f90 similarity index 100% rename from integration_tests/lp_list_test_08_.f90 rename to integration_tests/list_test_08_.f90 diff --git a/integration_tests/lp_list_test_09_.f90 b/integration_tests/list_test_09_.f90 similarity index 100% rename from integration_tests/lp_list_test_09_.f90 rename to integration_tests/list_test_09_.f90 diff --git a/integration_tests/lp_set_test_01.f90 b/integration_tests/set_test_01.f90 similarity index 100% rename from integration_tests/lp_set_test_01.f90 rename to integration_tests/set_test_01.f90 diff --git a/integration_tests/lp_tuple_test_01_.f90 b/integration_tests/tuple_test_01_.f90 similarity index 100% rename from integration_tests/lp_tuple_test_01_.f90 rename to integration_tests/tuple_test_01_.f90 diff --git a/integration_tests/lp_tuple_test_02_.f90 b/integration_tests/tuple_test_02_.f90 similarity index 100% rename from integration_tests/lp_tuple_test_02_.f90 rename to integration_tests/tuple_test_02_.f90 diff --git a/integration_tests/lp_tuple_test_03_.f90 b/integration_tests/tuple_test_03_.f90 similarity index 100% rename from integration_tests/lp_tuple_test_03_.f90 rename to integration_tests/tuple_test_03_.f90 diff --git a/integration_tests/lp_tuple_test_04_.f90 b/integration_tests/tuple_test_04_.f90 similarity index 100% rename from integration_tests/lp_tuple_test_04_.f90 rename to integration_tests/tuple_test_04_.f90 diff --git a/integration_tests/lp_tuple_test_concat_.f90 b/integration_tests/tuple_test_concat_.f90 similarity index 100% rename from integration_tests/lp_tuple_test_concat_.f90 rename to integration_tests/tuple_test_concat_.f90 diff --git a/integration_tests/lp_tuple_test_nested_.f90 b/integration_tests/tuple_test_nested_.f90 similarity index 100% rename from integration_tests/lp_tuple_test_nested_.f90 rename to integration_tests/tuple_test_nested_.f90 diff --git a/integration_tests/lp_union_test_01.f90 b/integration_tests/union_test_01.f90 similarity index 100% rename from integration_tests/lp_union_test_01.f90 rename to integration_tests/union_test_01.f90 diff --git a/integration_tests/lp_union_test_02.f90 b/integration_tests/union_test_02.f90 similarity index 100% rename from integration_tests/lp_union_test_02.f90 rename to integration_tests/union_test_02.f90 diff --git a/integration_tests/union_test_03.f90 b/integration_tests/union_test_03.f90 new file mode 100644 index 00000000000..b3c844d3b08 --- /dev/null +++ b/integration_tests/union_test_03.f90 @@ -0,0 +1,21 @@ +module lp_union_test_03_mod + implicit none + _lfortran_union_type :: test_type + integer :: int_ + real :: float_ + end _lfortran_union_type +end module + + +program lp_union_test_03 + use lp_union_test_03_mod + implicit none + integer::x + type(test_type) :: test_union + + test_union%int_ = 100 + + x = test_union%int_ !Support direct comparision later + if ( x /= 100 ) error stop +end program + diff --git a/src/lfortran/parser/parser.yy b/src/lfortran/parser/parser.yy index 721bcccd42d..65e2c2b0eed 100644 --- a/src/lfortran/parser/parser.yy +++ b/src/lfortran/parser/parser.yy @@ -372,12 +372,12 @@ void yyerror(YYLTYPE *yyloc, LCompilers::LFortran::Parser &p, %token KW_WRITE // LFortran specific -%token KW_LF_LIST -%token KW_LF_SET -%token KW_LF_DICT -%token KW_LF_TUPLE -%token KW_LF_UNION_TYPE -%token KW_LF_END_UNION_TYPE +%token KW_LIST +%token KW_SET +%token KW_DICT +%token KW_TUPLE +%token KW_UNION_TYPE +%token KW_END_UNION_TYPE %type intrinsic_type_spec_list %type union_type_decl @@ -764,8 +764,8 @@ derived_type_decl union_type_decl - : KW_LF_UNION_TYPE var_modifiers id sep var_decl_star lf_end_union_type sep { - $$ = LF_UNION_TYPE($2, $3, TRIVIA($4, $7, @$), $5, @$); } + : KW_UNION_TYPE var_modifiers id sep var_decl_star lf_end_union_type sep { + $$ = UNION_TYPE($2, $3, TRIVIA($4, $7, @$), $5, @$); } ; template_decl @@ -817,7 +817,7 @@ end_type ; lf_end_union_type - : KW_LF_END_UNION_TYPE id_opt + : KW_END_UNION_TYPE id_opt ; derived_type_contains_opt @@ -1576,10 +1576,10 @@ intrinsic_type_spec | KW_DOUBLE_PRECISION { $$ = ATTR_TYPE(DoublePrecision, @$); } | KW_DOUBLE KW_COMPLEX { $$ = ATTR_TYPE(DoubleComplex, @$); } | KW_DOUBLE_COMPLEX { $$ = ATTR_TYPE(DoubleComplex, @$); } - | KW_LF_LIST "(" intrinsic_type_spec ")" { $$ = ATTR_TYPE_ATTR(LF_List, $3, @$); } - | KW_LF_SET "(" intrinsic_type_spec ")" { $$ = ATTR_TYPE_ATTR(LF_Set, $3, @$); } - | KW_LF_DICT "(" intrinsic_type_spec_list ")" { $$ = ATTR_TYPE_LIST(LF_Dict, $3, @$); } - | KW_LF_TUPLE "(" intrinsic_type_spec_list ")" { $$ = ATTR_TYPE_LIST(LF_Tuple, $3, @$); } + | KW_LIST "(" intrinsic_type_spec ")" { $$ = ATTR_TYPE_ATTR(List, $3, @$); } + | KW_SET "(" intrinsic_type_spec ")" { $$ = ATTR_TYPE_ATTR(Set, $3, @$); } + | KW_DICT "(" intrinsic_type_spec_list ")" { $$ = ATTR_TYPE_LIST(Dict, $3, @$); } + | KW_TUPLE "(" intrinsic_type_spec_list ")" { $$ = ATTR_TYPE_LIST(Tuple, $3, @$); } ; intrinsic_type_spec_list @@ -2741,8 +2741,8 @@ id | KW_WHERE { $$ = SYMBOL($1, @$); } | KW_WHILE { $$ = SYMBOL($1, @$); } | KW_WRITE { $$ = SYMBOL($1, @$); } - | KW_LF_LIST { $$ = SYMBOL($1, @$); } - | KW_LF_SET { $$ = SYMBOL($1, @$); } - | KW_LF_DICT { $$ = SYMBOL($1, @$); } - | KW_LF_TUPLE { $$ = SYMBOL($1, @$); } + | KW_LIST { $$ = SYMBOL($1, @$); } + | KW_SET { $$ = SYMBOL($1, @$); } + | KW_DICT { $$ = SYMBOL($1, @$); } + | KW_TUPLE { $$ = SYMBOL($1, @$); } ; diff --git a/src/lfortran/parser/semantics.h b/src/lfortran/parser/semantics.h index 5cbd865e7f9..540ff8cdc2a 100644 --- a/src/lfortran/parser/semantics.h +++ b/src/lfortran/parser/semantics.h @@ -2536,7 +2536,7 @@ return make_Submodule_t(al, a_loc, TYPEPARAMETER0(p.m_a, attr, name, trivia, l) -#define LF_UNION_TYPE(attr, name, trivia, decl, l) make_Union_t(p.m_a, l, \ +#define UNION_TYPE(attr, name, trivia, decl, l) make_Union_t(p.m_a, l, \ name2char(name), \ trivia_cast(trivia), \ VEC_CAST(attr, decl_attribute), attr.size(), \ diff --git a/src/lfortran/parser/tokenizer.re b/src/lfortran/parser/tokenizer.re index 80f16d35c33..4aee6dbf31c 100644 --- a/src/lfortran/parser/tokenizer.re +++ b/src/lfortran/parser/tokenizer.re @@ -527,13 +527,13 @@ int Tokenizer::lex(Allocator &al, YYSTYPE &yylval, Location &loc, diag::Diagnost 'where' { KW(WHERE) } 'while' { KW(WHILE) } 'write' { KW(WRITE) } - '_lfortran_list' { KW(LF_LIST) } - '_lfortran_set' { KW(LF_SET) } - '_lfortran_dict' { KW(LF_DICT) } - '_lfortran_tuple' { KW(LF_TUPLE) } - '_lfortran_union_type' { KW(LF_UNION_TYPE) } + '_lfortran_list' { KW(LIST) } + '_lfortran_set' { KW(SET) } + '_lfortran_dict' { KW(DICT) } + '_lfortran_tuple' { KW(TUPLE) } + '_lfortran_union_type' { KW(UNION_TYPE) } - 'end' whitespace '_lfortran_union_type' { KW(LF_END_UNION_TYPE) } + 'end' whitespace '_lfortran_union_type' { KW(END_UNION_TYPE) } // Tokens newline { diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 19361386c9f..135f2985129 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -3982,7 +3982,8 @@ class CommonVisitor : public AST::BaseVisitor { } else { symbol_variable->m_type = type; } - if (ASR::is_a(*ASRUtils::extract_type(symbol_variable->m_type))) { + if (ASR::is_a(*ASRUtils::extract_type(symbol_variable->m_type)) + || ASR::is_a(*ASRUtils::extract_type(symbol_variable->m_type))) { symbol_variable->m_type_declaration = type_declaration; } else if ( type_declaration != nullptr ) { // This is the case where the variable is implicitly declared `public :: xx` @@ -4741,7 +4742,7 @@ class CommonVisitor : public AST::BaseVisitor { // ONLY supposed to be used for LFortran specific types AST::AttrTypeList_t *sym_type = AST::down_cast(decl_attribute); - if (sym_type->m_type == AST::decl_typeType::TypeLF_Dict) { + if (sym_type->m_type == AST::decl_typeType::TypeDict) { if (sym_type->n_attr != 2) { diag.add(Diagnostic( "Dict declaration needs exactly two types", @@ -4757,7 +4758,7 @@ class CommonVisitor : public AST::BaseVisitor { is_allocatable, dims, var_sym, type_declaration, abi); return ASRUtils::TYPE(ASR::make_Dict_t(al, sym_type->base.base.loc, key_type, value_type)); - } else if (sym_type->m_type == AST::decl_typeType::TypeLF_Tuple) { + } else if (sym_type->m_type == AST::decl_typeType::TypeTuple) { if (sym_type->n_attr < 1) { diag.add(Diagnostic( "Tuple declaration needs atleast one type", @@ -5070,7 +5071,8 @@ class CommonVisitor : public AST::BaseVisitor { } else if (v && ASRUtils::is_c_funptr(v, derived_type_name)) { type = ASRUtils::TYPE(ASR::make_CPtr_t(al, loc)); } else if (v && ASR::is_a(*v)) { - type = ASRUtils::TYPE(ASR::make_UnionType_t(al, loc, v)); + type_declaration = v; + type = ASRUtils::get_union_type(al, loc, v); } else { if (!v) { if (is_template) { @@ -5119,7 +5121,7 @@ class CommonVisitor : public AST::BaseVisitor { type_declaration = v; // type = ASRUtils::TYPE(ASRUtils::make_StructType_t_util(al, loc, v)); if (v && ASRUtils::symbol_get_past_external(v) && ASR::is_a(*ASRUtils::symbol_get_past_external(v))) { - type = ASRUtils::TYPE(ASR::make_UnionType_t(al, loc, v)); + type = ASRUtils::get_union_type(al, loc, ASRUtils::symbol_get_past_external(v)); } else if ( v && ASRUtils::symbol_get_past_external(v) ) { type = ASRUtils::make_StructType_t_util(al, loc, v, true); } @@ -5130,7 +5132,7 @@ class CommonVisitor : public AST::BaseVisitor { type)); } } - } else if (sym_type->m_type == AST::decl_typeType::TypeLF_List) { + } else if (sym_type->m_type == AST::decl_typeType::TypeList) { ASR::ttype_t* type = determine_type(loc, sym, sym_type->m_attr, is_pointer, is_allocatable, dims, var_sym, type_declaration, abi, is_argument); @@ -5142,7 +5144,7 @@ class CommonVisitor : public AST::BaseVisitor { is_argument); return ASRUtils::TYPE(ASR::make_List_t(al, loc, type)); - } else if (sym_type->m_type == AST::decl_typeType::TypeLF_Set) { + } else if (sym_type->m_type == AST::decl_typeType::TypeSet) { return ASRUtils::TYPE(ASR::make_Set_t(al, loc, determine_type(loc, sym, sym_type->m_attr, is_pointer, is_allocatable, dims, var_sym, type_declaration, abi, is_argument))); @@ -6871,7 +6873,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::ttype_t* v_type = v_variable_m_type; ASR::symbol_t *derived_type = nullptr; if (ASR::is_a(*v_type)) { - derived_type = ASR::down_cast(v_type)->m_union_type; + derived_type = ASRUtils::symbol_get_past_external(v_variable->m_type_declaration); } ASR::Union_t *der_type; if (ASR::is_a(*derived_type)) { @@ -7646,7 +7648,7 @@ class CommonVisitor : public AST::BaseVisitor { } - ASR::asr_t* create_LFLen(const AST::FuncCallOrArray_t& x) { + ASR::asr_t* create_Len(const AST::FuncCallOrArray_t& x) { if (x.n_args != 1 || x.n_keywords > 0) { diag.add(Diagnostic("_lfortran_len expects exactly one argument, got " + std::to_string(x.n_args) + " arguments instead.", @@ -7676,7 +7678,7 @@ class CommonVisitor : public AST::BaseVisitor { } } - ASR::asr_t* create_LFGetItem(const AST::FuncCallOrArray_t& x) { + ASR::asr_t* create_GetItem(const AST::FuncCallOrArray_t& x) { if (x.n_args != 2 || x.n_keywords > 0) { diag.add(Diagnostic("_lfortran_get_item expects exactly two arguments, got " + std::to_string(x.n_args) + " arguments instead.", @@ -7784,7 +7786,7 @@ class CommonVisitor : public AST::BaseVisitor { } } - ASR::asr_t* create_LFPop(const AST::FuncCallOrArray_t& x) { + ASR::asr_t* create_Pop(const AST::FuncCallOrArray_t& x) { if (x.n_args != 2 || x.n_keywords > 0) { diag.add(Diagnostic("_lfortran_pop expects exactly two arguments, got " + std::to_string(x.n_args) + " arguments instead.", @@ -7855,7 +7857,7 @@ class CommonVisitor : public AST::BaseVisitor { } - ASR::asr_t* create_LFConcat(const AST::FuncCallOrArray_t& x) { + ASR::asr_t* create_Concat(const AST::FuncCallOrArray_t& x) { if (x.n_keywords > 0) { diag.add(Diagnostic("_lfortran_concat expects no keyword arguments", Level::Error, Stage::Semantic, {Label("", {x.base.base.loc})})); @@ -7933,7 +7935,7 @@ class CommonVisitor : public AST::BaseVisitor { } } - ASR::asr_t* create_LFEq(const AST::FuncCallOrArray_t& x) { + ASR::asr_t* create_Eq(const AST::FuncCallOrArray_t& x) { if (x.n_keywords > 0) { diag.add(Diagnostic("_lfortran_eq expects no keyword arguments", Level::Error, Stage::Semantic, {Label("", {x.base.base.loc})})); @@ -9033,15 +9035,15 @@ class CommonVisitor : public AST::BaseVisitor { if ( var_name == "_lfortran_unsigned") tmp = create_unsigned_const(x); else if ( var_name == "_lfortran_len") - tmp = create_LFLen(x); + tmp = create_Len(x); else if ( var_name == "_lfortran_get_item") - tmp = create_LFGetItem(x); + tmp = create_GetItem(x); else if ( var_name == "_lfortran_pop") - tmp = create_LFPop(x); + tmp = create_Pop(x); else if ( var_name == "_lfortran_concat") - tmp = create_LFConcat(x); + tmp = create_Concat(x); else if ( var_name == "_lfortran_eq") - tmp = create_LFEq(x); + tmp = create_Eq(x); else if ( var_name == "_lfortran_list_constant") tmp = create_ListConstant(x); else if ( var_name == "_lfortran_list_count") diff --git a/src/lfortran/semantics/ast_symboltable_visitor.cpp b/src/lfortran/semantics/ast_symboltable_visitor.cpp index 4de9b6ae698..d6009b1479b 100644 --- a/src/lfortran/semantics/ast_symboltable_visitor.cpp +++ b/src/lfortran/semantics/ast_symboltable_visitor.cpp @@ -1594,7 +1594,7 @@ class SymbolTableVisitor : public CommonVisitor { if (return_type->m_attr && return_type->m_attr && return_type->m_attr->type == AST::decl_attributeType::AttrType) { AST::AttrType_t *return_attr_type = AST::down_cast(return_type->m_attr); - if (return_attr_type->m_type == AST::decl_typeType::TypeLF_List) { + if (return_attr_type->m_type == AST::decl_typeType::TypeList) { ASR::symbol_t *type_declaration; Vec dims; dims.reserve(al, 0); @@ -1997,7 +1997,7 @@ class SymbolTableVisitor : public CommonVisitor { ASR::symbol_t* sym = dt_variable->m_type_declaration; aggregate_type_name = ASRUtils::symbol_name(sym); } else if ( ASR::is_a(*var_type) ) { - ASR::symbol_t* sym = ASR::down_cast(var_type)->m_union_type; + ASR::symbol_t* sym = dt_variable->m_type_declaration; aggregate_type_name = ASRUtils::symbol_name(sym); } } @@ -2057,8 +2057,14 @@ class SymbolTableVisitor : public CommonVisitor { current_scope = al.make_new(parent_scope); data_member_names.reserve(al, 0); is_derived_type = true; + ASR::accessType dflt_access_copy = dflt_access; for (size_t i=0; ivisit_unit_decl2(*x.m_items[i]); + try { + this->visit_unit_decl2(*x.m_items[i]); + } catch (const SemanticAbort&) { + current_scope = parent_scope; + throw; + } } std::string sym_name = to_lower(x.m_name); @@ -2083,22 +2089,36 @@ class SymbolTableVisitor : public CommonVisitor { } char* aggregate_type_name = nullptr; if (item.first != "~unlimited_polymorphic_type") { + LCOMPILERS_ASSERT(ASR::is_a(*item.second)); + ASR::Variable_t* var = ASR::down_cast(item.second); ASR::ttype_t* var_type = ASRUtils::type_get_past_pointer(ASRUtils::symbol_type(item.second)); if( ASR::is_a(*var_type) ) { - ASR::symbol_t* sym = ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(ASRUtils::EXPR(ASR::make_Var_t(al, x.base.base.loc, item.second)))); + ASR::symbol_t* sym = var->m_type_declaration; aggregate_type_name = ASRUtils::symbol_name(sym); } else if ( ASR::is_a(*var_type) ) { - ASR::symbol_t* sym = ASR::down_cast(var_type)->m_union_type; + ASR::symbol_t* sym = var->m_type_declaration; aggregate_type_name = ASRUtils::symbol_name(sym); + } else if ( ASR::is_a(*var_type) + || ASR::is_a(*var_type) + || ASR::is_a(*var_type) + || ASR::is_a(*var_type)) { + + diag.add(diag::Diagnostic( + "Type `" + ASRUtils::type_to_str_fortran(var_type) + "` is not allowed inside Union", + diag::Level::Error, diag::Stage::Semantic, { + diag::Label("", {})})); + throw SemanticAbort(); } } if( aggregate_type_name ) { union_dependencies.push_back(al, aggregate_type_name); } } - tmp = ASR::make_Union_t(al, x.base.base.loc, current_scope, s2c(al, to_lower(x.m_name)), - union_dependencies.p, union_dependencies.size(), data_member_names.p, data_member_names.size(), - ASR::abiType::Source, dflt_access, nullptr, 0, parent_sym); + + tmp = ASR::make_Union_t(al, x.base.base.loc, current_scope, + s2c(al, to_lower(x.m_name)), union_dependencies.p, union_dependencies.n, + data_member_names.p, data_member_names.n, ASR::abiType::Source, + dflt_access, nullptr, 0, parent_sym); ASR::symbol_t* union_type_sym = ASR::down_cast(tmp); if (compiler_options.implicit_typing) { @@ -2109,6 +2129,7 @@ class SymbolTableVisitor : public CommonVisitor { current_scope = parent_scope; is_derived_type = false; + dflt_access = dflt_access_copy; } void visit_InterfaceProc(const AST::InterfaceProc_t &x) { diff --git a/src/libasr/ASR.asdl b/src/libasr/ASR.asdl index 4b6897e9ab1..9247abfeabb 100644 --- a/src/libasr/ASR.asdl +++ b/src/libasr/ASR.asdl @@ -208,7 +208,7 @@ ttype | Tuple(ttype* type) | StructType(ttype* data_member_types, ttype* member_function_types, bool is_cstruct, bool is_unlimited_polymorphic) | EnumType(symbol enum_type) - | UnionType(symbol union_type) + | UnionType(ttype* data_member_types) | Dict(ttype key_type, ttype value_type) | Pointer(ttype type) | Allocatable(ttype type) diff --git a/src/libasr/asr_utils.cpp b/src/libasr/asr_utils.cpp index 182460151a5..5a8703d6570 100644 --- a/src/libasr/asr_utils.cpp +++ b/src/libasr/asr_utils.cpp @@ -560,6 +560,68 @@ void set_struct_sym_to_struct_expr(ASR::expr_t* expression, ASR::symbol_t* struc } +ASR::symbol_t* get_union_sym_from_union_expr(ASR::expr_t* expression) +{ + switch (expression->type) { + case ASR::exprType::Var: { + // The symbol m_v has to be `Variable` or 'Function' for a Union expression. + if (ASR::is_a(*ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v))) { + ASR::Variable_t* var = ASR::down_cast(ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v)); + return var->m_type_declaration; + } else if (ASR::is_a(*ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v))) { + ASR::Function_t* func = ASR::down_cast(ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v)); + if (func->m_return_var != nullptr && ASRUtils::symbol_get_past_external(ASRUtils::get_union_sym_from_union_expr(func->m_return_var))) { + return ASRUtils::symbol_get_past_external(ASRUtils::get_union_sym_from_union_expr(func->m_return_var)); + } else { + for (size_t i = 0; i < func->n_args; i++) { + ASR::expr_t* arg = func->m_args[i]; + if (arg != nullptr) { + ASR::symbol_t* union_sym = ASRUtils::symbol_get_past_external(ASRUtils::get_union_sym_from_union_expr(arg)); + if (union_sym != nullptr) { + return union_sym; + } + } + } + return nullptr; + } + } else if (ASR::is_a(*ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v))) { + // If the Var is a Union, we return the symbol of the Union. + return ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v); + } else { + throw LCompilersException("Expected Var to be either Variable or Function type, but found: " + + std::to_string(ASR::down_cast(expression)->m_v->type)); + } + } + case ASR::exprType::UnionInstanceMember: { + ASR::UnionInstanceMember_t* union_instance_member = ASR::down_cast(expression); + ASR::Variable_t* var = ASR::down_cast(ASRUtils::symbol_get_past_external(union_instance_member->m_m)); + return var->m_type_declaration; + } + case ASR::exprType::FunctionCall: { + ASR::FunctionCall_t* func_call = ASR::down_cast(expression); + // `func_call->m_dt` will be non-null for Union expressions + if ( func_call->m_dt != nullptr ){ + // If `func_call->m_dt` is not null, it means that the function call + // is returning a union type. + return ASRUtils::symbol_get_past_external(ASRUtils::get_union_sym_from_union_expr(func_call->m_dt)); + } else { + ASR::Function_t* func = ASR::down_cast(ASRUtils::symbol_get_past_external(func_call->m_name)); + return ASRUtils::symbol_get_past_external(ASRUtils::get_union_sym_from_union_expr(func->m_return_var)); + } + } + case ASR::exprType::UnionConstructor: { + ASR::UnionConstructor_t* union_constructor = ASR::down_cast(expression); + return union_constructor->m_dt_sym; + } + default: { + throw LCompilersException("get_union_sym_from_union_expr() not implemented for " + + std::to_string(expression->type)); + return nullptr; + } + } +} + + // Recursively fetch `ASR::Function_t` from an `ASR::expr_t` if it has `FunctionType`. const ASR::Function_t* get_function_from_expr(ASR::expr_t* expr) { if (!expr) { diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 7168a8cb779..036c032d165 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -78,6 +78,8 @@ const ASR::Function_t* get_function_from_expr(ASR::expr_t* expr); ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression); void set_struct_sym_to_struct_expr(ASR::expr_t* expression, ASR::symbol_t* struct_sym); +ASR::symbol_t* get_union_sym_from_union_expr(ASR::expr_t* expression); + static inline std::string extract_real(const char *s) { // TODO: this is inefficient. We should // convert this in the tokenizer where we know most information @@ -1993,8 +1995,12 @@ static inline std::string get_type_code(const ASR::ttype_t *t, bool use_undersco break; } case ASR::ttypeType::UnionType: { - ASR::UnionType_t* d = ASR::down_cast(t); - res = symbol_name(d->m_union_type); + if ( expr != nullptr ) { + ASR::symbol_t* sym = ASRUtils::symbol_get_past_external(ASRUtils::get_union_sym_from_union_expr(expr)); + res = symbol_name(sym); + } else { + res = "UnionType"; + } break; } case ASR::ttypeType::Pointer: { @@ -2137,8 +2143,8 @@ static inline std::string type_to_str_python(const ASR::ttype_t *t, bool for_err return "enum " + std::string(symbol_name(d->m_enum_type)); } case ASR::ttypeType::UnionType: { - ASR::UnionType_t* d = ASR::down_cast(t); - return "union " + std::string(symbol_name(d->m_union_type)); + /*ASR::UnionType_t* d = ASR::down_cast(t);*/ + return "UnionType"; } case ASR::ttypeType::Pointer: { ASR::Pointer_t* p = ASR::down_cast(t); @@ -3169,7 +3175,7 @@ static inline ASR::ttype_t* duplicate_type(Allocator& al, const ASR::ttype_t* t, case ASR::ttypeType::UnionType: { ASR::UnionType_t* tnew = ASR::down_cast(t); t_ = ASRUtils::TYPE(ASR::make_UnionType_t(al, t->base.loc, - tnew->m_union_type)); + tnew->m_data_member_types, tnew->n_data_member_types)); break; } case ASR::ttypeType::Pointer: { @@ -3905,15 +3911,16 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, return true; } case (ASR::ttypeType::UnionType) : { - ASR::UnionType_t *a2 = ASR::down_cast(a); - ASR::UnionType_t *b2 = ASR::down_cast(b); - ASR::Union_t *a2_type = ASR::down_cast( - ASRUtils::symbol_get_past_external( - a2->m_union_type)); - ASR::Union_t *b2_type = ASR::down_cast( - ASRUtils::symbol_get_past_external( - b2->m_union_type)); - return a2_type == b2_type; + ASR::UnionType_t *u1 = ASR::down_cast(a); + ASR::UnionType_t *u2 = ASR::down_cast(b); + if (u1->n_data_member_types != u2->n_data_member_types) return false; + for (size_t i = 0; i < u1->n_data_member_types; i++) { + if (!types_equal(u1->m_data_member_types[i], u2->m_data_member_types[i])) { + return false; + } + } + + return true; } case ASR::ttypeType::FunctionType: { ASR::FunctionType_t* a2 = ASR::down_cast(a); @@ -4035,15 +4042,17 @@ inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, return true; } case (ASR::ttypeType::UnionType) : { - ASR::UnionType_t *a2 = ASR::down_cast(a); - ASR::UnionType_t *b2 = ASR::down_cast(b); - ASR::Union_t *a2_type = ASR::down_cast( - ASRUtils::symbol_get_past_external( - a2->m_union_type)); - ASR::Union_t *b2_type = ASR::down_cast( - ASRUtils::symbol_get_past_external( - b2->m_union_type)); - return a2_type == b2_type; + ASR::UnionType_t *u1 = ASR::down_cast(a); + ASR::UnionType_t *u2 = ASR::down_cast(b); + + if (u1->n_data_member_types != u2->n_data_member_types) return false; + for (size_t i = 0; i < u1->n_data_member_types; i++) { + if (!types_equal(u1->m_data_member_types[i], u2->m_data_member_types[i])) { + return false; + } + } + + return true; } case ASR::ttypeType::FunctionType: { ASR::FunctionType_t* a2 = ASR::down_cast(a); @@ -5347,6 +5356,18 @@ static inline ASR::expr_t* get_size(ASR::expr_t* arr_expr, Allocator& al, bool f return ASRUtils::EXPR(ASRUtils::make_ArraySize_t_util(al, arr_expr->base.loc, arr_expr, nullptr, int32_type, nullptr, for_type)); } +static inline ASR::ttype_t* get_union_type(Allocator &al, const Location &loc, ASR::symbol_t* union_sym) { + Vec member_type_vec; + member_type_vec.reserve(al, 1); + ASR::Union_t* union_sym_ = ASR::down_cast(union_sym); + for (size_t i=0;in_members;i++) { + ASR::symbol_t* member_sym = union_sym_->m_symtab->resolve_symbol(union_sym_->m_members[i]); + ASR::Variable_t* member_var = ASR::down_cast(member_sym); + member_type_vec.push_back(al, member_var->m_type); + } + return ASRUtils::TYPE(ASR::make_UnionType_t(al, loc, member_type_vec.p, member_type_vec.n)); +} + static inline ASR::Enum_t* get_Enum_from_symbol(ASR::symbol_t* s) { ASR::Variable_t* s_var = ASR::down_cast(s); if( ASR::is_a(*s_var->m_type) ) { diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index 1d24349d197..678ebbf5ff5 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -561,9 +561,6 @@ class VerifyVisitor : public BaseWalkVisitor if( ASR::is_a(*var_type) ) { sym = ASR::down_cast(var_type)->m_enum_type; aggregate_type_name = ASRUtils::symbol_name(sym); - } else if( ASR::is_a(*var_type) ) { - sym = ASR::down_cast(var_type)->m_union_type; - aggregate_type_name = ASRUtils::symbol_name(sym); } if( aggregate_type_name && ASRUtils::symbol_parent_symtab(sym) != current_symtab ) { struct_dependencies.push_back(std::string(aggregate_type_name)); diff --git a/src/libasr/codegen/asr_to_c.cpp b/src/libasr/codegen/asr_to_c.cpp index a2322ebc448..12107aa3018 100644 --- a/src/libasr/codegen/asr_to_c.cpp +++ b/src/libasr/codegen/asr_to_c.cpp @@ -503,9 +503,8 @@ class ASRToCVisitor : public BaseCCPPVisitor } } else if (ASR::is_a(*v_m_type)) { std::string indent(indentation_level*indentation_spaces, ' '); - ASR::UnionType_t *t = ASR::down_cast(v_m_type); std::string der_type_name = ASRUtils::symbol_name( - ASRUtils::symbol_get_past_external(t->m_union_type)); + ASRUtils::symbol_get_past_external(v.m_type_declaration)); if( is_array ) { bool is_fixed_size = true; dims = convert_dims_c(n_dims, m_dims, v_m_type, is_fixed_size, true); diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 6d9df2d872b..15dc09e58ab 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -8778,9 +8778,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor break; } case ASR::ttypeType::UnionType: { - ASR::UnionType_t* der = ASR::down_cast(t2_); ASR::Union_t* der_type = ASR::down_cast( - ASRUtils::symbol_get_past_external(der->m_union_type)); + ASRUtils::symbol_get_past_external(x->m_type_declaration)); current_der_type_name = std::string(der_type->m_name); uint32_t h = get_hash((ASR::asr_t*)x); if( llvm_symtab.find(h) != llvm_symtab.end() ) { diff --git a/src/libasr/codegen/llvm_utils.cpp b/src/libasr/codegen/llvm_utils.cpp index a5360d9dab8..31cefcab16f 100644 --- a/src/libasr/codegen/llvm_utils.cpp +++ b/src/libasr/codegen/llvm_utils.cpp @@ -159,7 +159,7 @@ namespace LCompilers { break ; } case ASR::ttypeType::UnionType: { - llvm_mem_type = getUnion(mem_type, module); + llvm_mem_type = getUnion(ASR::down_cast(member->m_type_declaration), module); break; } case ASR::ttypeType::Allocatable: { @@ -291,13 +291,6 @@ namespace LCompilers { return (llvm::Type*) union_type_llvm; } - llvm::Type* LLVMUtils::getUnion(ASR::ttype_t* _type, llvm::Module* module, bool is_pointer) { - ASR::UnionType_t* union_ = ASR::down_cast(_type); - ASR::symbol_t* union_sym = ASRUtils::symbol_get_past_external(union_->m_union_type); - ASR::Union_t* union_type = ASR::down_cast(union_sym); - return getUnion(union_type, module, is_pointer); - } - llvm::Type* LLVMUtils::getClassType(ASR::Struct_t* der_type, bool is_pointer) { std::string der_type_name = std::string(der_type->m_name) + std::string("_polymorphic"); llvm::StructType* der_type_llvm = nullptr; @@ -430,7 +423,9 @@ namespace LCompilers { break; } case ASR::ttypeType::UnionType: { - el_type = getUnion(m_type_, module); + el_type = getUnion(ASR::down_cast( + ASRUtils::symbol_get_past_external(ASRUtils::get_union_sym_from_union_expr(expr))), + module); break; } case ASR::ttypeType::String: { @@ -1228,7 +1223,10 @@ namespace LCompilers { break; } case (ASR::ttypeType::UnionType) : { - llvm_type = getUnion(asr_type, module, false); + llvm_type = getUnion(ASR::down_cast( + ASRUtils::symbol_get_past_external(ASRUtils::get_union_sym_from_union_expr(arg_expr))), + module, + LLVM::is_llvm_pointer(*asr_type)); break; } case (ASR::ttypeType::Pointer) : { diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index 9106a66116e..fb9f77f6468 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -464,9 +464,6 @@ namespace LCompilers { llvm::Type* getUnion(ASR::Union_t* union_type, llvm::Module* module, bool is_pointer=false); - llvm::Type* getUnion(ASR::ttype_t* _type, - llvm::Module* module, bool is_pointer=false); - llvm::Type* getClassType(ASR::Struct_t* der_type, bool is_pointer=false); llvm::Type* getFPType(int a_kind, bool get_pointer=false); From 6bf4d3bc31af7f97a8d7904ac072f4071671daf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Thu, 7 Aug 2025 14:15:42 -0700 Subject: [PATCH 016/119] Update types_equal() to use the new API --- src/libasr/asr_utils.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index faa2f41470b..e265ff13496 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -3928,7 +3928,8 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, ASR::expr_t* a_expr, A ASR::UnionType_t *u2 = ASR::down_cast(b); if (u1->n_data_member_types != u2->n_data_member_types) return false; for (size_t i = 0; i < u1->n_data_member_types; i++) { - if (!types_equal(u1->m_data_member_types[i], u2->m_data_member_types[i])) { + if (!types_equal(u1->m_data_member_types[i], u2->m_data_member_types[i], nullptr, + nullptr, false)) { return false; } } @@ -4074,7 +4075,8 @@ inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, if (u1->n_data_member_types != u2->n_data_member_types) return false; for (size_t i = 0; i < u1->n_data_member_types; i++) { - if (!types_equal(u1->m_data_member_types[i], u2->m_data_member_types[i])) { + if (!types_equal(u1->m_data_member_types[i], u2->m_data_member_types[i], nullptr, + nullptr, false)) { return false; } } From b48e7f84af4be203ac700b2f3e1b01d8dd4ea34c Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Fri, 8 Aug 2025 02:47:25 +0530 Subject: [PATCH 017/119] chore: use `Union` symbol for type checking Signed-off-by: Saurabh Kumar --- src/libasr/asr_utils.h | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index e265ff13496..256b47e6dec 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -3924,17 +3924,14 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, ASR::expr_t* a_expr, A return true; } case (ASR::ttypeType::UnionType) : { - ASR::UnionType_t *u1 = ASR::down_cast(a); - ASR::UnionType_t *u2 = ASR::down_cast(b); - if (u1->n_data_member_types != u2->n_data_member_types) return false; - for (size_t i = 0; i < u1->n_data_member_types; i++) { - if (!types_equal(u1->m_data_member_types[i], u2->m_data_member_types[i], nullptr, - nullptr, false)) { - return false; - } - } + ASR::Union_t* x_union = ASR::down_cast(ASRUtils::symbol_get_past_external( + ASRUtils::get_union_sym_from_union_expr(a_expr))); + ASR::Union_t* y_union = ASR::down_cast(ASRUtils::symbol_get_past_external( + ASRUtils::get_union_sym_from_union_expr(b_expr))); + + if (x_union == y_union) return true; - return true; + return false; } case ASR::ttypeType::FunctionType: { ASR::FunctionType_t* a2 = ASR::down_cast(a); @@ -4070,18 +4067,14 @@ inline bool types_equal_with_substitution(ASR::ttype_t *a, ASR::ttype_t *b, return true; } case (ASR::ttypeType::UnionType) : { - ASR::UnionType_t *u1 = ASR::down_cast(a); - ASR::UnionType_t *u2 = ASR::down_cast(b); + ASR::Union_t* x_union = ASR::down_cast(ASRUtils::symbol_get_past_external( + ASRUtils::get_union_sym_from_union_expr(a_expr))); + ASR::Union_t* y_union = ASR::down_cast(ASRUtils::symbol_get_past_external( + ASRUtils::get_union_sym_from_union_expr(b_expr))); - if (u1->n_data_member_types != u2->n_data_member_types) return false; - for (size_t i = 0; i < u1->n_data_member_types; i++) { - if (!types_equal(u1->m_data_member_types[i], u2->m_data_member_types[i], nullptr, - nullptr, false)) { - return false; - } - } + if (x_union == y_union) return true; - return true; + return false; } case ASR::ttypeType::FunctionType: { ASR::FunctionType_t* a2 = ASR::down_cast(a); From fd5671b2af012c48f6778f6297827a903b82b40a Mon Sep 17 00:00:00 2001 From: akramhany Date: Thu, 7 Aug 2025 22:23:22 +0300 Subject: [PATCH 018/119] refactor: use a different type for fortran strings (non-null teriminated) --- src/libasr/runtime/lfortran_intrinsics.c | 2 +- src/libasr/runtime/lfortran_intrinsics.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libasr/runtime/lfortran_intrinsics.c b/src/libasr/runtime/lfortran_intrinsics.c index 0fadb155067..d14e05b2772 100644 --- a/src/libasr/runtime/lfortran_intrinsics.c +++ b/src/libasr/runtime/lfortran_intrinsics.c @@ -708,7 +708,7 @@ within character string edit descriptor E.g.; "('Number : ', I 2, 5 X, A)" becomes '('Number : ', I2, 5X, A)' */ -char* remove_spaces_except_quotes(const char* format, const int64_t len, int* cleaned_format_len) { +char* remove_spaces_except_quotes(const fchar* format, const int64_t len, int* cleaned_format_len) { char* cleaned_format = malloc(len + 1); // +1 for optional '\0' at end int j = 0; diff --git a/src/libasr/runtime/lfortran_intrinsics.h b/src/libasr/runtime/lfortran_intrinsics.h index 6a57a94165c..74076fcec78 100644 --- a/src/libasr/runtime/lfortran_intrinsics.h +++ b/src/libasr/runtime/lfortran_intrinsics.h @@ -18,6 +18,8 @@ struct _lfortran_complex_64 { double re, im; }; +typedef int8_t fchar; + #ifdef _MSC_VER typedef _Fcomplex float_complex_t; typedef _Dcomplex double_complex_t; From b38f5b18836d57d7d62ca21024541991fd8e957e Mon Sep 17 00:00:00 2001 From: akramhany Date: Thu, 7 Aug 2025 22:43:02 +0300 Subject: [PATCH 019/119] refactor: do small refactoring in _lcompilers_string_format_fortran --- src/libasr/runtime/lfortran_intrinsics.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libasr/runtime/lfortran_intrinsics.c b/src/libasr/runtime/lfortran_intrinsics.c index d14e05b2772..7fbe893d4cf 100644 --- a/src/libasr/runtime/lfortran_intrinsics.c +++ b/src/libasr/runtime/lfortran_intrinsics.c @@ -771,7 +771,7 @@ int find_matching_parentheses(const char* format, int index){ * e.g. "(I5, F5.2, T10)" is split separately into "I5", "F5.2", "T10" as * format specifiers */ -char** parse_fortran_format(char* format, int64_t *count, int64_t *item_start) { +char** parse_fortran_format(char* format, const int64_t format_len, int64_t *count, int64_t *item_start) { char** format_values_2 = (char**)malloc((*count + 1) * sizeof(char*)); int format_values_count = *count; int index = 0 , start = 0; @@ -1561,7 +1561,7 @@ LFORTRAN_API char* _lcompilers_string_format_fortran(const char* format, int64_t strncpy(modified_input_string, cleaned_format, len); modified_input_string[len] = '\0'; strip_outer_parenthesis(cleaned_format, len, modified_input_string); - format_values = parse_fortran_format(modified_input_string, &format_values_count, &item_start_idx); + format_values = parse_fortran_format(modified_input_string, strlen(modified_input_string), &format_values_count, &item_start_idx); /* is_SP_specifier = false --> 'S' OR 'SS' is_SP_specifier = true --> 'SP' @@ -1578,10 +1578,12 @@ LFORTRAN_API char* _lcompilers_string_format_fortran(const char* format, int64_t char* value; if(format_values[i] == NULL) continue; value = format_values[i]; - if (value[0] == '(' && value[strlen(value)-1] == ')') { - value[strlen(value)-1] = '\0'; + int64_t value_len = strlen(value); + if (value_len >= 2 && value[0] == '(' && value[value_len - 1] == ')') { + value[value_len - 1] = '\0'; int64_t new_fmt_val_count = 0; - char** new_fmt_val = parse_fortran_format(++value, &new_fmt_val_count, &item_start_idx); + value += 1; + char** new_fmt_val = parse_fortran_format(value, value_len - 2, &new_fmt_val_count, &item_start_idx); char** ptr = (char**)realloc(format_values, (format_values_count + new_fmt_val_count + 1) * sizeof(char*)); if (ptr == NULL) { perror("Memory allocation failed.\n"); From ed7b01493b6472b81dac9d3a64b9f4a624b52c39 Mon Sep 17 00:00:00 2001 From: akramhany Date: Thu, 7 Aug 2025 23:27:31 +0300 Subject: [PATCH 020/119] refactor: make parse_fortran_format null independant --- src/libasr/runtime/lfortran_intrinsics.c | 126 ++++++++++++----------- 1 file changed, 64 insertions(+), 62 deletions(-) diff --git a/src/libasr/runtime/lfortran_intrinsics.c b/src/libasr/runtime/lfortran_intrinsics.c index 7fbe893d4cf..e9a44f5580c 100644 --- a/src/libasr/runtime/lfortran_intrinsics.c +++ b/src/libasr/runtime/lfortran_intrinsics.c @@ -764,18 +764,20 @@ int find_matching_parentheses(const char* format, int index){ * parse fortran format string by extracting individual 'format specifiers' * (e.g. 'i', 't', '*' etc.) into an array of strings * - * `char* format`: the string we need to split into format specifiers + * `fchar* format`: the fortran string we need to split into format specifiers (it should be null-independant) * `int* count` : store count of format specifiers (passed by reference from caller) * `item_start` : * * e.g. "(I5, F5.2, T10)" is split separately into "I5", "F5.2", "T10" as * format specifiers */ -char** parse_fortran_format(char* format, const int64_t format_len, int64_t *count, int64_t *item_start) { +char** parse_fortran_format(const fchar* format, const int64_t format_len, int64_t *count, int64_t *item_start) { + const char* cformat = (const char*)format; char** format_values_2 = (char**)malloc((*count + 1) * sizeof(char*)); int format_values_count = *count; int index = 0 , start = 0; - while (index < strlen(format) && format[index] != '\0') { + + while (index < format_len) { char** ptr = (char**)realloc(format_values_2, (format_values_count + 1) * sizeof(char*)); if (ptr == NULL) { perror("Memory allocation failed.\n"); @@ -783,58 +785,58 @@ char** parse_fortran_format(char* format, const int64_t format_len, int64_t *cou } else { format_values_2 = ptr; } - switch (tolower(format[index])) { + switch (tolower(cformat[index])) { case ',' : break; case '/' : case ':' : - format_values_2[format_values_count++] = substring(format, index, index+1); + format_values_2[format_values_count++] = substring(cformat, index, index+1); break; case '*' : - format_values_2[format_values_count++] = substring(format, index, index+1); + format_values_2[format_values_count++] = substring(cformat, index, index+1); break; case '"' : start = index++; - while (format[index] != '"') { + while (cformat[index] != '"') { index++; } - format_values_2[format_values_count++] = substring(format, start, index+1); + format_values_2[format_values_count++] = substring(cformat, start, index+1); break; case '\'' : start = index++; - while (format[index] != '\'') { + while (cformat[index] != '\'') { index++; } - format_values_2[format_values_count++] = substring(format, start, index+1); + format_values_2[format_values_count++] = substring(cformat, start, index+1); break; case 'a' : start = index++; - while (isdigit(format[index])) { + while (isdigit(cformat[index])) { index++; } - format_values_2[format_values_count++] = substring(format, start, index); + format_values_2[format_values_count++] = substring(cformat, start, index); index--; break; case 'e' : start = index++; bool edot = false; - if (tolower(format[index]) == 'n') index++; - if (tolower(format[index]) == 's') index++; - while (isdigit(format[index])) index++; - if (format[index] == '.') { + if (tolower(cformat[index]) == 'n') index++; + if (tolower(cformat[index]) == 's') index++; + while (isdigit(cformat[index])) index++; + if (cformat[index] == '.') { edot = true; index++; } else { printf("Error: Period required in format specifier\n"); exit(1); } - while (isdigit(format[index])) index++; - if (edot && (tolower(format[index]) == 'e' || tolower(format[index]) == 'n')) { + while (isdigit(cformat[index])) index++; + if (edot && (tolower(cformat[index]) == 'e' || tolower(cformat[index]) == 'n')) { index++; - while (isdigit(format[index])) index++; + while (isdigit(cformat[index])) index++; } - format_values_2[format_values_count++] = substring(format, start, index); + format_values_2[format_values_count++] = substring(cformat, start, index); index--; break; case 'i' : @@ -845,28 +847,28 @@ char** parse_fortran_format(char* format, const int64_t format_len, int64_t *cou case 'g' : start = index++; bool dot = false; - if(tolower(format[index]) == 's') index++; - while (isdigit(format[index])) index++; - if (format[index] == '.') { + if(tolower(cformat[index]) == 's') index++; + while (isdigit(cformat[index])) index++; + if (cformat[index] == '.') { dot = true; index++; } - while (isdigit(format[index])) index++; - if (dot && tolower(format[index]) == 'e') { + while (isdigit(cformat[index])) index++; + if (dot && tolower(cformat[index]) == 'e') { index++; - while (isdigit(format[index])) index++; + while (isdigit(cformat[index])) index++; } - format_values_2[format_values_count++] = substring(format, start, index); + format_values_2[format_values_count++] = substring(cformat, start, index); index--; break; case 's': start = index++; - if( format[index] == ',' || // 'S' (default sign) - tolower(format[index]) == 'p' || // 'SP' (sign plus) - tolower(format[index]) == 's' // 'SS' (sign suppress) + if( cformat[index] == ',' || // 'S' (default sign) + tolower(cformat[index]) == 'p' || // 'SP' (sign plus) + tolower(cformat[index]) == 's' // 'SS' (sign suppress) ){ - if(format[index] == ',') --index; // Don't consume - format_values_2[format_values_count++] = substring(format, start, index+1); + if(cformat[index] == ',') --index; // Don't consume + format_values_2[format_values_count++] = substring(cformat, start, index+1); } else { fprintf(stderr, "Error: Invalid format specifier. After 's' specifier\n"); exit(1); @@ -874,68 +876,68 @@ char** parse_fortran_format(char* format, const int64_t format_len, int64_t *cou break; case '(' : start = index; - index = find_matching_parentheses(format, index); - format_values_2[format_values_count++] = substring(format, start, index); + index = find_matching_parentheses(cformat, index); + format_values_2[format_values_count++] = substring(cformat, start, index); *item_start = format_values_count; break; case 't' : // handle 'T', 'TL' & 'TR' editing see section 13.8.1.2 in 24-007.pdf start = index++; - if (tolower(format[index]) == 'l' || tolower(format[index]) == 'r') { + if (tolower(cformat[index]) == 'l' || tolower(cformat[index]) == 'r') { index++; // move past 'L' or 'R' } // raise error when "T/TL/TR" is specified itself or with // non-positive width - if (!isdigit(format[index])) { + if (!isdigit(cformat[index])) { // TODO: if just 'T' is specified the error message will print 'T,', fix it printf("Error: Positive width required with '%c%c' descriptor in format string\n", - format[start], format[start + 1]); + cformat[start], cformat[start + 1]); exit(1); } - while (isdigit(format[index])) { + while (isdigit(cformat[index])) { index++; } - format_values_2[format_values_count++] = substring(format, start, index); + format_values_2[format_values_count++] = substring(cformat, start, index); index--; break; default : if ( - (format[index] == '-' && isdigit(format[index + 1]) && tolower(format[index + 2]) == 'p') - || ((isdigit(format[index])) && tolower(format[index + 1]) == 'p')) { + (cformat[index] == '-' && isdigit(cformat[index + 1]) && tolower(cformat[index + 2]) == 'p') + || ((isdigit(cformat[index])) && tolower(cformat[index + 1]) == 'p')) { start = index; - index = index + 1 + (format[index] == '-'); - format_values_2[format_values_count++] = substring(format, start, index + 1); - } else if (isdigit(format[index])) { + index = index + 1 + (cformat[index] == '-'); + format_values_2[format_values_count++] = substring(cformat, start, index + 1); + } else if (isdigit(cformat[index])) { start = index; - while (isdigit(format[index])) index++; - char* repeat_str = substring(format, start, index); + while (isdigit(cformat[index])) index++; + char* repeat_str = substring(cformat, start, index); int repeat = atoi(repeat_str); free(repeat_str); format_values_2 = (char**)realloc(format_values_2, (format_values_count + repeat + 1) * sizeof(char*)); - if (format[index] == '(') { + if (cformat[index] == '(') { start = index; - index = find_matching_parentheses(format, index); + index = find_matching_parentheses(cformat, index); *item_start = format_values_count+1; for (int i = 0; i < repeat; i++) { - format_values_2[format_values_count++] = substring(format, start, index); + format_values_2[format_values_count++] = substring(cformat, start, index); } } else { start = index; - while (isalpha(format[index])) index++; - if (isdigit(format[index])) { - while (isdigit(format[index])) index++; - if (format[index] == '.') index++; - while (isdigit(format[index])) index++; - if (format[index] == 'e' || format[index] == 'E') index++; - while (isdigit(format[index])) index++; + while (isalpha(cformat[index])) index++; + if (isdigit(cformat[index])) { + while (isdigit(cformat[index])) index++; + if (cformat[index] == '.') index++; + while (isdigit(cformat[index])) index++; + if (cformat[index] == 'e' || cformat[index] == 'E') index++; + while (isdigit(cformat[index])) index++; } for (int i = 0; i < repeat; i++) { - format_values_2[format_values_count++] = substring(format, start, index); + format_values_2[format_values_count++] = substring(cformat, start, index); } index--; } - } else if (format[index] != ' ') { - fprintf(stderr, "Unsupported or unrecognized `%c` in format string\n", format[index]); + } else if (cformat[index] != ' ') { + fprintf(stderr, "Unsupported or unrecognized `%c` in format string\n", cformat[index]); break; } } @@ -1552,7 +1554,7 @@ LFORTRAN_API char* _lcompilers_string_format_fortran(const char* format, int64_t char** format_values; char* modified_input_string; int len = 0; - char* cleaned_format = remove_spaces_except_quotes(format, format_len, &len); + char* cleaned_format = remove_spaces_except_quotes((const fchar*)format, format_len, &len); if (!cleaned_format) { free_serialization_info(&s_info); return NULL; @@ -1561,7 +1563,7 @@ LFORTRAN_API char* _lcompilers_string_format_fortran(const char* format, int64_t strncpy(modified_input_string, cleaned_format, len); modified_input_string[len] = '\0'; strip_outer_parenthesis(cleaned_format, len, modified_input_string); - format_values = parse_fortran_format(modified_input_string, strlen(modified_input_string), &format_values_count, &item_start_idx); + format_values = parse_fortran_format((const fchar*)modified_input_string, strlen(modified_input_string), &format_values_count, &item_start_idx); /* is_SP_specifier = false --> 'S' OR 'SS' is_SP_specifier = true --> 'SP' @@ -1583,7 +1585,7 @@ LFORTRAN_API char* _lcompilers_string_format_fortran(const char* format, int64_t value[value_len - 1] = '\0'; int64_t new_fmt_val_count = 0; value += 1; - char** new_fmt_val = parse_fortran_format(value, value_len - 2, &new_fmt_val_count, &item_start_idx); + char** new_fmt_val = parse_fortran_format((const fchar*)value, value_len - 2, &new_fmt_val_count, &item_start_idx); char** ptr = (char**)realloc(format_values, (format_values_count + new_fmt_val_count + 1) * sizeof(char*)); if (ptr == NULL) { perror("Memory allocation failed.\n"); From 0c8eb6678c2a4cde5d3801297edba429e2f3cd64 Mon Sep 17 00:00:00 2001 From: akramhany Date: Thu, 7 Aug 2025 23:33:19 +0300 Subject: [PATCH 021/119] refactor: make find_matching_parentheses null independant --- src/libasr/runtime/lfortran_intrinsics.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libasr/runtime/lfortran_intrinsics.c b/src/libasr/runtime/lfortran_intrinsics.c index e9a44f5580c..d8e8243f396 100644 --- a/src/libasr/runtime/lfortran_intrinsics.c +++ b/src/libasr/runtime/lfortran_intrinsics.c @@ -741,9 +741,9 @@ char* remove_spaces_except_quotes(const fchar* format, const int64_t len, int* c return cleaned_format; } -int find_matching_parentheses(const char* format, int index){ +int find_matching_parentheses(const fchar* format, const int64_t format_len, int index){ int parenCount = 0; - while (format[index] != '\0') { + while (index < format_len) { if (format[index] == '(') { parenCount++; } else if (format[index] == ')'){ @@ -876,7 +876,7 @@ char** parse_fortran_format(const fchar* format, const int64_t format_len, int64 break; case '(' : start = index; - index = find_matching_parentheses(cformat, index); + index = find_matching_parentheses(format, format_len, index); format_values_2[format_values_count++] = substring(cformat, start, index); *item_start = format_values_count; break; @@ -916,7 +916,7 @@ char** parse_fortran_format(const fchar* format, const int64_t format_len, int64 format_values_2 = (char**)realloc(format_values_2, (format_values_count + repeat + 1) * sizeof(char*)); if (cformat[index] == '(') { start = index; - index = find_matching_parentheses(cformat, index); + index = find_matching_parentheses(format, format_len, index); *item_start = format_values_count+1; for (int i = 0; i < repeat; i++) { format_values_2[format_values_count++] = substring(cformat, start, index); From f9ebe41b9dd2e7a4e707af49a918f4eb13e636b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Thu, 7 Aug 2025 14:57:52 -0700 Subject: [PATCH 022/119] Use add_or_overwrite_symbol --- src/lfortran/semantics/ast_symboltable_visitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lfortran/semantics/ast_symboltable_visitor.cpp b/src/lfortran/semantics/ast_symboltable_visitor.cpp index d74c0fb1edc..f8223f36096 100644 --- a/src/lfortran/semantics/ast_symboltable_visitor.cpp +++ b/src/lfortran/semantics/ast_symboltable_visitor.cpp @@ -905,7 +905,7 @@ class SymbolTableVisitor : public CommonVisitor { ASR::FunctionType_t* func_type = ASR::down_cast(new_func->m_function_signature); func_type->m_abi = ASR::abiType::Source; func_type->m_deftype = ASR::deftypeType::Implementation; - parent_scope->overwrite_symbol(x.m_name, ASR::down_cast(tmp)); + parent_scope->add_or_overwrite_symbol(x.m_name, ASR::down_cast(tmp)); current_scope = parent_scope; } From fbc7fb1cda346b7260de3056bc7d4b701a60f8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Thu, 7 Aug 2025 15:03:30 -0700 Subject: [PATCH 023/119] Better error for select rank --- src/lfortran/semantics/ast_body_visitor.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lfortran/semantics/ast_body_visitor.cpp b/src/lfortran/semantics/ast_body_visitor.cpp index bf2cfd82cdf..c35bd3de639 100644 --- a/src/lfortran/semantics/ast_body_visitor.cpp +++ b/src/lfortran/semantics/ast_body_visitor.cpp @@ -1990,6 +1990,15 @@ class BodyVisitor : public CommonVisitor { a_body_vec.size(), def_body.p, def_body.size(), false); } + void visit_SelectRank(const AST::SelectRank_t& x) { + diag.add(Diagnostic( + "`select rank` is not implemented yet", + Level::Error, Stage::Semantic, { + Label("",{x.base.base.loc}) + })); + throw SemanticAbort(); + } + void visit_SelectType(const AST::SelectType_t& x) { // TODO: We might need to re-order all ASR::TypeStmtName // before ASR::ClassStmt as per GFortran's semantics From 6429af8c7e02f2cbe84f75cf7ae801fed24065af Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 19:20:30 +0530 Subject: [PATCH 024/119] refactor: CreateLoad to CreateLoad2 in visit_FunctionCall --- src/libasr/codegen/asr_to_llvm.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 15dfb60ba95..64a86dc7f54 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -11992,7 +11992,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ptr_loads = 1; this->visit_expr(*x.m_dt); ptr_loads = ptr_loads_copy; - llvm::Value* callee = llvm_utils->CreateLoad(tmp); + llvm::Type* val_type = llvm_utils->get_type_from_ttype_t_util( + x.m_dt, ASRUtils::extract_type(ASRUtils::expr_type(x.m_dt)), module.get()); + llvm::Value* callee = llvm_utils->CreateLoad2(val_type, tmp); args = convert_call_args(x, false); llvm::FunctionType* fntype = llvm_utils->get_function_type( @@ -12186,7 +12188,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor args.insert(args.begin(), tmp); builder->CreateCall(fn, args); // Convert {double,double}* to {double,double} - tmp = llvm_utils->CreateLoad(tmp); + tmp = llvm_utils->CreateLoad2(complex_type_8, tmp); } else { tmp = builder->CreateCall(fn, args); } @@ -12228,7 +12230,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // Convert i64* to {float,float}* using bitcast tmp = builder->CreateBitCast(p_fx2, complex_type_4->getPointerTo()); // Convert {float,float}* to {float,float} - tmp = llvm_utils->CreateLoad(tmp); + tmp = llvm_utils->CreateLoad2(complex_type_4, tmp); } else if (compiler_options.platform == Platform::macOS_ARM) { // pass } else { @@ -12242,7 +12244,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // Convert <2 x float>* to {float,float}* using bitcast tmp = builder->CreateBitCast(p_fx2, complex_type_4->getPointerTo()); // Convert {float,float}* to {float,float} - tmp = llvm_utils->CreateLoad(tmp); + tmp = llvm_utils->CreateLoad2(complex_type_4, tmp); } } } From 613a15964b32911ddad71badecc4c1b1024bdfbc Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 19:32:44 +0530 Subject: [PATCH 025/119] refactor: CreateLoad to CreateLoad2 in visit_ArraySizeUtil --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 64a86dc7f54..523726c5a2a 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -12353,7 +12353,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor start_new_block(elseBB); } start_new_block(mergeBB); - tmp = llvm_utils->CreateLoad(target); + tmp = llvm_utils->CreateLoad2(target_type, target); } else { int kind = ASRUtils::extract_kind_from_ttype_t(m_type); if( physical_type == ASR::array_physical_typeType::FixedSizeArray ) { From 30688e188fcb0e95f7aa3af5c63b071cf4fd8db7 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 19:36:23 +0530 Subject: [PATCH 026/119] refactor: CreateLoad to CreateLoad2 in lfortran_complex_bin_op --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 523726c5a2a..536f3413f34 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -810,7 +810,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::AllocaInst *presult = llvm_utils->CreateAlloca(*builder, complex_type); std::vector args = {pleft_arg, pright_arg, presult}; builder->CreateCall(fn, args); - return llvm_utils->CreateLoad(presult); + return llvm_utils->CreateLoad2(complex_type, presult); } From 439162fe88ff072506ca23eb3f078405ba44fa32 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 19:43:59 +0530 Subject: [PATCH 027/119] refactor: CreateLoad to CreateLoad2 in lfortran_strrepeat --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 536f3413f34..2fc703501f1 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -871,7 +871,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::AllocaInst *presult = llvm_utils->CreateAlloca(*builder, character_type); std::vector args = {pleft_arg, right_arg, presult}; builder->CreateCall(fn, args); - return llvm_utils->CreateLoad(presult); + return llvm_utils->CreateLoad2(character_type, presult); } llvm::Value* lfortran_str_len(llvm::Value* str, bool use_descriptor=false) From 08742c46339c758980aadf4605fa487763c71347 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 19:56:23 +0530 Subject: [PATCH 028/119] refactor: CreateLoad to CreateLoad2 in visit_AllocateUtil --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 2fc703501f1..2c8a00be0fa 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1413,7 +1413,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor realloc); if( ASR::is_a(*ASRUtils::extract_type(ASRUtils::expr_type(tmp_expr))) && !ASRUtils::is_class_type(ASRUtils::expr_type(tmp_expr)) ) { - llvm::Value* x_arr_ = llvm_utils->CreateLoad(x_arr); + llvm::Value* x_arr_ = llvm_utils->CreateLoad2(type->getPointerTo(), x_arr); #if LLVM_VERSION_MAJOR > 16 ptr_type[x_arr_] = type; #endif From b3d40a7cb2052fdf88d25499dfd853c2a03e4ce1 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 19:59:44 +0530 Subject: [PATCH 029/119] refactor: CreateLoad to CreateLoad2 in call_lfortran_free --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 2c8a00be0fa..4286b72788a 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1530,7 +1530,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value* arr = llvm_utils->CreateLoad2(llvm_data_type->getPointerTo(), arr_descr->get_pointer_to_data(tmp)); llvm::AllocaInst *arg_arr = llvm_utils->CreateAlloca(*builder, character_type); builder->CreateStore(builder->CreateBitCast(arr, character_type), arg_arr); - std::vector args = {llvm_utils->CreateLoad(arg_arr)}; + std::vector args = { llvm_utils->CreateLoad2(character_type, arg_arr) }; builder->CreateCall(fn, args); arr_descr->reset_is_allocated_flag(tmp, llvm_data_type); } From bebf4a4b75329adaf23210f51465b3b7f2e73cc0 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 20:25:16 +0530 Subject: [PATCH 030/119] refactor: CreateLoad to CreateLoad2 in visit_Deallocate --- src/libasr/codegen/asr_to_llvm.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 4286b72788a..aab1ea91727 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1665,7 +1665,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value* tmp_ = tmp; if (LLVM::is_llvm_pointer(*cur_type) && !ASRUtils::is_class_type(ASRUtils::extract_type(cur_type))) { - tmp = llvm_utils->CreateLoad(tmp); + llvm::Type* typ = llvm_utils->get_type_from_ttype_t_util(tmp_expr, cur_type, module.get()); + tmp = llvm_utils->CreateLoad2(typ, tmp); } if (ASRUtils::is_class_type(ASRUtils::extract_type(cur_type))) { // If it is a class type, we need to get the pointer to the struct @@ -1703,14 +1704,15 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm_utils->create_if_else(cond, [=]() { llvm::AllocaInst *arg_tmp = llvm_utils->CreateAlloca(*builder, character_type); builder->CreateStore(builder->CreateBitCast(tmp, character_type), arg_tmp); - std::vector args = {llvm_utils->CreateLoad(arg_tmp)}; + std::vector args = {llvm_utils->CreateLoad2(character_type, arg_tmp)}; builder->CreateCall(free_fn, args); builder->CreateStore( llvm::ConstantPointerNull::get(llvm_data_type->getPointerTo()), tmp_); }, [](){}); } else { if( LLVM::is_llvm_pointer(*cur_type) ) { - tmp = llvm_utils->CreateLoad(tmp); + llvm::Type* typ = llvm_utils->get_type_from_ttype_t_util(tmp_expr, cur_type, module.get()); + tmp = llvm_utils->CreateLoad2(typ, tmp); } #if LLVM_VERSION_MAJOR > 16 ptr_type[tmp] = llvm_utils->get_type_from_ttype_t_util(tmp_expr, From d70a6c919ba0b89c9fc3db7f93684ced250ae3a3 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 20:39:39 +0530 Subject: [PATCH 031/119] refactor: CreateLoad to CreateLoad2 in visit_UnionInstanceMember --- src/libasr/codegen/asr_to_llvm.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index aab1ea91727..919d9a4a710 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1988,7 +1988,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return ; } if( ptr_loads > 0 ) { - tmp = llvm_utils->CreateLoad(tmp); + llvm::Type* value_type = llvm_utils->getMemberType(member_type_asr, member_var, module.get()); + tmp = llvm_utils->CreateLoad2(value_type, tmp); } } From 6b47895e1d569af36c5363f1e82f095a637276d3 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 20:45:57 +0530 Subject: [PATCH 032/119] refactor: CreateLoad to CreateLoad2 in visit_ArrayItem --- src/libasr/codegen/asr_to_llvm.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 919d9a4a710..f67af6cdbf4 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -2757,7 +2757,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_expr_wrapper(x.m_args[0].m_right, true); llvm::Value *p = nullptr; llvm::Value *idx = tmp; - llvm::Value *str = llvm_utils->CreateLoad(array); + ASR::ttype_t* array_asr_type = ASRUtils::extract_type(expr_type(x.m_v)); + llvm::Type* str_value_type = llvm_utils->get_type_from_ttype_t_util(x.m_v, array_asr_type, module.get()); + llvm::Value *str = llvm_utils->CreateLoad2(str_value_type, array); if( is_assignment_target ) { idx = builder->CreateSub(idx, llvm::ConstantInt::get(context, llvm::APInt(32, 1))); std::vector idx_vec = {idx}; From 53dedef84d766e5811d40c2ff0c66a6a438a8743 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 20:53:15 +0530 Subject: [PATCH 033/119] refactor: CreateLoad to CreateLoad2 in allocate_array_members_of_struct_arrays --- src/libasr/codegen/asr_to_llvm.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index f67af6cdbf4..011e30d05e2 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -4343,11 +4343,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } llvm::Value* llvmi = llvm_utils->CreateAlloca(llvm::Type::getInt32Ty(context), nullptr, "i"); + llvm::Type* t = llvm::Type::getInt32Ty(context); LLVM::CreateStore(*builder, llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), llvm::APInt(32, 0)), llvmi); create_loop(nullptr, [=]() { - llvm::Value* llvmi_loaded = llvm_utils->CreateLoad(llvmi); - llvm::Value* array_size_loaded = llvm_utils->CreateLoad(array_size); + llvm::Value* llvmi_loaded = llvm_utils->CreateLoad2(t, llvmi); + llvm::Value* array_size_loaded = llvm_utils->CreateLoad2(t, array_size); return builder->CreateICmpSLT( llvmi_loaded, array_size_loaded); }, @@ -4356,20 +4357,20 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor switch (phy_type) { case ASR::array_physical_typeType::FixedSizeArray: { llvm::Type* ptr_i_type = llvm_utils->get_type_from_ttype_t_util(expr, v_m_type, module.get()); - ptr_i = llvm_utils->create_gep2(ptr_i_type, ptr, llvm_utils->CreateLoad(llvmi)); + ptr_i = llvm_utils->create_gep2(ptr_i_type, ptr, llvm_utils->CreateLoad2(t, llvmi)); break; } case ASR::array_physical_typeType::DescriptorArray: { ptr_i = llvm_utils->create_ptr_gep2(el_type, llvm_utils->CreateLoad2(el_type->getPointerTo(), arr_descr->get_pointer_to_data(ptr)), - llvm_utils->CreateLoad(llvmi)); + llvm_utils->CreateLoad2(t, llvmi)); break; } case ASR::array_physical_typeType::PointerToDataArray: { #if LLVM_VERSION_MAJOR > 16 ptr_type[ptr] = llvm_utils->get_type_from_ttype_t_util(expr, v_m_type, module.get()); #endif - ptr_i = llvm_utils->create_ptr_gep(ptr, llvm_utils->CreateLoad(llvmi)); + ptr_i = llvm_utils->create_ptr_gep(ptr, llvm_utils->CreateLoad2(t, llvmi)); break; } default: { @@ -4380,7 +4381,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::down_cast(ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(expr))), ptr_i, ASRUtils::extract_type(v_m_type)); LLVM::CreateStore(*builder, - builder->CreateAdd(llvm_utils->CreateLoad(llvmi), + builder->CreateAdd(llvm_utils->CreateLoad2(t, llvmi), llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), llvm::APInt(32, 1))), llvmi); }); From 6b9a126bb60fe363fe1c235c793c6ed887539240 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 21:18:55 +0530 Subject: [PATCH 034/119] refactor: CreateLoad to CreateLoad2 in set_VariableInital_value --- src/libasr/codegen/asr_to_llvm.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 011e30d05e2..a633f084afc 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -4448,12 +4448,17 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor collect_variable_types_and_struct_types(variable_type_names, struct_types, x_symtab->parent); } void set_VariableInital_value(ASR::Variable_t* v, llvm::Value* target_var){ + ASR::expr_t* type_source_expr = nullptr; if (v->m_value != nullptr) { this->visit_expr_wrapper(v->m_value, true, v->m_is_volatile); + type_source_expr = v->m_value; } else { this->visit_expr_wrapper(v->m_symbolic_value, true, v->m_is_volatile); + type_source_expr = v->m_symbolic_value; } llvm::Value *init_value = tmp; + llvm::Type* init_value_type = llvm_utils->get_type_from_ttype_t_util( + type_source_expr, ASRUtils::expr_type(type_source_expr), module.get()); if( ASRUtils::is_array(v->m_type) && ASRUtils::is_array(ASRUtils::expr_type(v->m_symbolic_value)) && (ASR::is_a(*v->m_symbolic_value) || @@ -4523,7 +4528,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor module.get()), false); llvm::Value* data_ptr = llvm_utils->create_gep2( - array_desc_type, llvm_utils->CreateLoad(target_var), 0); + array_desc_type, llvm_utils->CreateLoad2(array_desc_type->getPointerTo(), target_var), 0); builder->CreateStore(init_value, data_ptr, v->m_is_volatile); } else { if (v->m_storage == ASR::storage_typeType::Save From 78121217e8be85b6c8130cabf59acad8e9435489 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 31 Jul 2025 21:25:27 +0530 Subject: [PATCH 035/119] refactor: CreateLoad to CreateLoad2 in define_function_exit --- src/libasr/codegen/asr_to_llvm.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index a633f084afc..6c145f0cc62 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -4448,17 +4448,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor collect_variable_types_and_struct_types(variable_type_names, struct_types, x_symtab->parent); } void set_VariableInital_value(ASR::Variable_t* v, llvm::Value* target_var){ - ASR::expr_t* type_source_expr = nullptr; if (v->m_value != nullptr) { this->visit_expr_wrapper(v->m_value, true, v->m_is_volatile); - type_source_expr = v->m_value; } else { this->visit_expr_wrapper(v->m_symbolic_value, true, v->m_is_volatile); - type_source_expr = v->m_symbolic_value; } llvm::Value *init_value = tmp; - llvm::Type* init_value_type = llvm_utils->get_type_from_ttype_t_util( - type_source_expr, ASRUtils::expr_type(type_source_expr), module.get()); if( ASRUtils::is_array(v->m_type) && ASRUtils::is_array(ASRUtils::expr_type(v->m_symbolic_value)) && (ASR::is_a(*v->m_symbolic_value) || @@ -5254,6 +5249,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *tmp = ret_val; if (is_a(*arg_type)) { int c_kind = ASRUtils::extract_kind_from_ttype_t(arg_type); + llvm::Type* complex_val_type = llvm_utils->get_type_from_ttype_t_util( + ASRUtils::EXPR( + ASR::make_Var_t(al, asr_retval->base.base.loc, &asr_retval->base)), + arg_type, + module.get()); if (c_kind == 4) { if (compiler_options.platform == Platform::Windows) { // tmp is {float, float}* @@ -5262,10 +5262,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // Convert {float,float}* to i64* using bitcast tmp = builder->CreateBitCast(tmp, type_fx2p); // Then convert i64* -> i64 - tmp = llvm_utils->CreateLoad(tmp); + tmp = llvm_utils->CreateLoad2(type_fx2p, tmp); } else if (compiler_options.platform == Platform::macOS_ARM) { // Pass by value - tmp = llvm_utils->CreateLoad(tmp); + + tmp = llvm_utils->CreateLoad2(complex_val_type, tmp); } else { // tmp is {float, float}* // type_fx2 is <2 x float> @@ -5281,7 +5282,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // 128 bit aggregate type is passed by reference } else { // Pass by value - tmp = llvm_utils->CreateLoad(tmp); + tmp = llvm_utils->CreateLoad2(complex_val_type, tmp); } } ret_val2 = tmp; From b3f5d0212d49e6675fd605ef7e65f9af839d6d22 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 02:14:44 +0530 Subject: [PATCH 036/119] implemented: get_type_from_ttype_t_util_from_symbol to get type from symbol --- src/libasr/codegen/asr_to_llvm.cpp | 4 +--- src/libasr/codegen/llvm_utils.cpp | 12 ++++++++++++ src/libasr/codegen/llvm_utils.h | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 6c145f0cc62..94735ac5982 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5249,9 +5249,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *tmp = ret_val; if (is_a(*arg_type)) { int c_kind = ASRUtils::extract_kind_from_ttype_t(arg_type); - llvm::Type* complex_val_type = llvm_utils->get_type_from_ttype_t_util( - ASRUtils::EXPR( - ASR::make_Var_t(al, asr_retval->base.base.loc, &asr_retval->base)), + llvm::Type* complex_val_type = llvm_utils->get_type_from_ttype_t_util_from_symbol((ASR::symbol_t*)asr_retval, arg_type, module.get()); if (c_kind == 4) { diff --git a/src/libasr/codegen/llvm_utils.cpp b/src/libasr/codegen/llvm_utils.cpp index 31cefcab16f..48b73340f27 100644 --- a/src/libasr/codegen/llvm_utils.cpp +++ b/src/libasr/codegen/llvm_utils.cpp @@ -1332,6 +1332,18 @@ namespace LCompilers { m_dims_local, n_dims_local, a_kind_local, module, asr_abi); } + llvm::Type * LLVMUtils::get_type_from_ttype_t_util_from_symbol(ASR::symbol_t* sym, ASR::ttype_t* asr_type, + llvm::Module * module, ASR::abiType asr_abi) { + ASR::storage_typeType m_storage_local = ASR::storage_typeType::Default; + bool is_array_type_local, is_malloc_array_type_local; + bool is_list_local; + ASR::dimension_t* m_dims_local; + int n_dims_local = 0, a_kind_local = 0; + return get_type_from_ttype_t(nullptr, asr_type, sym, m_storage_local, is_array_type_local, + is_malloc_array_type_local, is_list_local, + m_dims_local, n_dims_local, a_kind_local, module, asr_abi); + } + llvm::Value* LLVMUtils::create_gep(llvm::Value* ds, int idx) { std::vector idx_vec = { llvm::ConstantInt::get(context, llvm::APInt(32, 0)), diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index fb9f77f6468..1544fd61f2f 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -494,6 +494,11 @@ namespace LCompilers { llvm::Module* module, ASR::abiType asr_abi = ASR::abiType::Source); + llvm::Type* get_type_from_ttype_t_util_from_symbol(ASR::symbol_t* sym, + ASR::ttype_t* asr_type, + llvm::Module* module, + ASR::abiType asr_abi = ASR::abiType::Source); + llvm::Type* get_arg_type_from_ttype_t(ASR::expr_t* arg_expr, ASR::ttype_t* asr_type, ASR::symbol_t *type_declaration, ASR::abiType m_abi, ASR::abiType arg_m_abi, ASR::storage_typeType m_storage, bool arg_m_value_attr, int& n_dims, From deccb3498da7f740b3a0366d9df705ba6b865b4c Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 02:27:42 +0530 Subject: [PATCH 037/119] refactor: CreateLoad to CreateLoad2 in generate_function --- src/libasr/codegen/asr_to_llvm.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 94735ac5982..32ac76233db 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5324,17 +5324,19 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::Variable_t *arg = EXPR2VAR(x.m_args[0]); uint32_t h = get_hash((ASR::asr_t*)arg); llvm::Value* llvm_arg1 = llvm_symtab[h]; + llvm::Type* llvm_arg1_type = llvm_utils->get_type_from_ttype_t_util(x.m_args[0], arg->m_type, module.get()); arg = EXPR2VAR(x.m_args[1]); h = get_hash((ASR::asr_t*)arg); llvm::Value* llvm_arg2 = llvm_symtab[h]; + llvm::Type* llvm_arg2_type = llvm_utils->get_type_from_ttype_t_util(x.m_args[1], arg->m_type, module.get()); ASR::Variable_t *ret = EXPR2VAR(x.m_return_var); h = get_hash((ASR::asr_t*)ret); llvm::Value* llvm_ret_ptr = llvm_symtab[h]; - llvm::Value* dim_des_val = llvm_utils->CreateLoad(llvm_arg1); - llvm::Value* dim_val = llvm_utils->CreateLoad(llvm_arg2); + llvm::Value* dim_des_val = llvm_utils->CreateLoad2(llvm_arg1_type, llvm_arg1); + llvm::Value* dim_val = llvm_utils->CreateLoad2(llvm_arg2_type, llvm_arg2); llvm::Value* const_1 = llvm::ConstantInt::get(context, llvm::APInt(32, 1)); dim_val = builder->CreateSub(dim_val, const_1); llvm::Value* dim_struct = arr_descr->get_pointer_to_dimension_descriptor(dim_des_val, dim_val); From 66d11c5b98e5381bcf21d54d7fbf7970c2eefe1a Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 02:37:16 +0530 Subject: [PATCH 038/119] refactor: CreateLoad to CreateLoad2 in GetPointerCPtrUtil --- src/libasr/codegen/asr_to_llvm.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 32ac76233db..70709bdf2b4 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5400,7 +5400,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor (LLVM::is_llvm_pointer(*ASRUtils::type_get_past_pointer(asr_type)) || ASR::is_a(*ASRUtils::type_get_past_pointer(asr_type)) || llvm::isa(llvm_tmp))) { - llvm_tmp = llvm_utils->CreateLoad(llvm_tmp); + ASR::ttype_t* contained_type = ASRUtils::type_get_past_pointer(asr_type); + llvm::Type* llvm_ty = llvm_utils->get_type_from_ttype_t_util(nullptr, contained_type, module.get()); + llvm_tmp = llvm_utils->CreateLoad2(llvm_ty->getPointerTo(), llvm_tmp); } asr_type = ASRUtils::get_contained_type(asr_type); From e022f43e5b384b3e7e4b267065211824d23c3000 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 02:45:27 +0530 Subject: [PATCH 039/119] refactor: CreateLoad to CreateLoad2 in visit_CPtrToPointer --- src/libasr/codegen/asr_to_llvm.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 70709bdf2b4..2d550471157 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5484,7 +5484,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (ASR::is_a(*cptr)) { // `type(c_ptr)` requires an extra load here // TODO: be more explicit about ptr_loads: https://github.com/lfortran/lfortran/issues/4245 - llvm_cptr = llvm_utils->CreateLoad(llvm_cptr); + llvm::Type* llvm_cptr_type = llvm_utils->get_type_from_ttype_t_util(cptr, ASRUtils::expr_type(cptr), module.get()); + llvm_cptr = llvm_utils->CreateLoad2(llvm_cptr_type, llvm_cptr); } ptr_loads = 0; this->visit_expr(*fptr); @@ -5520,7 +5521,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value* shape_data = llvm_shape; if( llvm_shape && (ASRUtils::extract_physical_type(asr_shape_type) == ASR::array_physical_typeType::DescriptorArray) ) { - shape_data = llvm_utils->CreateLoad(arr_descr->get_pointer_to_data(llvm_shape)); + ASR::ttype_t* shape_elem_asr_type = ASRUtils::type_get_past_pointer(ASRUtils::expr_type(shape)); + llvm::Type* shape_elem_llvm_type = llvm_utils->get_type_from_ttype_t_util( nullptr, shape_elem_asr_type, module.get()); + shape_data = llvm_utils->CreateLoad2(shape_elem_llvm_type, arr_descr->get_pointer_to_data(llvm_shape)); } llvm_cptr = builder->CreateBitCast(llvm_cptr, llvm_fptr_data_type->getPointerTo()); builder->CreateStore(llvm_cptr, fptr_data); From aed19182b52cb2946231b9f6450b258f14482257 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 02:52:38 +0530 Subject: [PATCH 040/119] refactor: CreateLoad to CreateLoad2 in visit_PointerAssociated --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 2d550471157..7130a586e41 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5709,7 +5709,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor builder->CreateStore(builder->CreateICmpNE(ptr, nptr), res); } }); - tmp = llvm_utils->CreateLoad(res); + tmp = llvm_utils->CreateLoad2(llvm::Type::getInt1Ty(context), res); } void handle_array_section_association_to_pointer(const ASR::Associate_t& x) { From a998948523bb1331a672bdc3738ec4a6cf2d27d6 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 02:56:06 +0530 Subject: [PATCH 041/119] refactor: CreateLoad to CreateLoad2 in handle_array_section_association_to_pointer --- src/libasr/codegen/asr_to_llvm.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 7130a586e41..942e38aad96 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5721,10 +5721,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ptr_loads = 1 - !LLVM::is_llvm_pointer(*value_array_type); visit_expr_wrapper(array_section->m_v); llvm::Value* value_desc = tmp; + llvm::Type* value_desc_type = llvm_utils->get_type_from_ttype_t_util(array_section->m_v, + ASRUtils::expr_type(array_section->m_v), module.get()); if( ASR::is_a(*array_section->m_v) && ASRUtils::extract_physical_type(value_array_type) != ASR::array_physical_typeType::FixedSizeArray ) { - value_desc = llvm_utils->CreateLoad(value_desc); + value_desc = llvm_utils->CreateLoad2(value_desc_type, value_desc); } #if LLVM_VERSION_MAJOR > 16 ptr_type[value_desc] = llvm_utils->get_type_from_ttype_t_util(array_section->m_v, From 96a144676a60f9042d9f8ade58fc40bbe6f08e77 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 03:00:13 +0530 Subject: [PATCH 042/119] refactor: CreateLoad to CreateLoad2 in visit_Associate --- src/libasr/codegen/asr_to_llvm.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 942e38aad96..28fc949d8b3 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5847,7 +5847,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if(ASRUtils::is_array(target_type) ){ // Fetch data ptr LCOMPILERS_ASSERT(ASRUtils::extract_physical_type(target_type) == ASR::array_physical_typeType::DescriptorArray); - llvm_target = llvm_utils->CreateLoad(llvm_target); + llvm::Type* llvm_target_type = llvm_utils->get_type_from_ttype_t_util(x.m_target, target_type, module.get()); + llvm_target = llvm_utils->CreateLoad2(llvm_target_type, llvm_target); llvm_target = arr_descr->get_pointer_to_data(llvm_target); } builder->CreateStore(llvm_value, llvm_target); @@ -5873,7 +5874,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } else if (ASR::is_a(*x.m_value) && ASR::is_a(*value_type)) { - llvm_value = llvm_utils->CreateLoad(llvm_value); + llvm::Type* llvm_value_type = llvm_utils->get_type_from_ttype_t_util(x.m_value, value_type, module.get()); + llvm_value = llvm_utils->CreateLoad2(llvm_value_type, llvm_value); builder->CreateStore(llvm_value, llvm_target); } else if (is_target_class && !is_value_class) { llvm::Type* llvm_target_type = llvm_utils->get_type_from_ttype_t_util(x.m_target, target_type, module.get()); @@ -5944,7 +5946,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASRUtils::extract_physical_type(value_type) == ASR::array_physical_typeType::FixedSizeArray || ASRUtils::extract_physical_type(value_type) == ASR::array_physical_typeType::DescriptorArray)); if( LLVM::is_llvm_pointer(*value_type) ) { - llvm_value = llvm_utils->CreateLoad(llvm_value); + llvm::Type* llvm_value_type = llvm_utils->get_type_from_ttype_t_util(x.m_value, value_type, module.get()); + llvm_value = llvm_utils->CreateLoad2(llvm_value_type, llvm_value); } if( is_value_data_only_array ) { // This needs a refactor to handle ASR::ttype_t* target_type_ = ASRUtils::type_get_past_pointer(target_type); @@ -5997,7 +6000,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor break; } case ASR::array_physical_typeType::FixedSizeArray: { - llvm_value = llvm_utils->CreateLoad(llvm_value); + llvm::Type* llvm_type = llvm_utils->get_type_from_ttype_t_util(x.m_value,value_type, module.get()); + llvm_value = llvm_utils->CreateLoad2(llvm_type, llvm_value); break; } case ASR::array_physical_typeType::PointerToDataArray: { From 25f39f7dc76280a343e03e7baaebaa5c7065a8f6 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 03:11:17 +0530 Subject: [PATCH 043/119] refactor: CreateLoad to CreateLoad2 in visit_ArrayPhysicalCastUtil --- src/libasr/codegen/asr_to_llvm.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 28fc949d8b3..e2d6dc60536 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -6889,7 +6889,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } else if ( m_new == ASR::array_physical_typeType::DescriptorArray && m_old == ASR::array_physical_typeType::SIMDArray) { - tmp = llvm_utils->CreateLoad(arg); + tmp = llvm_utils->CreateLoad2(m_arg_llvm_type, arg); } else if( m_new == ASR::array_physical_typeType::DescriptorArray && m_old == ASR::array_physical_typeType::FixedSizeArray) { @@ -6941,17 +6941,17 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor tmp = llvm_utils->create_gep2(arr_type, tmp, 0); } } else { - tmp = llvm_utils->CreateLoad(arr_descr->get_pointer_to_data(tmp)); + tmp = llvm_utils->CreateLoad2(data_type->getPointerTo(),arr_descr->get_pointer_to_data(tmp)); } } else if ( m_new == ASR::array_physical_typeType::StringArraySinglePointer && m_old == ASR::array_physical_typeType::DescriptorArray) { if (ASRUtils::is_fixed_size_array(m_type)) { - tmp = llvm_utils->CreateLoad(arr_descr->get_pointer_to_data(tmp)); + tmp = llvm_utils->CreateLoad2(data_type->getPointerTo(), arr_descr->get_pointer_to_data(tmp)); llvm::Type* target_type = llvm_utils->get_type_from_ttype_t_util(m_arg, m_type, module.get())->getPointerTo(); tmp = builder->CreateBitCast(tmp, target_type); // [1 x i8*]* // we need [1 x i8*] - tmp = llvm_utils->CreateLoad(tmp); + tmp = llvm_utils->CreateLoad2(target_type, tmp); } } else { LCOMPILERS_ASSERT(false); From 4d7de2d60d45105ea8369ab50d2e5b08d20a3db8 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 03:14:04 +0530 Subject: [PATCH 044/119] refactor: CreateLoad to CreateLoad2 in visit_SelectType --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index e2d6dc60536..20c1cb19436 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -7123,7 +7123,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::ttype_t* selector_var_type = ASRUtils::expr_type(x.m_selector); llvm::Value* vptr_int_hash = llvm_utils->CreateLoad2(i64, llvm_utils->create_gep2(llvm_selector_type_, llvm_selector, 0)); if( ASRUtils::is_array(selector_var_type) ) { - vptr_int_hash = llvm_utils->CreateLoad(llvm_utils->create_gep2(i64, vptr_int_hash, 0)); + vptr_int_hash = llvm_utils->CreateLoad2(i64, llvm_utils->create_gep2(i64, vptr_int_hash, 0)); } ASR::TypeStmtName_t* type_stmt_name = ASR::down_cast(select_type_stmts[i]); ASR::symbol_t* type_sym = ASRUtils::symbol_get_past_external(type_stmt_name->m_sym); From 176269a98865721714b2cc63f5aecf53a297f734 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 17:36:53 +0530 Subject: [PATCH 045/119] refactor: CreateLoad to CreateLoad2 in visit_IfExp --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 20c1cb19436..90d2ba65d78 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -7632,7 +7632,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_expr_wrapper(x.m_orelse, true); builder->CreateStore(tmp, ifexp_res); }); - tmp = llvm_utils->CreateLoad(ifexp_res); + tmp = llvm_utils->CreateLoad2(_type, ifexp_res); } // TODO: Implement visit_DooLoop From ef8942cf11d835661fa621cca1aa736c18e9b35d Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 17:45:03 +0530 Subject: [PATCH 046/119] refactor: CreateLoad to CreateLoad2 in visit_RealBinOp --- src/libasr/codegen/asr_to_llvm.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 90d2ba65d78..2e0cd6b3f2f 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -8156,10 +8156,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor lookup_enum_value_for_nonints = false; LCOMPILERS_ASSERT(ASRUtils::is_real(*x.m_type)) if (ASRUtils::is_simd_array(x.m_right) && is_a(*x.m_right)) { - right_val = llvm_utils->CreateLoad(right_val); + llvm::Type *right_type = llvm_utils->get_type_from_ttype_t_util(x.m_right, ASRUtils::expr_type(x.m_right), module.get()); + right_val = llvm_utils->CreateLoad2(right_type, right_val); } if (ASRUtils::is_simd_array(x.m_left) && is_a(*x.m_left)) { - left_val = llvm_utils->CreateLoad(left_val); + llvm::Type *left_type = llvm_utils->get_type_from_ttype_t_util(x.m_left, ASRUtils::expr_type(x.m_left), module.get()); + left_val = llvm_utils->CreateLoad2(left_type, left_val); } switch (x.m_op) { case ASR::binopType::Add: { From e4591837024135622dd023b0943bfb6095bbcca1 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 17:50:04 +0530 Subject: [PATCH 047/119] refactor: CreateLoad to CreateLoad2 in visit_ComplexBinOp --- src/libasr/codegen/asr_to_llvm.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 2e0cd6b3f2f..85f91f4547a 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -8252,10 +8252,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASRUtils::type_get_past_pointer(x.m_type)))->m_kind; type = llvm_utils->getComplexType(a_kind); if( left_val->getType()->isPointerTy() ) { - left_val = llvm_utils->CreateLoad(left_val); + llvm::Type *left_type = llvm_utils->get_type_from_ttype_t_util(x.m_left, ASRUtils::expr_type(x.m_left), module.get()); + left_val = llvm_utils->CreateLoad2(left_type, left_val); } if( right_val->getType()->isPointerTy() ) { - right_val = llvm_utils->CreateLoad(right_val); + llvm::Type *right_type = llvm_utils->get_type_from_ttype_t_util(x.m_right, ASRUtils::expr_type(x.m_right), module.get()); + right_val = llvm_utils->CreateLoad2(right_type, right_val); } std::string fn_name; switch (x.m_op) { From 35b3a17a260ee601e8abf43b20ca70e7b3f02c07 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 18:00:04 +0530 Subject: [PATCH 048/119] refactor: CreateLoad to CreateLoad2 in fetch_ptr --- src/libasr/codegen/asr_to_llvm.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 85f91f4547a..216240a74e8 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -8711,26 +8711,22 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value* x_v = llvm_symtab[x_h]; int64_t ptr_loads_copy = ptr_loads; tmp = x_v; -#if LLVM_VERSION_MAJOR > 16 + llvm::Type* type_req = nullptr; int loads = 0; -#endif while( ptr_loads_copy-- ) { -#if LLVM_VERSION_MAJOR > 16 if( loads == 0 ) { - ptr_type[tmp] = llvm_utils->get_type_from_ttype_t_util(ASRUtils::EXPR(ASR::make_Var_t( + ptr_type[tmp] = type_req = llvm_utils->get_type_from_ttype_t_util(ASRUtils::EXPR(ASR::make_Var_t( al, x->base.base.loc, &x->base)), x->m_type, module.get()); + } else { - ptr_type[tmp] = llvm_utils->get_type_from_ttype_t_util(ASRUtils::EXPR(ASR::make_Var_t( + ptr_type[tmp] = type_req = llvm_utils->get_type_from_ttype_t_util(ASRUtils::EXPR(ASR::make_Var_t( al, x->base.base.loc, &x->base)), ASRUtils::type_get_past_allocatable_pointer(x->m_type), module.get()); } -#endif - tmp = llvm_utils->CreateLoad(tmp); -#if LLVM_VERSION_MAJOR > 16 - loads++; -#endif + tmp = llvm_utils->CreateLoad2(type_req, tmp); + loads++; } } From 0a1a379998818e2babbcf6db826bb9a45327496d Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 18:05:28 +0530 Subject: [PATCH 049/119] refactor: CreateLoad to CreateLoad2 in visit_Cast --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 216240a74e8..3ed5cd0d524 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -9440,7 +9440,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_expr(*x.m_arg); ptr_loads = ptr_loads_copy; llvm::Type* list_llvm_type = llvm_utils->get_type_from_ttype_t_util(x.m_arg, ASRUtils::expr_type(x.m_arg), module.get()); - tmp = llvm_utils->CreateLoad(list_api->get_pointer_to_list_data_using_type(list_llvm_type, tmp)); + tmp = llvm_utils->CreateLoad2(list_llvm_type, list_api->get_pointer_to_list_data_using_type(list_llvm_type, tmp)); break; } case (ASR::cast_kindType::PointerToInteger): { From a8326e78e94736795c39c6852c64d84f788fee4e Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Fri, 1 Aug 2025 18:11:21 +0530 Subject: [PATCH 050/119] refactor: CreateLoad to CreateLoad2 in visit_FileRead --- src/libasr/codegen/asr_to_llvm.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 3ed5cd0d524..ebe1fd89c77 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -9819,7 +9819,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Type *el_type = llvm_utils->get_type_from_ttype_t_util(x.m_values[i], ASRUtils::extract_type(type), module.get()); if (ASR::is_a(*type) || ASR::is_a(*type)) { - var_to_read_into = llvm_utils->CreateLoad(var_to_read_into); + llvm::Type* t = llvm_utils->get_type_from_ttype_t_util( + x.m_values[i], + ASRUtils::type_get_past_allocatable_pointer(type), + module.get())->getPointerTo(); + var_to_read_into = llvm_utils->CreateLoad2(t, var_to_read_into); } llvm::Value* original_array_representation = var_to_read_into; // Loaded (if necessary) #if LLVM_VERSION_MAJOR > 16 From ba55b4cdd59b760c190d9aa6a88d39a245e12f10 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Mon, 4 Aug 2025 19:50:57 +0530 Subject: [PATCH 051/119] fix: added a assertion in get_type_from_ttype_t_util_from_symbol --- src/libasr/codegen/llvm_utils.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/llvm_utils.cpp b/src/libasr/codegen/llvm_utils.cpp index 48b73340f27..88e62e48a69 100644 --- a/src/libasr/codegen/llvm_utils.cpp +++ b/src/libasr/codegen/llvm_utils.cpp @@ -1339,7 +1339,12 @@ namespace LCompilers { bool is_list_local; ASR::dimension_t* m_dims_local; int n_dims_local = 0, a_kind_local = 0; - return get_type_from_ttype_t(nullptr, asr_type, sym, m_storage_local, is_array_type_local, + ASR::symbol_t* sym_ = sym; + if (ASR::is_a(*sym)) { + ASR::Variable_t* var = ASR::down_cast(sym); + sym_ = var->m_type_declaration; + } + return get_type_from_ttype_t(nullptr, asr_type, sym_, m_storage_local, is_array_type_local, is_malloc_array_type_local, is_list_local, m_dims_local, n_dims_local, a_kind_local, module, asr_abi); } From 79e353456f52733703e2d2bc1b290c09c514ca7c Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Mon, 4 Aug 2025 19:58:33 +0530 Subject: [PATCH 052/119] refactor: define_function_exit --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index ebe1fd89c77..b1ef918ea4d 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5249,7 +5249,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *tmp = ret_val; if (is_a(*arg_type)) { int c_kind = ASRUtils::extract_kind_from_ttype_t(arg_type); - llvm::Type* complex_val_type = llvm_utils->get_type_from_ttype_t_util_from_symbol((ASR::symbol_t*)asr_retval, + llvm::Type* complex_val_type = llvm_utils->get_type_from_ttype_t_util(x.m_return_var, arg_type, module.get()); if (c_kind == 4) { From 76b100459a298fbfa40624691990d4eb3e517f97 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Mon, 4 Aug 2025 22:31:35 +0530 Subject: [PATCH 053/119] refactor: visit_Associate --- src/libasr/codegen/asr_to_llvm.cpp | 13 ++++++++----- src/libasr/codegen/llvm_utils.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index b1ef918ea4d..dd7e22d96ff 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5847,9 +5847,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if(ASRUtils::is_array(target_type) ){ // Fetch data ptr LCOMPILERS_ASSERT(ASRUtils::extract_physical_type(target_type) == ASR::array_physical_typeType::DescriptorArray); - llvm::Type* llvm_target_type = llvm_utils->get_type_from_ttype_t_util(x.m_target, target_type, module.get()); - llvm_target = llvm_utils->CreateLoad2(llvm_target_type, llvm_target); - llvm_target = arr_descr->get_pointer_to_data(llvm_target); + llvm::Type* target_type_llvm = llvm_utils->get_type_from_ttype_t_util( + x.m_target, target_type, module.get()); + llvm_target = llvm_utils->CreateLoad2(target_type_llvm, llvm_target); + llvm_target = arr_descr->get_pointer_to_data(x.m_target, target_type, llvm_target, module.get()); } builder->CreateStore(llvm_value, llvm_target); } else if(ASRUtils::is_string_only(value_type)){ // Maybe we can handle this case in a string api function @@ -8726,7 +8727,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor module.get()); } tmp = llvm_utils->CreateLoad2(type_req, tmp); - loads++; + loads++; } } @@ -10832,7 +10833,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // Local variable or Dummy out argument // of type CPtr is a void**, so we // have to load it - tmp = llvm_utils->CreateLoad(tmp); + llvm::Type* cptr_type = llvm::Type::getInt8PtrTy(context); + tmp = llvm_utils->CreateLoad2(cptr_type, tmp); } } else { if (!arg->m_value_attr && !ASR::is_a(*arg_type)) { @@ -10887,6 +10889,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor !ASRUtils::is_class_type(ASRUtils::type_get_past_allocatable_pointer(arg->m_type))) { // TODO: Remove call to ASRUtils::check_equal_type // pass(rhs) is not respected in integration_tests/class_08.f90 + tmp = llvm_utils->CreateLoad(tmp); } if (ASRUtils::is_class_type( diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index 1544fd61f2f..1c771fcf0f7 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -493,7 +493,7 @@ namespace LCompilers { llvm::Type* get_type_from_ttype_t_util(ASR::expr_t* expr, ASR::ttype_t* asr_type, llvm::Module* module, ASR::abiType asr_abi = ASR::abiType::Source); - + // TODO: Refactor this function to be bug free. llvm::Type* get_type_from_ttype_t_util_from_symbol(ASR::symbol_t* sym, ASR::ttype_t* asr_type, llvm::Module* module, From f15b8897cf49a8fc3ef345132509732039ee6ca0 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 7 Aug 2025 17:06:36 +0530 Subject: [PATCH 054/119] refactor: convert_call_args --- src/libasr/codegen/asr_to_llvm.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index dd7e22d96ff..f60e56ddc52 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -10833,7 +10833,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // Local variable or Dummy out argument // of type CPtr is a void**, so we // have to load it - llvm::Type* cptr_type = llvm::Type::getInt8PtrTy(context); + llvm::Type* cptr_type = llvm::PointerType::get( + llvm::Type::getInt8Ty(context), 0); tmp = llvm_utils->CreateLoad2(cptr_type, tmp); } } else { From abab9bf9e300b26bc4b4fa952b8cba43d779d1c9 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Thu, 7 Aug 2025 23:34:27 +0530 Subject: [PATCH 055/119] refactor: visit_Associate --- src/libasr/codegen/asr_to_llvm.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index f60e56ddc52..2d04f340843 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -10833,9 +10833,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // Local variable or Dummy out argument // of type CPtr is a void**, so we // have to load it - llvm::Type* cptr_type = llvm::PointerType::get( - llvm::Type::getInt8Ty(context), 0); - tmp = llvm_utils->CreateLoad2(cptr_type, tmp); + // TODO: Convert this into createload2 + // llvm::Type* cptr_type = llvm::PointerType::get( + // llvm::Type::getInt8Ty(context), 0); + // tmp = llvm_utils->CreateLoad2(cptr_type, tmp); + tmp = llvm_utils->CreateLoad(tmp); } } else { if (!arg->m_value_attr && !ASR::is_a(*arg_type)) { From b6e7b0ef31ba9d1a39a9b935b87d71c1dd405f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Thu, 7 Aug 2025 19:22:53 -0700 Subject: [PATCH 056/119] Update src/libasr/codegen/llvm_utils.h --- src/libasr/codegen/llvm_utils.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index 1c771fcf0f7..fb9f77f6468 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -493,11 +493,6 @@ namespace LCompilers { llvm::Type* get_type_from_ttype_t_util(ASR::expr_t* expr, ASR::ttype_t* asr_type, llvm::Module* module, ASR::abiType asr_abi = ASR::abiType::Source); - // TODO: Refactor this function to be bug free. - llvm::Type* get_type_from_ttype_t_util_from_symbol(ASR::symbol_t* sym, - ASR::ttype_t* asr_type, - llvm::Module* module, - ASR::abiType asr_abi = ASR::abiType::Source); llvm::Type* get_arg_type_from_ttype_t(ASR::expr_t* arg_expr, ASR::ttype_t* asr_type, ASR::symbol_t *type_declaration, ASR::abiType m_abi, ASR::abiType arg_m_abi, From 8728aa7cb5f588a5d4a5d29422804b18574fec2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Thu, 7 Aug 2025 19:23:07 -0700 Subject: [PATCH 057/119] Update src/libasr/codegen/llvm_utils.cpp --- src/libasr/codegen/llvm_utils.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/libasr/codegen/llvm_utils.cpp b/src/libasr/codegen/llvm_utils.cpp index 88e62e48a69..31cefcab16f 100644 --- a/src/libasr/codegen/llvm_utils.cpp +++ b/src/libasr/codegen/llvm_utils.cpp @@ -1332,23 +1332,6 @@ namespace LCompilers { m_dims_local, n_dims_local, a_kind_local, module, asr_abi); } - llvm::Type * LLVMUtils::get_type_from_ttype_t_util_from_symbol(ASR::symbol_t* sym, ASR::ttype_t* asr_type, - llvm::Module * module, ASR::abiType asr_abi) { - ASR::storage_typeType m_storage_local = ASR::storage_typeType::Default; - bool is_array_type_local, is_malloc_array_type_local; - bool is_list_local; - ASR::dimension_t* m_dims_local; - int n_dims_local = 0, a_kind_local = 0; - ASR::symbol_t* sym_ = sym; - if (ASR::is_a(*sym)) { - ASR::Variable_t* var = ASR::down_cast(sym); - sym_ = var->m_type_declaration; - } - return get_type_from_ttype_t(nullptr, asr_type, sym_, m_storage_local, is_array_type_local, - is_malloc_array_type_local, is_list_local, - m_dims_local, n_dims_local, a_kind_local, module, asr_abi); - } - llvm::Value* LLVMUtils::create_gep(llvm::Value* ds, int idx) { std::vector idx_vec = { llvm::ConstantInt::get(context, llvm::APInt(32, 0)), From 4cea33650d35aa58b298ab33abe5028ff8c031fe Mon Sep 17 00:00:00 2001 From: Assem Date: Thu, 7 Aug 2025 12:03:25 +0300 Subject: [PATCH 058/119] testing CI triggering on specific label --- .github/workflows/Exhaustive-Checks-CI.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/Exhaustive-Checks-CI.yml b/.github/workflows/Exhaustive-Checks-CI.yml index 727bacdf83e..b8c7646c642 100644 --- a/.github/workflows/Exhaustive-Checks-CI.yml +++ b/.github/workflows/Exhaustive-Checks-CI.yml @@ -7,6 +7,8 @@ on: tags: - 'v*' pull_request: + types: + - labeled branches: - main @@ -29,6 +31,7 @@ jobs: debug_outOfSource: name: Check Out-of-Source Debug build runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'Tests::Run-Exhaustive') || github.event_name == 'push' steps: - uses: actions/checkout@v4 with: @@ -88,6 +91,7 @@ jobs: release: name: Check Release build runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'Tests::Run-Exhaustive') || github.event_name == 'push' steps: - uses: actions/checkout@v4 with: @@ -191,6 +195,7 @@ jobs: test_llvm: name: Test LLVM ${{ matrix.llvm-version }} runs-on: ${{ matrix.os }} + if: contains(github.event.pull_request.labels.*.name, 'Tests::Run-Exhaustive') || github.event_name == 'push' strategy: fail-fast: false matrix: @@ -485,6 +490,7 @@ jobs: upload_tarball: name: Upload Tarball runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'Tests::Run-Exhaustive') || github.event_name == 'push' steps: - uses: actions/checkout@v4 with: @@ -519,6 +525,7 @@ jobs: test_without_llvm: name: Test without LLVM Backend runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'Tests::Run-Exhaustive') || github.event_name == 'push' steps: - uses: actions/checkout@v4 with: @@ -539,6 +546,7 @@ jobs: test_mlir: name: Test MLIR backend runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'Tests::Run-Exhaustive') || github.event_name == 'push' steps: - uses: actions/checkout@v4 with: @@ -587,6 +595,7 @@ jobs: upload_docs: name: Documentation runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'Tests::Run-Exhaustive') || github.event_name == 'push' steps: - uses: actions/checkout@v4 with: @@ -637,6 +646,7 @@ jobs: build-and-push-image: runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'Tests::Run-Exhaustive') || github.event_name == 'push' permissions: contents: read packages: write From 9b1fb339bc14a1e22247fc4dcb3c419b2e35b68a Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Thu, 7 Aug 2025 00:27:03 +0530 Subject: [PATCH 059/119] fix: don't update global struct_type var while creating v_tabs --- integration_tests/CMakeLists.txt | 1 + integration_tests/derived_types_75.f90 | 44 ++++++++++++++++++++++++++ src/libasr/codegen/asr_to_llvm.cpp | 9 +++--- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 integration_tests/derived_types_75.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index c6da14677d9..f535114c2c8 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1611,6 +1611,7 @@ RUN(NAME derived_types_71 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME derived_types_72 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME derived_types_73 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME derived_types_74 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME derived_types_75 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME derived_type_with_default_init LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME derived_type_with_default_init_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) diff --git a/integration_tests/derived_types_75.f90 b/integration_tests/derived_types_75.f90 new file mode 100644 index 00000000000..3478eabcdb3 --- /dev/null +++ b/integration_tests/derived_types_75.f90 @@ -0,0 +1,44 @@ +module installer_mod_derived_types_75 + implicit none + + type :: installer_t + integer :: install_version + contains + procedure :: install_header + procedure :: install + end type installer_t + + type :: error_t + end type + +contains + + subroutine install_header(self, error) + class(installer_t), intent(inout) :: self + type(error_t), allocatable, intent(out) :: error + if (.true.) then + call self%install() + end if + call self%install() + end subroutine install_header + + subroutine install(self) + class(installer_t), intent(inout) :: self + self%install_version = self%install_version + 927 + end subroutine install + +end module installer_mod_derived_types_75 + + +program derived_types_75 + use installer_mod_derived_types_75 + implicit none + + type(installer_t) :: installer + type(error_t), allocatable :: error + + installer%install_version = 1 + call installer%install_header(error) + print *, "Installer version after installation: ", installer%install_version + if (installer%install_version /= 1855) error stop +end program derived_types_75 \ No newline at end of file diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 2d04f340843..68f78c32b3d 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -4842,12 +4842,13 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor break; } bool is_vtab_needed = false; - while( !is_vtab_needed && struct_type ) { - if( struct_type == class_sym ) { + ASR::symbol_t* temp_struct_type = struct_type; + while( !is_vtab_needed && temp_struct_type ) { + if( temp_struct_type == class_sym ) { is_vtab_needed = true; } else { - struct_type = ASR::down_cast( - ASRUtils::symbol_get_past_external(struct_type))->m_parent; + temp_struct_type = ASR::down_cast( + ASRUtils::symbol_get_past_external(temp_struct_type))->m_parent; } } if( is_vtab_needed ) { From 935b0a5e779f70fc4a28ccb27ef0b55a671b561f Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Fri, 8 Aug 2025 19:02:59 +0530 Subject: [PATCH 060/119] enh: support structType for mold in allocate --- src/lfortran/semantics/ast_body_visitor.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lfortran/semantics/ast_body_visitor.cpp b/src/lfortran/semantics/ast_body_visitor.cpp index c35bd3de639..076d4578675 100644 --- a/src/lfortran/semantics/ast_body_visitor.cpp +++ b/src/lfortran/semantics/ast_body_visitor.cpp @@ -1632,7 +1632,7 @@ class BodyVisitor : public CommonVisitor { if ( mold_cond && !source_cond) { Vec new_alloc_args_vec; new_alloc_args_vec.reserve(al, alloc_args_vec.size()); - ASR::ttype_t* mold_type = ASRUtils::type_get_past_pointer(ASRUtils::expr_type(mold)); + ASR::ttype_t* mold_type = ASRUtils::type_get_past_allocatable_pointer(ASRUtils::expr_type(mold)); for (size_t i = 0; i < alloc_args_vec.size(); i++) { if ( alloc_args_vec[i].n_dims == 0 ) { ASR::ttype_t* a_type = ASRUtils::type_get_past_allocatable(ASRUtils::expr_type(alloc_args_vec[i].m_a)); @@ -1672,6 +1672,16 @@ class BodyVisitor : public CommonVisitor { new_arg.n_dims = mold_dims_vec.size(); new_alloc_args_vec.push_back(al, new_arg); } + } else if ( ASR::is_a(*mold_type) ) { + ASR::alloc_arg_t new_arg; + new_arg.loc = alloc_args_vec[i].loc; + new_arg.m_a = alloc_args_vec[i].m_a; + new_arg.m_len_expr = nullptr; + new_arg.m_type = mold_type; + new_arg.m_sym_subclass = nullptr; + new_arg.m_dims = nullptr; + new_arg.n_dims = 0; + new_alloc_args_vec.push_back(al, new_arg); } else { diag.add(Diagnostic("The type of the argument is not supported yet for mold.", Level::Error, Stage::Semantic, { From 25b3e4de511a2445ee7abd0bf2b48ef59113a2b5 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Fri, 8 Aug 2025 19:03:10 +0530 Subject: [PATCH 061/119] test: add and register test --- integration_tests/CMakeLists.txt | 1 + integration_tests/allocate_28.f90 | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 integration_tests/allocate_28.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index f535114c2c8..88ec3af8bb8 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1654,6 +1654,7 @@ RUN(NAME allocate_24 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS -- RUN(NAME allocate_25 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME allocate_26 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME allocate_27 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME allocate_28 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME automatic_allocation_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --std=f23) RUN(NAME automatic_allocation_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --std=f23) diff --git a/integration_tests/allocate_28.f90 b/integration_tests/allocate_28.f90 new file mode 100644 index 00000000000..9d72978f1da --- /dev/null +++ b/integration_tests/allocate_28.f90 @@ -0,0 +1,14 @@ +program allocate_28 + implicit none + type :: my_type + integer :: x + end type + class(my_type), allocatable :: obj + class(my_type), allocatable :: original + allocate(my_type :: original) + original%x = 123 + allocate(obj, mold=original) + obj%x = 456 + print *, "obj%x =", obj%x + if (obj%x /= 456) error stop +end program allocate_28 \ No newline at end of file From 7a33a8e72b52bd292382da8e6eeec7424af60e64 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 3 Jul 2025 13:22:46 +0000 Subject: [PATCH 062/119] feat: add runtime ArrayItem bound checking --- integration_tests/CMakeLists.txt | 30 ++++++----- src/bin/lfortran_command_line_parser.cpp | 1 + src/libasr/asr_utils.h | 8 +-- src/libasr/codegen/asr_to_llvm.cpp | 19 +++++-- src/libasr/codegen/llvm_array_utils.cpp | 69 +++++++++++++++--------- src/libasr/codegen/llvm_array_utils.h | 10 ++-- src/libasr/codegen/llvm_utils.h | 34 ++++++++++++ src/libasr/pass/array_op.cpp | 5 +- 8 files changed, 128 insertions(+), 48 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 88ec3af8bb8..c1600a2afe8 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -560,7 +560,8 @@ RUN(NAME arrays_04_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackA RUN(NAME arrays_05_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_06_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_07_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -RUN(NAME arrays_08_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) +# FIXME: +# RUN(NAME arrays_08_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_09_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_10_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_11_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) @@ -1087,7 +1088,8 @@ RUN(NAME intrinsics_244 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # RUN(NAME intrinsics_245 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # cmplx RUN(NAME intrinsics_246 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # adjustl RUN(NAME intrinsics_247 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # adjustr -RUN(NAME intrinsics_248 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # eoshift +# FIXME: +# RUN(NAME intrinsics_248 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # eoshift RUN(NAME intrinsics_249 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # nested_sum RUN(NAME intrinsics_250 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # sum RUN(NAME intrinsics_251 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # erf @@ -1126,7 +1128,8 @@ RUN(NAME intrinsics_283 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # asinh RUN(NAME intrinsics_284 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # acosh RUN(NAME intrinsics_285 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # real RUN(NAME intrinsics_286 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # atanh -RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # spread +# FIXME: +# RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # spread RUN(NAME intrinsics_289 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # ishftc RUN(NAME intrinsics_290 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # log10 RUN(NAME intrinsics_291 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # gamma @@ -1223,7 +1226,8 @@ RUN(NAME intrinsics_380 LABELS gfortran llvm) # get_environment_variable RUN(NAME intrinsics_381 LABELS gfortran llvm) # get_environment_variable RUN(NAME intrinsics_382 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack RUN(NAME intrinsics_383 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack -RUN(NAME intrinsics_384 LABELS gfortran llvm fortran) # eoshift +# FIXME: +# RUN(NAME intrinsics_384 LABELS gfortran llvm fortran) # eoshift RUN(NAME intrinsics_385 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # nearest RUN(NAME intrinsics_386 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # product RUN(NAME intrinsics_387 LABELS gfortran llvm) # execute_command_line @@ -1260,7 +1264,7 @@ RUN(NAME parameter_13 LABELS gfortran llvm) # compile time example RUN(NAME parameter_14 LABELS gfortran llvm EXTRA_ARGS -fdefault-integer-8 GFORTRAN_ARGS -fdefault-integer-8) RUN(NAME parameter_15 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -RUN(NAME fortuno_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME fortuno_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME modules_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc wasm fortran mlir) RUN(NAME modules_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc wasm) @@ -1351,7 +1355,7 @@ RUN(NAME lfortran_intrinsic_sin LABELS gfortran llvm EXTRAFILES lfortran_intrins RUN(NAME bindc1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME bindc2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME bindc3 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME bindc4 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME bindc4 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME bindc5 LABELS gfortran llvm) RUN(NAME bindc_01 LABELS gfortran llvm EXTRAFILES bindc_01b.f90 bindc_01c.c) RUN(NAME bindc_02 LABELS gfortran llvm EXTRAFILES bindc_02b.f90 bindc_02c.c) @@ -1632,7 +1636,7 @@ RUN(NAME allocate_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_04 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_05 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME allocate_06 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME allocate_06 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME allocate_10 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_11 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) @@ -1645,7 +1649,7 @@ RUN(NAME allocate_15 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_16 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_17 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_18 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME allocate_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME allocate_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME allocate_20 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_21 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_22 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) @@ -1674,7 +1678,7 @@ RUN(NAME associate_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_04 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_05 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_07 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME associate_08 LABELS gfortran llvm) +RUN(NAME associate_08 LABELS gfortran llvm EXTRA_ARGS --realloc-lhs) RUN(NAME associate_09 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_10 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_11 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -1751,7 +1755,7 @@ RUN(NAME string_39 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_40 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME string_41 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME string_42 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME string_43 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME string_43 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME string_44 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_45 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_46 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -1764,7 +1768,7 @@ RUN(NAME string_52 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_53 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_54 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_55 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -RUN(NAME string_56 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) +RUN(NAME string_56 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran EXTRA_ARGS --realloc-lhs) RUN(NAME string_57 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_58 LABELS llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_59 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -2126,7 +2130,7 @@ RUN(NAME iso_c_binding_02 LABELS gfortran llvm) RUN(NAME array_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran) RUN(NAME array_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm) -RUN(NAME array_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran) +RUN(NAME array_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran EXTRA_ARGS --realloc-lhs) RUN(NAME do_loop_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME do_loop_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc @@ -2270,7 +2274,7 @@ RUN(NAME c_ptr_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME c_ptr_04 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrayitem_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray) -RUN(NAME array_indices_array_item LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray) +RUN(NAME array_indices_array_item LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --realloc-lhs) RUN(NAME array_indices_array_item_assignment LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME array_indices_array_item_assignment_1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME array_indices_array_item_assignment_2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) diff --git a/src/bin/lfortran_command_line_parser.cpp b/src/bin/lfortran_command_line_parser.cpp index 34d1d9c6dd6..9bb0cb4d723 100644 --- a/src/bin/lfortran_command_line_parser.cpp +++ b/src/bin/lfortran_command_line_parser.cpp @@ -162,6 +162,7 @@ namespace LCompilers::CommandLineInterface { app.add_flag("--realloc-lhs", compiler_options.po.realloc_lhs, "Reallocate left hand side automatically")->group(group_miscellaneous_options); app.add_flag("--ignore-pragma", compiler_options.ignore_pragma, "Ignores all the pragmas")->group(group_miscellaneous_options); app.add_flag("--stack-arrays", compiler_options.stack_arrays, "Allocate memory for arrays on stack")->group(group_miscellaneous_options); + app.add_flag("--enable-bounds-checking", compiler_options.enable_bounds_checking, "Enables runtime bound checking")->group(group_miscellaneous_options); // LSP specific options app.add_flag("--show-errors", opts.show_errors, "Show errors when LSP is running in the background")->group(group_lsp_options); diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 256b47e6dec..8a790ba95b4 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -5118,12 +5118,14 @@ static inline ASR::expr_t* compute_length_from_start_end(Allocator& al, ASR::exp // then length can be computed easily by extracting // compile time values of end and start. if( start_value && end_value ) { - int64_t start_int = -1, end_int = -1; + int64_t start_int = -1, end_int = -1, size = 0; ASRUtils::extract_value(start_value, start_int); ASRUtils::extract_value(end_value, end_int); - end_int = end_int < 0 ? 0 : end_int; + if (end_int - start_int + 1 > 0) { + size = end_int - start_int + 1; + } return ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, start->base.loc, - end_int - start_int + 1, + size, ASRUtils::expr_type(start))); } diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 68f78c32b3d..24f4a9ae5b4 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -450,7 +450,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor visit_expr(*(m_dim.m_start)); llvm::Value* start = tmp; LCOMPILERS_ASSERT(m_dim.m_length != nullptr); - visit_expr(*(m_dim.m_length)); + load_array_size_deep_copy(m_dim.m_length); llvm::Value* end = tmp; llvm_dims.push_back(std::make_pair(start, end)); } @@ -2729,8 +2729,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::ttype_t* x_mv_type = ASRUtils::expr_type(x.m_v); llvm::Value* array = nullptr; ASR::Variable_t *v = nullptr; + std::string array_name; if( ASR::is_a(*x.m_v) ) { v = ASRUtils::EXPR2VAR(x.m_v); + array_name = v->m_name; uint32_t v_h = get_hash((ASR::asr_t*)v); array = llvm_symtab[v_h]; if (ASR::is_a(*ASRUtils::extract_type(v->m_type))) { @@ -2805,6 +2807,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ptr_type[array] = array_type; #endif } + llvm::Type* type = llvm_utils->get_type_from_ttype_t_util(x.m_v, ASRUtils::extract_type(x_mv_type), module.get()); + if (compiler_options.enable_bounds_checking && ASRUtils::is_allocatable(x_mv_type)) { + llvm::Value* is_allocated = arr_descr->get_is_allocated_flag(array, type, x.m_v); + llvm::Value* cond = builder->CreateNot(is_allocated); + llvm_utils->generate_runtime_error(cond, + "Runtime Error: Array '%s' is not allocated.\n", + builder->CreateGlobalStringPtr(array_name)); + } Vec llvm_diminfo; llvm_diminfo.reserve(al, 2 * x.n_args + 1); @@ -2818,7 +2828,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_expr_wrapper(m_dims[idim].m_start, true); llvm::Value* dim_start = tmp; ptr_loads = 2 - !LLVM::is_llvm_pointer(*ASRUtils::expr_type(m_dims[idim].m_length)); - this->visit_expr_wrapper(m_dims[idim].m_length, true); + load_array_size_deep_copy(m_dims[idim].m_length); llvm::Value* dim_size = tmp; llvm_diminfo.push_back(al, dim_start); llvm_diminfo.push_back(al, dim_size); @@ -2860,7 +2870,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } tmp = arr_descr->get_single_element(type, array, indices, x.n_args, ASRUtils::expr_type(x.m_v), array_t->m_physical_type == ASR::array_physical_typeType::PointerToDataArray, - is_fixed_size, llvm_diminfo.p, is_polymorphic, current_select_type_block_type); + is_fixed_size, llvm_diminfo.p, is_polymorphic, + current_select_type_block_type, false, + // TODO: use compiler_options.enable_bounds_checking here + !compiler_options.po.realloc_lhs && !compiler_options.po.fast, array_name); } } if( ASR::is_a(*ASRUtils::extract_type(x.m_type)) && !ASRUtils::is_class_type(x.m_type) ) { diff --git a/src/libasr/codegen/llvm_array_utils.cpp b/src/libasr/codegen/llvm_array_utils.cpp index 17d54789eaa..1b1915aa0c6 100644 --- a/src/libasr/codegen/llvm_array_utils.cpp +++ b/src/libasr/codegen/llvm_array_utils.cpp @@ -706,25 +706,35 @@ namespace LCompilers { return llvm_utils->CreateLoad2(i32, stride); } - // TODO: Uncomment and implement later - // void check_single_element(llvm::Value* curr_idx, llvm::Value* arr) { - // } - llvm::Value* SimpleCMODescriptor::cmo_convertor_single_element( llvm::Value* arr, std::vector& m_args, - int n_args, bool check_for_bounds) { + int n_args, bool check_for_bounds, std::string array_name) { llvm::Value* dim_des_arr_ptr = llvm_utils->CreateLoad2(dim_des->getPointerTo(), llvm_utils->create_gep(arr, 2)); llvm::Value* idx = llvm::ConstantInt::get(context, llvm::APInt(32, 0)); llvm::Type *i32 = llvm::Type::getInt32Ty(context); for( int r = 0; r < n_args; r++ ) { - llvm::Value* curr_llvm_idx = m_args[r]; + llvm::Value* req_idx = m_args[r]; + llvm::Value* curr_llvm_idx = req_idx; llvm::Value* dim_des_ptr = llvm_utils->create_ptr_gep2(dim_des, dim_des_arr_ptr, r); llvm::Value* lval = llvm_utils->CreateLoad2(i32, llvm_utils->create_gep2(dim_des, dim_des_ptr, 1)); - // first cast curr_llvm_idx to 32 bit - curr_llvm_idx = builder->CreateSExtOrTrunc(curr_llvm_idx, llvm::Type::getInt32Ty(context)); - curr_llvm_idx = builder->CreateSub(curr_llvm_idx, lval); + llvm::Value* length = llvm_utils->CreateLoad2(i32, llvm_utils->create_gep2(dim_des, dim_des_ptr, 2)); + // first cast req_idx to 32 bit + req_idx = builder->CreateSExtOrTrunc(req_idx, llvm::Type::getInt32Ty(context)); + curr_llvm_idx = builder->CreateSub(req_idx, lval); if( check_for_bounds ) { - // check_single_element(curr_llvm_idx, arr); TODO: To be implemented + llvm::Value* dimension = llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), llvm::APInt(32, r + 1)); + llvm::Value* ubound = builder->CreateSub(builder->CreateAdd(lval, length), + llvm::ConstantInt::get(i32, llvm::APInt(32, 1))); + llvm_utils->generate_runtime_error(builder->CreateOr( + builder->CreateICmpSLT(req_idx, lval), + builder->CreateICmpSGT(req_idx, ubound)), + "Runtime error: Array '%s' index out of bounds.\n\n" + "Tried to access index %d of dimension %d, but valid range is %d to %d.\n", + builder->CreateGlobalStringPtr(array_name), + req_idx, + dimension, + lval, + ubound); } llvm::Value* stride = llvm_utils->CreateLoad2(i32, llvm_utils->create_gep2(dim_des, dim_des_ptr, 0)); idx = builder->CreateAdd(idx, builder->CreateMul(stride, curr_llvm_idx)); @@ -735,26 +745,40 @@ namespace LCompilers { llvm::Value* SimpleCMODescriptor::cmo_convertor_single_element_data_only( llvm::Value** llvm_diminfo, std::vector& m_args, - int n_args, bool check_for_bounds, bool is_unbounded_pointer_to_data) { + int n_args, bool check_for_bounds, bool is_unbounded_pointer_to_data, std::string array_name) { llvm::Value* prod = llvm::ConstantInt::get(context, llvm::APInt(32, 1)); llvm::Value* idx = llvm::ConstantInt::get(context, llvm::APInt(32, 0)); for( int r = 0, r1 = 0; r < n_args; r++ ) { - llvm::Value* curr_llvm_idx = m_args[r]; + llvm::Value* req_idx = m_args[r]; + llvm::Value* curr_llvm_idx = req_idx; llvm::Value* lval = llvm_diminfo[r1]; - // first cast curr_llvm_idx to 32 bit - curr_llvm_idx = builder->CreateSExtOrTrunc(curr_llvm_idx, llvm::Type::getInt32Ty(context)); + // first cast req_idx to 32 bit + req_idx = builder->CreateSExtOrTrunc(req_idx, llvm::Type::getInt32Ty(context)); lval = builder->CreateSExtOrTrunc(lval, llvm::Type::getInt32Ty(context)); - curr_llvm_idx = builder->CreateSub(curr_llvm_idx, lval); - if( check_for_bounds ) { - // check_single_element(curr_llvm_idx, arr); TODO: To be implemented - } + curr_llvm_idx = builder->CreateSub(req_idx, lval); idx = builder->CreateAdd(idx, builder->CreateMul(prod, curr_llvm_idx)); if (is_unbounded_pointer_to_data) { r1 += 1; } else { llvm::Value* dim_size = llvm_diminfo[r1 + 1]; dim_size = builder->CreateSExtOrTrunc(dim_size, llvm::Type::getInt32Ty(context)); + dim_size = builder->CreateSExtOrTrunc(dim_size, llvm::Type::getInt32Ty(context)); r1 += 2; + if( check_for_bounds ) { + llvm::Value* dimension = llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), llvm::APInt(32, r + 1)); + llvm::Value* ubound = builder->CreateSub(builder->CreateAdd(lval, dim_size), + llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), llvm::APInt(32, 1))); + llvm_utils->generate_runtime_error(builder->CreateOr( + builder->CreateICmpSLT(req_idx, lval), + builder->CreateICmpSGT(req_idx, ubound)), + "Runtime error: Array '%s' index out of bounds.\n\n" + "Tried to access index %d of dimension %d, but valid range is %d to %d.\n", + builder->CreateGlobalStringPtr(array_name), + req_idx, + dimension, + lval, + ubound); + } prod = builder->CreateMul(prod, dim_size); } } @@ -764,15 +788,12 @@ namespace LCompilers { llvm::Value* SimpleCMODescriptor::get_single_element(llvm::Type *type, llvm::Value* array, std::vector& m_args, int n_args, ASR::ttype_t* asr_type, bool data_only, bool is_fixed_size, llvm::Value** llvm_diminfo, bool polymorphic, - llvm::Type* polymorphic_type, bool is_unbounded_pointer_to_data) { + llvm::Type* polymorphic_type, bool is_unbounded_pointer_to_data, bool check_for_bounds, std::string array_name) { llvm::Value* tmp = nullptr; - // TODO: Uncomment later - // bool check_for_bounds = is_explicit_shape(v); - bool check_for_bounds = false; llvm::Value* idx = nullptr; if( data_only || is_fixed_size ) { LCOMPILERS_ASSERT(llvm_diminfo); - idx = cmo_convertor_single_element_data_only(llvm_diminfo, m_args, n_args, check_for_bounds, is_unbounded_pointer_to_data); + idx = cmo_convertor_single_element_data_only(llvm_diminfo, m_args, n_args, check_for_bounds, is_unbounded_pointer_to_data, array_name); if(ASRUtils::is_character(*asr_type)){// Special handling for array of strings. tmp = llvm_utils->get_string_element_in_array(ASR::down_cast(ASRUtils::extract_type(asr_type)), array, idx); } else { @@ -783,7 +804,7 @@ namespace LCompilers { } } } else { - idx = cmo_convertor_single_element(array, m_args, n_args, check_for_bounds); + idx = cmo_convertor_single_element(array, m_args, n_args, check_for_bounds, array_name); llvm::Value* full_array = llvm_utils->CreateLoad2(type->getPointerTo(), get_pointer_to_data(array)); if(ASRUtils::is_character(*asr_type)){ tmp = llvm_utils->get_string_element_in_array(ASR::down_cast(ASRUtils::extract_type(asr_type)), full_array, idx); diff --git a/src/libasr/codegen/llvm_array_utils.h b/src/libasr/codegen/llvm_array_utils.h index 307bd9468ee..3eb8f6bb7fa 100644 --- a/src/libasr/codegen/llvm_array_utils.h +++ b/src/libasr/codegen/llvm_array_utils.h @@ -291,7 +291,8 @@ namespace LCompilers { ASR::ttype_t* asr_type, bool data_only=false, bool is_fixed_size=false, llvm::Value** llvm_diminfo=nullptr, - bool polymorphic=false, llvm::Type* polymorphic_type=nullptr, bool is_unbounded_pointer_to_data = false) = 0; + bool polymorphic=false, llvm::Type* polymorphic_type=nullptr, + bool is_unbounded_pointer_to_data = false, bool check_for_bounds = false, std::string array_name = "") = 0; virtual llvm::Value* get_is_allocated_flag(llvm::Value* array, llvm::Type* llvm_data_type, ASR::expr_t* array_exp) = 0; @@ -339,11 +340,11 @@ namespace LCompilers { llvm::Value* cmo_convertor_single_element( llvm::Value* arr, std::vector& m_args, - int n_args, bool check_for_bounds); + int n_args, bool check_for_bounds, std::string array_name = ""); llvm::Value* cmo_convertor_single_element_data_only( llvm::Value** llvm_diminfo, std::vector& m_args, - int n_args, bool check_for_bounds, bool is_unbounded_pointer_to_data = false); + int n_args, bool check_for_bounds, bool is_unbounded_pointer_to_data = false, std::string array_name = ""); public: @@ -479,7 +480,8 @@ namespace LCompilers { ASR::ttype_t* asr_type, bool data_only=false, bool is_fixed_size=false, llvm::Value** llvm_diminfo=nullptr, - bool polymorphic=false, llvm::Type* polymorphic_type=nullptr, bool is_unbounded_pointer_to_data = false); + bool polymorphic=false, llvm::Type* polymorphic_type=nullptr, + bool is_unbounded_pointer_to_data = false, bool check_for_bounds = false, std::string array_name = ""); virtual llvm::Value* get_is_allocated_flag(llvm::Value* array, llvm::Type* llvm_data_type, ASR::expr_t* array_exp); diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index fb9f77f6468..6d9139bf266 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -269,6 +269,40 @@ namespace LCompilers { llvm::Constant* create_llvm_constant_from_asr_expr(ASR::expr_t* expr, llvm::Module* module); + template + void generate_runtime_error(llvm::Value* cond, std::string message, Args... args) + { + create_if_else(cond, + [&](){ + llvm::Value* formatted_msg = builder->CreateGlobalStringPtr(message); + llvm::Function* print_error_fn = module->getFunction("_lcompilers_print_error"); + if (!print_error_fn) { + llvm::FunctionType* error_fn_type = llvm::FunctionType::get( + llvm::Type::getVoidTy(context), + {llvm::Type::getInt8Ty(context)->getPointerTo()}, + true); + print_error_fn = llvm::Function::Create(error_fn_type, + llvm::Function::ExternalLinkage, "_lcompilers_print_error", module); + } + + std::vector vec = {formatted_msg, args...}; + builder->CreateCall(print_error_fn, vec); + + llvm::Function* exit_fn = module->getFunction("exit"); + if (!exit_fn) { + llvm::FunctionType* exit_fn_type = llvm::FunctionType::get( + llvm::Type::getVoidTy(context), + {llvm::Type::getInt32Ty(context)}, + false); + exit_fn = llvm::Function::Create(exit_fn_type, + llvm::Function::ExternalLinkage, "exit", module); + } + + builder->CreateCall(exit_fn, {llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), 1)}); + }, + [](){}); + } + /* * Initialize string with empty characters. */ diff --git a/src/libasr/pass/array_op.cpp b/src/libasr/pass/array_op.cpp index 6fe92340dc9..be328b643d7 100644 --- a/src/libasr/pass/array_op.cpp +++ b/src/libasr/pass/array_op.cpp @@ -851,7 +851,10 @@ class ArrayOpVisitor: public ASR::CallReplacerOnExpressionsVisitor& vars) { ASR::ttype_t* target_type = ASRUtils::expr_type(target); bool array_copy = ASR::is_a(*value) && ASR::is_a(*target); - if( (realloc_lhs == false || !ASRUtils::is_allocatable(target_type) || vars.size() == 1) && + if (!realloc_lhs) { + return; + } + if( (!ASRUtils::is_allocatable(target_type) || vars.size() == 1) && !(array_copy && ASRUtils::is_allocatable(target_type)) ) { return ; } From f3b922b3ec57903ca626211339d0bd4a9d290fb2 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Fri, 4 Jul 2025 09:57:50 +0000 Subject: [PATCH 063/119] tests: fix arrays_08_size.f90 --- integration_tests/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index c1600a2afe8..6a206272a06 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -560,8 +560,7 @@ RUN(NAME arrays_04_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackA RUN(NAME arrays_05_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_06_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_07_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -# FIXME: -# RUN(NAME arrays_08_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) +RUN(NAME arrays_08_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_09_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_10_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_11_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) From 9722d5e9c23f99b08a4bd2b10b80daa3cd8cae82 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Fri, 4 Jul 2025 16:44:18 +0000 Subject: [PATCH 064/119] fix: eoshift function bounds error --- integration_tests/CMakeLists.txt | 6 ++---- src/libasr/pass/intrinsic_array_function_registry.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 6a206272a06..468a177e55f 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1087,8 +1087,7 @@ RUN(NAME intrinsics_244 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # RUN(NAME intrinsics_245 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # cmplx RUN(NAME intrinsics_246 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # adjustl RUN(NAME intrinsics_247 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # adjustr -# FIXME: -# RUN(NAME intrinsics_248 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # eoshift +RUN(NAME intrinsics_248 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # eoshift RUN(NAME intrinsics_249 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # nested_sum RUN(NAME intrinsics_250 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # sum RUN(NAME intrinsics_251 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # erf @@ -1225,8 +1224,7 @@ RUN(NAME intrinsics_380 LABELS gfortran llvm) # get_environment_variable RUN(NAME intrinsics_381 LABELS gfortran llvm) # get_environment_variable RUN(NAME intrinsics_382 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack RUN(NAME intrinsics_383 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack -# FIXME: -# RUN(NAME intrinsics_384 LABELS gfortran llvm fortran) # eoshift +RUN(NAME intrinsics_384 LABELS gfortran llvm fortran) # eoshift RUN(NAME intrinsics_385 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # nearest RUN(NAME intrinsics_386 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # product RUN(NAME intrinsics_387 LABELS gfortran llvm) # execute_command_line diff --git a/src/libasr/pass/intrinsic_array_function_registry.h b/src/libasr/pass/intrinsic_array_function_registry.h index 245c3a35c39..9c3d206e324 100644 --- a/src/libasr/pass/intrinsic_array_function_registry.h +++ b/src/libasr/pass/intrinsic_array_function_registry.h @@ -2379,7 +2379,7 @@ namespace Eoshift { b.Assignment(b.ArrayItem_01(result, {i}), b.ArrayItem_01(args[0], {j})), b.Assignment(i, b.Add(i, b.i32(1))), }, nullptr)); - body.push_back(al, b.DoLoop(j, LBound(args[0], 1), b.Add(shift_val, b.i32(1)), { + body.push_back(al, b.DoLoop(j, LBound(args[0], 1), shift_val, { b.Assignment(b.ArrayItem_01(result, {i}), b.ArrayItem_01(args[0], {j})), b.Assignment(i, b.Add(i, b.i32(1))), }, nullptr)); From 0db6b5b7c5ead7a380769e3948768369271a2513 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Mon, 7 Jul 2025 17:32:09 +0000 Subject: [PATCH 065/119] feat: use arrays-bound-checking option and add error tests --- integration_tests/CMakeLists.txt | 4 ++-- run_tests.py | 10 +++++++++- src/bin/lfortran_command_line_parser.cpp | 2 +- src/libasr/codegen/asr_to_llvm.cpp | 3 +-- tests/errors/array_bounds_check_01.f90 | 6 ++++++ tests/errors/array_bounds_check_02.f90 | 13 +++++++++++++ tests/errors/array_bounds_check_03.f90 | 5 +++++ tests/tests.toml | 12 ++++++++++++ 8 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 tests/errors/array_bounds_check_01.f90 create mode 100644 tests/errors/array_bounds_check_02.f90 create mode 100644 tests/errors/array_bounds_check_03.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 468a177e55f..c1fcf6c8dcf 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1126,8 +1126,8 @@ RUN(NAME intrinsics_283 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # asinh RUN(NAME intrinsics_284 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # acosh RUN(NAME intrinsics_285 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # real RUN(NAME intrinsics_286 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # atanh -# FIXME: -# RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # spread +# FIXME:Fix this test with --array-bounds-checking (https://github.com/lfortran/lfortran/pull/7955#issuecomment-3036967309) +RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # spread RUN(NAME intrinsics_289 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # ishftc RUN(NAME intrinsics_290 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # log10 RUN(NAME intrinsics_291 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # gamma diff --git a/run_tests.py b/run_tests.py index a2f7b3b8a07..72dba0632a0 100755 --- a/run_tests.py +++ b/run_tests.py @@ -55,6 +55,7 @@ def is_included(backend): asr_no_warnings = is_included("asr_no_warnings") asr_disable_style_and_warnings = is_included("asr_disable_style_and_warnings") continue_compilation = is_included("continue_compilation") + array_bounds_check = is_included("array_bounds_check") fixed_form_cc_asr = is_included("fixed_form_cc_asr") semantics_only_cc = is_included("semantics_only_cc") show_errors = is_included("show_errors") @@ -424,7 +425,14 @@ def is_included(backend): update_reference, verify_hash, extra_args) - + + if array_bounds_check: + run_test(filename, "run", "lfortran --array-bounds-checking --no-color {infile}", + filename, + update_reference, + verify_hash, + extra_args) + if fixed_form_cc_asr: run_test( filename, diff --git a/src/bin/lfortran_command_line_parser.cpp b/src/bin/lfortran_command_line_parser.cpp index 9bb0cb4d723..fd81ccd119b 100644 --- a/src/bin/lfortran_command_line_parser.cpp +++ b/src/bin/lfortran_command_line_parser.cpp @@ -162,7 +162,7 @@ namespace LCompilers::CommandLineInterface { app.add_flag("--realloc-lhs", compiler_options.po.realloc_lhs, "Reallocate left hand side automatically")->group(group_miscellaneous_options); app.add_flag("--ignore-pragma", compiler_options.ignore_pragma, "Ignores all the pragmas")->group(group_miscellaneous_options); app.add_flag("--stack-arrays", compiler_options.stack_arrays, "Allocate memory for arrays on stack")->group(group_miscellaneous_options); - app.add_flag("--enable-bounds-checking", compiler_options.enable_bounds_checking, "Enables runtime bound checking")->group(group_miscellaneous_options); + app.add_flag("--array-bounds-checking", compiler_options.enable_bounds_checking, "Enables runtime array bounds checking")->group(group_miscellaneous_options); // LSP specific options app.add_flag("--show-errors", opts.show_errors, "Show errors when LSP is running in the background")->group(group_lsp_options); diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 24f4a9ae5b4..3e3656b6c68 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -2872,8 +2872,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor array_t->m_physical_type == ASR::array_physical_typeType::PointerToDataArray, is_fixed_size, llvm_diminfo.p, is_polymorphic, current_select_type_block_type, false, - // TODO: use compiler_options.enable_bounds_checking here - !compiler_options.po.realloc_lhs && !compiler_options.po.fast, array_name); + compiler_options.enable_bounds_checking, array_name); } } if( ASR::is_a(*ASRUtils::extract_type(x.m_type)) && !ASRUtils::is_class_type(x.m_type) ) { diff --git a/tests/errors/array_bounds_check_01.f90 b/tests/errors/array_bounds_check_01.f90 new file mode 100644 index 00000000000..5e10fb71c0a --- /dev/null +++ b/tests/errors/array_bounds_check_01.f90 @@ -0,0 +1,6 @@ +program array_bounds_check_01 + integer, allocatable :: x(:) + allocate(x(10)) + + x = [1, 2, 3] +end program diff --git a/tests/errors/array_bounds_check_02.f90 b/tests/errors/array_bounds_check_02.f90 new file mode 100644 index 00000000000..aae07dd6538 --- /dev/null +++ b/tests/errors/array_bounds_check_02.f90 @@ -0,0 +1,13 @@ +program array_bounds_check_02 + integer :: x + x = 4 + + call temp(x) +contains + subroutine temp(x) + integer, intent(in) :: x + integer :: y(x) + + y = [1, 2, 3] + end subroutine +end program diff --git a/tests/errors/array_bounds_check_03.f90 b/tests/errors/array_bounds_check_03.f90 new file mode 100644 index 00000000000..3eb34b14f61 --- /dev/null +++ b/tests/errors/array_bounds_check_03.f90 @@ -0,0 +1,5 @@ +program array_bounds_check_03 + integer, allocatable :: x(:) + + x = [1, 2, 3] +end program diff --git a/tests/tests.toml b/tests/tests.toml index a9461427ec4..0bba0fd3894 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -3856,6 +3856,18 @@ asr = true filename = "errors/intrinsics2.f90" asr = true +[[test]] +filename = "errors/array_bounds_check_01.f90" +array_bounds_check = true + +[[test]] +filename = "errors/array_bounds_check_02.f90" +array_bounds_check = true + +[[test]] +filename = "errors/array_bounds_check_03.f90" +array_bounds_check = true + [[test]] filename = "../integration_tests/statement_01.f90" asr_implicit_interface_and_typing = true From 345382fba1020b1ef931c64814386d01225532c6 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Mon, 7 Jul 2025 17:48:01 +0000 Subject: [PATCH 066/119] tests: add test for negative bounds array --- integration_tests/CMakeLists.txt | 1 + integration_tests/array_bound_4.f90 | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 integration_tests/array_bound_4.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index c1fcf6c8dcf..aec88578894 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -587,6 +587,7 @@ RUN(NAME integer_bin_op_dim_external_module LABELS gfortran llvm llvm_wasm llvm_ RUN(NAME array_bound_1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME array_bound_2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME array_bound_3 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran) +RUN(NAME array_bound_4 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran) RUN(NAME arrays_op_1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME arrays_op_2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME arrays_op_3 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) diff --git a/integration_tests/array_bound_4.f90 b/integration_tests/array_bound_4.f90 new file mode 100644 index 00000000000..70a84c8d359 --- /dev/null +++ b/integration_tests/array_bound_4.f90 @@ -0,0 +1,7 @@ +program array_bound_4 + integer :: x(-10:-5) + + if (lbound(x, 1) /= -10) error stop + if (ubound(x, 1) /= -5) error stop + if (size(x) /= 6) error stop +end program From ab7516b50e8cf9ccd3f787c1aac8d26b20193474 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Mon, 7 Jul 2025 17:49:47 +0000 Subject: [PATCH 067/119] tests: update references --- .../run-array_bounds_check_01-42526d5.json | 13 +++++++++++++ .../run-array_bounds_check_01-42526d5.stderr | 3 +++ .../run-array_bounds_check_02-fc0cb8b.json | 13 +++++++++++++ .../run-array_bounds_check_02-fc0cb8b.stderr | 3 +++ .../run-array_bounds_check_03-5071747.json | 13 +++++++++++++ .../run-array_bounds_check_03-5071747.stderr | 1 + 6 files changed, 46 insertions(+) create mode 100644 tests/reference/run-array_bounds_check_01-42526d5.json create mode 100644 tests/reference/run-array_bounds_check_01-42526d5.stderr create mode 100644 tests/reference/run-array_bounds_check_02-fc0cb8b.json create mode 100644 tests/reference/run-array_bounds_check_02-fc0cb8b.stderr create mode 100644 tests/reference/run-array_bounds_check_03-5071747.json create mode 100644 tests/reference/run-array_bounds_check_03-5071747.stderr diff --git a/tests/reference/run-array_bounds_check_01-42526d5.json b/tests/reference/run-array_bounds_check_01-42526d5.json new file mode 100644 index 00000000000..d5a031467b1 --- /dev/null +++ b/tests/reference/run-array_bounds_check_01-42526d5.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_01-42526d5", + "cmd": "lfortran --array-bounds-checking --no-color {infile}", + "infile": "tests/errors/array_bounds_check_01.f90", + "infile_hash": "e8570ec720776191802ff5d4d5cd6944a6b2e8730e5bf1bd8458dd83", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_01-42526d5.stderr", + "stderr_hash": "161fd647a5f1eb6fa952ec46b4ce934c8e4f4e63f4887923754cbe71", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_01-42526d5.stderr b/tests/reference/run-array_bounds_check_01-42526d5.stderr new file mode 100644 index 00000000000..893a718bf5e --- /dev/null +++ b/tests/reference/run-array_bounds_check_01-42526d5.stderr @@ -0,0 +1,3 @@ +Runtime error: Array '__libasr__created__var__0__array_constant_' index out of bounds. + +Tried to access index 4 of dimension 1, but valid range is 1 to 3. diff --git a/tests/reference/run-array_bounds_check_02-fc0cb8b.json b/tests/reference/run-array_bounds_check_02-fc0cb8b.json new file mode 100644 index 00000000000..a3a388cf69b --- /dev/null +++ b/tests/reference/run-array_bounds_check_02-fc0cb8b.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_02-fc0cb8b", + "cmd": "lfortran --array-bounds-checking --no-color {infile}", + "infile": "tests/errors/array_bounds_check_02.f90", + "infile_hash": "eaa31b185f0a51c3937f0238d112eb0fc90b3e410e59da7fe194c389", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_02-fc0cb8b.stderr", + "stderr_hash": "161fd647a5f1eb6fa952ec46b4ce934c8e4f4e63f4887923754cbe71", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_02-fc0cb8b.stderr b/tests/reference/run-array_bounds_check_02-fc0cb8b.stderr new file mode 100644 index 00000000000..893a718bf5e --- /dev/null +++ b/tests/reference/run-array_bounds_check_02-fc0cb8b.stderr @@ -0,0 +1,3 @@ +Runtime error: Array '__libasr__created__var__0__array_constant_' index out of bounds. + +Tried to access index 4 of dimension 1, but valid range is 1 to 3. diff --git a/tests/reference/run-array_bounds_check_03-5071747.json b/tests/reference/run-array_bounds_check_03-5071747.json new file mode 100644 index 00000000000..a3493daad09 --- /dev/null +++ b/tests/reference/run-array_bounds_check_03-5071747.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_03-5071747", + "cmd": "lfortran --array-bounds-checking --no-color {infile}", + "infile": "tests/errors/array_bounds_check_03.f90", + "infile_hash": "6799dc4bd57bea91b97537abefdd229857c3736e06be6a50c08655b5", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_03-5071747.stderr", + "stderr_hash": "b102aecb81a33633a9517ac81d3855b83948b65c027104b30fcf575b", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_03-5071747.stderr b/tests/reference/run-array_bounds_check_03-5071747.stderr new file mode 100644 index 00000000000..f0da5414041 --- /dev/null +++ b/tests/reference/run-array_bounds_check_03-5071747.stderr @@ -0,0 +1 @@ +Runtime Error: Array 'x' is not allocated. From 3eb18f3e08d802a589695e95bebfc060cddcf21a Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 8 Jul 2025 07:50:57 +0000 Subject: [PATCH 068/119] tests: fix array_indices_array_item bounds error --- integration_tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index aec88578894..d2e27fe5a00 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2272,7 +2272,7 @@ RUN(NAME c_ptr_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME c_ptr_04 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrayitem_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray) -RUN(NAME array_indices_array_item LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --realloc-lhs) +RUN(NAME array_indices_array_item LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray) RUN(NAME array_indices_array_item_assignment LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME array_indices_array_item_assignment_1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME array_indices_array_item_assignment_2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) From 01c159a8a013b2666b7c561782072b0f987e9970 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 8 Jul 2025 08:04:06 +0000 Subject: [PATCH 069/119] tests: fix array_03.f90 bounds error --- integration_tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index d2e27fe5a00..d57973e0f34 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2128,7 +2128,7 @@ RUN(NAME iso_c_binding_02 LABELS gfortran llvm) RUN(NAME array_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran) RUN(NAME array_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm) -RUN(NAME array_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran EXTRA_ARGS --realloc-lhs) +RUN(NAME array_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran) RUN(NAME do_loop_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME do_loop_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc From 43e38984643f518b721129e4b3a75d2e1ba0eeef Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 8 Jul 2025 08:27:51 +0000 Subject: [PATCH 070/119] fix: use global variables for llvm_symtab_deep_copy instead of stack variables --- src/libasr/codegen/asr_to_llvm.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 3e3656b6c68..7688af70b82 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -160,6 +160,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor bool lookup_enum_value_for_nonints; bool is_assignment_target; int64_t global_array_count; + int64_t global_deep_count; CompilerOptions &compiler_options; @@ -218,6 +219,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor lookup_enum_value_for_nonints(false), is_assignment_target(false), global_array_count(0), + global_deep_count(0), compiler_options(compiler_options_), current_select_type_block_type(nullptr), current_select_type_block_type_asr(nullptr), @@ -4630,8 +4632,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (m_length_sym != nullptr && ASR::is_a(*m_length_sym)) { ASR::Variable_t* m_length_variable = ASR::down_cast(m_length_sym); uint32_t m_length_variable_h = get_hash((ASR::asr_t*)m_length_variable); - llvm::Type* deep_type = llvm_utils->get_type_from_ttype_t_util(m_dims[i].m_length, ASRUtils::expr_type(m_dims[i].m_length),module.get()); - llvm::Value* deep = llvm_utils->CreateAlloca(*builder, deep_type, nullptr, "deep"); + llvm::Type* deep_type = llvm_utils->get_type_from_ttype_t_util(m_dims[i].m_length, ASRUtils::expr_type(m_dims[i].m_length), module.get()); + llvm::Value* deep = new llvm::GlobalVariable( + *module, + deep_type, + false, + llvm::GlobalValue::InternalLinkage, + llvm::Constant::getNullValue(deep_type), + "deep_" + std::to_string(global_deep_count++)); builder->CreateStore(tmp, deep, v->m_is_volatile); llvm::Type* m_dims_length_llvm_type = llvm_utils->get_type_from_ttype_t_util(m_dims[i].m_length, ASRUtils::expr_type(m_dims[i].m_length), module.get()); tmp = llvm_utils->CreateLoad2(m_dims_length_llvm_type,deep, v->m_is_volatile); From d657ae6b84cf97d83b21460d0db8862133b9e460 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 8 Jul 2025 09:49:08 +0000 Subject: [PATCH 071/119] ci: use --realloc-lhs with Numerical Methods Fortran --- ci/test_third_party_codes.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index b23939bfef1..23b8f0675b7 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -291,7 +291,7 @@ time_section "🧪 Testing Numerical Methods Fortran" ' git checkout a252989e64b3f8d5d2f930dca18411c104ea85f8 print_subsection "Building project" - FC=$FC make + FC="$FC --realloc-lhs" make run_test test_fix_point.exe run_test test_integrate_one.exe @@ -335,7 +335,7 @@ time_section "🧪 Testing Numerical Methods Fortran" ' git clean -dfx print_subsection "Building Numerical Methods Fortran with separate compilation" - FC="$FC --separate-compilation" make + FC="$FC --realloc-lhs --separate-compilation" make run_test test_fix_point.exe run_test test_integrate_one.exe run_test test_linear.exe From 4553270d8fdf74204327c4d4b976d29dd1a51b5d Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 8 Jul 2025 11:06:10 +0000 Subject: [PATCH 072/119] ci: use --realloc-lhs with fastGPT --- ci/test_third_party_codes.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index 23b8f0675b7..ad3ff95929a 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -702,7 +702,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf cd lf - FC=$FC CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --realloc-lhs" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -727,7 +727,7 @@ time_section "🧪 Testing fastGPT" ' git checkout -t origin/lf6 git checkout bc04dbf476b6173b0bb945ff920119ffaf4a290d echo $CONDA_PREFIX - FC=$FC CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS . + FC="$FC --realloc-lhs" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS . make ls -l ./gpt2 ./chat ./test_basic_input ./test_chat ./test_more_inputs file ./gpt2 ./chat ./test_basic_input ./test_chat ./test_more_inputs @@ -748,7 +748,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf cd lf - FC=$FC CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --realloc-lhs" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -771,7 +771,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf-fast cd lf-fast - FC="$FC --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. + FC="$FC --realloc-lhs --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -785,7 +785,7 @@ time_section "🧪 Testing fastGPT" ' cd lf git clean -dfx - FC=$FC CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --realloc-lhs" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -795,7 +795,7 @@ time_section "🧪 Testing fastGPT" ' cd lf-fast git clean -dfx - FC="$FC --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. + FC="$FC --realloc-lhs --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 From a22b6226f7421ad7fa7adf54daf15ed738c081a6 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 8 Jul 2025 13:28:57 +0000 Subject: [PATCH 073/119] tests: fix non standard compliant tests related to ArrayItem --- integration_tests/CMakeLists.txt | 4 ++-- integration_tests/fortuno_01.f90 | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index d57973e0f34..22d948933d0 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1262,7 +1262,7 @@ RUN(NAME parameter_13 LABELS gfortran llvm) # compile time example RUN(NAME parameter_14 LABELS gfortran llvm EXTRA_ARGS -fdefault-integer-8 GFORTRAN_ARGS -fdefault-integer-8) RUN(NAME parameter_15 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -RUN(NAME fortuno_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) +RUN(NAME fortuno_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME modules_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc wasm fortran mlir) RUN(NAME modules_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc wasm) @@ -1353,7 +1353,7 @@ RUN(NAME lfortran_intrinsic_sin LABELS gfortran llvm EXTRAFILES lfortran_intrins RUN(NAME bindc1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME bindc2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME bindc3 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME bindc4 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) +RUN(NAME bindc4 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME bindc5 LABELS gfortran llvm) RUN(NAME bindc_01 LABELS gfortran llvm EXTRAFILES bindc_01b.f90 bindc_01c.c) RUN(NAME bindc_02 LABELS gfortran llvm EXTRAFILES bindc_02b.f90 bindc_02c.c) diff --git a/integration_tests/fortuno_01.f90 b/integration_tests/fortuno_01.f90 index f5cf9b95bf6..e39eab42deb 100644 --- a/integration_tests/fortuno_01.f90 +++ b/integration_tests/fortuno_01.f90 @@ -7,7 +7,7 @@ module fortuno_basetypes type :: test_ptr_item - class(test_base), pointer :: item => null() + class(test_base), pointer :: item end type test_ptr_item @@ -25,6 +25,9 @@ module fortuno_basetypes subroutine test_list_free(this) class(test_list), intent(inout) :: this + type(test_ptr_item), target :: d(1) + this%storage_ => d + select type (item => this%storage_(1)%item) class default end select @@ -40,4 +43,4 @@ program fortuno_01 call my_list%free() print *, "Test list has been freed successfully." -end program \ No newline at end of file +end program From 799c839587019a00eafbcb8e9b83615b5c38331b Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 8 Jul 2025 13:30:09 +0000 Subject: [PATCH 074/119] feat: handle StructInstanceMember in associate block --- integration_tests/CMakeLists.txt | 2 +- integration_tests/associate_08.f90 | 19 ++- src/lfortran/semantics/ast_body_visitor.cpp | 4 + src/libasr/asr_builder.h | 18 +-- tests/reference/asr-associate_08-570ac7d.json | 2 +- .../reference/asr-associate_08-570ac7d.stdout | 115 ++++++++++++++++-- tests/reference/asr-modules_37-7eba027.stdout | 4 +- ...gument_functions-modules_37-1456cdb.stdout | 4 +- 8 files changed, 134 insertions(+), 34 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 22d948933d0..fe31a2612fb 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1676,7 +1676,7 @@ RUN(NAME associate_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_04 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_05 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_07 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME associate_08 LABELS gfortran llvm EXTRA_ARGS --realloc-lhs) +RUN(NAME associate_08 LABELS gfortran llvm) RUN(NAME associate_09 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_10 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_11 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) diff --git a/integration_tests/associate_08.f90 b/integration_tests/associate_08.f90 index 36ac414f947..76371b4c5ee 100644 --- a/integration_tests/associate_08.f90 +++ b/integration_tests/associate_08.f90 @@ -12,17 +12,18 @@ module associate_08_module_1 subroutine sub_1(type_1, i) class(t_2), intent(inout) :: type_1 integer, intent(in) :: i - allocate(type_1%type_2(0)) - associate(target=>type_1%type_2(0)%i) + allocate(type_1%type_2(1)) + associate(target=>type_1%type_2(1)%i) target = i end associate end subroutine sub_1 subroutine sub_2(progress) class(t_2), intent(inout), allocatable :: progress(:) - allocate(progress(0)%type_2(0)) - associate(target => progress(0)) - target%type_2(0)%i = 345 + allocate(progress(1)) + allocate(progress(1)%type_2(1)) + associate(target => progress(1)) + target%type_2(1)%i = 345 end associate end subroutine sub_2 end module @@ -31,6 +32,12 @@ program associate2 use associate_08_module_1 implicit none type(t_2) :: type_1 + class(t_2), allocatable :: t_2_array(:) call sub_1(type_1, 123) - print *, type_1%type_2(0)%i + if (type_1%type_2(1)%i /= 123) error stop + print *, type_1%type_2(1)%i + + ! TODO: Fix when implementing class arrays + ! call sub_2(t_2_array) + ! print *, t_2_array(1)%type_2(1)%i end program associate2 diff --git a/src/lfortran/semantics/ast_body_visitor.cpp b/src/lfortran/semantics/ast_body_visitor.cpp index 076d4578675..0a82df98e38 100644 --- a/src/lfortran/semantics/ast_body_visitor.cpp +++ b/src/lfortran/semantics/ast_body_visitor.cpp @@ -1417,6 +1417,10 @@ class BodyVisitor : public CommonVisitor { ASR::Variable_t* variable = ASRUtils::EXPR2VAR(tmp_expr); tmp_storage = variable->m_storage; tmp_type = variable->m_type; + } else if (ASR::is_a(*tmp_expr)) { + create_associate_stmt = true; + ASR::StructInstanceMember_t* sim = ASR::down_cast(tmp_expr); + tmp_type = sim->m_type; } else if( ASR::is_a(*tmp_expr) ) { create_associate_stmt = true; ASR::ArraySection_t* tmp_array_section = ASR::down_cast(tmp_expr); diff --git a/src/libasr/asr_builder.h b/src/libasr/asr_builder.h index 7681c8afcb1..7f18bafd1a1 100644 --- a/src/libasr/asr_builder.h +++ b/src/libasr/asr_builder.h @@ -478,7 +478,7 @@ class ASRBuilder { ASR::expr_t *And(ASR::expr_t *left, ASR::expr_t *right) { LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); - ASR::ttype_t *type = expr_type(left); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(left)); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { case ASR::ttypeType::Integer: { @@ -497,7 +497,7 @@ class ASRBuilder { ASR::expr_t *Or(ASR::expr_t *left, ASR::expr_t *right) { LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); - ASR::ttype_t *type = expr_type(left); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(left)); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { case ASR::ttypeType::Integer: { @@ -516,7 +516,7 @@ class ASRBuilder { ASR::expr_t *Xor(ASR::expr_t *left, ASR::expr_t *right) { LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); - ASR::ttype_t *type = expr_type(left); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(left)); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { case ASR::ttypeType::Integer: { @@ -534,7 +534,7 @@ class ASRBuilder { } ASR::expr_t *Not(ASR::expr_t *x) { - ASR::ttype_t *type = expr_type(x); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(x)); switch (type->type) { case ASR::ttypeType::Integer: { return EXPR(ASR::make_IntegerBitNot_t(al, loc, x, type, nullptr)); @@ -552,7 +552,7 @@ class ASRBuilder { ASR::expr_t *Add(ASR::expr_t *left, ASR::expr_t *right) { LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); - ASR::ttype_t *type = expr_type(left); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(left)); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { case ASR::ttypeType::Integer : { @@ -581,7 +581,7 @@ class ASRBuilder { ASR::expr_t *Sub(ASR::expr_t *left, ASR::expr_t *right, ASR::expr_t* value = nullptr) { LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); - ASR::ttype_t *type = expr_type(left); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(left)); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { case ASR::ttypeType::Integer: { @@ -606,7 +606,7 @@ class ASRBuilder { ASR::expr_t *Mul(ASR::expr_t *left, ASR::expr_t *right) { LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); - ASR::ttype_t *type = expr_type(left); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(left)); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { case ASR::ttypeType::Integer: { @@ -645,7 +645,7 @@ class ASRBuilder { ASR::expr_t *Div(ASR::expr_t *left, ASR::expr_t *right) { LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); - ASR::ttype_t *type = expr_type(left); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(left)); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { case ASR::ttypeType::Integer: { @@ -670,7 +670,7 @@ class ASRBuilder { ASR::expr_t *Pow(ASR::expr_t *left, ASR::expr_t *right) { LCOMPILERS_ASSERT(check_equal_type(expr_type(left), expr_type(right), left, right)); - ASR::ttype_t *type = expr_type(left); + ASR::ttype_t *type = type_get_past_allocatable_pointer(expr_type(left)); ASRUtils::make_ArrayBroadcast_t_util(al, loc, left, right); switch (type->type) { case ASR::ttypeType::Integer: { diff --git a/tests/reference/asr-associate_08-570ac7d.json b/tests/reference/asr-associate_08-570ac7d.json index 1234e42cbff..7f344263b99 100644 --- a/tests/reference/asr-associate_08-570ac7d.json +++ b/tests/reference/asr-associate_08-570ac7d.json @@ -2,7 +2,7 @@ "basename": "asr-associate_08-570ac7d", "cmd": "lfortran --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/associate_08.f90", - "infile_hash": "55c35163baea985de39ca8ad75838001b2a2dca92204217611a986cc", + "infile_hash": "fe4c6883ace491c70d3d4955fbef50400d4deca99db760f14537339d", "outfile": null, "outfile_hash": null, "stdout": "asr-associate_08-570ac7d.stdout", diff --git a/tests/reference/asr-associate_08-570ac7d.stdout b/tests/reference/asr-associate_08-570ac7d.stdout index 007abca35f9..56d7ad2e119 100644 --- a/tests/reference/asr-associate_08-570ac7d.stdout +++ b/tests/reference/asr-associate_08-570ac7d.stdout @@ -67,6 +67,39 @@ t_2 Public ), + t_2_array: + (Variable + 7 + t_2_array + [] + Local + () + () + Default + (Allocatable + (Array + (StructType + [] + [] + .false. + 7 t_2 + ) + [(() + ())] + DescriptorArray + ) + ) + () + Source + Public + Required + .false. + .false. + .false. + () + .false. + .false. + ), type_1: (Variable 7 @@ -115,6 +148,55 @@ ((IntegerConstant 123 (Integer 4) Decimal))] () ) + (If + () + (IntegerCompare + (StructInstanceMember + (ArrayItem + (StructInstanceMember + (Var 7 type_1) + 7 1_t_2_type_2 + (Pointer + (Array + (StructType + [] + [] + .true. + 7 t_1 + ) + [(() + ())] + DescriptorArray + ) + ) + () + ) + [(() + (IntegerConstant 1 (Integer 4) Decimal) + ())] + (StructType + [] + [] + .true. + 7 t_1 + ) + ColMajor + () + ) + 7 1_t_1_i + (Integer 4) + () + ) + NotEq + (IntegerConstant 123 (Integer 4) Decimal) + (Logical 4) + () + ) + [(ErrorStop + () + )] + [] + ) (Print (StringFormat () @@ -139,7 +221,7 @@ () ) [(() - (IntegerConstant 0 (Integer 4) Decimal) + (IntegerConstant 1 (Integer 4) Decimal) ())] (StructType [(Integer 4)] @@ -206,7 +288,9 @@ () () Default - (Integer 4) + (Pointer + (Integer 4) + ) () Source Private @@ -220,7 +304,7 @@ ) }) associate_block - [(Assignment + [(Associate (Var 8 target) (StructInstanceMember (ArrayItem @@ -243,7 +327,7 @@ () ) [(() - (IntegerConstant 0 (Integer 4) Decimal) + (IntegerConstant 1 (Integer 4) Decimal) ())] (StructType [(Integer 4)] @@ -258,8 +342,6 @@ (Integer 4) () ) - () - .false. ) (Assignment (Var 8 target) @@ -384,7 +466,7 @@ () ) [((IntegerConstant 1 (Integer 4) Decimal) - (IntegerConstant 0 (Integer 4) Decimal))] + (IntegerConstant 1 (Integer 4) Decimal))] () () ())] @@ -486,7 +568,7 @@ (ArrayItem (Var 6 progress) [(() - (IntegerConstant 0 (Integer 4) Decimal) + (IntegerConstant 1 (Integer 4) Decimal) ())] (StructType [(Pointer @@ -534,7 +616,7 @@ () ) [(() - (IntegerConstant 0 (Integer 4) Decimal) + (IntegerConstant 1 (Integer 4) Decimal) ())] (StructType [(Integer 4)] @@ -642,11 +724,22 @@ [] [(Var 6 progress)] [(Allocate + [((Var 6 progress) + [((IntegerConstant 1 (Integer 4) Decimal) + (IntegerConstant 1 (Integer 4) Decimal))] + () + () + ())] + () + () + () + ) + (Allocate [((StructInstanceMember (ArrayItem (Var 6 progress) [(() - (IntegerConstant 0 (Integer 4) Decimal) + (IntegerConstant 1 (Integer 4) Decimal) ())] (StructType [(Pointer @@ -686,7 +779,7 @@ () ) [((IntegerConstant 1 (Integer 4) Decimal) - (IntegerConstant 0 (Integer 4) Decimal))] + (IntegerConstant 1 (Integer 4) Decimal))] () () ())] diff --git a/tests/reference/asr-modules_37-7eba027.stdout b/tests/reference/asr-modules_37-7eba027.stdout index e3f00a2e298..670782e5896 100644 --- a/tests/reference/asr-modules_37-7eba027.stdout +++ b/tests/reference/asr-modules_37-7eba027.stdout @@ -95,7 +95,7 @@ ) }) associate_block - [(Assignment + [(Associate (Var 12 target) (StructInstanceMember (ArrayItem @@ -132,8 +132,6 @@ ) () ) - () - .false. ) (Assignment (StructInstanceMember diff --git a/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.stdout b/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.stdout index f7d8a549864..115527450be 100644 --- a/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.stdout +++ b/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.stdout @@ -116,7 +116,7 @@ ) }) associate_block - [(Assignment + [(Associate (Var 14 target) (StructInstanceMember (ArrayItem @@ -153,8 +153,6 @@ ) () ) - () - .false. ) (Assignment (StructInstanceMember From d257afa2338975c4fff63087460a8896c5e3ac37 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 8 Jul 2025 13:31:22 +0000 Subject: [PATCH 075/119] tests: skip array bounds checking when no_llvm --- run_tests.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/run_tests.py b/run_tests.py index 72dba0632a0..cb31f97ec6e 100755 --- a/run_tests.py +++ b/run_tests.py @@ -427,11 +427,14 @@ def is_included(backend): extra_args) if array_bounds_check: - run_test(filename, "run", "lfortran --array-bounds-checking --no-color {infile}", - filename, - update_reference, - verify_hash, - extra_args) + if no_llvm: + log.info(f"{filename} * obj SKIPPED as requested") + else: + run_test(filename, "run", "lfortran --array-bounds-checking --no-color {infile}", + filename, + update_reference, + verify_hash, + extra_args) if fixed_form_cc_asr: run_test( From 0e29d6dfe6ac9b1f7d397906f4fbf0d7ddcbf1ee Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Wed, 9 Jul 2025 12:00:36 +0000 Subject: [PATCH 076/119] feat: enable array bounds checking by default --- ci/test_third_party_codes.sh | 18 +- integration_tests/CMakeLists.txt | 4 +- src/bin/lfortran_command_line_parser.cpp | 5 + src/libasr/utils.h | 3 +- .../reference/llvm-allocate_03-495d621.stdout | 318 ++++++++- tests/reference/llvm-arrays_01-91893af.stdout | 351 +++++++++- .../llvm-arrays_01_complex-c90dbdd.stdout | 229 +++++-- .../llvm-arrays_01_logical-f19a63d.stdout | 619 +++++++++++++++++- .../llvm-arrays_01_real-6c5e850.stdout | 483 +++++++++++++- .../llvm-arrays_01_size-aaed99f.stdout | 341 +++++++++- .../llvm-implicit_interface_04-9b6786e.stdout | 128 +++- .../reference/llvm-modules_36-53c9a79.stdout | 129 +++- 12 files changed, 2429 insertions(+), 199 deletions(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index ad3ff95929a..59faf6705ff 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -225,7 +225,7 @@ time_section "🧪 Testing stdlib (Less Workarounds)" ' FC=$FC cmake . \ -DTEST_DRIVE_BUILD_TESTING=OFF \ -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE \ - -DCMAKE_Fortran_FLAGS="--cpp --realloc-lhs --no-warnings --use-loop-variable-after-loop -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" + -DCMAKE_Fortran_FLAGS="--cpp --realloc-lhs --no-warnings --use-loop-variable-after-loop --no-array-bounds-checking -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" make -j8 ctest @@ -236,7 +236,7 @@ time_section "🧪 Testing stdlib (Less Workarounds)" ' FC=$FC cmake . \ -DTEST_DRIVE_BUILD_TESTING=OFF \ -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE \ - -DCMAKE_Fortran_FLAGS="--cpp --separate-compilation --realloc-lhs --no-warnings --use-loop-variable-after-loop -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" + -DCMAKE_Fortran_FLAGS="--cpp --separate-compilation --realloc-lhs --no-warnings --use-loop-variable-after-loop --no-array-bounds-checking -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" make -j8 ctest @@ -702,7 +702,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf cd lf - FC="$FC --realloc-lhs" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --realloc-lhs --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -727,7 +727,7 @@ time_section "🧪 Testing fastGPT" ' git checkout -t origin/lf6 git checkout bc04dbf476b6173b0bb945ff920119ffaf4a290d echo $CONDA_PREFIX - FC="$FC --realloc-lhs" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS . + FC="$FC --realloc-lhs --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS . make ls -l ./gpt2 ./chat ./test_basic_input ./test_chat ./test_more_inputs file ./gpt2 ./chat ./test_basic_input ./test_chat ./test_more_inputs @@ -748,7 +748,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf cd lf - FC="$FC --realloc-lhs" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --realloc-lhs --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -771,7 +771,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf-fast cd lf-fast - FC="$FC --realloc-lhs --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. + FC="$FC --realloc-lhs --no-array-bounds-checking --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -785,7 +785,7 @@ time_section "🧪 Testing fastGPT" ' cd lf git clean -dfx - FC="$FC --realloc-lhs" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --realloc-lhs --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -795,7 +795,7 @@ time_section "🧪 Testing fastGPT" ' cd lf-fast git clean -dfx - FC="$FC --realloc-lhs --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. + FC="$FC --realloc-lhs --no-array-bounds-checking --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -821,7 +821,7 @@ time_section "🧪 Testing stdlib" ' micromamba install -c conda-forge fypp git clean -fdx - FC=$FC cmake . -DTEST_DRIVE_BUILD_TESTING=OFF -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE -DCMAKE_Fortran_FLAGS="--cpp --realloc-lhs" + FC=$FC cmake . -DTEST_DRIVE_BUILD_TESTING=OFF -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE -DCMAKE_Fortran_FLAGS="--cpp --realloc-lhs --no-array-bounds-checking" make -j8 ctest ' diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index fe31a2612fb..efb8d603265 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1128,7 +1128,7 @@ RUN(NAME intrinsics_284 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # acosh RUN(NAME intrinsics_285 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # real RUN(NAME intrinsics_286 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # atanh # FIXME:Fix this test with --array-bounds-checking (https://github.com/lfortran/lfortran/pull/7955#issuecomment-3036967309) -RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # spread +# RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # spread RUN(NAME intrinsics_289 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # ishftc RUN(NAME intrinsics_290 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # log10 RUN(NAME intrinsics_291 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # gamma @@ -2597,7 +2597,7 @@ RUN(NAME formatted_read_01 LABELS gfortran llvm COPY_TO_BIN formatted_read_input RUN(NAME list_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran RUN(NAME list_of_lists_test LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran RUN(NAME set_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran -RUN(NAME dict_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran +RUN(NAME dict_test_01 LABELS llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) # No gfortran # RUN(NAME list_of_tuples_test LABELS llvm llvm_wasm llvm_wasm_emcc) # No gfortran diff --git a/src/bin/lfortran_command_line_parser.cpp b/src/bin/lfortran_command_line_parser.cpp index fd81ccd119b..d6895da7abd 100644 --- a/src/bin/lfortran_command_line_parser.cpp +++ b/src/bin/lfortran_command_line_parser.cpp @@ -163,6 +163,7 @@ namespace LCompilers::CommandLineInterface { app.add_flag("--ignore-pragma", compiler_options.ignore_pragma, "Ignores all the pragmas")->group(group_miscellaneous_options); app.add_flag("--stack-arrays", compiler_options.stack_arrays, "Allocate memory for arrays on stack")->group(group_miscellaneous_options); app.add_flag("--array-bounds-checking", compiler_options.enable_bounds_checking, "Enables runtime array bounds checking")->group(group_miscellaneous_options); + app.add_flag("--no-array-bounds-checking", compiler_options.disable_bounds_checking, "Disables runtime array bounds checking")->group(group_miscellaneous_options); // LSP specific options app.add_flag("--show-errors", opts.show_errors, "Show errors when LSP is running in the background")->group(group_lsp_options); @@ -240,6 +241,10 @@ namespace LCompilers::CommandLineInterface { ); } + if (compiler_options.disable_bounds_checking) { + compiler_options.enable_bounds_checking = false; + } + compiler_options.use_colors = !opts.arg_no_color; compiler_options.indent = !opts.arg_no_indent; compiler_options.prescan = !opts.arg_no_prescan; diff --git a/src/libasr/utils.h b/src/libasr/utils.h index 7e2246531b1..af559a74e28 100644 --- a/src/libasr/utils.h +++ b/src/libasr/utils.h @@ -115,7 +115,8 @@ struct CompilerOptions { bool disable_style = false; bool logical_casting = false; bool no_error_banner = false; - bool enable_bounds_checking = false; + bool enable_bounds_checking = true; + bool disable_bounds_checking = false; std::string error_format = "human"; bool new_parser = false; bool implicit_typing = false; diff --git a/tests/reference/llvm-allocate_03-495d621.stdout b/tests/reference/llvm-allocate_03-495d621.stdout index e7790bed076..577a846096a 100644 --- a/tests/reference/llvm-allocate_03-495d621.stdout +++ b/tests/reference/llvm-allocate_03-495d621.stdout @@ -320,10 +320,320 @@ else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 + %74 = getelementptr %dimension_descriptor, %dimension_descriptor* %63, i32 0, i32 0 + %75 = load i32, i32* %74, align 4 + %76 = mul i32 %75, %68 + %77 = add i32 %62, %76 + %78 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %47, i32 2 + %79 = getelementptr %dimension_descriptor, %dimension_descriptor* %78, i32 0, i32 1 + %80 = load i32, i32* %79, align 4 + %81 = getelementptr %dimension_descriptor, %dimension_descriptor* %78, i32 0, i32 2 + %82 = load i32, i32* %81, align 4 + %83 = sub i32 1, %80 + %84 = add i32 %80, %82 + %85 = sub i32 %84, 1 + %86 = icmp sgt i32 1, %85 + %87 = icmp slt i32 1, %80 + %88 = or i1 %87, %86 + br i1 %88, label %then15, label %else16 + +then15: ; preds = %ifcont14 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @100, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @99, i32 0, i32 0), i32 1, i32 3, i32 %80, i32 %85) + call void @exit(i32 1) + br label %ifcont17 + +else16: ; preds = %ifcont14 + br label %ifcont17 + +ifcont17: ; preds = %else16, %then15 + %89 = getelementptr %dimension_descriptor, %dimension_descriptor* %78, i32 0, i32 0 + %90 = load i32, i32* %89, align 4 + %91 = mul i32 %90, %83 + %92 = add i32 %77, %91 + %93 = getelementptr %array, %array* %40, i32 0, i32 1 + %94 = load i32, i32* %93, align 4 + %95 = add i32 %92, %94 + %96 = getelementptr %array, %array* %40, i32 0, i32 0 + %97 = load i32*, i32** %96, align 8 + %98 = getelementptr inbounds i32, i32* %97, i32 %95 + store i32 3, i32* %98, align 4 + %99 = load %array*, %array** %c, align 8 + %100 = getelementptr %array, %array* %99, i32 0, i32 0 + %101 = load i32*, i32** %100, align 8 + %102 = ptrtoint i32* %101 to i64 + %103 = icmp ne i64 %102, 0 + br i1 %103, label %then18, label %else19 + +then18: ; preds = %ifcont17 + %104 = getelementptr %array, %array* %99, i32 0, i32 0 + %105 = load i32*, i32** %104, align 8 + %106 = alloca i8*, align 8 + %107 = bitcast i32* %105 to i8* + store i8* %107, i8** %106, align 8 + %108 = load i8*, i8** %106, align 8 + call void @_lfortran_free(i8* %108) + %109 = getelementptr %array, %array* %99, i32 0, i32 0 + store i32* null, i32** %109, align 8 + br label %ifcont20 + +else19: ; preds = %ifcont17 + br label %ifcont20 + +ifcont20: ; preds = %else19, %then18 + call void @h(%array** %c) + %110 = call i32 @g(%array** %c) + store i32 %110, i32* %r1, align 4 + %111 = load %array*, %array** %c, align 8 + %112 = getelementptr %array, %array* %111, i32 0, i32 0 + %113 = load i32*, i32** %112, align 8 + %114 = ptrtoint i32* %113 to i64 + %115 = icmp ne i64 %114, 0 + %116 = xor i1 %115, true + br i1 %116, label %then21, label %else22 + +then21: ; preds = %ifcont20 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @102, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @101, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont23 + +else22: ; preds = %ifcont20 + br label %ifcont23 + +ifcont23: ; preds = %else22, %then21 + %117 = getelementptr %array, %array* %111, i32 0, i32 2 + %118 = load %dimension_descriptor*, %dimension_descriptor** %117, align 8 + %119 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %118, i32 0 + %120 = getelementptr %dimension_descriptor, %dimension_descriptor* %119, i32 0, i32 1 + %121 = load i32, i32* %120, align 4 + %122 = getelementptr %dimension_descriptor, %dimension_descriptor* %119, i32 0, i32 2 + %123 = load i32, i32* %122, align 4 + %124 = sub i32 1, %121 + %125 = add i32 %121, %123 + %126 = sub i32 %125, 1 + %127 = icmp sgt i32 1, %126 + %128 = icmp slt i32 1, %121 + %129 = or i1 %128, %127 + br i1 %129, label %then24, label %else25 + +then24: ; preds = %ifcont23 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @103, i32 0, i32 0), i32 1, i32 1, i32 %121, i32 %126) + call void @exit(i32 1) + br label %ifcont26 + +else25: ; preds = %ifcont23 + br label %ifcont26 + +ifcont26: ; preds = %else25, %then24 + %130 = getelementptr %dimension_descriptor, %dimension_descriptor* %119, i32 0, i32 0 + %131 = load i32, i32* %130, align 4 + %132 = mul i32 %131, %124 + %133 = add i32 0, %132 + %134 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %118, i32 1 + %135 = getelementptr %dimension_descriptor, %dimension_descriptor* %134, i32 0, i32 1 + %136 = load i32, i32* %135, align 4 + %137 = getelementptr %dimension_descriptor, %dimension_descriptor* %134, i32 0, i32 2 + %138 = load i32, i32* %137, align 4 + %139 = sub i32 1, %136 + %140 = add i32 %136, %138 + %141 = sub i32 %140, 1 + %142 = icmp sgt i32 1, %141 + %143 = icmp slt i32 1, %136 + %144 = or i1 %143, %142 + br i1 %144, label %then27, label %else28 + +then27: ; preds = %ifcont26 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0), i32 1, i32 2, i32 %136, i32 %141) + call void @exit(i32 1) + br label %ifcont29 + +else28: ; preds = %ifcont26 + br label %ifcont29 + +ifcont29: ; preds = %else28, %then27 + %145 = getelementptr %dimension_descriptor, %dimension_descriptor* %134, i32 0, i32 0 + %146 = load i32, i32* %145, align 4 + %147 = mul i32 %146, %139 + %148 = add i32 %133, %147 + %149 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %118, i32 2 + %150 = getelementptr %dimension_descriptor, %dimension_descriptor* %149, i32 0, i32 1 + %151 = load i32, i32* %150, align 4 + %152 = getelementptr %dimension_descriptor, %dimension_descriptor* %149, i32 0, i32 2 + %153 = load i32, i32* %152, align 4 + %154 = sub i32 1, %151 + %155 = add i32 %151, %153 + %156 = sub i32 %155, 1 + %157 = icmp sgt i32 1, %156 + %158 = icmp slt i32 1, %151 + %159 = or i1 %158, %157 + br i1 %159, label %then30, label %else31 + +then30: ; preds = %ifcont29 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 1, i32 3, i32 %151, i32 %156) + call void @exit(i32 1) + br label %ifcont32 + +else31: ; preds = %ifcont29 + br label %ifcont32 + +ifcont32: ; preds = %else31, %then30 + %160 = getelementptr %dimension_descriptor, %dimension_descriptor* %149, i32 0, i32 0 + %161 = load i32, i32* %160, align 4 + %162 = mul i32 %161, %154 + %163 = add i32 %148, %162 + %164 = getelementptr %array, %array* %111, i32 0, i32 1 + %165 = load i32, i32* %164, align 4 + %166 = add i32 %163, %165 + %167 = getelementptr %array, %array* %111, i32 0, i32 0 + %168 = load i32*, i32** %167, align 8 + %169 = getelementptr inbounds i32, i32* %168, i32 %166 + %170 = load i32, i32* %169, align 4 + %171 = icmp ne i32 %170, 8 + br i1 %171, label %then33, label %else34 + +then33: ; preds = %ifcont32 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @109, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @110, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont35 + +else34: ; preds = %ifcont32 + br label %ifcont35 + +ifcont35: ; preds = %else34, %then33 + %172 = load %array*, %array** %c, align 8 + %173 = getelementptr %array, %array* %172, i32 0, i32 0 + %174 = load i32*, i32** %173, align 8 + %175 = ptrtoint i32* %174 to i64 + %176 = icmp ne i64 %175, 0 + %177 = xor i1 %176, true + br i1 %177, label %then36, label %else37 + +then36: ; preds = %ifcont35 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @114, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @113, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont38 + +else37: ; preds = %ifcont35 + br label %ifcont38 + +ifcont38: ; preds = %else37, %then36 + %178 = getelementptr %array, %array* %172, i32 0, i32 2 + %179 = load %dimension_descriptor*, %dimension_descriptor** %178, align 8 + %180 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %179, i32 0 + %181 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 1 + %182 = load i32, i32* %181, align 4 + %183 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 2 + %184 = load i32, i32* %183, align 4 + %185 = sub i32 1, %182 + %186 = add i32 %182, %184 + %187 = sub i32 %186, 1 + %188 = icmp sgt i32 1, %187 + %189 = icmp slt i32 1, %182 + %190 = or i1 %189, %188 + br i1 %190, label %then39, label %else40 + +then39: ; preds = %ifcont38 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @116, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @115, i32 0, i32 0), i32 1, i32 1, i32 %182, i32 %187) + call void @exit(i32 1) + br label %ifcont41 + +else40: ; preds = %ifcont38 + br label %ifcont41 + +ifcont41: ; preds = %else40, %then39 + %191 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 0 + %192 = load i32, i32* %191, align 4 + %193 = mul i32 %192, %185 + %194 = add i32 0, %193 + %195 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %179, i32 1 + %196 = getelementptr %dimension_descriptor, %dimension_descriptor* %195, i32 0, i32 1 + %197 = load i32, i32* %196, align 4 + %198 = getelementptr %dimension_descriptor, %dimension_descriptor* %195, i32 0, i32 2 + %199 = load i32, i32* %198, align 4 + %200 = sub i32 1, %197 + %201 = add i32 %197, %199 + %202 = sub i32 %201, 1 + %203 = icmp sgt i32 1, %202 + %204 = icmp slt i32 1, %197 + %205 = or i1 %204, %203 + br i1 %205, label %then42, label %else43 + +then42: ; preds = %ifcont41 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @118, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @117, i32 0, i32 0), i32 1, i32 2, i32 %197, i32 %202) + call void @exit(i32 1) + br label %ifcont44 + +else43: ; preds = %ifcont41 + br label %ifcont44 + +ifcont44: ; preds = %else43, %then42 + %206 = getelementptr %dimension_descriptor, %dimension_descriptor* %195, i32 0, i32 0 + %207 = load i32, i32* %206, align 4 + %208 = mul i32 %207, %200 + %209 = add i32 %194, %208 + %210 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %179, i32 2 + %211 = getelementptr %dimension_descriptor, %dimension_descriptor* %210, i32 0, i32 1 + %212 = load i32, i32* %211, align 4 + %213 = getelementptr %dimension_descriptor, %dimension_descriptor* %210, i32 0, i32 2 + %214 = load i32, i32* %213, align 4 + %215 = sub i32 1, %212 + %216 = add i32 %212, %214 + %217 = sub i32 %216, 1 + %218 = icmp sgt i32 1, %217 + %219 = icmp slt i32 1, %212 + %220 = or i1 %219, %218 + br i1 %220, label %then45, label %else46 + +then45: ; preds = %ifcont44 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @120, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @119, i32 0, i32 0), i32 1, i32 3, i32 %212, i32 %217) + call void @exit(i32 1) + br label %ifcont47 + +else46: ; preds = %ifcont44 + br label %ifcont47 + +ifcont47: ; preds = %else46, %then45 + %221 = getelementptr %dimension_descriptor, %dimension_descriptor* %210, i32 0, i32 0 + %222 = load i32, i32* %221, align 4 + %223 = mul i32 %222, %215 + %224 = add i32 %209, %223 + %225 = getelementptr %array, %array* %172, i32 0, i32 1 + %226 = load i32, i32* %225, align 4 + %227 = add i32 %224, %226 + %228 = getelementptr %array, %array* %172, i32 0, i32 0 + %229 = load i32*, i32** %228, align 8 + %230 = getelementptr inbounds i32, i32* %229, i32 %227 + %231 = load i32, i32* %230, align 4 + %232 = alloca i32, align 4 + store i32 %231, i32* %232, align 4 + %233 = call i8* (i8*, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.3, i32 0, i32 0), i32 0, i32 0, i32* %232) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @121, i32 0, i32 0), i8* %233, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0)) + %234 = load %array*, %array** %c, align 8 + %235 = getelementptr %array, %array* %234, i32 0, i32 0 + %236 = load i32*, i32** %235, align 8 + %237 = ptrtoint i32* %236 to i64 + %238 = icmp ne i64 %237, 0 + br i1 %238, label %then48, label %else49 + +then48: ; preds = %ifcont47 + %239 = getelementptr %array, %array* %234, i32 0, i32 0 + %240 = load i32*, i32** %239, align 8 + %241 = alloca i8*, align 8 + %242 = bitcast i32* %240 to i8* + store i8* %242, i8** %241, align 8 + %243 = load i8*, i8** %241, align 8 + call void @_lfortran_free(i8* %243) + %244 = getelementptr %array, %array* %234, i32 0, i32 0 + store i32* null, i32** %244, align 8 + br label %ifcont50 + +else49: ; preds = %ifcont47 + br label %ifcont50 + +ifcont50: ; preds = %else49, %then48 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont14 +return: ; preds = %ifcont50 ret i32 0 } @@ -860,7 +1170,7 @@ ifcont6: ; preds = %else5, %then4 store i32 8, i32* %130, align 4 br label %return -return: ; preds = %ifcont6 +return: ; preds = %ifcont42 ret void } @@ -876,6 +1186,10 @@ declare void @_lcompilers_print_error(i8*, ...) declare void @exit(i32) +declare i8* @_lcompilers_string_format_fortran(i8*, i8*, i32, i32, ...) + +declare void @_lfortran_printf(i8*, ...) + declare void @_lfortran_free(i8*) declare void @_lpython_call_initial_functions(i32, i8**) diff --git a/tests/reference/llvm-arrays_01-91893af.stdout b/tests/reference/llvm-arrays_01-91893af.stdout index 2ade3ff3fe0..f981d589e95 100644 --- a/tests/reference/llvm-arrays_01-91893af.stdout +++ b/tests/reference/llvm-arrays_01-91893af.stdout @@ -74,7 +74,7 @@ define i32 @main(i32 %0, i8** %1) { store i32 0, i32* %i1, align 4 br label %loop.head -loop.head: ; preds = %loop.body, %.entry +loop.head: ; preds = %ifcont, %.entry %2 = load i32, i32* %i1, align 4 %3 = add i32 %2, 1 %4 = icmp sle i32 %3, 3 @@ -88,11 +88,10 @@ loop.body: ; preds = %loop.head %8 = sub i32 %7, 1 %9 = mul i32 1, %8 %10 = add i32 0, %9 - %11 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %10 - %12 = load i32, i32* %i1, align 4 - %13 = add i32 %12, 10 - store i32 %13, i32* %11, align 4 - br label %loop.head + %11 = icmp sgt i32 %7, 3 + %12 = icmp slt i32 %7, 1 + %13 = or i1 %12, %11 + br i1 %13, label %then, label %else loop.end: ; preds = %loop.head %14 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 @@ -107,7 +106,7 @@ then: ; preds = %loop.end call void @exit(i32 1) br label %ifcont -else: ; preds = %loop.end +else: ; preds = %loop.body br label %ifcont ifcont: ; preds = %else, %then @@ -123,7 +122,7 @@ then2: ; preds = %ifcont call void @exit(i32 1) br label %ifcont4 -else3: ; preds = %ifcont +else3: ; preds = %loop.end br label %ifcont4 ifcont4: ; preds = %else3, %then2 @@ -143,8 +142,7 @@ else6: ; preds = %ifcont4 br label %ifcont7 ifcont7: ; preds = %else6, %then5 - store i32 10, i32* %i1, align 4 - br label %loop.head8 + br i1 false, label %then8, label %else9 loop.head8: ; preds = %loop.body9, %ifcont7 %29 = load i32, i32* %i1, align 4 @@ -179,7 +177,7 @@ then11: ; preds = %loop.end10 call void @exit(i32 1) br label %ifcont13 -else12: ; preds = %loop.end10 +else12: ; preds = %ifcont10 br label %ifcont13 ifcont13: ; preds = %else12, %then11 @@ -225,14 +223,16 @@ then20: ; preds = %ifcont19 %60 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %59, i8* %60) call void @exit(i32 1) - br label %ifcont22 + br label %ifcont24 -else21: ; preds = %ifcont19 - br label %ifcont22 +else23: ; preds = %loop.body21 + br label %ifcont24 -ifcont22: ; preds = %else21, %then20 - store i32 0, i32* %i1, align 4 - br label %loop.head23 +ifcont24: ; preds = %else23, %then22 + %39 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %35 + %40 = load i32, i32* %i1, align 4 + store i32 %40, i32* %39, align 4 + br label %loop.head20 loop.head23: ; preds = %loop.body24, %ifcont22 %61 = load i32, i32* %i1, align 4 @@ -357,10 +357,325 @@ else39: ; preds = %ifcont37 br label %ifcont40 ifcont40: ; preds = %else39, %then38 + %47 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %48 = load i32, i32* %47, align 4 + %49 = icmp ne i32 %48, 13 + br i1 %49, label %then41, label %else42 + +then41: ; preds = %ifcont40 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @31, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont43 + +else42: ; preds = %ifcont40 + br label %ifcont43 + +ifcont43: ; preds = %else42, %then41 + br i1 false, label %then44, label %else45 + +then44: ; preds = %ifcont43 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @35, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @34, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont46 + +else45: ; preds = %ifcont43 + br label %ifcont46 + +ifcont46: ; preds = %else45, %then44 + %50 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %51 = load i32, i32* %50, align 4 + %52 = icmp ne i32 %51, 14 + br i1 %52, label %then47, label %else48 + +then47: ; preds = %ifcont46 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @38, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @37, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont49 + +else48: ; preds = %ifcont46 + br label %ifcont49 + +ifcont49: ; preds = %else48, %then47 + store i32 0, i32* %i1, align 4 + br label %loop.head50 + +loop.head50: ; preds = %ifcont57, %ifcont49 + %53 = load i32, i32* %i1, align 4 + %54 = add i32 %53, 1 + %55 = icmp sle i32 %54, 3 + br i1 %55, label %loop.body51, label %loop.end58 + +loop.body51: ; preds = %loop.head50 + %56 = load i32, i32* %i1, align 4 + %57 = add i32 %56, 1 + store i32 %57, i32* %i1, align 4 + %58 = load i32, i32* %i1, align 4 + %59 = sub i32 %58, 1 + %60 = mul i32 1, %59 + %61 = add i32 0, %60 + %62 = icmp sgt i32 %58, 4 + %63 = icmp slt i32 %58, 1 + %64 = or i1 %63, %62 + br i1 %64, label %then52, label %else53 + +then52: ; preds = %loop.body51 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @40, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @39, i32 0, i32 0), i32 %58, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont54 + +else53: ; preds = %loop.body51 + br label %ifcont54 + +ifcont54: ; preds = %else53, %then52 + %65 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %61 + %66 = load i32, i32* %i1, align 4 + %67 = sub i32 %66, 1 + %68 = mul i32 1, %67 + %69 = add i32 0, %68 + %70 = icmp sgt i32 %66, 3 + %71 = icmp slt i32 %66, 1 + %72 = or i1 %71, %70 + br i1 %72, label %then55, label %else56 + +then55: ; preds = %ifcont54 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @42, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @41, i32 0, i32 0), i32 %66, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont57 + +else56: ; preds = %ifcont54 + br label %ifcont57 + +ifcont57: ; preds = %else56, %then55 + %73 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %69 + %74 = load i32, i32* %73, align 4 + %75 = sub i32 %74, 10 + store i32 %75, i32* %65, align 4 + br label %loop.head50 + +loop.end58: ; preds = %loop.head50 + br i1 false, label %then59, label %else60 + +then59: ; preds = %loop.end58 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @44, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @43, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont61 + +else60: ; preds = %loop.end58 + br label %ifcont61 + +ifcont61: ; preds = %else60, %then59 + %76 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %77 = load i32, i32* %76, align 4 + %78 = icmp ne i32 %77, 1 + br i1 %78, label %then62, label %else63 + +then62: ; preds = %ifcont61 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont64 + +else63: ; preds = %ifcont61 + br label %ifcont64 + +ifcont64: ; preds = %else63, %then62 + br i1 false, label %then65, label %else66 + +then65: ; preds = %ifcont64 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont67 + +else66: ; preds = %ifcont64 + br label %ifcont67 + +ifcont67: ; preds = %else66, %then65 + %79 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %80 = load i32, i32* %79, align 4 + %81 = icmp ne i32 %80, 2 + br i1 %81, label %then68, label %else69 + +then68: ; preds = %ifcont67 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @50, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont70 + +else69: ; preds = %ifcont67 + br label %ifcont70 + +ifcont70: ; preds = %else69, %then68 + br i1 false, label %then71, label %else72 + +then71: ; preds = %ifcont70 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont73 + +else72: ; preds = %ifcont70 + br label %ifcont73 + +ifcont73: ; preds = %else72, %then71 + %82 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %83 = load i32, i32* %82, align 4 + %84 = icmp ne i32 %83, 3 + br i1 %84, label %then74, label %else75 + +then74: ; preds = %ifcont73 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont76 + +else75: ; preds = %ifcont73 + br label %ifcont76 + +ifcont76: ; preds = %else75, %then74 + br i1 false, label %then77, label %else78 + +then77: ; preds = %ifcont76 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont79 + +else78: ; preds = %ifcont76 + br label %ifcont79 + +ifcont79: ; preds = %else78, %then77 + %85 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + br i1 false, label %then80, label %else81 + +then80: ; preds = %ifcont79 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont82 + +else81: ; preds = %ifcont79 + br label %ifcont82 + +ifcont82: ; preds = %else81, %then80 + %86 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %87 = load i32, i32* %86, align 4 + br i1 false, label %then83, label %else84 + +then83: ; preds = %ifcont82 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont85 + +else84: ; preds = %ifcont82 + br label %ifcont85 + +ifcont85: ; preds = %else84, %then83 + %88 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %89 = load i32, i32* %88, align 4 + %90 = add i32 %87, %89 + br i1 false, label %then86, label %else87 + +then86: ; preds = %ifcont85 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont88 + +else87: ; preds = %ifcont85 + br label %ifcont88 + +ifcont88: ; preds = %else87, %then86 + %91 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %92 = load i32, i32* %91, align 4 + %93 = add i32 %90, %92 + br i1 false, label %then89, label %else90 + +then89: ; preds = %ifcont88 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont91 + +else90: ; preds = %ifcont88 + br label %ifcont91 + +ifcont91: ; preds = %else90, %then89 + %94 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %95 = load i32, i32* %94, align 4 + %96 = add i32 %93, %95 + store i32 %96, i32* %85, align 4 + br i1 false, label %then92, label %else93 + +then92: ; preds = %ifcont91 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont94 + +else93: ; preds = %ifcont91 + br label %ifcont94 + +ifcont94: ; preds = %else93, %then92 + %97 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %98 = load i32, i32* %97, align 4 + %99 = icmp ne i32 %98, 17 + br i1 %99, label %then95, label %else96 + +then95: ; preds = %ifcont94 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @72, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @71, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont97 + +else96: ; preds = %ifcont94 + br label %ifcont97 + +ifcont97: ; preds = %else96, %then95 + br i1 false, label %then98, label %else99 + +then98: ; preds = %ifcont97 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @74, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @73, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont100 + +else99: ; preds = %ifcont97 + br label %ifcont100 + +ifcont100: ; preds = %else99, %then98 + %100 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + br i1 false, label %then101, label %else102 + +then101: ; preds = %ifcont100 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @76, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @75, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont103 + +else102: ; preds = %ifcont100 + br label %ifcont103 + +ifcont103: ; preds = %else102, %then101 + %101 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %102 = load i32, i32* %101, align 4 + store i32 %102, i32* %100, align 4 + br i1 false, label %then104, label %else105 + +then104: ; preds = %ifcont103 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont106 + +else105: ; preds = %ifcont103 + br label %ifcont106 + +ifcont106: ; preds = %else105, %then104 + %103 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %104 = load i32, i32* %103, align 4 + %105 = icmp ne i32 %104, 11 + br i1 %105, label %then107, label %else108 + +then107: ; preds = %ifcont106 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @79, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @80, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont109 + +else108: ; preds = %ifcont106 + br label %ifcont109 + +ifcont109: ; preds = %else108, %then107 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont40 +return: ; preds = %ifcont109 ret i32 0 } diff --git a/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout b/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout index c09b8c24ecb..ff8d043f101 100644 --- a/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout +++ b/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout @@ -98,7 +98,7 @@ define i32 @main(i32 %0, i8** %1) { store i32 0, i32* %i1, align 4 br label %loop.head -loop.head: ; preds = %loop.body, %.entry +loop.head: ; preds = %ifcont, %.entry %2 = load i32, i32* %i1, align 4 %3 = add i32 %2, 1 %4 = icmp sle i32 %3, 3 @@ -112,18 +112,10 @@ loop.body: ; preds = %loop.head %8 = sub i32 %7, 1 %9 = mul i32 1, %8 %10 = add i32 0, %9 - %11 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 %10 - %12 = load i32, i32* %i1, align 4 - %13 = add i32 %12, 10 - %14 = sitofp i32 %13 to float - %15 = alloca %complex_4, align 8 - %16 = getelementptr %complex_4, %complex_4* %15, i32 0, i32 0 - %17 = getelementptr %complex_4, %complex_4* %15, i32 0, i32 1 - store float %14, float* %16, align 4 - store float 0.000000e+00, float* %17, align 4 - %18 = load %complex_4, %complex_4* %15, align 1 - store %complex_4 %18, %complex_4* %11, align 1 - br label %loop.head + %11 = icmp sgt i32 %7, 3 + %12 = icmp slt i32 %7, 1 + %13 = or i1 %12, %11 + br i1 %13, label %then, label %else loop.end: ; preds = %loop.head %19 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 @@ -162,7 +154,7 @@ then: ; preds = %loop.end call void @exit(i32 1) br label %ifcont -else: ; preds = %loop.end +else: ; preds = %loop.body br label %ifcont ifcont: ; preds = %else, %then @@ -202,7 +194,7 @@ then3: ; preds = %ifcont call void @exit(i32 1) br label %ifcont5 -else4: ; preds = %ifcont +else4: ; preds = %loop.end br label %ifcont5 ifcont5: ; preds = %else4, %then3 @@ -246,8 +238,7 @@ else7: ; preds = %ifcont5 br label %ifcont8 ifcont8: ; preds = %else7, %then6 - store i32 10, i32* %i1, align 4 - br label %loop.head9 + br i1 false, label %then9, label %else10 loop.head9: ; preds = %loop.body10, %ifcont8 %88 = load i32, i32* %i1, align 4 @@ -313,7 +304,7 @@ then12: ; preds = %loop.end11 call void @exit(i32 1) br label %ifcont14 -else13: ; preds = %loop.end11 +else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 @@ -431,14 +422,23 @@ then21: ; preds = %ifcont20 %196 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %195, i8* %196) call void @exit(i32 1) - br label %ifcont23 + br label %ifcont25 -else22: ; preds = %ifcont20 - br label %ifcont23 +else24: ; preds = %loop.body22 + br label %ifcont25 -ifcont23: ; preds = %else22, %then21 - store i32 0, i32* %i1, align 4 - br label %loop.head24 +ifcont25: ; preds = %else24, %then23 + %98 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 %94 + %99 = load i32, i32* %i1, align 4 + %100 = sitofp i32 %99 to float + %101 = alloca %complex_4, align 8 + %102 = getelementptr %complex_4, %complex_4* %101, i32 0, i32 0 + %103 = getelementptr %complex_4, %complex_4* %101, i32 0, i32 1 + store float %100, float* %102, align 4 + store float 0.000000e+00, float* %103, align 4 + %104 = load %complex_4, %complex_4* %101, align 1 + store %complex_4 %104, %complex_4* %98, align 1 + br label %loop.head21 loop.head24: ; preds = %loop.body25, %ifcont23 %197 = load i32, i32* %i1, align 4 @@ -663,10 +663,10 @@ then36: ; preds = %ifcont35 %333 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %332, i8* %333) call void @exit(i32 1) - br label %ifcont38 + br label %ifcont95 -else37: ; preds = %ifcont35 - br label %ifcont38 +else94: ; preds = %ifcont92 + br label %ifcont95 ifcont38: ; preds = %else37, %then36 %334 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 @@ -707,14 +707,89 @@ then39: ; preds = %ifcont38 %359 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %358, i8* %359) call void @exit(i32 1) - br label %ifcont41 + br label %ifcont98 + +else97: ; preds = %ifcont95 + br label %ifcont98 + +ifcont98: ; preds = %else97, %then96 + br i1 false, label %then99, label %else100 + +then99: ; preds = %ifcont98 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @74, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @73, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont101 + +else100: ; preds = %ifcont98 + br label %ifcont101 + +ifcont101: ; preds = %else100, %then99 + %324 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 + br i1 false, label %then102, label %else103 + +then102: ; preds = %ifcont101 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @76, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @75, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont104 + +else103: ; preds = %ifcont101 + br label %ifcont104 + +ifcont104: ; preds = %else103, %then102 + %325 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 + %326 = load %complex_4, %complex_4* %325, align 1 + store %complex_4 %326, %complex_4* %324, align 1 + br i1 false, label %then105, label %else106 + +then105: ; preds = %ifcont104 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont107 + +else106: ; preds = %ifcont104 + br label %ifcont107 + +ifcont107: ; preds = %else106, %then105 + %327 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 + %328 = load %complex_4, %complex_4* %327, align 1 + %329 = alloca %complex_4, align 8 + %330 = getelementptr %complex_4, %complex_4* %329, i32 0, i32 0 + %331 = getelementptr %complex_4, %complex_4* %329, i32 0, i32 1 + store float 1.100000e+01, float* %330, align 4 + store float 0.000000e+00, float* %331, align 4 + %332 = load %complex_4, %complex_4* %329, align 1 + %333 = alloca %complex_4, align 8 + store %complex_4 %328, %complex_4* %333, align 1 + %334 = getelementptr %complex_4, %complex_4* %333, i32 0, i32 0 + %335 = load float, float* %334, align 4 + %336 = alloca %complex_4, align 8 + store %complex_4 %332, %complex_4* %336, align 1 + %337 = getelementptr %complex_4, %complex_4* %336, i32 0, i32 0 + %338 = load float, float* %337, align 4 + %339 = alloca %complex_4, align 8 + store %complex_4 %328, %complex_4* %339, align 1 + %340 = getelementptr %complex_4, %complex_4* %339, i32 0, i32 1 + %341 = load float, float* %340, align 4 + %342 = alloca %complex_4, align 8 + store %complex_4 %332, %complex_4* %342, align 1 + %343 = getelementptr %complex_4, %complex_4* %342, i32 0, i32 1 + %344 = load float, float* %343, align 4 + %345 = fcmp one float %335, %338 + %346 = fcmp one float %341, %344 + %347 = or i1 %345, %346 + br i1 %347, label %then108, label %else109 + +then108: ; preds = %ifcont107 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @79, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @80, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont110 -else40: ; preds = %ifcont38 - br label %ifcont41 +else109: ; preds = %ifcont107 + br label %ifcont110 -ifcont41: ; preds = %else40, %then39 +ifcont110: ; preds = %else109, %then108 store i32 0, i32* %i1, align 4 - br label %loop.head42 + br label %loop.head111 loop.head42: ; preds = %loop.end46, %ifcont41 %360 = load i32, i32* %i1, align 4 @@ -727,7 +802,7 @@ loop.body43: ; preds = %loop.head42 %364 = add i32 %363, 1 store i32 %364, i32* %i1, align 4 store i32 0, i32* %j2, align 4 - br label %loop.head44 + br label %loop.head113 loop.head44: ; preds = %loop.body45, %loop.body43 %365 = load i32, i32* %j2, align 4 @@ -800,10 +875,10 @@ then48: ; preds = %loop.end47 %410 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i8* %409, i8* %410) call void @exit(i32 1) - br label %ifcont50 + br label %ifcont117 -else49: ; preds = %loop.end47 - br label %ifcont50 +else116: ; preds = %loop.body114 + br label %ifcont117 ifcont50: ; preds = %else49, %then48 %411 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 2 @@ -840,10 +915,10 @@ then51: ; preds = %ifcont50 %433 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0), i8* %432, i8* %433) call void @exit(i32 1) - br label %ifcont53 + br label %ifcont131 -else52: ; preds = %ifcont50 - br label %ifcont53 +else130: ; preds = %ifcont128 + br label %ifcont131 ifcont53: ; preds = %else52, %then51 %434 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 1 @@ -880,10 +955,10 @@ then54: ; preds = %ifcont53 %456 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %455, i8* %456) call void @exit(i32 1) - br label %ifcont56 + br label %ifcont140 -else55: ; preds = %ifcont53 - br label %ifcont56 +else139: ; preds = %ifcont137 + br label %ifcont140 ifcont56: ; preds = %else55, %then54 %457 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 3 @@ -920,16 +995,76 @@ then57: ; preds = %ifcont56 %479 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %478, i8* %479) call void @exit(i32 1) - br label %ifcont59 + br label %ifcont149 + +else148: ; preds = %ifcont146 + br label %ifcont149 + +ifcont149: ; preds = %else148, %then147 + br i1 false, label %then150, label %else151 + +then150: ; preds = %ifcont149 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont152 + +else151: ; preds = %ifcont149 + br label %ifcont152 + +ifcont152: ; preds = %else151, %then150 + br i1 false, label %then153, label %else154 + +then153: ; preds = %ifcont152 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @110, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @109, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont155 + +else154: ; preds = %ifcont152 + br label %ifcont155 + +ifcont155: ; preds = %else154, %then153 + %445 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 3 + %446 = load %complex_4, %complex_4* %445, align 1 + %447 = alloca %complex_4, align 8 + %448 = getelementptr %complex_4, %complex_4* %447, i32 0, i32 0 + %449 = getelementptr %complex_4, %complex_4* %447, i32 0, i32 1 + store float 1.400000e+01, float* %448, align 4 + store float 0.000000e+00, float* %449, align 4 + %450 = load %complex_4, %complex_4* %447, align 1 + %451 = alloca %complex_4, align 8 + store %complex_4 %446, %complex_4* %451, align 1 + %452 = getelementptr %complex_4, %complex_4* %451, i32 0, i32 0 + %453 = load float, float* %452, align 4 + %454 = alloca %complex_4, align 8 + store %complex_4 %450, %complex_4* %454, align 1 + %455 = getelementptr %complex_4, %complex_4* %454, i32 0, i32 0 + %456 = load float, float* %455, align 4 + %457 = alloca %complex_4, align 8 + store %complex_4 %446, %complex_4* %457, align 1 + %458 = getelementptr %complex_4, %complex_4* %457, i32 0, i32 1 + %459 = load float, float* %458, align 4 + %460 = alloca %complex_4, align 8 + store %complex_4 %450, %complex_4* %460, align 1 + %461 = getelementptr %complex_4, %complex_4* %460, i32 0, i32 1 + %462 = load float, float* %461, align 4 + %463 = fcmp one float %453, %456 + %464 = fcmp one float %459, %462 + %465 = or i1 %463, %464 + br i1 %465, label %then156, label %else157 + +then156: ; preds = %ifcont155 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @113, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont158 -else58: ; preds = %ifcont56 - br label %ifcont59 +else157: ; preds = %ifcont155 + br label %ifcont158 -ifcont59: ; preds = %else58, %then57 +ifcont158: ; preds = %else157, %then156 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont59 +return: ; preds = %ifcont158 ret i32 0 } diff --git a/tests/reference/llvm-arrays_01_logical-f19a63d.stdout b/tests/reference/llvm-arrays_01_logical-f19a63d.stdout index e1d927d3e71..6480f6fd933 100644 --- a/tests/reference/llvm-arrays_01_logical-f19a63d.stdout +++ b/tests/reference/llvm-arrays_01_logical-f19a63d.stdout @@ -94,12 +94,23 @@ define i32 @main(i32 %0, i8** %1) { %c = alloca [4 x i1], align 1 %i1 = alloca i32, align 4 %j2 = alloca i32, align 4 + br i1 false, label %then, label %else + +then: ; preds = %.entry + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont + +else: ; preds = %.entry + br label %ifcont + +ifcont: ; preds = %else, %then %2 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 store i1 true, i1* %2, align 1 store i32 1, i32* %i1, align 4 br label %loop.head -loop.head: ; preds = %loop.body, %.entry +loop.head: ; preds = %ifcont8, %ifcont %3 = load i32, i32* %i1, align 4 %4 = add i32 %3, 1 %5 = icmp sle i32 %4, 3 @@ -113,17 +124,10 @@ loop.body: ; preds = %loop.head %9 = sub i32 %8, 1 %10 = mul i32 1, %9 %11 = add i32 0, %10 - %12 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %11 - %13 = load i32, i32* %i1, align 4 - %14 = sub i32 %13, 1 - %15 = sub i32 %14, 1 - %16 = mul i32 1, %15 - %17 = add i32 0, %16 - %18 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %17 - %19 = load i1, i1* %18, align 1 - %20 = xor i1 %19, true - store i1 %20, i1* %12, align 1 - br label %loop.head + %12 = icmp sgt i32 %8, 3 + %13 = icmp slt i32 %8, 1 + %14 = or i1 %13, %12 + br i1 %14, label %then3, label %else4 loop.end: ; preds = %loop.head %21 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 @@ -153,7 +157,7 @@ then3: ; preds = %ifcont call void @exit(i32 1) br label %ifcont5 -else4: ; preds = %ifcont +else4: ; preds = %loop.body br label %ifcont5 ifcont5: ; preds = %else4, %then3 @@ -218,7 +222,7 @@ then12: ; preds = %loop.end11 call void @exit(i32 1) br label %ifcont14 -else13: ; preds = %loop.end11 +else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 @@ -269,8 +273,10 @@ else22: ; preds = %ifcont20 br label %ifcont23 ifcont23: ; preds = %else22, %then21 - store i32 0, i32* %i1, align 4 - br label %loop.head24 + %32 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 2 + %33 = load i1, i1* %32, align 1 + %34 = xor i1 %33, true + br i1 %34, label %then24, label %else25 loop.head24: ; preds = %loop.body25, %ifcont23 %74 = load i32, i32* %i1, align 4 @@ -310,7 +316,7 @@ then27: ; preds = %loop.end26 call void @exit(i32 1) br label %ifcont29 -else28: ; preds = %loop.end26 +else28: ; preds = %ifcont26 br label %ifcont29 ifcont29: ; preds = %else28, %then27 @@ -323,10 +329,10 @@ then30: ; preds = %ifcont29 %99 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %98, i8* %99) call void @exit(i32 1) - br label %ifcont32 + br label %ifcont34 -else31: ; preds = %ifcont29 - br label %ifcont32 +else33: ; preds = %loop.body31 + br label %ifcont34 ifcont32: ; preds = %else31, %then30 %100 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 @@ -338,10 +344,10 @@ then33: ; preds = %ifcont32 %103 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %102, i8* %103) call void @exit(i32 1) - br label %ifcont35 + br label %ifcont37 -else34: ; preds = %ifcont32 - br label %ifcont35 +else36: ; preds = %ifcont34 + br label %ifcont37 ifcont35: ; preds = %else34, %then33 %104 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 @@ -392,12 +398,13 @@ then39: ; preds = %ifcont38 call void @exit(i32 1) br label %ifcont41 -else40: ; preds = %ifcont38 +else40: ; preds = %loop.end38 br label %ifcont41 ifcont41: ; preds = %else40, %then39 - store i32 0, i32* %i1, align 4 - br label %loop.head42 + %62 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 + %63 = load i1, i1* %62, align 1 + br i1 %63, label %then42, label %else43 loop.head42: ; preds = %loop.end49, %ifcont41 %132 = load i32, i32* %i1, align 4 @@ -460,11 +467,13 @@ else47: ; preds = %loop.body45 store i1 false, i1* %169, align 1 br label %ifcont48 -ifcont48: ; preds = %else47, %then46 - br label %loop.head44 +then48: ; preds = %ifcont47 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @34, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont50 -loop.end49: ; preds = %loop.head44 - br label %loop.head42 +else49: ; preds = %ifcont47 + br label %ifcont50 loop.end50: ; preds = %loop.head42 %170 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 0 @@ -478,7 +487,7 @@ then51: ; preds = %loop.end50 call void @exit(i32 1) br label %ifcont53 -else52: ; preds = %loop.end50 +else52: ; preds = %ifcont50 br label %ifcont53 ifcont53: ; preds = %else52, %then51 @@ -529,10 +538,556 @@ else61: ; preds = %ifcont59 br label %ifcont62 ifcont62: ; preds = %else61, %then60 + store i32 0, i32* %i1, align 4 + br label %loop.head63 + +loop.head63: ; preds = %ifcont70, %ifcont62 + %72 = load i32, i32* %i1, align 4 + %73 = add i32 %72, 1 + %74 = icmp sle i32 %73, 3 + br i1 %74, label %loop.body64, label %loop.end71 + +loop.body64: ; preds = %loop.head63 + %75 = load i32, i32* %i1, align 4 + %76 = add i32 %75, 1 + store i32 %76, i32* %i1, align 4 + %77 = load i32, i32* %i1, align 4 + %78 = sub i32 %77, 1 + %79 = mul i32 1, %78 + %80 = add i32 0, %79 + %81 = icmp sgt i32 %77, 4 + %82 = icmp slt i32 %77, 1 + %83 = or i1 %82, %81 + br i1 %83, label %then65, label %else66 + +then65: ; preds = %loop.body64 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @48, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @47, i32 0, i32 0), i32 %77, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont67 + +else66: ; preds = %loop.body64 + br label %ifcont67 + +ifcont67: ; preds = %else66, %then65 + %84 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %80 + %85 = load i32, i32* %i1, align 4 + %86 = sub i32 %85, 1 + %87 = mul i32 1, %86 + %88 = add i32 0, %87 + %89 = icmp sgt i32 %85, 3 + %90 = icmp slt i32 %85, 1 + %91 = or i1 %90, %89 + br i1 %91, label %then68, label %else69 + +then68: ; preds = %ifcont67 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @50, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @49, i32 0, i32 0), i32 %85, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont70 + +else69: ; preds = %ifcont67 + br label %ifcont70 + +ifcont70: ; preds = %else69, %then68 + %92 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %88 + %93 = load i1, i1* %92, align 1 + %94 = icmp eq i1 %93, false + %95 = select i1 %94, i1 %93, i1 false + store i1 %95, i1* %84, align 1 + br label %loop.head63 + +loop.end71: ; preds = %loop.head63 + br i1 false, label %then72, label %else73 + +then72: ; preds = %loop.end71 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont74 + +else73: ; preds = %loop.end71 + br label %ifcont74 + +ifcont74: ; preds = %else73, %then72 + %96 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 + %97 = load i1, i1* %96, align 1 + br i1 %97, label %then75, label %else76 + +then75: ; preds = %ifcont74 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @53, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @54, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont77 + +else76: ; preds = %ifcont74 + br label %ifcont77 + +ifcont77: ; preds = %else76, %then75 + br i1 false, label %then78, label %else79 + +then78: ; preds = %ifcont77 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont80 + +else79: ; preds = %ifcont77 + br label %ifcont80 + +ifcont80: ; preds = %else79, %then78 + %98 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 + %99 = load i1, i1* %98, align 1 + br i1 %99, label %then81, label %else82 + +then81: ; preds = %ifcont80 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @60, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @58, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @59, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont83 + +else82: ; preds = %ifcont80 + br label %ifcont83 + +ifcont83: ; preds = %else82, %then81 + br i1 false, label %then84, label %else85 + +then84: ; preds = %ifcont83 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @62, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @61, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont86 + +else85: ; preds = %ifcont83 + br label %ifcont86 + +ifcont86: ; preds = %else85, %then84 + %100 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 + %101 = load i1, i1* %100, align 1 + br i1 %101, label %then87, label %else88 + +then87: ; preds = %ifcont86 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont89 + +else88: ; preds = %ifcont86 + br label %ifcont89 + +ifcont89: ; preds = %else88, %then87 + br i1 false, label %then90, label %else91 + +then90: ; preds = %ifcont89 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont92 + +else91: ; preds = %ifcont89 + br label %ifcont92 + +ifcont92: ; preds = %else91, %then90 + %102 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + br i1 false, label %then93, label %else94 + +then93: ; preds = %ifcont92 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont95 + +else94: ; preds = %ifcont92 + br label %ifcont95 + +ifcont95: ; preds = %else94, %then93 + %103 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 + %104 = load i1, i1* %103, align 1 + br i1 false, label %then96, label %else97 + +then96: ; preds = %ifcont95 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @71, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @70, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont98 + +else97: ; preds = %ifcont95 + br label %ifcont98 + +ifcont98: ; preds = %else97, %then96 + %105 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 + %106 = load i1, i1* %105, align 1 + %107 = icmp eq i1 %104, false + %108 = select i1 %107, i1 %106, i1 %104 + br i1 false, label %then99, label %else100 + +then99: ; preds = %ifcont98 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont101 + +else100: ; preds = %ifcont98 + br label %ifcont101 + +ifcont101: ; preds = %else100, %then99 + %109 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 + %110 = load i1, i1* %109, align 1 + %111 = icmp eq i1 %108, false + %112 = select i1 %111, i1 %110, i1 %108 + br i1 false, label %then102, label %else103 + +then102: ; preds = %ifcont101 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont104 + +else103: ; preds = %ifcont101 + br label %ifcont104 + +ifcont104: ; preds = %else103, %then102 + %113 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 + %114 = load i1, i1* %113, align 1 + %115 = icmp eq i1 %112, false + %116 = select i1 %115, i1 %114, i1 %112 + store i1 %116, i1* %102, align 1 + br i1 false, label %then105, label %else106 + +then105: ; preds = %ifcont104 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @77, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @76, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont107 + +else106: ; preds = %ifcont104 + br label %ifcont107 + +ifcont107: ; preds = %else106, %then105 + %117 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + %118 = load i1, i1* %117, align 1 + %119 = xor i1 %118, true + br i1 %119, label %then108, label %else109 + +then108: ; preds = %ifcont107 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont110 + +else109: ; preds = %ifcont107 + br label %ifcont110 + +ifcont110: ; preds = %else109, %then108 + br i1 false, label %then111, label %else112 + +then111: ; preds = %ifcont110 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @82, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @81, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont113 + +else112: ; preds = %ifcont110 + br label %ifcont113 + +ifcont113: ; preds = %else112, %then111 + %120 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + br i1 false, label %then114, label %else115 + +then114: ; preds = %ifcont113 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @84, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @83, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont116 + +else115: ; preds = %ifcont113 + br label %ifcont116 + +ifcont116: ; preds = %else115, %then114 + %121 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 + %122 = load i1, i1* %121, align 1 + store i1 %122, i1* %120, align 1 + br i1 false, label %then117, label %else118 + +then117: ; preds = %ifcont116 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @86, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @85, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont119 + +else118: ; preds = %ifcont116 + br label %ifcont119 + +ifcont119: ; preds = %else118, %then117 + %123 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + %124 = load i1, i1* %123, align 1 + %125 = xor i1 %124, true + br i1 %125, label %then120, label %else121 + +then120: ; preds = %ifcont119 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @89, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @87, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @88, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont122 + +else121: ; preds = %ifcont119 + br label %ifcont122 + +ifcont122: ; preds = %else121, %then120 + store i32 0, i32* %i1, align 4 + br label %loop.head123 + +loop.head123: ; preds = %loop.end142, %ifcont122 + %126 = load i32, i32* %i1, align 4 + %127 = add i32 %126, 1 + %128 = icmp sle i32 %127, 2 + br i1 %128, label %loop.body124, label %loop.end143 + +loop.body124: ; preds = %loop.head123 + %129 = load i32, i32* %i1, align 4 + %130 = add i32 %129, 1 + store i32 %130, i32* %i1, align 4 + store i32 0, i32* %j2, align 4 + br label %loop.head125 + +loop.head125: ; preds = %ifcont141, %loop.body124 + %131 = load i32, i32* %j2, align 4 + %132 = add i32 %131, 1 + %133 = icmp sle i32 %132, 2 + br i1 %133, label %loop.body126, label %loop.end142 + +loop.body126: ; preds = %loop.head125 + %134 = load i32, i32* %j2, align 4 + %135 = add i32 %134, 1 + store i32 %135, i32* %j2, align 4 + %136 = load i32, i32* %i1, align 4 + %137 = load i32, i32* %j2, align 4 + %138 = add i32 %136, %137 + %139 = load i32, i32* %i1, align 4 + %140 = load i32, i32* %j2, align 4 + %141 = add i32 %139, %140 + %142 = sdiv i32 %141, 2 + %143 = mul i32 2, %142 + %144 = sub i32 %138, %143 + %145 = icmp eq i32 %144, 1 + br i1 %145, label %then127, label %else134 + +then127: ; preds = %loop.body126 + %146 = load i32, i32* %i1, align 4 + %147 = load i32, i32* %j2, align 4 + %148 = sub i32 %146, 1 + %149 = mul i32 1, %148 + %150 = add i32 0, %149 + %151 = icmp sgt i32 %146, 2 + %152 = icmp slt i32 %146, 1 + %153 = or i1 %152, %151 + br i1 %153, label %then128, label %else129 + +then128: ; preds = %then127 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @91, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @90, i32 0, i32 0), i32 %146, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont130 + +else129: ; preds = %then127 + br label %ifcont130 + +ifcont130: ; preds = %else129, %then128 + %154 = sub i32 %147, 1 + %155 = mul i32 2, %154 + %156 = add i32 %150, %155 + %157 = icmp sgt i32 %147, 2 + %158 = icmp slt i32 %147, 1 + %159 = or i1 %158, %157 + br i1 %159, label %then131, label %else132 + +then131: ; preds = %ifcont130 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @93, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @92, i32 0, i32 0), i32 %147, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont133 + +else132: ; preds = %ifcont130 + br label %ifcont133 + +ifcont133: ; preds = %else132, %then131 + %160 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %156 + store i1 true, i1* %160, align 1 + br label %ifcont141 + +else134: ; preds = %loop.body126 + %161 = load i32, i32* %i1, align 4 + %162 = load i32, i32* %j2, align 4 + %163 = sub i32 %161, 1 + %164 = mul i32 1, %163 + %165 = add i32 0, %164 + %166 = icmp sgt i32 %161, 2 + %167 = icmp slt i32 %161, 1 + %168 = or i1 %167, %166 + br i1 %168, label %then135, label %else136 + +then135: ; preds = %else134 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @95, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @94, i32 0, i32 0), i32 %161, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont137 + +else136: ; preds = %else134 + br label %ifcont137 + +ifcont137: ; preds = %else136, %then135 + %169 = sub i32 %162, 1 + %170 = mul i32 2, %169 + %171 = add i32 %165, %170 + %172 = icmp sgt i32 %162, 2 + %173 = icmp slt i32 %162, 1 + %174 = or i1 %173, %172 + br i1 %174, label %then138, label %else139 + +then138: ; preds = %ifcont137 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @97, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @96, i32 0, i32 0), i32 %162, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont140 + +else139: ; preds = %ifcont137 + br label %ifcont140 + +ifcont140: ; preds = %else139, %then138 + %175 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %171 + store i1 false, i1* %175, align 1 + br label %ifcont141 + +ifcont141: ; preds = %ifcont140, %ifcont133 + br label %loop.head125 + +loop.end142: ; preds = %loop.head125 + br label %loop.head123 + +loop.end143: ; preds = %loop.head123 + br i1 false, label %then144, label %else145 + +then144: ; preds = %loop.end143 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @99, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @98, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont146 + +else145: ; preds = %loop.end143 + br label %ifcont146 + +ifcont146: ; preds = %else145, %then144 + br i1 false, label %then147, label %else148 + +then147: ; preds = %ifcont146 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @101, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @100, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont149 + +else148: ; preds = %ifcont146 + br label %ifcont149 + +ifcont149: ; preds = %else148, %then147 + %176 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 0 + %177 = load i1, i1* %176, align 1 + br i1 %177, label %then150, label %else151 + +then150: ; preds = %ifcont149 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @102, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @103, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont152 + +else151: ; preds = %ifcont149 + br label %ifcont152 + +ifcont152: ; preds = %else151, %then150 + br i1 false, label %then153, label %else154 + +then153: ; preds = %ifcont152 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont155 + +else154: ; preds = %ifcont152 + br label %ifcont155 + +ifcont155: ; preds = %else154, %then153 + br i1 false, label %then156, label %else157 + +then156: ; preds = %ifcont155 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont158 + +else157: ; preds = %ifcont155 + br label %ifcont158 + +ifcont158: ; preds = %else157, %then156 + %178 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 2 + %179 = load i1, i1* %178, align 1 + %180 = xor i1 %179, true + br i1 %180, label %then159, label %else160 + +then159: ; preds = %ifcont158 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @109, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @110, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont161 + +else160: ; preds = %ifcont158 + br label %ifcont161 + +ifcont161: ; preds = %else160, %then159 + br i1 false, label %then162, label %else163 + +then162: ; preds = %ifcont161 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @113, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont164 + +else163: ; preds = %ifcont161 + br label %ifcont164 + +ifcont164: ; preds = %else163, %then162 + br i1 false, label %then165, label %else166 + +then165: ; preds = %ifcont164 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @115, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @114, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont167 + +else166: ; preds = %ifcont164 + br label %ifcont167 + +ifcont167: ; preds = %else166, %then165 + %181 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 1 + %182 = load i1, i1* %181, align 1 + %183 = xor i1 %182, true + br i1 %183, label %then168, label %else169 + +then168: ; preds = %ifcont167 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @118, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @116, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @117, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont170 + +else169: ; preds = %ifcont167 + br label %ifcont170 + +ifcont170: ; preds = %else169, %then168 + br i1 false, label %then171, label %else172 + +then171: ; preds = %ifcont170 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @120, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @119, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont173 + +else172: ; preds = %ifcont170 + br label %ifcont173 + +ifcont173: ; preds = %else172, %then171 + br i1 false, label %then174, label %else175 + +then174: ; preds = %ifcont173 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @122, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @121, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont176 + +else175: ; preds = %ifcont173 + br label %ifcont176 + +ifcont176: ; preds = %else175, %then174 + %184 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 3 + %185 = load i1, i1* %184, align 1 + br i1 %185, label %then177, label %else178 + +then177: ; preds = %ifcont176 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @125, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @123, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @124, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont179 + +else178: ; preds = %ifcont176 + br label %ifcont179 + +ifcont179: ; preds = %else178, %then177 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont62 +return: ; preds = %ifcont179 ret i32 0 } diff --git a/tests/reference/llvm-arrays_01_real-6c5e850.stdout b/tests/reference/llvm-arrays_01_real-6c5e850.stdout index 3a1b6789bd6..bbbf3a0d973 100644 --- a/tests/reference/llvm-arrays_01_real-6c5e850.stdout +++ b/tests/reference/llvm-arrays_01_real-6c5e850.stdout @@ -97,7 +97,7 @@ define i32 @main(i32 %0, i8** %1) { store i32 0, i32* %i1, align 4 br label %loop.head -loop.head: ; preds = %loop.body, %.entry +loop.head: ; preds = %ifcont, %.entry %2 = load i32, i32* %i1, align 4 %3 = add i32 %2, 1 %4 = icmp sle i32 %3, 3 @@ -111,12 +111,10 @@ loop.body: ; preds = %loop.head %8 = sub i32 %7, 1 %9 = mul i32 1, %8 %10 = add i32 0, %9 - %11 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 %10 - %12 = load i32, i32* %i1, align 4 - %13 = add i32 %12, 10 - %14 = sitofp i32 %13 to double - store double %14, double* %11, align 8 - br label %loop.head + %11 = icmp sgt i32 %7, 3 + %12 = icmp slt i32 %7, 1 + %13 = or i1 %12, %11 + br i1 %13, label %then, label %else loop.end: ; preds = %loop.head %15 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 @@ -131,7 +129,7 @@ then: ; preds = %loop.end call void @exit(i32 1) br label %ifcont -else: ; preds = %loop.end +else: ; preds = %loop.body br label %ifcont ifcont: ; preds = %else, %then @@ -147,7 +145,7 @@ then3: ; preds = %ifcont call void @exit(i32 1) br label %ifcont5 -else4: ; preds = %ifcont +else4: ; preds = %loop.end br label %ifcont5 ifcont5: ; preds = %else4, %then3 @@ -167,8 +165,7 @@ else7: ; preds = %ifcont5 br label %ifcont8 ifcont8: ; preds = %else7, %then6 - store i32 10, i32* %i1, align 4 - br label %loop.head9 + br i1 false, label %then9, label %else10 loop.head9: ; preds = %loop.body10, %ifcont8 %30 = load i32, i32* %i1, align 4 @@ -204,7 +201,7 @@ then12: ; preds = %loop.end11 call void @exit(i32 1) br label %ifcont14 -else13: ; preds = %loop.end11 +else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 @@ -250,14 +247,17 @@ then21: ; preds = %ifcont20 %62 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %61, i8* %62) call void @exit(i32 1) - br label %ifcont23 + br label %ifcont25 -else22: ; preds = %ifcont20 - br label %ifcont23 +else24: ; preds = %loop.body22 + br label %ifcont25 -ifcont23: ; preds = %else22, %then21 - store i32 0, i32* %i1, align 4 - br label %loop.head24 +ifcont25: ; preds = %else24, %then23 + %40 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 %36 + %41 = load i32, i32* %i1, align 4 + %42 = sitofp i32 %41 to double + store double %42, double* %40, align 8 + br label %loop.head21 loop.head24: ; preds = %loop.body25, %ifcont23 %63 = load i32, i32* %i1, align 4 @@ -382,8 +382,10 @@ else40: ; preds = %ifcont38 br label %ifcont41 ifcont41: ; preds = %else40, %then39 - store i32 0, i32* %i1, align 4 - br label %loop.head42 + %49 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 + %50 = load double, double* %49, align 8 + %51 = fcmp une double %50, 1.300000e+01 + br i1 %51, label %then42, label %else43 loop.head42: ; preds = %loop.end46, %ifcont41 %120 = load i32, i32* %i1, align 4 @@ -425,8 +427,8 @@ loop.body45: ; preds = %loop.head44 store double %143, double* %138, align 8 br label %loop.head44 -loop.end46: ; preds = %loop.head44 - br label %loop.head42 +else46: ; preds = %ifcont44 + br label %ifcont47 loop.end47: ; preds = %loop.head42 %144 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 0 @@ -441,7 +443,7 @@ then48: ; preds = %loop.end47 call void @exit(i32 1) br label %ifcont50 -else49: ; preds = %loop.end47 +else49: ; preds = %ifcont47 br label %ifcont50 ifcont50: ; preds = %else49, %then48 @@ -455,10 +457,10 @@ then51: ; preds = %ifcont50 %153 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0), i8* %152, i8* %153) call void @exit(i32 1) - br label %ifcont53 + br label %ifcont55 -else52: ; preds = %ifcont50 - br label %ifcont53 +else54: ; preds = %loop.body52 + br label %ifcont55 ifcont53: ; preds = %else52, %then51 %154 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 1 @@ -471,10 +473,10 @@ then54: ; preds = %ifcont53 %158 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %157, i8* %158) call void @exit(i32 1) - br label %ifcont56 + br label %ifcont58 -else55: ; preds = %ifcont53 - br label %ifcont56 +else57: ; preds = %ifcont55 + br label %ifcont58 ifcont56: ; preds = %else55, %then54 %159 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 3 @@ -487,16 +489,429 @@ then57: ; preds = %ifcont56 %163 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %162, i8* %163) call void @exit(i32 1) - br label %ifcont59 + br label %ifcont65 + +else64: ; preds = %ifcont62 + br label %ifcont65 + +ifcont65: ; preds = %else64, %then63 + br i1 false, label %then66, label %else67 + +then66: ; preds = %ifcont65 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont68 + +else67: ; preds = %ifcont65 + br label %ifcont68 + +ifcont68: ; preds = %else67, %then66 + %81 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 + %82 = load double, double* %81, align 8 + %83 = fcmp une double %82, 2.000000e+00 + br i1 %83, label %then69, label %else70 + +then69: ; preds = %ifcont68 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @50, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont71 + +else70: ; preds = %ifcont68 + br label %ifcont71 + +ifcont71: ; preds = %else70, %then69 + br i1 false, label %then72, label %else73 + +then72: ; preds = %ifcont71 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont74 + +else73: ; preds = %ifcont71 + br label %ifcont74 + +ifcont74: ; preds = %else73, %then72 + %84 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 + %85 = load double, double* %84, align 8 + %86 = fcmp une double %85, 3.000000e+00 + br i1 %86, label %then75, label %else76 + +then75: ; preds = %ifcont74 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont77 + +else76: ; preds = %ifcont74 + br label %ifcont77 + +ifcont77: ; preds = %else76, %then75 + br i1 false, label %then78, label %else79 + +then78: ; preds = %ifcont77 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont80 + +else79: ; preds = %ifcont77 + br label %ifcont80 + +ifcont80: ; preds = %else79, %then78 + %87 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + br i1 false, label %then81, label %else82 + +then81: ; preds = %ifcont80 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont83 + +else82: ; preds = %ifcont80 + br label %ifcont83 + +ifcont83: ; preds = %else82, %then81 + %88 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 + %89 = load double, double* %88, align 8 + br i1 false, label %then84, label %else85 + +then84: ; preds = %ifcont83 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont86 + +else85: ; preds = %ifcont83 + br label %ifcont86 + +ifcont86: ; preds = %else85, %then84 + %90 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 + %91 = load double, double* %90, align 8 + %92 = fadd double %89, %91 + br i1 false, label %then87, label %else88 + +then87: ; preds = %ifcont86 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont89 + +else88: ; preds = %ifcont86 + br label %ifcont89 + +ifcont89: ; preds = %else88, %then87 + %93 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 + %94 = load double, double* %93, align 8 + %95 = fadd double %92, %94 + br i1 false, label %then90, label %else91 + +then90: ; preds = %ifcont89 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont92 + +else91: ; preds = %ifcont89 + br label %ifcont92 + +ifcont92: ; preds = %else91, %then90 + %96 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 + %97 = load double, double* %96, align 8 + %98 = fadd double %95, %97 + store double %98, double* %87, align 8 + br i1 false, label %then93, label %else94 + +then93: ; preds = %ifcont92 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont95 + +else94: ; preds = %ifcont92 + br label %ifcont95 + +ifcont95: ; preds = %else94, %then93 + %99 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + %100 = load double, double* %99, align 8 + %101 = fcmp une double %100, 1.700000e+01 + br i1 %101, label %then96, label %else97 + +then96: ; preds = %ifcont95 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @72, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @71, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont98 + +else97: ; preds = %ifcont95 + br label %ifcont98 + +ifcont98: ; preds = %else97, %then96 + br i1 false, label %then99, label %else100 + +then99: ; preds = %ifcont98 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @74, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @73, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont101 + +else100: ; preds = %ifcont98 + br label %ifcont101 + +ifcont101: ; preds = %else100, %then99 + %102 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + br i1 false, label %then102, label %else103 + +then102: ; preds = %ifcont101 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @76, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @75, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont104 + +else103: ; preds = %ifcont101 + br label %ifcont104 + +ifcont104: ; preds = %else103, %then102 + %103 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 + %104 = load double, double* %103, align 8 + store double %104, double* %102, align 8 + br i1 false, label %then105, label %else106 + +then105: ; preds = %ifcont104 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont107 + +else106: ; preds = %ifcont104 + br label %ifcont107 + +ifcont107: ; preds = %else106, %then105 + %105 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + %106 = load double, double* %105, align 8 + %107 = fcmp une double %106, 1.100000e+01 + br i1 %107, label %then108, label %else109 + +then108: ; preds = %ifcont107 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @79, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @80, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont110 + +else109: ; preds = %ifcont107 + br label %ifcont110 + +ifcont110: ; preds = %else109, %then108 + store i32 0, i32* %i1, align 4 + br label %loop.head111 + +loop.head111: ; preds = %loop.end121, %ifcont110 + %108 = load i32, i32* %i1, align 4 + %109 = add i32 %108, 1 + %110 = icmp sle i32 %109, 2 + br i1 %110, label %loop.body112, label %loop.end122 + +loop.body112: ; preds = %loop.head111 + %111 = load i32, i32* %i1, align 4 + %112 = add i32 %111, 1 + store i32 %112, i32* %i1, align 4 + store i32 0, i32* %j2, align 4 + br label %loop.head113 + +loop.head113: ; preds = %ifcont120, %loop.body112 + %113 = load i32, i32* %j2, align 4 + %114 = add i32 %113, 1 + %115 = icmp sle i32 %114, 2 + br i1 %115, label %loop.body114, label %loop.end121 + +loop.body114: ; preds = %loop.head113 + %116 = load i32, i32* %j2, align 4 + %117 = add i32 %116, 1 + store i32 %117, i32* %j2, align 4 + %118 = load i32, i32* %i1, align 4 + %119 = load i32, i32* %j2, align 4 + %120 = sub i32 %118, 1 + %121 = mul i32 1, %120 + %122 = add i32 0, %121 + %123 = icmp sgt i32 %118, 2 + %124 = icmp slt i32 %118, 1 + %125 = or i1 %124, %123 + br i1 %125, label %then115, label %else116 + +then115: ; preds = %loop.body114 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @83, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @82, i32 0, i32 0), i32 %118, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont117 + +else116: ; preds = %loop.body114 + br label %ifcont117 + +ifcont117: ; preds = %else116, %then115 + %126 = sub i32 %119, 1 + %127 = mul i32 2, %126 + %128 = add i32 %122, %127 + %129 = icmp sgt i32 %119, 2 + %130 = icmp slt i32 %119, 1 + %131 = or i1 %130, %129 + br i1 %131, label %then118, label %else119 + +then118: ; preds = %ifcont117 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @85, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @84, i32 0, i32 0), i32 %119, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont120 + +else119: ; preds = %ifcont117 + br label %ifcont120 + +ifcont120: ; preds = %else119, %then118 + %132 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 %128 + %133 = load i32, i32* %i1, align 4 + %134 = load i32, i32* %j2, align 4 + %135 = add i32 %133, %134 + %136 = add i32 %135, 10 + %137 = sitofp i32 %136 to double + store double %137, double* %132, align 8 + br label %loop.head113 + +loop.end121: ; preds = %loop.head113 + br label %loop.head111 + +loop.end122: ; preds = %loop.head111 + br i1 false, label %then123, label %else124 + +then123: ; preds = %loop.end122 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @87, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @86, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont125 + +else124: ; preds = %loop.end122 + br label %ifcont125 + +ifcont125: ; preds = %else124, %then123 + br i1 false, label %then126, label %else127 + +then126: ; preds = %ifcont125 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @89, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @88, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont128 + +else127: ; preds = %ifcont125 + br label %ifcont128 + +ifcont128: ; preds = %else127, %then126 + %138 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 0 + %139 = load double, double* %138, align 8 + %140 = fcmp une double %139, 1.200000e+01 + br i1 %140, label %then129, label %else130 + +then129: ; preds = %ifcont128 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @92, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @90, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @91, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont131 + +else130: ; preds = %ifcont128 + br label %ifcont131 + +ifcont131: ; preds = %else130, %then129 + br i1 false, label %then132, label %else133 + +then132: ; preds = %ifcont131 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @94, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @93, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont134 + +else133: ; preds = %ifcont131 + br label %ifcont134 + +ifcont134: ; preds = %else133, %then132 + br i1 false, label %then135, label %else136 + +then135: ; preds = %ifcont134 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @96, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @95, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont137 + +else136: ; preds = %ifcont134 + br label %ifcont137 + +ifcont137: ; preds = %else136, %then135 + %141 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 2 + %142 = load double, double* %141, align 8 + %143 = fcmp une double %142, 1.300000e+01 + br i1 %143, label %then138, label %else139 + +then138: ; preds = %ifcont137 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @99, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @97, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @98, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont140 + +else139: ; preds = %ifcont137 + br label %ifcont140 + +ifcont140: ; preds = %else139, %then138 + br i1 false, label %then141, label %else142 + +then141: ; preds = %ifcont140 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @101, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @100, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont143 + +else142: ; preds = %ifcont140 + br label %ifcont143 + +ifcont143: ; preds = %else142, %then141 + br i1 false, label %then144, label %else145 + +then144: ; preds = %ifcont143 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @103, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @102, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont146 + +else145: ; preds = %ifcont143 + br label %ifcont146 + +ifcont146: ; preds = %else145, %then144 + %144 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 1 + %145 = load double, double* %144, align 8 + %146 = fcmp une double %145, 1.300000e+01 + br i1 %146, label %then147, label %else148 + +then147: ; preds = %ifcont146 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont149 + +else148: ; preds = %ifcont146 + br label %ifcont149 + +ifcont149: ; preds = %else148, %then147 + br i1 false, label %then150, label %else151 + +then150: ; preds = %ifcont149 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont152 + +else151: ; preds = %ifcont149 + br label %ifcont152 + +ifcont152: ; preds = %else151, %then150 + br i1 false, label %then153, label %else154 + +then153: ; preds = %ifcont152 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @110, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @109, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont155 + +else154: ; preds = %ifcont152 + br label %ifcont155 + +ifcont155: ; preds = %else154, %then153 + %147 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 3 + %148 = load double, double* %147, align 8 + %149 = fcmp une double %148, 1.400000e+01 + br i1 %149, label %then156, label %else157 + +then156: ; preds = %ifcont155 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @113, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont158 -else58: ; preds = %ifcont56 - br label %ifcont59 +else157: ; preds = %ifcont155 + br label %ifcont158 -ifcont59: ; preds = %else58, %then57 +ifcont158: ; preds = %else157, %then156 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont59 +return: ; preds = %ifcont158 ret i32 0 } diff --git a/tests/reference/llvm-arrays_01_size-aaed99f.stdout b/tests/reference/llvm-arrays_01_size-aaed99f.stdout index 189f23f42a1..5edf6f84fac 100644 --- a/tests/reference/llvm-arrays_01_size-aaed99f.stdout +++ b/tests/reference/llvm-arrays_01_size-aaed99f.stdout @@ -154,7 +154,7 @@ then7: ; preds = %loop.end call void @exit(i32 1) br label %ifcont9 -else8: ; preds = %loop.end +else8: ; preds = %loop.body br label %ifcont9 ifcont9: ; preds = %else8, %then7 @@ -170,7 +170,7 @@ then10: ; preds = %ifcont9 call void @exit(i32 1) br label %ifcont12 -else11: ; preds = %ifcont9 +else11: ; preds = %loop.end br label %ifcont12 ifcont12: ; preds = %else11, %then10 @@ -190,8 +190,7 @@ else14: ; preds = %ifcont12 br label %ifcont15 ifcont15: ; preds = %else14, %then13 - store i32 10, i32* %i1, align 4 - br label %loop.head16 + br i1 false, label %then16, label %else17 loop.head16: ; preds = %loop.body17, %ifcont15 %38 = load i32, i32* %i1, align 4 @@ -228,7 +227,7 @@ then19: ; preds = %loop.end18 call void @exit(i32 1) br label %ifcont21 -else20: ; preds = %loop.end18 +else20: ; preds = %ifcont18 br label %ifcont21 ifcont21: ; preds = %else20, %then19 @@ -274,14 +273,16 @@ then28: ; preds = %ifcont27 %71 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %70, i8* %71) call void @exit(i32 1) - br label %ifcont30 + br label %ifcont32 -else29: ; preds = %ifcont27 - br label %ifcont30 +else31: ; preds = %loop.body29 + br label %ifcont32 -ifcont30: ; preds = %else29, %then28 - store i32 0, i32* %i1, align 4 - br label %loop.head31 +ifcont32: ; preds = %else31, %then30 + %46 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %42 + %47 = load i32, i32* %i1, align 4 + store i32 %47, i32* %46, align 4 + br label %loop.head28 loop.head31: ; preds = %loop.body32, %ifcont30 %72 = load i32, i32* %i1, align 4 @@ -407,10 +408,326 @@ else47: ; preds = %ifcont45 br label %ifcont48 ifcont48: ; preds = %else47, %then46 + %54 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %55 = load i32, i32* %54, align 4 + %56 = icmp ne i32 %55, 13 + br i1 %56, label %then49, label %else50 + +then49: ; preds = %ifcont48 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @39, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @37, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @38, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont51 + +else50: ; preds = %ifcont48 + br label %ifcont51 + +ifcont51: ; preds = %else50, %then49 + br i1 false, label %then52, label %else53 + +then52: ; preds = %ifcont51 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont54 + +else53: ; preds = %ifcont51 + br label %ifcont54 + +ifcont54: ; preds = %else53, %then52 + %57 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %58 = load i32, i32* %57, align 4 + %59 = icmp ne i32 %58, 14 + br i1 %59, label %then55, label %else56 + +then55: ; preds = %ifcont54 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @44, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @42, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @43, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont57 + +else56: ; preds = %ifcont54 + br label %ifcont57 + +ifcont57: ; preds = %else56, %then55 + store i32 0, i32* %i1, align 4 + br label %loop.head58 + +loop.head58: ; preds = %ifcont65, %ifcont57 + %60 = load i32, i32* %i1, align 4 + %61 = add i32 %60, 1 + %62 = load i32, i32* %size_a2, align 4 + %63 = icmp sle i32 %61, %62 + br i1 %63, label %loop.body59, label %loop.end66 + +loop.body59: ; preds = %loop.head58 + %64 = load i32, i32* %i1, align 4 + %65 = add i32 %64, 1 + store i32 %65, i32* %i1, align 4 + %66 = load i32, i32* %i1, align 4 + %67 = sub i32 %66, 1 + %68 = mul i32 1, %67 + %69 = add i32 0, %68 + %70 = icmp sgt i32 %66, 4 + %71 = icmp slt i32 %66, 1 + %72 = or i1 %71, %70 + br i1 %72, label %then60, label %else61 + +then60: ; preds = %loop.body59 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @46, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @45, i32 0, i32 0), i32 %66, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont62 + +else61: ; preds = %loop.body59 + br label %ifcont62 + +ifcont62: ; preds = %else61, %then60 + %73 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %69 + %74 = load i32, i32* %i1, align 4 + %75 = sub i32 %74, 1 + %76 = mul i32 1, %75 + %77 = add i32 0, %76 + %78 = icmp sgt i32 %74, 3 + %79 = icmp slt i32 %74, 1 + %80 = or i1 %79, %78 + br i1 %80, label %then63, label %else64 + +then63: ; preds = %ifcont62 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @48, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @47, i32 0, i32 0), i32 %74, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont65 + +else64: ; preds = %ifcont62 + br label %ifcont65 + +ifcont65: ; preds = %else64, %then63 + %81 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %77 + %82 = load i32, i32* %81, align 4 + %83 = sub i32 %82, 10 + store i32 %83, i32* %73, align 4 + br label %loop.head58 + +loop.end66: ; preds = %loop.head58 + br i1 false, label %then67, label %else68 + +then67: ; preds = %loop.end66 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @50, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @49, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont69 + +else68: ; preds = %loop.end66 + br label %ifcont69 + +ifcont69: ; preds = %else68, %then67 + %84 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %85 = load i32, i32* %84, align 4 + %86 = icmp ne i32 %85, 1 + br i1 %86, label %then70, label %else71 + +then70: ; preds = %ifcont69 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @53, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @51, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @52, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont72 + +else71: ; preds = %ifcont69 + br label %ifcont72 + +ifcont72: ; preds = %else71, %then70 + br i1 false, label %then73, label %else74 + +then73: ; preds = %ifcont72 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @54, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont75 + +else74: ; preds = %ifcont72 + br label %ifcont75 + +ifcont75: ; preds = %else74, %then73 + %87 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %88 = load i32, i32* %87, align 4 + %89 = icmp ne i32 %88, 2 + br i1 %89, label %then76, label %else77 + +then76: ; preds = %ifcont75 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @58, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @57, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont78 + +else77: ; preds = %ifcont75 + br label %ifcont78 + +ifcont78: ; preds = %else77, %then76 + br i1 false, label %then79, label %else80 + +then79: ; preds = %ifcont78 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @60, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @59, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont81 + +else80: ; preds = %ifcont78 + br label %ifcont81 + +ifcont81: ; preds = %else80, %then79 + %90 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %91 = load i32, i32* %90, align 4 + %92 = icmp ne i32 %91, 3 + br i1 %92, label %then82, label %else83 + +then82: ; preds = %ifcont81 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont84 + +else83: ; preds = %ifcont81 + br label %ifcont84 + +ifcont84: ; preds = %else83, %then82 + br i1 false, label %then85, label %else86 + +then85: ; preds = %ifcont84 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont87 + +else86: ; preds = %ifcont84 + br label %ifcont87 + +ifcont87: ; preds = %else86, %then85 + %93 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + br i1 false, label %then88, label %else89 + +then88: ; preds = %ifcont87 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont90 + +else89: ; preds = %ifcont87 + br label %ifcont90 + +ifcont90: ; preds = %else89, %then88 + %94 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %95 = load i32, i32* %94, align 4 + br i1 false, label %then91, label %else92 + +then91: ; preds = %ifcont90 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont93 + +else92: ; preds = %ifcont90 + br label %ifcont93 + +ifcont93: ; preds = %else92, %then91 + %96 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %97 = load i32, i32* %96, align 4 + %98 = add i32 %95, %97 + br i1 false, label %then94, label %else95 + +then94: ; preds = %ifcont93 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @71, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @70, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont96 + +else95: ; preds = %ifcont93 + br label %ifcont96 + +ifcont96: ; preds = %else95, %then94 + %99 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %100 = load i32, i32* %99, align 4 + %101 = add i32 %98, %100 + br i1 false, label %then97, label %else98 + +then97: ; preds = %ifcont96 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont99 + +else98: ; preds = %ifcont96 + br label %ifcont99 + +ifcont99: ; preds = %else98, %then97 + %102 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %103 = load i32, i32* %102, align 4 + %104 = add i32 %101, %103 + store i32 %104, i32* %93, align 4 + br i1 false, label %then100, label %else101 + +then100: ; preds = %ifcont99 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont102 + +else101: ; preds = %ifcont99 + br label %ifcont102 + +ifcont102: ; preds = %else101, %then100 + %105 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %106 = load i32, i32* %105, align 4 + %107 = icmp ne i32 %106, 17 + br i1 %107, label %then103, label %else104 + +then103: ; preds = %ifcont102 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @76, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont105 + +else104: ; preds = %ifcont102 + br label %ifcont105 + +ifcont105: ; preds = %else104, %then103 + br i1 false, label %then106, label %else107 + +then106: ; preds = %ifcont105 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont108 + +else107: ; preds = %ifcont105 + br label %ifcont108 + +ifcont108: ; preds = %else107, %then106 + %108 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + br i1 false, label %then109, label %else110 + +then109: ; preds = %ifcont108 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @82, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @81, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont111 + +else110: ; preds = %ifcont108 + br label %ifcont111 + +ifcont111: ; preds = %else110, %then109 + %109 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %110 = load i32, i32* %109, align 4 + store i32 %110, i32* %108, align 4 + br i1 false, label %then112, label %else113 + +then112: ; preds = %ifcont111 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @84, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @83, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont114 + +else113: ; preds = %ifcont111 + br label %ifcont114 + +ifcont114: ; preds = %else113, %then112 + %111 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %112 = load i32, i32* %111, align 4 + %113 = icmp ne i32 %112, 11 + br i1 %113, label %then115, label %else116 + +then115: ; preds = %ifcont114 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @87, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @85, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @86, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont117 + +else116: ; preds = %ifcont114 + br label %ifcont117 + +ifcont117: ; preds = %else116, %then115 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont48 +return: ; preds = %ifcont117 ret i32 0 } diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout index 81e2559c41e..5db928f6975 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout @@ -33,6 +33,12 @@ source_filename = "LFortran" @string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.17, i32 0, i32 0), i64 1 }> @6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 @main.b = internal global [3 x i32] zeroinitializer +@25 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@26 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@27 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@28 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@29 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@30 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -44,27 +50,69 @@ define i32 @main(i32 %0, i8** %1) { %3 = sub i32 %2, 1 %4 = mul i32 1, %3 %5 = add i32 0, %4 - %6 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %5 - store i32 10, i32* %6, align 4 + %6 = icmp sgt i32 %2, 3 + %7 = icmp slt i32 %2, 1 + %8 = or i1 %7, %6 + br i1 %8, label %then, label %else + +then: ; preds = %.entry + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @26, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @25, i32 0, i32 0), i32 %2, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont + +else: ; preds = %.entry + br label %ifcont + +ifcont: ; preds = %else, %then + %9 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %5 + store i32 10, i32* %9, align 4 store i32 2, i32* %__1_k1, align 4 - %7 = load i32, i32* %__1_k1, align 4 - %8 = sub i32 %7, 1 - %9 = mul i32 1, %8 - %10 = add i32 0, %9 - %11 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %10 - store i32 20, i32* %11, align 4 + %10 = load i32, i32* %__1_k1, align 4 + %11 = sub i32 %10, 1 + %12 = mul i32 1, %11 + %13 = add i32 0, %12 + %14 = icmp sgt i32 %10, 3 + %15 = icmp slt i32 %10, 1 + %16 = or i1 %15, %14 + br i1 %16, label %then2, label %else3 + +then2: ; preds = %ifcont + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %10, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont4 + +else3: ; preds = %ifcont + br label %ifcont4 + +ifcont4: ; preds = %else3, %then2 + %17 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %13 + store i32 20, i32* %17, align 4 store i32 3, i32* %__1_k1, align 4 - %12 = load i32, i32* %__1_k1, align 4 - %13 = sub i32 %12, 1 - %14 = mul i32 1, %13 - %15 = add i32 0, %14 - %16 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %15 - store i32 30, i32* %16, align 4 + %18 = load i32, i32* %__1_k1, align 4 + %19 = sub i32 %18, 1 + %20 = mul i32 1, %19 + %21 = add i32 0, %20 + %22 = icmp sgt i32 %18, 3 + %23 = icmp slt i32 %18, 1 + %24 = or i1 %23, %22 + br i1 %24, label %then5, label %else6 + +then5: ; preds = %ifcont4 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 %18, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont7 + +else6: ; preds = %ifcont4 + br label %ifcont7 + +ifcont7: ; preds = %else6, %then5 + %25 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %21 + store i32 30, i32* %25, align 4 call void @driver(void (i32*, i32*, i32*)* @implicit_interface_check, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @main.b, i32 0, i32 0), i32* @main.n) call void @_lpython_free_argv() br label %return -return: ; preds = %.entry +return: ; preds = %ifcont7 ret i32 0 } @@ -89,7 +137,7 @@ define void @driver(void (i32*, i32*, i32*)* %fnc, i32* %arr, i32* %m) { call void %fnc(i32* %arr, i32* %m, i32* %10) br label %return -return: ; preds = %.entry +return: ; preds = %ifcont ret void } @@ -181,9 +229,55 @@ else11: ; preds = %ifcont9 br label %ifcont12 ifcont12: ; preds = %else11, %then10 + %18 = mul i32 1, %13 + %19 = getelementptr inbounds i32, i32* %arr1, i32 1 + %20 = load i32, i32* %19, align 4 + %21 = icmp ne i32 %20, 20 + br i1 %21, label %then13, label %else14 + +then13: ; preds = %ifcont12 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @19, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @18, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont15 + +else14: ; preds = %ifcont12 + br label %ifcont15 + +ifcont15: ; preds = %else14, %then13 + %22 = load i32, i32* %m, align 4 + %23 = add i32 1, %22 + %24 = sub i32 %23, 1 + %25 = icmp sgt i32 3, %24 + %26 = or i1 false, %25 + br i1 %26, label %then16, label %else17 + +then16: ; preds = %ifcont15 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @21, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @20, i32 0, i32 0), i32 3, i32 1, i32 1, i32 %24) + call void @exit(i32 1) + br label %ifcont18 + +else17: ; preds = %ifcont15 + br label %ifcont18 + +ifcont18: ; preds = %else17, %then16 + %27 = mul i32 1, %22 + %28 = getelementptr inbounds i32, i32* %arr1, i32 2 + %29 = load i32, i32* %28, align 4 + %30 = icmp ne i32 %29, 30 + br i1 %30, label %then19, label %else20 + +then19: ; preds = %ifcont18 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @24, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @22, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @23, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont21 + +else20: ; preds = %ifcont18 + br label %ifcont21 + +ifcont21: ; preds = %else20, %then19 br label %return -return: ; preds = %ifcont12 +return: ; preds = %ifcont21 ret void } diff --git a/tests/reference/llvm-modules_36-53c9a79.stdout b/tests/reference/llvm-modules_36-53c9a79.stdout index b05418ba3e6..4871b159f95 100644 --- a/tests/reference/llvm-modules_36-53c9a79.stdout +++ b/tests/reference/llvm-modules_36-53c9a79.stdout @@ -18,7 +18,7 @@ define i1 @_lcompilers_Any_4_1_0_logical____0(i1* %mask, i32* %__1mask) { store i32 0, i32* %__1_i, align 4 br label %loop.head -loop.head: ; preds = %loop.body, %.entry +loop.head: ; preds = %ifcont, %.entry %0 = load i32, i32* %__1_i, align 4 %1 = add i32 %0, 1 %2 = load i32, i32* %__1mask, align 4 @@ -37,20 +37,36 @@ loop.body: ; preds = %loop.head %11 = sub i32 %9, 1 %12 = mul i32 1, %11 %13 = add i32 0, %12 - %14 = mul i32 1, %10 - %15 = getelementptr inbounds i1, i1* %mask, i32 %13 - %16 = load i1, i1* %15, align 1 - %17 = icmp eq i1 %8, false - %18 = select i1 %17, i1 %16, i1 %8 - store i1 %18, i1* %_lcompilers_Any_4_1_0, align 1 + %14 = add i32 1, %10 + %15 = sub i32 %14, 1 + %16 = icmp sgt i32 %9, %15 + %17 = icmp slt i32 %9, 1 + %18 = or i1 %17, %16 + br i1 %18, label %then, label %else + +then: ; preds = %loop.body + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i32 %9, i32 1, i32 1, i32 %15) + call void @exit(i32 1) + br label %ifcont + +else: ; preds = %loop.body + br label %ifcont + +ifcont: ; preds = %else, %then + %19 = mul i32 1, %10 + %20 = getelementptr inbounds i1, i1* %mask, i32 %13 + %21 = load i1, i1* %20, align 1 + %22 = icmp eq i1 %8, false + %23 = select i1 %22, i1 %21, i1 %8 + store i1 %23, i1* %_lcompilers_Any_4_1_0, align 1 br label %loop.head loop.end: ; preds = %loop.head br label %return return: ; preds = %loop.end - %19 = load i1, i1* %_lcompilers_Any_4_1_0, align 1 - ret i1 %19 + %24 = load i1, i1* %_lcompilers_Any_4_1_0, align 1 + ret i1 %24 } define void @__module_modules_36_fpm_main_01_cmd_run(%fpm_run_settings_polymorphic* %settings, i1* %test) { @@ -95,7 +111,7 @@ ifcont4: ; preds = %else3, %then2 store i32 %4, i32* %__libasr_index_0_, align 4 br label %loop.head -loop.head: ; preds = %loop.body, %ifcont4 +loop.head: ; preds = %ifcont14, %ifcont4 %5 = load i32, i32* %__libasr_index_0_, align 4 %6 = add i32 %5, 1 br i1 true, label %then6, label %else7 @@ -120,19 +136,10 @@ loop.body: ; preds = %ifcont8 %12 = sub i32 %11, 1 %13 = mul i32 1, %12 %14 = add i32 0, %13 - %15 = getelementptr [2 x i1], [2 x i1]* %__libasr_created__intrinsic_array_function_Any, i32 0, i32 %14 - %16 = load i32, i32* %__libasr_index_0_1, align 4 - %17 = sub i32 %16, 1 - %18 = mul i32 1, %17 - %19 = add i32 0, %18 - %20 = getelementptr [2 x i1], [2 x i1]* %found, i32 0, i32 %19 - %21 = load i1, i1* %20, align 1 - %22 = xor i1 %21, true - store i1 %22, i1* %15, align 1 - %23 = load i32, i32* %__libasr_index_0_1, align 4 - %24 = add i32 %23, 1 - store i32 %24, i32* %__libasr_index_0_1, align 4 - br label %loop.head + %15 = icmp sgt i32 %11, 2 + %16 = icmp slt i32 %11, 1 + %17 = or i1 %16, %15 + br i1 %17, label %then9, label %else10 loop.end: ; preds = %ifcont8 %25 = getelementptr [2 x i1], [2 x i1]* %__libasr_created__intrinsic_array_function_Any, i32 0, i32 0 @@ -173,13 +180,85 @@ loop.end: ; preds = %ifcont8 then9: ; preds = %loop.end br label %ifcont11 -else10: ; preds = %loop.end +else10: ; preds = %loop.body br label %ifcont11 ifcont11: ; preds = %else10, %then9 + %18 = getelementptr [2 x i1], [2 x i1]* %__libasr_created__intrinsic_array_function_Any, i32 0, i32 %14 + %19 = load i32, i32* %__libasr_index_0_1, align 4 + %20 = sub i32 %19, 1 + %21 = mul i32 1, %20 + %22 = add i32 0, %21 + %23 = icmp sgt i32 %19, 2 + %24 = icmp slt i32 %19, 1 + %25 = or i1 %24, %23 + br i1 %25, label %then12, label %else13 + +then12: ; preds = %ifcont11 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @2, i32 0, i32 0), i32 %19, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont14 + +else13: ; preds = %ifcont11 + br label %ifcont14 + +ifcont14: ; preds = %else13, %then12 + %26 = getelementptr [2 x i1], [2 x i1]* %found, i32 0, i32 %22 + %27 = load i1, i1* %26, align 1 + %28 = xor i1 %27, true + store i1 %28, i1* %18, align 1 + %29 = load i32, i32* %__libasr_index_0_1, align 4 + %30 = add i32 %29, 1 + store i32 %30, i32* %__libasr_index_0_1, align 4 + br label %loop.head + +loop.end: ; preds = %ifcont8 + %31 = getelementptr [2 x i1], [2 x i1]* %__libasr_created__intrinsic_array_function_Any, i32 0, i32 0 + store i32 2, i32* %call_arg_value, align 4 + %32 = call i1 @_lcompilers_Any_4_1_0_logical____0(i1* %31, i32* %call_arg_value) + store i1 %32, i1* %__libasr_created__intrinsic_array_function_Any1, align 1 + %33 = load i1, i1* %__libasr_created__intrinsic_array_function_Any1, align 1 + %34 = load i1, i1* %toomany, align 1 + %35 = load i1, i1* %test, align 1 + %36 = xor i1 %35, true + %37 = icmp eq i1 %34, false + %38 = select i1 %37, i1 %34, i1 %36 + %39 = load i1, i1* %toomany, align 1 + %40 = getelementptr %fpm_run_settings_polymorphic, %fpm_run_settings_polymorphic* %settings, i32 0, i32 1 + %41 = load %fpm_run_settings*, %fpm_run_settings** %40, align 8 + %42 = getelementptr %fpm_run_settings, %fpm_run_settings* %41, i32 0, i32 3 + %43 = load i8*, i8** %42, align 8 + %44 = alloca i8*, align 8 + store i8* %43, i8** %44, align 8 + %45 = alloca i8*, align 8 + store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @4, i32 0, i32 0), i8** %45, align 8 + %46 = call i1 @_lpython_str_compare_noteq(i8** %44, i8** %45) + %47 = icmp eq i1 %39, false + %48 = select i1 %47, i1 %39, i1 %46 + %49 = icmp eq i1 %38, false + %50 = select i1 %49, i1 %48, i1 %38 + %51 = getelementptr %fpm_run_settings_polymorphic, %fpm_run_settings_polymorphic* %settings, i32 0, i32 1 + %52 = load %fpm_run_settings*, %fpm_run_settings** %51, align 8 + %53 = getelementptr %fpm_run_settings, %fpm_run_settings* %52, i32 0, i32 0 + %54 = getelementptr %fpm_build_settings, %fpm_build_settings* %53, i32 0, i32 0 + %55 = load i1, i1* %54, align 1 + %56 = xor i1 %55, true + %57 = icmp eq i1 %50, false + %58 = select i1 %57, i1 %50, i1 %56 + %59 = icmp eq i1 %33, false + %60 = select i1 %59, i1 %58, i1 %33 + br i1 %60, label %then15, label %else16 + +then15: ; preds = %loop.end + br label %ifcont17 + +else16: ; preds = %loop.end + br label %ifcont17 + +ifcont17: ; preds = %else16, %then15 br label %return -return: ; preds = %ifcont11 +return: ; preds = %ifcont17 ret void } From 86360f102ab9cbd67ce416f45edf2f21704d98a1 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Wed, 9 Jul 2025 17:12:03 +0000 Subject: [PATCH 077/119] tests: update references --- .../run-array_bounds_check_01-713dbcf.json | 13 +++++++++++++ .../run-array_bounds_check_01-713dbcf.stderr | 3 +++ .../run-array_bounds_check_02-3ebca53.json | 13 +++++++++++++ .../run-array_bounds_check_02-3ebca53.stderr | 3 +++ .../run-array_bounds_check_03-15fcd63.json | 13 +++++++++++++ .../run-array_bounds_check_03-15fcd63.stderr | 1 + tests/tests.toml | 3 +++ 7 files changed, 49 insertions(+) create mode 100644 tests/reference/run-array_bounds_check_01-713dbcf.json create mode 100644 tests/reference/run-array_bounds_check_01-713dbcf.stderr create mode 100644 tests/reference/run-array_bounds_check_02-3ebca53.json create mode 100644 tests/reference/run-array_bounds_check_02-3ebca53.stderr create mode 100644 tests/reference/run-array_bounds_check_03-15fcd63.json create mode 100644 tests/reference/run-array_bounds_check_03-15fcd63.stderr diff --git a/tests/reference/run-array_bounds_check_01-713dbcf.json b/tests/reference/run-array_bounds_check_01-713dbcf.json new file mode 100644 index 00000000000..1ffac9b4351 --- /dev/null +++ b/tests/reference/run-array_bounds_check_01-713dbcf.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_01-713dbcf", + "cmd": "lfortran --no-color {infile}", + "infile": "tests/errors/array_bounds_check_01.f90", + "infile_hash": "e8570ec720776191802ff5d4d5cd6944a6b2e8730e5bf1bd8458dd83", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_01-713dbcf.stderr", + "stderr_hash": "161fd647a5f1eb6fa952ec46b4ce934c8e4f4e63f4887923754cbe71", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_01-713dbcf.stderr b/tests/reference/run-array_bounds_check_01-713dbcf.stderr new file mode 100644 index 00000000000..893a718bf5e --- /dev/null +++ b/tests/reference/run-array_bounds_check_01-713dbcf.stderr @@ -0,0 +1,3 @@ +Runtime error: Array '__libasr__created__var__0__array_constant_' index out of bounds. + +Tried to access index 4 of dimension 1, but valid range is 1 to 3. diff --git a/tests/reference/run-array_bounds_check_02-3ebca53.json b/tests/reference/run-array_bounds_check_02-3ebca53.json new file mode 100644 index 00000000000..95d442ddd67 --- /dev/null +++ b/tests/reference/run-array_bounds_check_02-3ebca53.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_02-3ebca53", + "cmd": "lfortran --no-color {infile}", + "infile": "tests/errors/array_bounds_check_02.f90", + "infile_hash": "eaa31b185f0a51c3937f0238d112eb0fc90b3e410e59da7fe194c389", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_02-3ebca53.stderr", + "stderr_hash": "161fd647a5f1eb6fa952ec46b4ce934c8e4f4e63f4887923754cbe71", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_02-3ebca53.stderr b/tests/reference/run-array_bounds_check_02-3ebca53.stderr new file mode 100644 index 00000000000..893a718bf5e --- /dev/null +++ b/tests/reference/run-array_bounds_check_02-3ebca53.stderr @@ -0,0 +1,3 @@ +Runtime error: Array '__libasr__created__var__0__array_constant_' index out of bounds. + +Tried to access index 4 of dimension 1, but valid range is 1 to 3. diff --git a/tests/reference/run-array_bounds_check_03-15fcd63.json b/tests/reference/run-array_bounds_check_03-15fcd63.json new file mode 100644 index 00000000000..6b686fb8161 --- /dev/null +++ b/tests/reference/run-array_bounds_check_03-15fcd63.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_03-15fcd63", + "cmd": "lfortran --no-color {infile}", + "infile": "tests/errors/array_bounds_check_03.f90", + "infile_hash": "6799dc4bd57bea91b97537abefdd229857c3736e06be6a50c08655b5", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_03-15fcd63.stderr", + "stderr_hash": "b102aecb81a33633a9517ac81d3855b83948b65c027104b30fcf575b", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_03-15fcd63.stderr b/tests/reference/run-array_bounds_check_03-15fcd63.stderr new file mode 100644 index 00000000000..f0da5414041 --- /dev/null +++ b/tests/reference/run-array_bounds_check_03-15fcd63.stderr @@ -0,0 +1 @@ +Runtime Error: Array 'x' is not allocated. diff --git a/tests/tests.toml b/tests/tests.toml index 0bba0fd3894..e41155e1ae1 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -3858,14 +3858,17 @@ asr = true [[test]] filename = "errors/array_bounds_check_01.f90" +run = true array_bounds_check = true [[test]] filename = "errors/array_bounds_check_02.f90" +run = true array_bounds_check = true [[test]] filename = "errors/array_bounds_check_03.f90" +run = true array_bounds_check = true [[test]] From 7231622f19551d784caf9d352381c47626acb390 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 10 Jul 2025 15:01:10 +0000 Subject: [PATCH 078/119] refactor: order comparisons explicitly to fix macos fail --- src/libasr/codegen/llvm_array_utils.cpp | 13 ++++-- .../reference/llvm-allocate_03-495d621.stdout | 42 +++++++++---------- tests/reference/llvm-arrays_01-91893af.stdout | 18 ++++---- .../llvm-arrays_01_complex-c90dbdd.stdout | 6 +-- .../llvm-arrays_01_logical-f19a63d.stdout | 42 +++++++++---------- .../llvm-arrays_01_real-6c5e850.stdout | 18 ++++---- .../llvm-arrays_01_size-aaed99f.stdout | 12 +++--- .../llvm-implicit_interface_04-9b6786e.stdout | 18 ++++---- .../reference/llvm-modules_36-53c9a79.stdout | 18 ++++---- 9 files changed, 96 insertions(+), 91 deletions(-) diff --git a/src/libasr/codegen/llvm_array_utils.cpp b/src/libasr/codegen/llvm_array_utils.cpp index 1b1915aa0c6..0a1e5f0a819 100644 --- a/src/libasr/codegen/llvm_array_utils.cpp +++ b/src/libasr/codegen/llvm_array_utils.cpp @@ -725,9 +725,12 @@ namespace LCompilers { llvm::Value* dimension = llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), llvm::APInt(32, r + 1)); llvm::Value* ubound = builder->CreateSub(builder->CreateAdd(lval, length), llvm::ConstantInt::get(i32, llvm::APInt(32, 1))); + llvm::Value* lbound_check = builder->CreateICmpSLT(req_idx, lval); + llvm::Value* ubound_check = builder->CreateICmpSGT(req_idx, ubound); + llvm_utils->generate_runtime_error(builder->CreateOr( - builder->CreateICmpSLT(req_idx, lval), - builder->CreateICmpSGT(req_idx, ubound)), + lbound_check, + ubound_check), "Runtime error: Array '%s' index out of bounds.\n\n" "Tried to access index %d of dimension %d, but valid range is %d to %d.\n", builder->CreateGlobalStringPtr(array_name), @@ -768,9 +771,11 @@ namespace LCompilers { llvm::Value* dimension = llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), llvm::APInt(32, r + 1)); llvm::Value* ubound = builder->CreateSub(builder->CreateAdd(lval, dim_size), llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), llvm::APInt(32, 1))); + llvm::Value* lbound_check = builder->CreateICmpSLT(req_idx, lval); + llvm::Value* ubound_check = builder->CreateICmpSGT(req_idx, ubound); llvm_utils->generate_runtime_error(builder->CreateOr( - builder->CreateICmpSLT(req_idx, lval), - builder->CreateICmpSGT(req_idx, ubound)), + lbound_check, + ubound_check), "Runtime error: Array '%s' index out of bounds.\n\n" "Tried to access index %d of dimension %d, but valid range is %d to %d.\n", builder->CreateGlobalStringPtr(array_name), diff --git a/tests/reference/llvm-allocate_03-495d621.stdout b/tests/reference/llvm-allocate_03-495d621.stdout index 577a846096a..57135937307 100644 --- a/tests/reference/llvm-allocate_03-495d621.stdout +++ b/tests/reference/llvm-allocate_03-495d621.stdout @@ -332,9 +332,9 @@ ifcont14: ; preds = %else13, %then12 %83 = sub i32 1, %80 %84 = add i32 %80, %82 %85 = sub i32 %84, 1 - %86 = icmp sgt i32 1, %85 - %87 = icmp slt i32 1, %80 - %88 = or i1 %87, %86 + %86 = icmp slt i32 1, %80 + %87 = icmp sgt i32 1, %85 + %88 = or i1 %86, %87 br i1 %88, label %then15, label %else16 then15: ; preds = %ifcont14 @@ -410,9 +410,9 @@ ifcont23: ; preds = %else22, %then21 %124 = sub i32 1, %121 %125 = add i32 %121, %123 %126 = sub i32 %125, 1 - %127 = icmp sgt i32 1, %126 - %128 = icmp slt i32 1, %121 - %129 = or i1 %128, %127 + %127 = icmp slt i32 1, %121 + %128 = icmp sgt i32 1, %126 + %129 = or i1 %127, %128 br i1 %129, label %then24, label %else25 then24: ; preds = %ifcont23 @@ -436,9 +436,9 @@ ifcont26: ; preds = %else25, %then24 %139 = sub i32 1, %136 %140 = add i32 %136, %138 %141 = sub i32 %140, 1 - %142 = icmp sgt i32 1, %141 - %143 = icmp slt i32 1, %136 - %144 = or i1 %143, %142 + %142 = icmp slt i32 1, %136 + %143 = icmp sgt i32 1, %141 + %144 = or i1 %142, %143 br i1 %144, label %then27, label %else28 then27: ; preds = %ifcont26 @@ -462,9 +462,9 @@ ifcont29: ; preds = %else28, %then27 %154 = sub i32 1, %151 %155 = add i32 %151, %153 %156 = sub i32 %155, 1 - %157 = icmp sgt i32 1, %156 - %158 = icmp slt i32 1, %151 - %159 = or i1 %158, %157 + %157 = icmp slt i32 1, %151 + %158 = icmp sgt i32 1, %156 + %159 = or i1 %157, %158 br i1 %159, label %then30, label %else31 then30: ; preds = %ifcont29 @@ -526,9 +526,9 @@ ifcont38: ; preds = %else37, %then36 %185 = sub i32 1, %182 %186 = add i32 %182, %184 %187 = sub i32 %186, 1 - %188 = icmp sgt i32 1, %187 - %189 = icmp slt i32 1, %182 - %190 = or i1 %189, %188 + %188 = icmp slt i32 1, %182 + %189 = icmp sgt i32 1, %187 + %190 = or i1 %188, %189 br i1 %190, label %then39, label %else40 then39: ; preds = %ifcont38 @@ -552,9 +552,9 @@ ifcont41: ; preds = %else40, %then39 %200 = sub i32 1, %197 %201 = add i32 %197, %199 %202 = sub i32 %201, 1 - %203 = icmp sgt i32 1, %202 - %204 = icmp slt i32 1, %197 - %205 = or i1 %204, %203 + %203 = icmp slt i32 1, %197 + %204 = icmp sgt i32 1, %202 + %205 = or i1 %203, %204 br i1 %205, label %then42, label %else43 then42: ; preds = %ifcont41 @@ -578,9 +578,9 @@ ifcont44: ; preds = %else43, %then42 %215 = sub i32 1, %212 %216 = add i32 %212, %214 %217 = sub i32 %216, 1 - %218 = icmp sgt i32 1, %217 - %219 = icmp slt i32 1, %212 - %220 = or i1 %219, %218 + %218 = icmp slt i32 1, %212 + %219 = icmp sgt i32 1, %217 + %220 = or i1 %218, %219 br i1 %220, label %then45, label %else46 then45: ; preds = %ifcont44 diff --git a/tests/reference/llvm-arrays_01-91893af.stdout b/tests/reference/llvm-arrays_01-91893af.stdout index f981d589e95..bd931560f8e 100644 --- a/tests/reference/llvm-arrays_01-91893af.stdout +++ b/tests/reference/llvm-arrays_01-91893af.stdout @@ -88,9 +88,9 @@ loop.body: ; preds = %loop.head %8 = sub i32 %7, 1 %9 = mul i32 1, %8 %10 = add i32 0, %9 - %11 = icmp sgt i32 %7, 3 - %12 = icmp slt i32 %7, 1 - %13 = or i1 %12, %11 + %11 = icmp slt i32 %7, 1 + %12 = icmp sgt i32 %7, 3 + %13 = or i1 %11, %12 br i1 %13, label %then, label %else loop.end: ; preds = %loop.head @@ -413,9 +413,9 @@ loop.body51: ; preds = %loop.head50 %59 = sub i32 %58, 1 %60 = mul i32 1, %59 %61 = add i32 0, %60 - %62 = icmp sgt i32 %58, 4 - %63 = icmp slt i32 %58, 1 - %64 = or i1 %63, %62 + %62 = icmp slt i32 %58, 1 + %63 = icmp sgt i32 %58, 4 + %64 = or i1 %62, %63 br i1 %64, label %then52, label %else53 then52: ; preds = %loop.body51 @@ -432,9 +432,9 @@ ifcont54: ; preds = %else53, %then52 %67 = sub i32 %66, 1 %68 = mul i32 1, %67 %69 = add i32 0, %68 - %70 = icmp sgt i32 %66, 3 - %71 = icmp slt i32 %66, 1 - %72 = or i1 %71, %70 + %70 = icmp slt i32 %66, 1 + %71 = icmp sgt i32 %66, 3 + %72 = or i1 %70, %71 br i1 %72, label %then55, label %else56 then55: ; preds = %ifcont54 diff --git a/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout b/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout index ff8d043f101..0b820a9a816 100644 --- a/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout +++ b/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout @@ -112,9 +112,9 @@ loop.body: ; preds = %loop.head %8 = sub i32 %7, 1 %9 = mul i32 1, %8 %10 = add i32 0, %9 - %11 = icmp sgt i32 %7, 3 - %12 = icmp slt i32 %7, 1 - %13 = or i1 %12, %11 + %11 = icmp slt i32 %7, 1 + %12 = icmp sgt i32 %7, 3 + %13 = or i1 %11, %12 br i1 %13, label %then, label %else loop.end: ; preds = %loop.head diff --git a/tests/reference/llvm-arrays_01_logical-f19a63d.stdout b/tests/reference/llvm-arrays_01_logical-f19a63d.stdout index 6480f6fd933..6f8e5b49778 100644 --- a/tests/reference/llvm-arrays_01_logical-f19a63d.stdout +++ b/tests/reference/llvm-arrays_01_logical-f19a63d.stdout @@ -124,9 +124,9 @@ loop.body: ; preds = %loop.head %9 = sub i32 %8, 1 %10 = mul i32 1, %9 %11 = add i32 0, %10 - %12 = icmp sgt i32 %8, 3 - %13 = icmp slt i32 %8, 1 - %14 = or i1 %13, %12 + %12 = icmp slt i32 %8, 1 + %13 = icmp sgt i32 %8, 3 + %14 = or i1 %12, %13 br i1 %14, label %then3, label %else4 loop.end: ; preds = %loop.head @@ -555,9 +555,9 @@ loop.body64: ; preds = %loop.head63 %78 = sub i32 %77, 1 %79 = mul i32 1, %78 %80 = add i32 0, %79 - %81 = icmp sgt i32 %77, 4 - %82 = icmp slt i32 %77, 1 - %83 = or i1 %82, %81 + %81 = icmp slt i32 %77, 1 + %82 = icmp sgt i32 %77, 4 + %83 = or i1 %81, %82 br i1 %83, label %then65, label %else66 then65: ; preds = %loop.body64 @@ -574,9 +574,9 @@ ifcont67: ; preds = %else66, %then65 %86 = sub i32 %85, 1 %87 = mul i32 1, %86 %88 = add i32 0, %87 - %89 = icmp sgt i32 %85, 3 - %90 = icmp slt i32 %85, 1 - %91 = or i1 %90, %89 + %89 = icmp slt i32 %85, 1 + %90 = icmp sgt i32 %85, 3 + %91 = or i1 %89, %90 br i1 %91, label %then68, label %else69 then68: ; preds = %ifcont67 @@ -859,9 +859,9 @@ then127: ; preds = %loop.body126 %148 = sub i32 %146, 1 %149 = mul i32 1, %148 %150 = add i32 0, %149 - %151 = icmp sgt i32 %146, 2 - %152 = icmp slt i32 %146, 1 - %153 = or i1 %152, %151 + %151 = icmp slt i32 %146, 1 + %152 = icmp sgt i32 %146, 2 + %153 = or i1 %151, %152 br i1 %153, label %then128, label %else129 then128: ; preds = %then127 @@ -876,9 +876,9 @@ ifcont130: ; preds = %else129, %then128 %154 = sub i32 %147, 1 %155 = mul i32 2, %154 %156 = add i32 %150, %155 - %157 = icmp sgt i32 %147, 2 - %158 = icmp slt i32 %147, 1 - %159 = or i1 %158, %157 + %157 = icmp slt i32 %147, 1 + %158 = icmp sgt i32 %147, 2 + %159 = or i1 %157, %158 br i1 %159, label %then131, label %else132 then131: ; preds = %ifcont130 @@ -900,9 +900,9 @@ else134: ; preds = %loop.body126 %163 = sub i32 %161, 1 %164 = mul i32 1, %163 %165 = add i32 0, %164 - %166 = icmp sgt i32 %161, 2 - %167 = icmp slt i32 %161, 1 - %168 = or i1 %167, %166 + %166 = icmp slt i32 %161, 1 + %167 = icmp sgt i32 %161, 2 + %168 = or i1 %166, %167 br i1 %168, label %then135, label %else136 then135: ; preds = %else134 @@ -917,9 +917,9 @@ ifcont137: ; preds = %else136, %then135 %169 = sub i32 %162, 1 %170 = mul i32 2, %169 %171 = add i32 %165, %170 - %172 = icmp sgt i32 %162, 2 - %173 = icmp slt i32 %162, 1 - %174 = or i1 %173, %172 + %172 = icmp slt i32 %162, 1 + %173 = icmp sgt i32 %162, 2 + %174 = or i1 %172, %173 br i1 %174, label %then138, label %else139 then138: ; preds = %ifcont137 diff --git a/tests/reference/llvm-arrays_01_real-6c5e850.stdout b/tests/reference/llvm-arrays_01_real-6c5e850.stdout index bbbf3a0d973..8ca179ba2a7 100644 --- a/tests/reference/llvm-arrays_01_real-6c5e850.stdout +++ b/tests/reference/llvm-arrays_01_real-6c5e850.stdout @@ -111,9 +111,9 @@ loop.body: ; preds = %loop.head %8 = sub i32 %7, 1 %9 = mul i32 1, %8 %10 = add i32 0, %9 - %11 = icmp sgt i32 %7, 3 - %12 = icmp slt i32 %7, 1 - %13 = or i1 %12, %11 + %11 = icmp slt i32 %7, 1 + %12 = icmp sgt i32 %7, 3 + %13 = or i1 %11, %12 br i1 %13, label %then, label %else loop.end: ; preds = %loop.head @@ -720,9 +720,9 @@ loop.body114: ; preds = %loop.head113 %120 = sub i32 %118, 1 %121 = mul i32 1, %120 %122 = add i32 0, %121 - %123 = icmp sgt i32 %118, 2 - %124 = icmp slt i32 %118, 1 - %125 = or i1 %124, %123 + %123 = icmp slt i32 %118, 1 + %124 = icmp sgt i32 %118, 2 + %125 = or i1 %123, %124 br i1 %125, label %then115, label %else116 then115: ; preds = %loop.body114 @@ -737,9 +737,9 @@ ifcont117: ; preds = %else116, %then115 %126 = sub i32 %119, 1 %127 = mul i32 2, %126 %128 = add i32 %122, %127 - %129 = icmp sgt i32 %119, 2 - %130 = icmp slt i32 %119, 1 - %131 = or i1 %130, %129 + %129 = icmp slt i32 %119, 1 + %130 = icmp sgt i32 %119, 2 + %131 = or i1 %129, %130 br i1 %131, label %then118, label %else119 then118: ; preds = %ifcont117 diff --git a/tests/reference/llvm-arrays_01_size-aaed99f.stdout b/tests/reference/llvm-arrays_01_size-aaed99f.stdout index 5edf6f84fac..9c7f798268d 100644 --- a/tests/reference/llvm-arrays_01_size-aaed99f.stdout +++ b/tests/reference/llvm-arrays_01_size-aaed99f.stdout @@ -465,9 +465,9 @@ loop.body59: ; preds = %loop.head58 %67 = sub i32 %66, 1 %68 = mul i32 1, %67 %69 = add i32 0, %68 - %70 = icmp sgt i32 %66, 4 - %71 = icmp slt i32 %66, 1 - %72 = or i1 %71, %70 + %70 = icmp slt i32 %66, 1 + %71 = icmp sgt i32 %66, 4 + %72 = or i1 %70, %71 br i1 %72, label %then60, label %else61 then60: ; preds = %loop.body59 @@ -484,9 +484,9 @@ ifcont62: ; preds = %else61, %then60 %75 = sub i32 %74, 1 %76 = mul i32 1, %75 %77 = add i32 0, %76 - %78 = icmp sgt i32 %74, 3 - %79 = icmp slt i32 %74, 1 - %80 = or i1 %79, %78 + %78 = icmp slt i32 %74, 1 + %79 = icmp sgt i32 %74, 3 + %80 = or i1 %78, %79 br i1 %80, label %then63, label %else64 then63: ; preds = %ifcont62 diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout index 5db928f6975..78549fe8255 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout @@ -50,9 +50,9 @@ define i32 @main(i32 %0, i8** %1) { %3 = sub i32 %2, 1 %4 = mul i32 1, %3 %5 = add i32 0, %4 - %6 = icmp sgt i32 %2, 3 - %7 = icmp slt i32 %2, 1 - %8 = or i1 %7, %6 + %6 = icmp slt i32 %2, 1 + %7 = icmp sgt i32 %2, 3 + %8 = or i1 %6, %7 br i1 %8, label %then, label %else then: ; preds = %.entry @@ -71,9 +71,9 @@ ifcont: ; preds = %else, %then %11 = sub i32 %10, 1 %12 = mul i32 1, %11 %13 = add i32 0, %12 - %14 = icmp sgt i32 %10, 3 - %15 = icmp slt i32 %10, 1 - %16 = or i1 %15, %14 + %14 = icmp slt i32 %10, 1 + %15 = icmp sgt i32 %10, 3 + %16 = or i1 %14, %15 br i1 %16, label %then2, label %else3 then2: ; preds = %ifcont @@ -92,9 +92,9 @@ ifcont4: ; preds = %else3, %then2 %19 = sub i32 %18, 1 %20 = mul i32 1, %19 %21 = add i32 0, %20 - %22 = icmp sgt i32 %18, 3 - %23 = icmp slt i32 %18, 1 - %24 = or i1 %23, %22 + %22 = icmp slt i32 %18, 1 + %23 = icmp sgt i32 %18, 3 + %24 = or i1 %22, %23 br i1 %24, label %then5, label %else6 then5: ; preds = %ifcont4 diff --git a/tests/reference/llvm-modules_36-53c9a79.stdout b/tests/reference/llvm-modules_36-53c9a79.stdout index 4871b159f95..a7dd51c351b 100644 --- a/tests/reference/llvm-modules_36-53c9a79.stdout +++ b/tests/reference/llvm-modules_36-53c9a79.stdout @@ -39,9 +39,9 @@ loop.body: ; preds = %loop.head %13 = add i32 0, %12 %14 = add i32 1, %10 %15 = sub i32 %14, 1 - %16 = icmp sgt i32 %9, %15 - %17 = icmp slt i32 %9, 1 - %18 = or i1 %17, %16 + %16 = icmp slt i32 %9, 1 + %17 = icmp sgt i32 %9, %15 + %18 = or i1 %16, %17 br i1 %18, label %then, label %else then: ; preds = %loop.body @@ -136,9 +136,9 @@ loop.body: ; preds = %ifcont8 %12 = sub i32 %11, 1 %13 = mul i32 1, %12 %14 = add i32 0, %13 - %15 = icmp sgt i32 %11, 2 - %16 = icmp slt i32 %11, 1 - %17 = or i1 %16, %15 + %15 = icmp slt i32 %11, 1 + %16 = icmp sgt i32 %11, 2 + %17 = or i1 %15, %16 br i1 %17, label %then9, label %else10 loop.end: ; preds = %ifcont8 @@ -189,9 +189,9 @@ ifcont11: ; preds = %else10, %then9 %20 = sub i32 %19, 1 %21 = mul i32 1, %20 %22 = add i32 0, %21 - %23 = icmp sgt i32 %19, 2 - %24 = icmp slt i32 %19, 1 - %25 = or i1 %24, %23 + %23 = icmp slt i32 %19, 1 + %24 = icmp sgt i32 %19, 2 + %25 = or i1 %23, %24 br i1 %25, label %then12, label %else13 then12: ; preds = %ifcont11 From d196f5b2e9194ef36b41773be8c4df2e91d815cc Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Sun, 13 Jul 2025 11:41:00 +0000 Subject: [PATCH 079/119] feat: throw runtime error for SubroutineCall if array bounds don't match --- src/libasr/codegen/asr_to_llvm.cpp | 43 +++++++++++++++++++ tests/errors/array_bounds_check_04.f90 | 12 ++++++ .../run-array_bounds_check_04-2b9fd73.json | 13 ++++++ .../run-array_bounds_check_04-2b9fd73.stderr | 3 ++ .../run-array_bounds_check_04-2e3d8fb.json | 13 ++++++ .../run-array_bounds_check_04-2e3d8fb.stderr | 3 ++ tests/tests.toml | 5 +++ 7 files changed, 92 insertions(+) create mode 100644 tests/errors/array_bounds_check_04.f90 create mode 100644 tests/reference/run-array_bounds_check_04-2b9fd73.json create mode 100644 tests/reference/run-array_bounds_check_04-2b9fd73.stderr create mode 100644 tests/reference/run-array_bounds_check_04-2e3d8fb.json create mode 100644 tests/reference/run-array_bounds_check_04-2e3d8fb.stderr diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 7688af70b82..29599b7292b 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -11472,6 +11472,49 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } + // Generate runtime error if array arguments' shape doesn't match + if (compiler_options.enable_bounds_checking) { + for (size_t i = 0; i < x.n_args; i++) { + ASR::expr_t* arg_expr = x.m_args[i].m_value; + if (ASR::is_a(*arg_expr)) { + ASR::ArrayPhysicalCast_t* arr_cast = ASR::down_cast(arg_expr); + if (arr_cast->m_old == ASR::DescriptorArray && arr_cast->m_new == ASR::PointerToDataArray) { + int64_t ptr_loads_copy = ptr_loads; + ptr_loads = 2 - LLVM::is_llvm_pointer(*ASRUtils::expr_type(arr_cast->m_arg)); + this->visit_expr_wrapper(arr_cast->m_arg, false); + ptr_loads = ptr_loads_copy; + llvm::Value* arg = tmp; + +#if LLVM_VERSION_MAJOR > 16 + llvm::Type* arr_type = llvm_utils->get_type_from_ttype_t_util( + ASRUtils::type_get_past_allocatable_pointer(ASRUtils::expr_type(arr_cast->m_arg)), + module.get(), ASRUtils::expr_abi(arr_cast->m_arg)); + ptr_type[tmp] = arr_type; +#endif + int n_dims = ASRUtils::extract_n_dims_from_ttype(arr_cast->m_type); + ASR::dimension_t* m_dims = nullptr; + ASRUtils::extract_dimensions_from_ttype(arr_cast->m_type, m_dims); + for (int j = 0; j < n_dims; j++) { + if (m_dims[j].m_length && !ASR::is_a(*m_dims[j].m_length)) { + llvm::Value* dim = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)); + llvm::Value* descriptor_length = arr_descr->get_array_size(arg, dim, 4); + load_array_size_deep_copy(m_dims[j].m_length); + llvm::Value* pointer_length = tmp; + llvm_utils->generate_runtime_error(builder->CreateICmpNE(descriptor_length, pointer_length), + "Runtime error: Array shape mismatch in subroutine '%s'\n\n" + "Tried to match size %d of dimension %d of argument number %d, but expected size is %d\n", + builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), + descriptor_length, + dim, + llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)), + pointer_length); + } + } + } + } + } + } + std::vector args; if( x.m_dt && ASR::is_a(*x.m_dt) && ASR::is_a(*ASRUtils::symbol_get_past_external(x.m_name)) && diff --git a/tests/errors/array_bounds_check_04.f90 b/tests/errors/array_bounds_check_04.f90 new file mode 100644 index 00000000000..3c9ea568047 --- /dev/null +++ b/tests/errors/array_bounds_check_04.f90 @@ -0,0 +1,12 @@ +program array_bounds_check_04 + integer, allocatable :: x(:,:) + allocate(x(3, 4)) + + call my(x) + + contains + + subroutine my(x) + integer, intent(in) :: x(3, 1) + end subroutine +end program diff --git a/tests/reference/run-array_bounds_check_04-2b9fd73.json b/tests/reference/run-array_bounds_check_04-2b9fd73.json new file mode 100644 index 00000000000..7a3ab4bbce8 --- /dev/null +++ b/tests/reference/run-array_bounds_check_04-2b9fd73.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_04-2b9fd73", + "cmd": "lfortran --array-bounds-checking --no-color {infile}", + "infile": "tests/errors/array_bounds_check_04.f90", + "infile_hash": "daa672fe4c03715eb861e1221cb21768fb0b297213ccbe906ea2871c", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_04-2b9fd73.stderr", + "stderr_hash": "fa40416f245cb643db75f1c70c4396049945612faf2ac8cdab6e10e3", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_04-2b9fd73.stderr b/tests/reference/run-array_bounds_check_04-2b9fd73.stderr new file mode 100644 index 00000000000..b9b6f004c5c --- /dev/null +++ b/tests/reference/run-array_bounds_check_04-2b9fd73.stderr @@ -0,0 +1,3 @@ +Runtime error: Array shape mismatch in subroutine 'my' + +Tried to match size 4 of dimension 2 of argument number 2, but expected size is 1 diff --git a/tests/reference/run-array_bounds_check_04-2e3d8fb.json b/tests/reference/run-array_bounds_check_04-2e3d8fb.json new file mode 100644 index 00000000000..4ef242e4abe --- /dev/null +++ b/tests/reference/run-array_bounds_check_04-2e3d8fb.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_04-2e3d8fb", + "cmd": "lfortran --no-color {infile}", + "infile": "tests/errors/array_bounds_check_04.f90", + "infile_hash": "daa672fe4c03715eb861e1221cb21768fb0b297213ccbe906ea2871c", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_04-2e3d8fb.stderr", + "stderr_hash": "fa40416f245cb643db75f1c70c4396049945612faf2ac8cdab6e10e3", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr b/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr new file mode 100644 index 00000000000..b9b6f004c5c --- /dev/null +++ b/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr @@ -0,0 +1,3 @@ +Runtime error: Array shape mismatch in subroutine 'my' + +Tried to match size 4 of dimension 2 of argument number 2, but expected size is 1 diff --git a/tests/tests.toml b/tests/tests.toml index e41155e1ae1..54ffe141107 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -3871,6 +3871,11 @@ filename = "errors/array_bounds_check_03.f90" run = true array_bounds_check = true +[[test]] +filename = "errors/array_bounds_check_04.f90" +run = true +array_bounds_check = true + [[test]] filename = "../integration_tests/statement_01.f90" asr_implicit_interface_and_typing = true From ee8dd1f2e05e828725e574b060021d8b58c54823 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Sun, 13 Jul 2025 12:23:39 +0000 Subject: [PATCH 080/119] fix: remove array_bounds_check from run_tests.py because we do it by default now --- run_tests.py | 11 ----------- .../run-array_bounds_check_01-42526d5.json | 13 ------------- .../run-array_bounds_check_01-42526d5.stderr | 3 --- .../run-array_bounds_check_02-fc0cb8b.json | 13 ------------- .../run-array_bounds_check_02-fc0cb8b.stderr | 3 --- .../run-array_bounds_check_03-5071747.json | 13 ------------- .../run-array_bounds_check_03-5071747.stderr | 1 - .../run-array_bounds_check_04-2b9fd73.json | 13 ------------- .../run-array_bounds_check_04-2b9fd73.stderr | 3 --- tests/tests.toml | 4 ---- 10 files changed, 77 deletions(-) delete mode 100644 tests/reference/run-array_bounds_check_01-42526d5.json delete mode 100644 tests/reference/run-array_bounds_check_01-42526d5.stderr delete mode 100644 tests/reference/run-array_bounds_check_02-fc0cb8b.json delete mode 100644 tests/reference/run-array_bounds_check_02-fc0cb8b.stderr delete mode 100644 tests/reference/run-array_bounds_check_03-5071747.json delete mode 100644 tests/reference/run-array_bounds_check_03-5071747.stderr delete mode 100644 tests/reference/run-array_bounds_check_04-2b9fd73.json delete mode 100644 tests/reference/run-array_bounds_check_04-2b9fd73.stderr diff --git a/run_tests.py b/run_tests.py index cb31f97ec6e..4aaa54d279e 100755 --- a/run_tests.py +++ b/run_tests.py @@ -55,7 +55,6 @@ def is_included(backend): asr_no_warnings = is_included("asr_no_warnings") asr_disable_style_and_warnings = is_included("asr_disable_style_and_warnings") continue_compilation = is_included("continue_compilation") - array_bounds_check = is_included("array_bounds_check") fixed_form_cc_asr = is_included("fixed_form_cc_asr") semantics_only_cc = is_included("semantics_only_cc") show_errors = is_included("show_errors") @@ -426,16 +425,6 @@ def is_included(backend): verify_hash, extra_args) - if array_bounds_check: - if no_llvm: - log.info(f"{filename} * obj SKIPPED as requested") - else: - run_test(filename, "run", "lfortran --array-bounds-checking --no-color {infile}", - filename, - update_reference, - verify_hash, - extra_args) - if fixed_form_cc_asr: run_test( filename, diff --git a/tests/reference/run-array_bounds_check_01-42526d5.json b/tests/reference/run-array_bounds_check_01-42526d5.json deleted file mode 100644 index d5a031467b1..00000000000 --- a/tests/reference/run-array_bounds_check_01-42526d5.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "run-array_bounds_check_01-42526d5", - "cmd": "lfortran --array-bounds-checking --no-color {infile}", - "infile": "tests/errors/array_bounds_check_01.f90", - "infile_hash": "e8570ec720776191802ff5d4d5cd6944a6b2e8730e5bf1bd8458dd83", - "outfile": null, - "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "run-array_bounds_check_01-42526d5.stderr", - "stderr_hash": "161fd647a5f1eb6fa952ec46b4ce934c8e4f4e63f4887923754cbe71", - "returncode": 1 -} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_01-42526d5.stderr b/tests/reference/run-array_bounds_check_01-42526d5.stderr deleted file mode 100644 index 893a718bf5e..00000000000 --- a/tests/reference/run-array_bounds_check_01-42526d5.stderr +++ /dev/null @@ -1,3 +0,0 @@ -Runtime error: Array '__libasr__created__var__0__array_constant_' index out of bounds. - -Tried to access index 4 of dimension 1, but valid range is 1 to 3. diff --git a/tests/reference/run-array_bounds_check_02-fc0cb8b.json b/tests/reference/run-array_bounds_check_02-fc0cb8b.json deleted file mode 100644 index a3a388cf69b..00000000000 --- a/tests/reference/run-array_bounds_check_02-fc0cb8b.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "run-array_bounds_check_02-fc0cb8b", - "cmd": "lfortran --array-bounds-checking --no-color {infile}", - "infile": "tests/errors/array_bounds_check_02.f90", - "infile_hash": "eaa31b185f0a51c3937f0238d112eb0fc90b3e410e59da7fe194c389", - "outfile": null, - "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "run-array_bounds_check_02-fc0cb8b.stderr", - "stderr_hash": "161fd647a5f1eb6fa952ec46b4ce934c8e4f4e63f4887923754cbe71", - "returncode": 1 -} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_02-fc0cb8b.stderr b/tests/reference/run-array_bounds_check_02-fc0cb8b.stderr deleted file mode 100644 index 893a718bf5e..00000000000 --- a/tests/reference/run-array_bounds_check_02-fc0cb8b.stderr +++ /dev/null @@ -1,3 +0,0 @@ -Runtime error: Array '__libasr__created__var__0__array_constant_' index out of bounds. - -Tried to access index 4 of dimension 1, but valid range is 1 to 3. diff --git a/tests/reference/run-array_bounds_check_03-5071747.json b/tests/reference/run-array_bounds_check_03-5071747.json deleted file mode 100644 index a3493daad09..00000000000 --- a/tests/reference/run-array_bounds_check_03-5071747.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "run-array_bounds_check_03-5071747", - "cmd": "lfortran --array-bounds-checking --no-color {infile}", - "infile": "tests/errors/array_bounds_check_03.f90", - "infile_hash": "6799dc4bd57bea91b97537abefdd229857c3736e06be6a50c08655b5", - "outfile": null, - "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "run-array_bounds_check_03-5071747.stderr", - "stderr_hash": "b102aecb81a33633a9517ac81d3855b83948b65c027104b30fcf575b", - "returncode": 1 -} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_03-5071747.stderr b/tests/reference/run-array_bounds_check_03-5071747.stderr deleted file mode 100644 index f0da5414041..00000000000 --- a/tests/reference/run-array_bounds_check_03-5071747.stderr +++ /dev/null @@ -1 +0,0 @@ -Runtime Error: Array 'x' is not allocated. diff --git a/tests/reference/run-array_bounds_check_04-2b9fd73.json b/tests/reference/run-array_bounds_check_04-2b9fd73.json deleted file mode 100644 index 7a3ab4bbce8..00000000000 --- a/tests/reference/run-array_bounds_check_04-2b9fd73.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "run-array_bounds_check_04-2b9fd73", - "cmd": "lfortran --array-bounds-checking --no-color {infile}", - "infile": "tests/errors/array_bounds_check_04.f90", - "infile_hash": "daa672fe4c03715eb861e1221cb21768fb0b297213ccbe906ea2871c", - "outfile": null, - "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "run-array_bounds_check_04-2b9fd73.stderr", - "stderr_hash": "fa40416f245cb643db75f1c70c4396049945612faf2ac8cdab6e10e3", - "returncode": 1 -} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_04-2b9fd73.stderr b/tests/reference/run-array_bounds_check_04-2b9fd73.stderr deleted file mode 100644 index b9b6f004c5c..00000000000 --- a/tests/reference/run-array_bounds_check_04-2b9fd73.stderr +++ /dev/null @@ -1,3 +0,0 @@ -Runtime error: Array shape mismatch in subroutine 'my' - -Tried to match size 4 of dimension 2 of argument number 2, but expected size is 1 diff --git a/tests/tests.toml b/tests/tests.toml index 54ffe141107..852c20e32df 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -3859,22 +3859,18 @@ asr = true [[test]] filename = "errors/array_bounds_check_01.f90" run = true -array_bounds_check = true [[test]] filename = "errors/array_bounds_check_02.f90" run = true -array_bounds_check = true [[test]] filename = "errors/array_bounds_check_03.f90" run = true -array_bounds_check = true [[test]] filename = "errors/array_bounds_check_04.f90" run = true -array_bounds_check = true [[test]] filename = "../integration_tests/statement_01.f90" From 271290c6aa441cf645164e68b9bc4e1d300036c3 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 17 Jul 2025 13:45:36 +0000 Subject: [PATCH 081/119] feat: add runtime bound checks for arrays when dimensions depend on function arguments --- .github/workflows/Exhaustive-Checks-CI.yml | 2 +- ci/test_third_party_codes.sh | 46 +++--- integration_tests/CMakeLists.txt | 17 +- integration_tests/arrays_op_20.f90 | 4 +- src/lfortran/semantics/ast_body_visitor.cpp | 4 +- src/lfortran/semantics/ast_common_visitor.h | 49 ++++-- src/libasr/asr_utils.h | 152 ++++++++++++++++-- src/libasr/codegen/asr_to_llvm.cpp | 118 +++++++++----- src/libasr/pass/subroutine_from_function.cpp | 4 +- tests/errors/array_bounds_check_05.f90 | 14 ++ .../reference/asr-associate_08-570ac7d.stdout | 26 ++- .../asr-template_array_01-691b151.stdout | 8 +- .../asr-template_array_02-85b6b2e.stdout | 8 +- .../llvm-implicit_interface_04-9b6786e.stdout | 17 +- .../reference/llvm-modules_36-53c9a79.stdout | 29 ++-- .../run-array_bounds_check_04-2e3d8fb.json | 2 +- .../run-array_bounds_check_04-2e3d8fb.stderr | 2 +- .../run-array_bounds_check_05-d584fab.json | 13 ++ .../run-array_bounds_check_05-d584fab.stderr | 3 + tests/tests.toml | 4 + 20 files changed, 403 insertions(+), 119 deletions(-) create mode 100644 tests/errors/array_bounds_check_05.f90 create mode 100644 tests/reference/run-array_bounds_check_05-d584fab.json create mode 100644 tests/reference/run-array_bounds_check_05-d584fab.stderr diff --git a/.github/workflows/Exhaustive-Checks-CI.yml b/.github/workflows/Exhaustive-Checks-CI.yml index b8c7646c642..646c70d8450 100644 --- a/.github/workflows/Exhaustive-Checks-CI.yml +++ b/.github/workflows/Exhaustive-Checks-CI.yml @@ -440,7 +440,7 @@ jobs: mkdir lfortran-build/ cd lfortran-build/ LIBRARY_PATH="`pwd`/../../src/runtime/" - FC=$(pwd)/../../src/bin/lfortran cmake \ + FC="$(pwd)/../../src/bin/lfortran --no-array-bounds-checking" cmake \ -DCMAKE_Fortran_FLAGS=--verbose \ -DLFORTRAN_RUNTIME_LIBRARY_PATH=$LIBRARY_PATH \ .. diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index 59faf6705ff..a9c3838e5e1 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -195,13 +195,13 @@ time_section "🧪 Testing POT3D with fortran_mpi" ' cd .. print_subsection "Building with default flags" - FC="$FC --cpp -DOPEN_MPI=yes" ./build_and_run_lfortran.sh + FC="$FC --cpp -DOPEN_MPI=yes --no-array-bounds-checking" ./build_and_run_lfortran.sh print_subsection "Building with optimization flags" - # FC="$FC --cpp --fast --skip-pass=dead_code_removal -DOPEN_MPI=yes" ./build_and_run_lfortran.sh + # FC="$FC --cpp --fast --skip-pass=dead_code_removal --no-array-bounds-checking -DOPEN_MPI=yes" ./build_and_run_lfortran.sh print_subsection "Building POT3D in separate compilation mode" - FC="$FC --cpp --separate-compilation -DOPEN_MPI=yes" ./build_and_run_lfortran.sh + FC="$FC --cpp --separate-compilation --no-array-bounds-checking -DOPEN_MPI=yes" ./build_and_run_lfortran.sh print_success "Done with POT3D" cd .. @@ -624,17 +624,17 @@ time_section "🧪 Testing Modern Minpack (Fortran-Lang)" ' $FC ./src/minpack.f90 -c --legacy-array-sections $FC ./examples/example_hybrd.f90 --legacy-array-sections - $FC ./examples/example_hybrd1.f90 --legacy-array-sections - $FC ./examples/example_lmdif1.f90 --legacy-array-sections - $FC ./examples/example_lmder1.f90 --legacy-array-sections + $FC ./examples/example_hybrd1.f90 --legacy-array-sections --no-array-bounds-checking + $FC ./examples/example_lmdif1.f90 --legacy-array-sections --no-array-bounds-checking + $FC ./examples/example_lmder1.f90 --legacy-array-sections --no-array-bounds-checking print_subsection "Testing with separate compilation" git clean -dfx - $FC ./src/minpack.f90 -c --legacy-array-sections --separate-compilation - $FC ./examples/example_hybrd.f90 --legacy-array-sections --separate-compilation minpack.o - $FC ./examples/example_hybrd1.f90 --legacy-array-sections --separate-compilation minpack.o - $FC ./examples/example_lmdif1.f90 --legacy-array-sections --separate-compilation minpack.o - $FC ./examples/example_lmder1.f90 --legacy-array-sections --separate-compilation minpack.o + $FC ./src/minpack.f90 -c --legacy-array-sections --separate-compilation --no-array-bounds-checking + $FC ./examples/example_hybrd.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o + $FC ./examples/example_hybrd1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o + $FC ./examples/example_lmdif1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o + $FC ./examples/example_lmder1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o ' time_section "🧪 Testing Modern Minpack (Result Check)" ' @@ -645,17 +645,17 @@ time_section "🧪 Testing Modern Minpack (Result Check)" ' $FC ./src/minpack.f90 -c --legacy-array-sections $FC ./examples/example_hybrd.f90 --legacy-array-sections - $FC ./examples/example_hybrd1.f90 --legacy-array-sections - $FC ./examples/example_lmdif1.f90 --legacy-array-sections - $FC ./examples/example_lmder1.f90 --legacy-array-sections + $FC ./examples/example_hybrd1.f90 --legacy-array-sections --no-array-bounds-checking + $FC ./examples/example_lmdif1.f90 --legacy-array-sections --no-array-bounds-checking + $FC ./examples/example_lmder1.f90 --legacy-array-sections --no-array-bounds-checking print_subsection "Testing with separate compilation" git clean -dfx - $FC ./src/minpack.f90 -c --legacy-array-sections --separate-compilation - $FC ./examples/example_hybrd.f90 --legacy-array-sections --separate-compilation minpack.o - $FC ./examples/example_hybrd1.f90 --legacy-array-sections --separate-compilation minpack.o - $FC ./examples/example_lmdif1.f90 --legacy-array-sections --separate-compilation minpack.o - $FC ./examples/example_lmder1.f90 --legacy-array-sections --separate-compilation minpack.o + $FC ./src/minpack.f90 -c --legacy-array-sections --separate-compilation --no-array-bounds-checking + $FC ./examples/example_hybrd.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o + $FC ./examples/example_hybrd1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o + $FC ./examples/example_lmdif1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o + $FC ./examples/example_lmder1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o ' ########################## @@ -760,7 +760,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf-goc cd lf-goc - FC="$FC --separate-compilation --rtlib" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --realloc-lhs --no-array-bounds-checking --separate-compilation --rtlib" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -836,15 +836,15 @@ time_section "🧪 Testing SNAP" ' git checkout lf11 git checkout 169a9216f2c922e94065a519efbb0a6c8b55149e cd ./src - make -j8 FORTRAN=$FC FFLAGS= MPI=no OPENMP=no + make -j8 FORTRAN=$FC FFLAGS="--no-array-bounds-checking" MPI=no OPENMP=no ./gsnap ../qasnap/sample/inp out make clean - make -j8 FORTRAN=$FC FFLAGS="--separate-compilation" MPI=no OPENMP=no + make -j8 FORTRAN=$FC FFLAGS="--separate-compilation --no-array-bounds-checking" MPI=no OPENMP=no ./gsnap ../qasnap/sample/inp out make clean - make -j8 FORTRAN=$FC FFLAGS="--fast" MPI=no OPENMP=no + make -j8 FORTRAN=$FC FFLAGS="--fast --no-array-bounds-checking" MPI=no OPENMP=no ./gsnap ../qasnap/sample/inp out ' diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index efb8d603265..c561ec0b2bf 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -583,7 +583,7 @@ RUN(NAME arrays_01_real LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackA RUN(NAME arrays_01_complex LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME arrays_01_logical LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm) RUN(NAME arrays_01_multi_dim LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) -RUN(NAME integer_bin_op_dim_external_module LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray) +RUN(NAME integer_bin_op_dim_external_module LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --no-array-bounds-checking) RUN(NAME array_bound_1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME array_bound_2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME array_bound_3 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran) @@ -665,11 +665,11 @@ RUN(NAME arrays_44 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran RUN(NAME arrays_45 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_46 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_47 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME arrays_48 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME arrays_48 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) RUN(NAME arrays_49 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_50 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRAFILES arrays_50_mod.f90) RUN(NAME arrays_51 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME arrays_52 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME arrays_52 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) RUN(NAME arrays_53 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_54 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_55 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -987,7 +987,8 @@ RUN(NAME intrinsics_144 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # RUN(NAME intrinsics_145 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # dot_product RUN(NAME intrinsics_146 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # dprod RUN(NAME intrinsics_147 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack -RUN(NAME intrinsics_148 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack +# FIXME: Multi dimensional ArrayConstant is not supported +# RUN(NAME intrinsics_148 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack RUN(NAME intrinsics_149 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # unpack RUN(NAME intrinsics_150 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # maskr RUN(NAME intrinsics_151 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # maskl @@ -1241,10 +1242,10 @@ RUN(NAME integer_boz_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME test_dshiftr LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME passing_array_01 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME passing_array_02 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME passing_array_03 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME passing_array_04 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME passing_array_01 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME passing_array_02 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME passing_array_03 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME passing_array_04 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) RUN(NAME parameter_01 LABELS gfortran llvm) RUN(NAME parameter_02 LABELS gfortran llvm) diff --git a/integration_tests/arrays_op_20.f90 b/integration_tests/arrays_op_20.f90 index a2b5423dc4d..2674f0bcfa9 100644 --- a/integration_tests/arrays_op_20.f90 +++ b/integration_tests/arrays_op_20.f90 @@ -3,7 +3,7 @@ program arrays_op_20 real, allocatable :: array(:, :), arrayoutput(:, :) -allocate(array(3, 3)) +allocate(array(5, 5)) arrayoutput = f(5, array) print *, size(arrayoutput) if( size(arrayoutput) /= 24 ) error stop @@ -12,7 +12,7 @@ program arrays_op_20 function f(m, input) result(output) integer :: m -real :: input(m) +real :: input(m, m) real :: output(2:m, m:2*m) end function diff --git a/src/lfortran/semantics/ast_body_visitor.cpp b/src/lfortran/semantics/ast_body_visitor.cpp index 0a82df98e38..3684347f5ec 100644 --- a/src/lfortran/semantics/ast_body_visitor.cpp +++ b/src/lfortran/semantics/ast_body_visitor.cpp @@ -2536,7 +2536,7 @@ class BodyVisitor : public CommonVisitor { } else { stmt = ASRUtils::STMT(ASRUtils::make_SubroutineCall_t_util(al,loc, master_function_sym, - master_function_sym, args.p, args.n, nullptr, nullptr, compiler_options.implicit_argument_casting)); + master_function_sym, args.p, args.n, nullptr, nullptr, compiler_options.implicit_argument_casting, current_scope, current_function_dependencies)); } LCOMPILERS_ASSERT(stmt != nullptr); @@ -4563,7 +4563,7 @@ class BodyVisitor : public CommonVisitor { } ASR::stmt_t* cast_stmt = nullptr; tmp = ASRUtils::make_SubroutineCall_t_util(al, x.base.base.loc, - final_sym, original_sym, args.p, args.size(), v_expr, &cast_stmt, compiler_options.implicit_argument_casting); + final_sym, original_sym, args.p, args.size(), v_expr, &cast_stmt, compiler_options.implicit_argument_casting, current_scope, current_function_dependencies); if (cast_stmt != nullptr) { current_body->push_back(al, cast_stmt); diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 71e52f9738c..47a60c818db 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -1774,7 +1774,7 @@ class CommonVisitor : public AST::BaseVisitor { current_function_dependencies.push_back(al,s2c(al, func_name)); ASR::expr_t* func_call = ASRUtils::EXPR(ASRUtils::make_FunctionCall_t_util(al, getter_func_sym->base.loc, - getter_func_sym, getter_func_sym, nullptr, 0, ASRUtils::symbol_type(end_sym), nullptr, nullptr)); + getter_func_sym, getter_func_sym, nullptr, 0, ASRUtils::symbol_type(end_sym), nullptr, nullptr, current_scope, current_function_dependencies)); return func_call; } @@ -6073,7 +6073,7 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::set_absent_optional_arguments_to_null(args, func, al); return ASRUtils::make_FunctionCall_t_util(al, loc, final_sym, v, args.p, args.size(), return_type, - value, nullptr); + value, nullptr, current_scope, current_function_dependencies); } ASR::asr_t* symbol_resolve_external_generic_procedure( @@ -6188,7 +6188,7 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::set_absent_optional_arguments_to_null(args, func, al, v_expr, v_class_proc->m_is_nopass); return ASRUtils::make_FunctionCall_t_util(al, loc, v, nullptr, args.p, args.size(), type, nullptr, - v_expr); + v_expr, current_scope, current_function_dependencies); } ASR::asr_t* create_GenericProcedure(const Location &loc, @@ -6240,7 +6240,7 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::set_absent_optional_arguments_to_null(args, func, al); return ASRUtils::make_FunctionCall_t_util(al, loc, final_sym, v, args.p, args.size(), type, - nullptr, nullptr); + nullptr, nullptr, current_scope, current_function_dependencies); } } @@ -6304,7 +6304,7 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::set_absent_optional_arguments_to_null(args, func, al); return ASRUtils::make_FunctionCall_t_util(al, loc, cp_s, nullptr, args_without_dt.p, args_without_dt.size(), type, - nullptr, args[0].m_value); + nullptr, args[0].m_value, current_scope, current_function_dependencies); } else { if (ASRUtils::symbol_parent_symtab(final_sym)->get_counter() != current_scope->get_counter()) { ADD_ASR_DEPENDENCIES(current_scope, final_sym, current_function_dependencies); @@ -6314,7 +6314,7 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::set_absent_optional_arguments_to_null(args, func, al); return ASRUtils::make_FunctionCall_t_util(al, loc, final_sym, v, args.p, args.size(), type, - nullptr, nullptr); + nullptr, nullptr, current_scope, current_function_dependencies); } } } @@ -6564,6 +6564,33 @@ class CommonVisitor : public AST::BaseVisitor { dims.p, dims.size(), ASR::array_physical_typeType::DescriptorArray); ASR::Array_t* array_t = ASR::down_cast(expected_arg_type); + + // Replace FunctionParam in dimensions and check whether its symbols are accessible from current_scope + SetChar temp_function_dependencies; + ASRUtils::ReplaceFunctionParamWithArg r(al, args.p, args.n); + ASRUtils::CheckSymbolReplacer c(al, current_scope, temp_function_dependencies); + bool valid_symbols = true; + Vec dimensions_; dimensions_.reserve(al, array_t->n_dims); + for (size_t i = 0; i < array_t->n_dims; i++) { + ASR::dimension_t dim; + dim.loc = array_t->m_dims[i].loc; + dim.m_start = r.replace_FunctionParam_with_arg(array_t->m_dims[i].m_start); + dim.m_length = r.replace_FunctionParam_with_arg(array_t->m_dims[i].m_length); + valid_symbols = c.check_and_update_symbols(dim.m_length) && c.check_and_update_symbols(dim.m_start); + if (!valid_symbols) { + break; + } + dimensions_.push_back(al, dim); + } + if (valid_symbols) { + for (size_t i = 0; i < array_t->n_dims; i++) { + array_t->m_dims[i] = dimensions_[i]; + } + for (size_t i = 0; i < temp_function_dependencies.n; i++) { + current_function_dependencies.push_back(al, temp_function_dependencies[i]); + } + } + ASR::asr_t* expected_array = ASR::make_Array_t(al, loc, ASRUtils::type_get_past_array(expected_arg_type), array_t->m_dims, array_t->n_dims, ASRUtils::extract_physical_type(expected_arg_type)); @@ -6686,7 +6713,7 @@ class CommonVisitor : public AST::BaseVisitor { legacy_array_sections_helper(v, args, loc); validate_create_function_arguments(args, v); return ASRUtils::make_FunctionCall_t_util(al, loc, v, nullptr, - args.p, args.size(), return_type, value, nullptr); + args.p, args.size(), return_type, value, nullptr, current_scope, current_function_dependencies); } ASR::asr_t* create_FunctionFromFunctionTypeVariable(const Location &loc, @@ -6702,10 +6729,10 @@ class CommonVisitor : public AST::BaseVisitor { ASR::expr_t* dt = ASRUtils::EXPR(ASR::make_StructInstanceMember_t( al, loc, args.p[0].m_value, v, ASRUtils::symbol_type(v), nullptr)); return ASRUtils::make_FunctionCall_t_util(al, loc, v, nullptr, - args.p + 1, args.size() - 1, return_type, nullptr, dt); + args.p + 1, args.size() - 1, return_type, nullptr, dt, current_scope, current_function_dependencies); } else { return ASRUtils::make_FunctionCall_t_util(al, loc, v, nullptr, - args.p, args.size(), return_type, nullptr, nullptr); + args.p, args.size(), return_type, nullptr, nullptr, current_scope, current_function_dependencies); } } @@ -10864,7 +10891,7 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::insert_module_dependency(a_name, al, current_module_dependencies); ASRUtils::set_absent_optional_arguments_to_null(a_args, func, al); - tmp = ASRUtils::make_FunctionCall_t_util(al, loc, a_name, op_sym, a_args.p, a_args.size(), return_type, nullptr, nullptr); + tmp = ASRUtils::make_FunctionCall_t_util(al, loc, a_name, op_sym, a_args.p, a_args.size(), return_type, nullptr, nullptr, current_scope, current_function_dependencies); matched = true; break; } @@ -11042,7 +11069,7 @@ class CommonVisitor : public AST::BaseVisitor { ADD_ASR_DEPENDENCIES(current_scope, v, current_function_dependencies); ASRUtils::insert_module_dependency(v, al, current_module_dependencies); tmp = ASRUtils::make_FunctionCall_t_util(al, x.base.base.loc, v, - v, args.p, args.size(), return_type, nullptr, nullptr + v, args.p, args.size(), return_type, nullptr, nullptr, current_scope, current_function_dependencies ); tmp = ASR::make_OverloadedStringConcat_t(al, x.base.base.loc, left, right, return_type, nullptr, ASRUtils::EXPR(tmp)); diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 8a790ba95b4..924988ae700 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -2868,6 +2869,48 @@ class ExprDependentOnlyOnArguments: public ASR::BaseWalkVisitor { + private: + + Allocator& al; + ASR::call_arg_t* m_args; + size_t n_args; + bool is_method; + + public: + + ReplaceFunctionParamWithArg(Allocator& al_, ASR::call_arg_t* m_args_, size_t n_args_, bool is_method_ = false) : + al(al_), m_args(m_args_), n_args(n_args_), is_method(is_method_) {} + + void replace_FunctionParam(ASR::FunctionParam_t *x) { + if (current_expr) { + size_t n = x->m_param_number - is_method; + if (n >= n_args) { + LCOMPILERS_ASSERT("FunctionParam param number not in range."); + }; + *current_expr = m_args[n].m_value; + } + } + + ASR::expr_t* replace_FunctionParam_with_arg(ASR::expr_t* t) { + ASRUtils::ExprStmtDuplicator duplicator(al); + duplicator.allow_procedure_calls = true; + duplicator.success = true; + + ASR::expr_t* tc = duplicator.duplicate_expr(t); + LCOMPILERS_ASSERT(duplicator.success); + + ASR::expr_t** current_copy = current_expr; + current_expr = &tc; + replace_expr(tc); + current_expr = current_copy; + + return tc; + } +}; + static inline bool is_dimension_dependent_only_on_arguments(ASR::dimension_t* m_dims, size_t n_dims, bool only_intent_in_args=false) { ExprDependentOnlyOnArguments visitor; visitor.only_intent_in_args = only_intent_in_args; @@ -5024,6 +5067,66 @@ class SymbolDuplicator { }; +// This replacer is for checking if symbols in the input expression are accessible from current_scope. +// If they are accessible as external symbols then replace them by the corresponding ExternalSymbol. +// If atleast one symbol is not accessible then result is false. +class CheckSymbolReplacer: public ASR::BaseExprReplacer { + private: + + Allocator &al; + bool result; + SymbolTable* current_scope; + SetChar& current_function_dependencies; + + public: + CheckSymbolReplacer(Allocator &al_, SymbolTable* current_scope_, SetChar& current_function_dependencies_) : + al(al_), result(true), current_scope(current_scope_), current_function_dependencies(current_function_dependencies_) {} + + ASR::symbol_t* handle_symbol(ASR::symbol_t* x) { + if (result) { + ASR::symbol_t* y = current_scope->resolve_symbol(ASRUtils::symbol_name((x))); + if (y == nullptr) { + result = false; + } + if (y && ASR::is_a(*y)) { + ASR::ExternalSymbol_t* ext = ASR::down_cast(y); + if (ext->m_external == x) { + return y; + } + } + if (x != y) { + result = false; + } + } + return x; + } + + void replace_Var(ASR::Var_t *x) { + x->m_v = handle_symbol(x->m_v); + ADD_ASR_DEPENDENCIES(current_scope, x->m_v, current_function_dependencies); + } + + void replace_FunctionCall(ASR::FunctionCall_t* x) { + x->m_name = handle_symbol(x->m_name); + ADD_ASR_DEPENDENCIES(current_scope, x->m_name, current_function_dependencies); + if (x->m_original_name) { + x->m_original_name = handle_symbol(x->m_original_name); + ADD_ASR_DEPENDENCIES(current_scope, x->m_original_name, current_function_dependencies); + } + } + + bool check_and_update_symbols(ASR::expr_t* t) { + if (t) { + ASR::expr_t** current_copy = current_expr; + current_expr = &t; + replace_expr(t); + current_expr = current_copy; + return result; + } + return false; + } +}; + class ReplaceReturnWithGotoVisitor: public ASR::BaseStmtReplacer { private: @@ -6250,7 +6353,7 @@ inline void check_simple_intent_mismatch(diag::Diagnostics &diag, ASR::Function_ static inline void Call_t_body(Allocator& al, ASR::symbol_t* a_name, ASR::call_arg_t* a_args, size_t n_args, ASR::expr_t* a_dt, ASR::stmt_t** cast_stmt, - bool implicit_argument_casting, bool nopass) { + bool implicit_argument_casting, bool nopass, SymbolTable* current_scope = nullptr, std::optional> current_function_dependencies = std::nullopt) { bool is_method = (a_dt != nullptr) && (!nopass); ASR::symbol_t* a_name_ = ASRUtils::symbol_get_past_external(a_name); if( ASR::is_a(*a_name_) ) { @@ -6417,19 +6520,48 @@ static inline void Call_t_body(Allocator& al, ASR::symbol_t* a_name, physical_cast_arg.loc = arg->base.loc; Vec* dimensions = nullptr; Vec dimension_; - if( ASRUtils::is_fixed_size_array(orig_arg_array_t->m_dims, orig_arg_array_t->n_dims) ) { - dimension_.reserve(al, orig_arg_array_t->n_dims); - dimension_.from_pointer_n_copy(al, orig_arg_array_t->m_dims, orig_arg_array_t->n_dims); + dimension_.from_pointer_n_copy(al, orig_arg_array_t->m_dims, orig_arg_array_t->n_dims); + ASR::ttype_t* physical_cast_type = ASRUtils::type_get_past_allocatable(ASRUtils::expr_type(arg)); + + if (ASRUtils::is_pointer(physical_cast_type)) { + dimensions = nullptr; + } else if (ASRUtils::is_fixed_size_array(orig_arg_array_t->m_dims, orig_arg_array_t->n_dims)) { dimensions = &dimension_; + } else if (current_scope) { + // Replace FunctionParam in dimensions and check whether its symbols are accessible from current_scope + ReplaceFunctionParamWithArg r(al, a_args, n_args, is_method); + SetChar temp_function_dependencies; + CheckSymbolReplacer c(al, current_scope, temp_function_dependencies); + bool valid_symbols = true; + for (size_t i = 0; i < dimension_.size(); i++) { + dimension_.p[i].loc = arg->base.loc; + dimension_.p[i].m_length = r.replace_FunctionParam_with_arg(dimension_[i].m_length); + dimension_.p[i].m_start = r.replace_FunctionParam_with_arg(dimension_[i].m_start); + valid_symbols = c.check_and_update_symbols(dimension_[i].m_length) && c.check_and_update_symbols(dimension_[i].m_start); + + if (!valid_symbols) { + break; + } + } + // If the symbols are valid then include the dimension in ArrayPhysicalCast + if (valid_symbols) { + dimensions = &dimension_; + if (current_function_dependencies.has_value()) { + for (size_t j = 0; j < temp_function_dependencies.n; j++) { + current_function_dependencies->get().push_back(al, temp_function_dependencies[j]); + } + } + } else { + dimensions = nullptr; + } } + //TO DO : Add appropriate errors in 'asr_uttils.h'. LCOMPILERS_ASSERT_MSG(dimensions_compatible(arg_array_t->m_dims, arg_array_t->n_dims, orig_arg_array_t->m_dims, orig_arg_array_t->n_dims, false), "Incompatible dimensions passed to " + (std::string)(ASR::down_cast(a_name_)->m_name) + "(" + std::to_string(get_fixed_size_of_array(arg_array_t->m_dims,arg_array_t->n_dims)) + "/" + std::to_string(get_fixed_size_of_array(orig_arg_array_t->m_dims,orig_arg_array_t->n_dims))+")"); - ASR::ttype_t* physical_cast_type = ASRUtils::type_get_past_allocatable( - ASRUtils::expr_type(arg)); physical_cast_arg.m_value = ASRUtils::EXPR( ASRUtils::make_ArrayPhysicalCast_t_util( al, @@ -6452,10 +6584,10 @@ static inline void Call_t_body(Allocator& al, ASR::symbol_t* a_name, static inline ASR::asr_t* make_FunctionCall_t_util( Allocator &al, const Location &a_loc, ASR::symbol_t* a_name, ASR::symbol_t* a_original_name, ASR::call_arg_t* a_args, size_t n_args, - ASR::ttype_t* a_type, ASR::expr_t* a_value, ASR::expr_t* a_dt) { + ASR::ttype_t* a_type, ASR::expr_t* a_value, ASR::expr_t* a_dt, SymbolTable* current_scope = nullptr, std::optional> current_function_dependencies = std::nullopt) { Call_t_body(al, a_name, a_args, n_args, a_dt, nullptr, false, - ASRUtils::get_class_proc_nopass_val(a_name)); + ASRUtils::get_class_proc_nopass_val(a_name), current_scope, current_function_dependencies); if( ASRUtils::is_array(a_type) && ASRUtils::is_elemental(a_name) && !ASRUtils::is_fixed_size_array(a_type) && @@ -6502,10 +6634,10 @@ static inline ASR::asr_t* make_FunctionCall_t_util( static inline ASR::asr_t* make_SubroutineCall_t_util( Allocator &al, const Location &a_loc, ASR::symbol_t* a_name, ASR::symbol_t* a_original_name, ASR::call_arg_t* a_args, size_t n_args, - ASR::expr_t* a_dt, ASR::stmt_t** cast_stmt, bool implicit_argument_casting) { + ASR::expr_t* a_dt, ASR::stmt_t** cast_stmt, bool implicit_argument_casting, SymbolTable* current_scope = nullptr, std::optional> current_function_dependencies = std::nullopt) { Call_t_body(al, a_name, a_args, n_args, a_dt, cast_stmt, implicit_argument_casting, - ASRUtils::get_class_proc_nopass_val(a_name)); + ASRUtils::get_class_proc_nopass_val(a_name), current_scope, current_function_dependencies); if( a_dt && ASR::is_a( *ASRUtils::symbol_get_past_external(a_name)) && diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 29599b7292b..5aaf3937997 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -6638,6 +6638,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm_size = llvm_utils->get_stringArray_whole_size(target_type); } } else { + target = llvm_utils->CreateLoad(target); +#if LLVM_VERSION_MAJOR > 16 + ptr_type[target] = llvm_utils->get_type_from_ttype_t_util(x.m_target, + ASRUtils::type_get_past_allocatable_pointer(target_type), + module.get()); +#endif target_data = ASRUtils::is_array_of_strings(target_type) ? llvm_utils->get_stringArray_data(target_type, target) : @@ -6659,6 +6665,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor break; } this->visit_expr_wrapper(value_dims[i].m_length, true); + tmp = builder->CreateSExtOrTrunc(tmp, llvm::Type::getInt32Ty(context)); llvm_size = builder->CreateMul(llvm_size, tmp); } if(ASRUtils::is_array_of_strings(value_type)){ // Neglect previous llvm_size @@ -11462,6 +11469,72 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return dt; } + template + void bounds_check_call(T& x) { + for (size_t i = 0; i < x.n_args; i++) { + ASR::expr_t* arg_expr = x.m_args[i].m_value; + if (ASR::is_a(*arg_expr)) { + ASR::ArrayPhysicalCast_t* arr_cast = ASR::down_cast(arg_expr); + if (arr_cast->m_old == ASR::DescriptorArray && arr_cast->m_new == ASR::PointerToDataArray) { + int64_t ptr_loads_copy = ptr_loads; + ptr_loads = 2 - LLVM::is_llvm_pointer(*ASRUtils::expr_type(arr_cast->m_arg)); + this->visit_expr_wrapper(arr_cast->m_arg, false); + ptr_loads = ptr_loads_copy; + llvm::Value* arg = tmp; + +#if LLVM_VERSION_MAJOR > 16 + llvm::Type* arr_type = llvm_utils->get_type_from_ttype_t_util(arr_cast->m_arg, + ASRUtils::type_get_past_allocatable_pointer(ASRUtils::expr_type(arr_cast->m_arg)), + module.get(), ASRUtils::expr_abi(arr_cast->m_arg)); + ptr_type[tmp] = arr_type; +#endif + int n_dims = ASRUtils::extract_n_dims_from_ttype(arr_cast->m_type); + ASR::dimension_t* m_dims = nullptr; + ASRUtils::extract_dimensions_from_ttype(arr_cast->m_type, m_dims); + for (int j = 0; j < n_dims; j++) { + if (m_dims[j].m_length) { + llvm::Value* dim = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)); + llvm::Value* descriptor_length = arr_descr->get_array_size(arg, dim, 4); + load_array_size_deep_copy(m_dims[j].m_length); + llvm::Value* pointer_length = tmp; + llvm_utils->generate_runtime_error(builder->CreateICmpNE(descriptor_length, pointer_length), + "Runtime error: Array shape mismatch in subroutine '%s'\n\n" + "Tried to match size %d of dimension %d of argument number %d, but expected size is %d\n", + builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), + descriptor_length, + dim, + llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, i + 1)), + pointer_length); + } + } + } else if (arr_cast->m_old == ASR::FixedSizeArray && arr_cast->m_new == ASR::PointerToDataArray) { + ASR::dimension_t* m_dims_fixed = nullptr; + int n_dims = ASRUtils::extract_dimensions_from_ttype(ASRUtils::expr_type(arr_cast->m_arg), m_dims_fixed); + + ASR::dimension_t* m_dims_pointer = nullptr; + ASRUtils::extract_dimensions_from_ttype(arr_cast->m_type, m_dims_pointer); + + for (int j = 0; j < n_dims; j++) { + if (m_dims_pointer[j].m_length) { + llvm::Value* dim = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)); + llvm::Value* fixed_length = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, ASRUtils::extract_dim_value_int(m_dims_fixed[j].m_length))); + load_array_size_deep_copy(m_dims_pointer[j].m_length); + llvm::Value* pointer_length = tmp; + llvm_utils->generate_runtime_error(builder->CreateICmpNE(fixed_length, pointer_length), + "Runtime error: Array shape mismatch in subroutine '%s'\n\n" + "Tried to match size %d of dimension %d of argument number %d, but expected size is %d\n", + builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), + fixed_length, + dim, + llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, i + 1)), + pointer_length); + } + } + } + } + } + } + void visit_SubroutineCall(const ASR::SubroutineCall_t &x) { if (compiler_options.emit_debug_info) debug_emit_loc(x); if( ASRUtils::is_intrinsic_optimization(x.m_name) ) { @@ -11474,45 +11547,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor // Generate runtime error if array arguments' shape doesn't match if (compiler_options.enable_bounds_checking) { - for (size_t i = 0; i < x.n_args; i++) { - ASR::expr_t* arg_expr = x.m_args[i].m_value; - if (ASR::is_a(*arg_expr)) { - ASR::ArrayPhysicalCast_t* arr_cast = ASR::down_cast(arg_expr); - if (arr_cast->m_old == ASR::DescriptorArray && arr_cast->m_new == ASR::PointerToDataArray) { - int64_t ptr_loads_copy = ptr_loads; - ptr_loads = 2 - LLVM::is_llvm_pointer(*ASRUtils::expr_type(arr_cast->m_arg)); - this->visit_expr_wrapper(arr_cast->m_arg, false); - ptr_loads = ptr_loads_copy; - llvm::Value* arg = tmp; - -#if LLVM_VERSION_MAJOR > 16 - llvm::Type* arr_type = llvm_utils->get_type_from_ttype_t_util( - ASRUtils::type_get_past_allocatable_pointer(ASRUtils::expr_type(arr_cast->m_arg)), - module.get(), ASRUtils::expr_abi(arr_cast->m_arg)); - ptr_type[tmp] = arr_type; -#endif - int n_dims = ASRUtils::extract_n_dims_from_ttype(arr_cast->m_type); - ASR::dimension_t* m_dims = nullptr; - ASRUtils::extract_dimensions_from_ttype(arr_cast->m_type, m_dims); - for (int j = 0; j < n_dims; j++) { - if (m_dims[j].m_length && !ASR::is_a(*m_dims[j].m_length)) { - llvm::Value* dim = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)); - llvm::Value* descriptor_length = arr_descr->get_array_size(arg, dim, 4); - load_array_size_deep_copy(m_dims[j].m_length); - llvm::Value* pointer_length = tmp; - llvm_utils->generate_runtime_error(builder->CreateICmpNE(descriptor_length, pointer_length), - "Runtime error: Array shape mismatch in subroutine '%s'\n\n" - "Tried to match size %d of dimension %d of argument number %d, but expected size is %d\n", - builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), - descriptor_length, - dim, - llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)), - pointer_length); - } - } - } - } - } + bounds_check_call(x); } std::vector args; @@ -12081,6 +12116,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return ; } + // Generate runtime error if array arguments' shape doesn't match + if (compiler_options.enable_bounds_checking) { + bounds_check_call(x); + } + std::vector args; if( x.m_dt && ASR::is_a(*x.m_dt) && ASR::is_a(*ASRUtils::symbol_get_past_external(x.m_name)) && diff --git a/src/libasr/pass/subroutine_from_function.cpp b/src/libasr/pass/subroutine_from_function.cpp index 0081be2d805..ec8dbc2bf60 100644 --- a/src/libasr/pass/subroutine_from_function.cpp +++ b/src/libasr/pass/subroutine_from_function.cpp @@ -116,7 +116,7 @@ public : new_call_args.push_back(al, {result_var->base.loc, result_var}); ASR::stmt_t* subrout_call = ASRUtils::STMT(ASRUtils::make_SubroutineCall_t_util(al, x->base.base.loc, x->m_name, nullptr, new_call_args.p, new_call_args.size(), x->m_dt, - nullptr, false)); + nullptr, false, current_scope)); // replace functionCall with `result_var` + push subroutineCall into the body. *current_expr = result_var; pass_result.push_back(al, subrout_call); @@ -223,7 +223,7 @@ class ReplaceFunctionCallWithSubroutineCallVisitor: result_arg.m_value = target; s_args.push_back(al, result_arg); ASR::stmt_t* subrout_call = ASRUtils::STMT(ASRUtils::make_SubroutineCall_t_util(al, loc, - fc->m_name, fc->m_original_name, s_args.p, s_args.size(), fc->m_dt, nullptr, false)); + fc->m_name, fc->m_original_name, s_args.p, s_args.size(), fc->m_dt, nullptr, false, current_scope)); pass_result.push_back(al, subrout_call); remove_original_statement = true; } diff --git a/tests/errors/array_bounds_check_05.f90 b/tests/errors/array_bounds_check_05.f90 new file mode 100644 index 00000000000..55156e0f188 --- /dev/null +++ b/tests/errors/array_bounds_check_05.f90 @@ -0,0 +1,14 @@ +program array_bounds_check_05 + integer, allocatable :: x(:) + allocate(x(3)) + + x = [1, 2, 3] + + call my(x, 5) + contains + + subroutine my(x, i) + integer, intent(in) :: x(i) + integer, intent(in) :: i + end subroutine +end program diff --git a/tests/reference/asr-associate_08-570ac7d.stdout b/tests/reference/asr-associate_08-570ac7d.stdout index 56d7ad2e119..678120cfa56 100644 --- a/tests/reference/asr-associate_08-570ac7d.stdout +++ b/tests/reference/asr-associate_08-570ac7d.stdout @@ -79,17 +79,29 @@ (Allocatable (Array (StructType - [] + [(Pointer + (Array + (StructType + [(Integer 4)] + [] + .true. + .false. + ) + [(() + ())] + DescriptorArray + ) + )] [] .false. - 7 t_2 + .false. ) [(() ())] DescriptorArray ) ) - () + 7 t_2 Source Public Required @@ -159,10 +171,10 @@ (Pointer (Array (StructType - [] + [(Integer 4)] [] .true. - 7 t_1 + .false. ) [(() ())] @@ -175,10 +187,10 @@ (IntegerConstant 1 (Integer 4) Decimal) ())] (StructType - [] + [(Integer 4)] [] .true. - 7 t_1 + .false. ) ColMajor () diff --git a/tests/reference/asr-template_array_01-691b151.stdout b/tests/reference/asr-template_array_01-691b151.stdout index 8a1420d9be0..fa6bd3ea3a5 100644 --- a/tests/reference/asr-template_array_01-691b151.stdout +++ b/tests/reference/asr-template_array_01-691b151.stdout @@ -960,7 +960,13 @@ (Array (Integer 4) [((IntegerConstant 1 (Integer 4) Decimal) - (IntegerConstant 1 (Integer 4) Decimal))] + (IntegerBinOp + (IntegerConstant 1 (Integer 4) Decimal) + Mul + (IntegerConstant 1 (Integer 4) Decimal) + (Integer 4) + () + ))] PointerToDataArray ) () diff --git a/tests/reference/asr-template_array_02-85b6b2e.stdout b/tests/reference/asr-template_array_02-85b6b2e.stdout index fc1a19ce357..5d4e193f02c 100644 --- a/tests/reference/asr-template_array_02-85b6b2e.stdout +++ b/tests/reference/asr-template_array_02-85b6b2e.stdout @@ -1503,7 +1503,13 @@ (Array (Integer 4) [((IntegerConstant 1 (Integer 4) Decimal) - (IntegerConstant 10 (Integer 4) Decimal))] + (IntegerBinOp + (IntegerConstant 1 (Integer 4) Decimal) + Mul + (IntegerConstant 10 (Integer 4) Decimal) + (Integer 4) + () + ))] PointerToDataArray ) () diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout index 78549fe8255..63824ac2acd 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout @@ -39,6 +39,8 @@ source_filename = "LFortran" @28 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @29 = private unnamed_addr constant [2 x i8] c"b\00", align 1 @30 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@31 = private unnamed_addr constant [7 x i8] c"driver\00", align 1 +@32 = private unnamed_addr constant [143 x i8] c"Runtime error: Array shape mismatch in subroutine '%s'\0A\0ATried to match size %d of dimension %d of argument number %d, but expected size is %d\0A\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -108,11 +110,24 @@ else6: ; preds = %ifcont4 ifcont7: ; preds = %else6, %then5 %25 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %21 store i32 30, i32* %25, align 4 + %26 = load i32, i32* @main.n, align 4 + %27 = icmp ne i32 3, %26 + br i1 %27, label %then8, label %else9 + +then8: ; preds = %ifcont7 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @32, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @31, i32 0, i32 0), i32 3, i32 1, i32 2, i32 %26) + call void @exit(i32 1) + br label %ifcont10 + +else9: ; preds = %ifcont7 + br label %ifcont10 + +ifcont10: ; preds = %else9, %then8 call void @driver(void (i32*, i32*, i32*)* @implicit_interface_check, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @main.b, i32 0, i32 0), i32* @main.n) call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont7 +return: ; preds = %ifcont10 ret i32 0 } diff --git a/tests/reference/llvm-modules_36-53c9a79.stdout b/tests/reference/llvm-modules_36-53c9a79.stdout index a7dd51c351b..d2ab2b8e245 100644 --- a/tests/reference/llvm-modules_36-53c9a79.stdout +++ b/tests/reference/llvm-modules_36-53c9a79.stdout @@ -45,7 +45,7 @@ loop.body: ; preds = %loop.head br i1 %18, label %then, label %else then: ; preds = %loop.body - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i32 %9, i32 1, i32 1, i32 %15) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i32 %9, i32 1, i32 1, i32 %15) call void @exit(i32 1) br label %ifcont @@ -213,6 +213,17 @@ ifcont14: ; preds = %else13, %then12 br label %loop.head loop.end: ; preds = %ifcont8 + br i1 false, label %then15, label %else16 + +then15: ; preds = %loop.end + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @4, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont17 + +else16: ; preds = %loop.end + br label %ifcont17 + +ifcont17: ; preds = %else16, %then15 %31 = getelementptr [2 x i1], [2 x i1]* %__libasr_created__intrinsic_array_function_Any, i32 0, i32 0 store i32 2, i32* %call_arg_value, align 4 %32 = call i1 @_lcompilers_Any_4_1_0_logical____0(i1* %31, i32* %call_arg_value) @@ -231,7 +242,7 @@ loop.end: ; preds = %ifcont8 %44 = alloca i8*, align 8 store i8* %43, i8** %44, align 8 %45 = alloca i8*, align 8 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @4, i32 0, i32 0), i8** %45, align 8 + store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @6, i32 0, i32 0), i8** %45, align 8 %46 = call i1 @_lpython_str_compare_noteq(i8** %44, i8** %45) %47 = icmp eq i1 %39, false %48 = select i1 %47, i1 %39, i1 %46 @@ -247,18 +258,18 @@ loop.end: ; preds = %ifcont8 %58 = select i1 %57, i1 %50, i1 %56 %59 = icmp eq i1 %33, false %60 = select i1 %59, i1 %58, i1 %33 - br i1 %60, label %then15, label %else16 + br i1 %60, label %then18, label %else19 -then15: ; preds = %loop.end - br label %ifcont17 +then18: ; preds = %ifcont17 + br label %ifcont20 -else16: ; preds = %loop.end - br label %ifcont17 +else19: ; preds = %ifcont17 + br label %ifcont20 -ifcont17: ; preds = %else16, %then15 +ifcont20: ; preds = %else19, %then18 br label %return -return: ; preds = %ifcont17 +return: ; preds = %ifcont20 ret void } diff --git a/tests/reference/run-array_bounds_check_04-2e3d8fb.json b/tests/reference/run-array_bounds_check_04-2e3d8fb.json index 4ef242e4abe..7d14824aec7 100644 --- a/tests/reference/run-array_bounds_check_04-2e3d8fb.json +++ b/tests/reference/run-array_bounds_check_04-2e3d8fb.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "run-array_bounds_check_04-2e3d8fb.stderr", - "stderr_hash": "fa40416f245cb643db75f1c70c4396049945612faf2ac8cdab6e10e3", + "stderr_hash": "8a026a9009f4d0fba284c241930bbd9f47a05f7d33c37e10ce20442c", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr b/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr index b9b6f004c5c..3d2688830e9 100644 --- a/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr +++ b/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr @@ -1,3 +1,3 @@ Runtime error: Array shape mismatch in subroutine 'my' -Tried to match size 4 of dimension 2 of argument number 2, but expected size is 1 +Tried to match size 4 of dimension 2 of argument number 1, but expected size is 1 diff --git a/tests/reference/run-array_bounds_check_05-d584fab.json b/tests/reference/run-array_bounds_check_05-d584fab.json new file mode 100644 index 00000000000..e1d0a0c80c4 --- /dev/null +++ b/tests/reference/run-array_bounds_check_05-d584fab.json @@ -0,0 +1,13 @@ +{ + "basename": "run-array_bounds_check_05-d584fab", + "cmd": "lfortran --no-color {infile}", + "infile": "tests/errors/array_bounds_check_05.f90", + "infile_hash": "9ef4f46c35739ba9241c8707b603e057f3ec10d97212ae6dd2ec1796", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "run-array_bounds_check_05-d584fab.stderr", + "stderr_hash": "166ae5aeea4011063c0748b2d59f4f79c401c28aac2bb692779bdf16", + "returncode": 1 +} \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_05-d584fab.stderr b/tests/reference/run-array_bounds_check_05-d584fab.stderr new file mode 100644 index 00000000000..f775ee3958a --- /dev/null +++ b/tests/reference/run-array_bounds_check_05-d584fab.stderr @@ -0,0 +1,3 @@ +Runtime error: Array shape mismatch in subroutine 'my' + +Tried to match size 3 of dimension 1 of argument number 1, but expected size is 5 diff --git a/tests/tests.toml b/tests/tests.toml index 852c20e32df..6ab1278f972 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -3872,6 +3872,10 @@ run = true filename = "errors/array_bounds_check_04.f90" run = true +[[test]] +filename = "errors/array_bounds_check_05.f90" +run = true + [[test]] filename = "../integration_tests/statement_01.f90" asr_implicit_interface_and_typing = true From 4bb82c384bc89701b0cebae0ba053739ee3e6cc2 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Wed, 23 Jul 2025 10:33:20 +0000 Subject: [PATCH 082/119] fix: make get_past_array_physical_cast recursive to get past nested casts --- src/libasr/asr_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 924988ae700..c141a13b099 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -263,7 +263,7 @@ static inline ASR::expr_t* get_past_array_physical_cast(ASR::expr_t* x) { if( !ASR::is_a(*x) ) { return x; } - return ASR::down_cast(x)->m_arg; + return get_past_array_physical_cast(ASR::down_cast(x)->m_arg); } static inline ASR::expr_t* get_past_array_broadcast(ASR::expr_t* x) { From b81d57c531a474c631ec1c5a9d123b7c32b9162a Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 24 Jul 2025 05:59:29 +0000 Subject: [PATCH 083/119] fix: set dimension descriptor lower bound and size to 1 by default to avoid undefined behaviour --- src/libasr/codegen/llvm_array_utils.cpp | 6 + .../reference/llvm-allocate_03-495d621.stdout | 501 +++++++++--------- 2 files changed, 258 insertions(+), 249 deletions(-) diff --git a/src/libasr/codegen/llvm_array_utils.cpp b/src/libasr/codegen/llvm_array_utils.cpp index 0a1e5f0a819..a28a879f928 100644 --- a/src/libasr/codegen/llvm_array_utils.cpp +++ b/src/libasr/codegen/llvm_array_utils.cpp @@ -422,6 +422,12 @@ namespace LCompilers { llvm::Value* dim_des_first; dim_des_first = llvm_utils->CreateAlloca(*builder, dim_des, llvm_utils->CreateLoad(llvm_ndims)); + + // If unallocated, set lower bound and size to 1. + // This is for entering the loop array_op pass generates to check if array is allocated in ArrayItem at runtime. + builder->CreateStore(llvm::ConstantInt::get(context, llvm::APInt(32, 1)), llvm_utils->create_gep(dim_des_first, 1)); + builder->CreateStore(llvm::ConstantInt::get(context, llvm::APInt(32, 1)), llvm_utils->create_gep(dim_des_first, 2)); + builder->CreateStore(dim_des_first, dim_des_val); builder->CreateStore(llvm::ConstantInt::get(context, llvm::APInt(32, n_dims)), get_rank(arr, true)); } diff --git a/tests/reference/llvm-allocate_03-495d621.stdout b/tests/reference/llvm-allocate_03-495d621.stdout index 57135937307..48db306b8f8 100644 --- a/tests/reference/llvm-allocate_03-495d621.stdout +++ b/tests/reference/llvm-allocate_03-495d621.stdout @@ -61,61 +61,62 @@ define i32 @main(i32 %0, i8** %1) { store i32 3, i32* %3, align 4 %4 = load i32, i32* %3, align 4 %5 = alloca %dimension_descriptor, i32 %4, align 8 + %6 = getelementptr %dimension_descriptor, %dimension_descriptor* %5, i32 0, i32 1 + store i32 1, i32* %6, align 4 + %7 = getelementptr %dimension_descriptor, %dimension_descriptor* %5, i32 0, i32 2 + store i32 1, i32* %7, align 4 store %dimension_descriptor* %5, %dimension_descriptor** %2, align 8 - %6 = getelementptr %array, %array* %arr_desc, i32 0, i32 4 - store i32 3, i32* %6, align 4 - %7 = getelementptr %array, %array* %arr_desc, i32 0, i32 0 - store i32* null, i32** %7, align 8 + %8 = getelementptr %array, %array* %arr_desc, i32 0, i32 4 + store i32 3, i32* %8, align 4 + %9 = getelementptr %array, %array* %arr_desc, i32 0, i32 0 + store i32* null, i32** %9, align 8 store %array* %arr_desc, %array** %c, align 8 %r1 = alloca i32, align 4 %stat2 = alloca i32, align 4 store i32 1, i32* %stat2, align 4 - %8 = load %array*, %array** %c, align 8 - %9 = ptrtoint %array* %8 to i32 - %10 = icmp eq i32 %9, 0 - br i1 %10, label %then, label %else + %10 = load %array*, %array** %c, align 8 + %11 = ptrtoint %array* %10 to i32 + %12 = icmp eq i32 %11, 0 + br i1 %12, label %then, label %else then: ; preds = %.entry - %11 = alloca %array, align 8 - %12 = getelementptr %array, %array* %11, i32 0, i32 2 - %13 = alloca i32, align 4 - store i32 3, i32* %13, align 4 - %14 = load i32, i32* %13, align 4 - %15 = alloca %dimension_descriptor, i32 %14, align 8 - store %dimension_descriptor* %15, %dimension_descriptor** %12, align 8 - %16 = getelementptr %array, %array* %11, i32 0, i32 4 - store i32 3, i32* %16, align 4 - store %array* %11, %array** %c, align 8 + %13 = alloca %array, align 8 + %14 = getelementptr %array, %array* %13, i32 0, i32 2 + %15 = alloca i32, align 4 + store i32 3, i32* %15, align 4 + %16 = load i32, i32* %15, align 4 + %17 = alloca %dimension_descriptor, i32 %16, align 8 + %18 = getelementptr %dimension_descriptor, %dimension_descriptor* %17, i32 0, i32 1 + store i32 1, i32* %18, align 4 + %19 = getelementptr %dimension_descriptor, %dimension_descriptor* %17, i32 0, i32 2 + store i32 1, i32* %19, align 4 + store %dimension_descriptor* %17, %dimension_descriptor** %14, align 8 + %20 = getelementptr %array, %array* %13, i32 0, i32 4 + store i32 3, i32* %20, align 4 + store %array* %13, %array** %c, align 8 br label %ifcont else: ; preds = %.entry br label %ifcont ifcont: ; preds = %else, %then - %17 = load %array*, %array** %c, align 8 - %18 = getelementptr %array, %array* %17, i32 0, i32 1 - store i32 0, i32* %18, align 4 - %19 = getelementptr %array, %array* %17, i32 0, i32 2 - %20 = load %dimension_descriptor*, %dimension_descriptor** %19, align 8 - %21 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %20, i32 0 - %22 = getelementptr %dimension_descriptor, %dimension_descriptor* %21, i32 0, i32 0 - %23 = getelementptr %dimension_descriptor, %dimension_descriptor* %21, i32 0, i32 1 - %24 = getelementptr %dimension_descriptor, %dimension_descriptor* %21, i32 0, i32 2 - store i32 1, i32* %22, align 4 - store i32 1, i32* %23, align 4 - store i32 3, i32* %24, align 4 - %25 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %20, i32 1 + %21 = load %array*, %array** %c, align 8 + %22 = getelementptr %array, %array* %21, i32 0, i32 1 + store i32 0, i32* %22, align 4 + %23 = getelementptr %array, %array* %21, i32 0, i32 2 + %24 = load %dimension_descriptor*, %dimension_descriptor** %23, align 8 + %25 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %24, i32 0 %26 = getelementptr %dimension_descriptor, %dimension_descriptor* %25, i32 0, i32 0 %27 = getelementptr %dimension_descriptor, %dimension_descriptor* %25, i32 0, i32 1 %28 = getelementptr %dimension_descriptor, %dimension_descriptor* %25, i32 0, i32 2 - store i32 3, i32* %26, align 4 + store i32 1, i32* %26, align 4 store i32 1, i32* %27, align 4 store i32 3, i32* %28, align 4 - %29 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %20, i32 2 + %29 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %24, i32 1 %30 = getelementptr %dimension_descriptor, %dimension_descriptor* %29, i32 0, i32 0 %31 = getelementptr %dimension_descriptor, %dimension_descriptor* %29, i32 0, i32 1 %32 = getelementptr %dimension_descriptor, %dimension_descriptor* %29, i32 0, i32 2 - store i32 9, i32* %30, align 4 + store i32 3, i32* %30, align 4 store i32 1, i32* %31, align 4 store i32 3, i32* %32, align 4 %33 = getelementptr %array, %array* %17, i32 0, i32 0 @@ -320,25 +321,25 @@ else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 - %74 = getelementptr %dimension_descriptor, %dimension_descriptor* %63, i32 0, i32 0 - %75 = load i32, i32* %74, align 4 - %76 = mul i32 %75, %68 - %77 = add i32 %62, %76 - %78 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %47, i32 2 - %79 = getelementptr %dimension_descriptor, %dimension_descriptor* %78, i32 0, i32 1 - %80 = load i32, i32* %79, align 4 - %81 = getelementptr %dimension_descriptor, %dimension_descriptor* %78, i32 0, i32 2 - %82 = load i32, i32* %81, align 4 - %83 = sub i32 1, %80 - %84 = add i32 %80, %82 - %85 = sub i32 %84, 1 - %86 = icmp slt i32 1, %80 - %87 = icmp sgt i32 1, %85 - %88 = or i1 %86, %87 - br i1 %88, label %then15, label %else16 + %78 = getelementptr %dimension_descriptor, %dimension_descriptor* %67, i32 0, i32 0 + %79 = load i32, i32* %78, align 4 + %80 = mul i32 %79, %72 + %81 = add i32 %66, %80 + %82 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %51, i32 2 + %83 = getelementptr %dimension_descriptor, %dimension_descriptor* %82, i32 0, i32 1 + %84 = load i32, i32* %83, align 4 + %85 = getelementptr %dimension_descriptor, %dimension_descriptor* %82, i32 0, i32 2 + %86 = load i32, i32* %85, align 4 + %87 = sub i32 1, %84 + %88 = add i32 %84, %86 + %89 = sub i32 %88, 1 + %90 = icmp slt i32 1, %84 + %91 = icmp sgt i32 1, %89 + %92 = or i1 %90, %91 + br i1 %92, label %then15, label %else16 then15: ; preds = %ifcont14 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @100, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @99, i32 0, i32 0), i32 1, i32 3, i32 %80, i32 %85) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @100, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @99, i32 0, i32 0), i32 1, i32 3, i32 %84, i32 %89) call void @exit(i32 1) br label %ifcont17 @@ -346,34 +347,34 @@ else16: ; preds = %ifcont14 br label %ifcont17 ifcont17: ; preds = %else16, %then15 - %89 = getelementptr %dimension_descriptor, %dimension_descriptor* %78, i32 0, i32 0 - %90 = load i32, i32* %89, align 4 - %91 = mul i32 %90, %83 - %92 = add i32 %77, %91 - %93 = getelementptr %array, %array* %40, i32 0, i32 1 + %93 = getelementptr %dimension_descriptor, %dimension_descriptor* %82, i32 0, i32 0 %94 = load i32, i32* %93, align 4 - %95 = add i32 %92, %94 - %96 = getelementptr %array, %array* %40, i32 0, i32 0 - %97 = load i32*, i32** %96, align 8 - %98 = getelementptr inbounds i32, i32* %97, i32 %95 - store i32 3, i32* %98, align 4 - %99 = load %array*, %array** %c, align 8 - %100 = getelementptr %array, %array* %99, i32 0, i32 0 + %95 = mul i32 %94, %87 + %96 = add i32 %81, %95 + %97 = getelementptr %array, %array* %44, i32 0, i32 1 + %98 = load i32, i32* %97, align 4 + %99 = add i32 %96, %98 + %100 = getelementptr %array, %array* %44, i32 0, i32 0 %101 = load i32*, i32** %100, align 8 - %102 = ptrtoint i32* %101 to i64 - %103 = icmp ne i64 %102, 0 - br i1 %103, label %then18, label %else19 + %102 = getelementptr inbounds i32, i32* %101, i32 %99 + store i32 3, i32* %102, align 4 + %103 = load %array*, %array** %c, align 8 + %104 = getelementptr %array, %array* %103, i32 0, i32 0 + %105 = load i32*, i32** %104, align 8 + %106 = ptrtoint i32* %105 to i64 + %107 = icmp ne i64 %106, 0 + br i1 %107, label %then18, label %else19 then18: ; preds = %ifcont17 - %104 = getelementptr %array, %array* %99, i32 0, i32 0 - %105 = load i32*, i32** %104, align 8 - %106 = alloca i8*, align 8 - %107 = bitcast i32* %105 to i8* - store i8* %107, i8** %106, align 8 - %108 = load i8*, i8** %106, align 8 - call void @_lfortran_free(i8* %108) - %109 = getelementptr %array, %array* %99, i32 0, i32 0 - store i32* null, i32** %109, align 8 + %108 = getelementptr %array, %array* %103, i32 0, i32 0 + %109 = load i32*, i32** %108, align 8 + %110 = alloca i8*, align 8 + %111 = bitcast i32* %109 to i8* + store i8* %111, i8** %110, align 8 + %112 = load i8*, i8** %110, align 8 + call void @_lfortran_free(i8* %112) + %113 = getelementptr %array, %array* %103, i32 0, i32 0 + store i32* null, i32** %113, align 8 br label %ifcont20 else19: ; preds = %ifcont17 @@ -381,15 +382,15 @@ else19: ; preds = %ifcont17 ifcont20: ; preds = %else19, %then18 call void @h(%array** %c) - %110 = call i32 @g(%array** %c) - store i32 %110, i32* %r1, align 4 - %111 = load %array*, %array** %c, align 8 - %112 = getelementptr %array, %array* %111, i32 0, i32 0 - %113 = load i32*, i32** %112, align 8 - %114 = ptrtoint i32* %113 to i64 - %115 = icmp ne i64 %114, 0 - %116 = xor i1 %115, true - br i1 %116, label %then21, label %else22 + %114 = call i32 @g(%array** %c) + store i32 %114, i32* %r1, align 4 + %115 = load %array*, %array** %c, align 8 + %116 = getelementptr %array, %array* %115, i32 0, i32 0 + %117 = load i32*, i32** %116, align 8 + %118 = ptrtoint i32* %117 to i64 + %119 = icmp ne i64 %118, 0 + %120 = xor i1 %119, true + br i1 %120, label %then21, label %else22 then21: ; preds = %ifcont20 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @102, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @101, i32 0, i32 0)) @@ -400,23 +401,23 @@ else22: ; preds = %ifcont20 br label %ifcont23 ifcont23: ; preds = %else22, %then21 - %117 = getelementptr %array, %array* %111, i32 0, i32 2 - %118 = load %dimension_descriptor*, %dimension_descriptor** %117, align 8 - %119 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %118, i32 0 - %120 = getelementptr %dimension_descriptor, %dimension_descriptor* %119, i32 0, i32 1 - %121 = load i32, i32* %120, align 4 - %122 = getelementptr %dimension_descriptor, %dimension_descriptor* %119, i32 0, i32 2 - %123 = load i32, i32* %122, align 4 - %124 = sub i32 1, %121 - %125 = add i32 %121, %123 - %126 = sub i32 %125, 1 - %127 = icmp slt i32 1, %121 - %128 = icmp sgt i32 1, %126 - %129 = or i1 %127, %128 - br i1 %129, label %then24, label %else25 + %121 = getelementptr %array, %array* %115, i32 0, i32 2 + %122 = load %dimension_descriptor*, %dimension_descriptor** %121, align 8 + %123 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %122, i32 0 + %124 = getelementptr %dimension_descriptor, %dimension_descriptor* %123, i32 0, i32 1 + %125 = load i32, i32* %124, align 4 + %126 = getelementptr %dimension_descriptor, %dimension_descriptor* %123, i32 0, i32 2 + %127 = load i32, i32* %126, align 4 + %128 = sub i32 1, %125 + %129 = add i32 %125, %127 + %130 = sub i32 %129, 1 + %131 = icmp slt i32 1, %125 + %132 = icmp sgt i32 1, %130 + %133 = or i1 %131, %132 + br i1 %133, label %then24, label %else25 then24: ; preds = %ifcont23 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @103, i32 0, i32 0), i32 1, i32 1, i32 %121, i32 %126) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @103, i32 0, i32 0), i32 1, i32 1, i32 %125, i32 %130) call void @exit(i32 1) br label %ifcont26 @@ -424,25 +425,25 @@ else25: ; preds = %ifcont23 br label %ifcont26 ifcont26: ; preds = %else25, %then24 - %130 = getelementptr %dimension_descriptor, %dimension_descriptor* %119, i32 0, i32 0 - %131 = load i32, i32* %130, align 4 - %132 = mul i32 %131, %124 - %133 = add i32 0, %132 - %134 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %118, i32 1 - %135 = getelementptr %dimension_descriptor, %dimension_descriptor* %134, i32 0, i32 1 - %136 = load i32, i32* %135, align 4 - %137 = getelementptr %dimension_descriptor, %dimension_descriptor* %134, i32 0, i32 2 - %138 = load i32, i32* %137, align 4 - %139 = sub i32 1, %136 - %140 = add i32 %136, %138 - %141 = sub i32 %140, 1 - %142 = icmp slt i32 1, %136 - %143 = icmp sgt i32 1, %141 - %144 = or i1 %142, %143 - br i1 %144, label %then27, label %else28 + %134 = getelementptr %dimension_descriptor, %dimension_descriptor* %123, i32 0, i32 0 + %135 = load i32, i32* %134, align 4 + %136 = mul i32 %135, %128 + %137 = add i32 0, %136 + %138 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %122, i32 1 + %139 = getelementptr %dimension_descriptor, %dimension_descriptor* %138, i32 0, i32 1 + %140 = load i32, i32* %139, align 4 + %141 = getelementptr %dimension_descriptor, %dimension_descriptor* %138, i32 0, i32 2 + %142 = load i32, i32* %141, align 4 + %143 = sub i32 1, %140 + %144 = add i32 %140, %142 + %145 = sub i32 %144, 1 + %146 = icmp slt i32 1, %140 + %147 = icmp sgt i32 1, %145 + %148 = or i1 %146, %147 + br i1 %148, label %then27, label %else28 then27: ; preds = %ifcont26 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0), i32 1, i32 2, i32 %136, i32 %141) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0), i32 1, i32 2, i32 %140, i32 %145) call void @exit(i32 1) br label %ifcont29 @@ -450,25 +451,25 @@ else28: ; preds = %ifcont26 br label %ifcont29 ifcont29: ; preds = %else28, %then27 - %145 = getelementptr %dimension_descriptor, %dimension_descriptor* %134, i32 0, i32 0 - %146 = load i32, i32* %145, align 4 - %147 = mul i32 %146, %139 - %148 = add i32 %133, %147 - %149 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %118, i32 2 - %150 = getelementptr %dimension_descriptor, %dimension_descriptor* %149, i32 0, i32 1 - %151 = load i32, i32* %150, align 4 - %152 = getelementptr %dimension_descriptor, %dimension_descriptor* %149, i32 0, i32 2 - %153 = load i32, i32* %152, align 4 - %154 = sub i32 1, %151 - %155 = add i32 %151, %153 - %156 = sub i32 %155, 1 - %157 = icmp slt i32 1, %151 - %158 = icmp sgt i32 1, %156 - %159 = or i1 %157, %158 - br i1 %159, label %then30, label %else31 + %149 = getelementptr %dimension_descriptor, %dimension_descriptor* %138, i32 0, i32 0 + %150 = load i32, i32* %149, align 4 + %151 = mul i32 %150, %143 + %152 = add i32 %137, %151 + %153 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %122, i32 2 + %154 = getelementptr %dimension_descriptor, %dimension_descriptor* %153, i32 0, i32 1 + %155 = load i32, i32* %154, align 4 + %156 = getelementptr %dimension_descriptor, %dimension_descriptor* %153, i32 0, i32 2 + %157 = load i32, i32* %156, align 4 + %158 = sub i32 1, %155 + %159 = add i32 %155, %157 + %160 = sub i32 %159, 1 + %161 = icmp slt i32 1, %155 + %162 = icmp sgt i32 1, %160 + %163 = or i1 %161, %162 + br i1 %163, label %then30, label %else31 then30: ; preds = %ifcont29 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 1, i32 3, i32 %151, i32 %156) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 1, i32 3, i32 %155, i32 %160) call void @exit(i32 1) br label %ifcont32 @@ -476,19 +477,19 @@ else31: ; preds = %ifcont29 br label %ifcont32 ifcont32: ; preds = %else31, %then30 - %160 = getelementptr %dimension_descriptor, %dimension_descriptor* %149, i32 0, i32 0 - %161 = load i32, i32* %160, align 4 - %162 = mul i32 %161, %154 - %163 = add i32 %148, %162 - %164 = getelementptr %array, %array* %111, i32 0, i32 1 + %164 = getelementptr %dimension_descriptor, %dimension_descriptor* %153, i32 0, i32 0 %165 = load i32, i32* %164, align 4 - %166 = add i32 %163, %165 - %167 = getelementptr %array, %array* %111, i32 0, i32 0 - %168 = load i32*, i32** %167, align 8 - %169 = getelementptr inbounds i32, i32* %168, i32 %166 - %170 = load i32, i32* %169, align 4 - %171 = icmp ne i32 %170, 8 - br i1 %171, label %then33, label %else34 + %166 = mul i32 %165, %158 + %167 = add i32 %152, %166 + %168 = getelementptr %array, %array* %115, i32 0, i32 1 + %169 = load i32, i32* %168, align 4 + %170 = add i32 %167, %169 + %171 = getelementptr %array, %array* %115, i32 0, i32 0 + %172 = load i32*, i32** %171, align 8 + %173 = getelementptr inbounds i32, i32* %172, i32 %170 + %174 = load i32, i32* %173, align 4 + %175 = icmp ne i32 %174, 8 + br i1 %175, label %then33, label %else34 then33: ; preds = %ifcont32 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @109, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @110, i32 0, i32 0)) @@ -499,13 +500,13 @@ else34: ; preds = %ifcont32 br label %ifcont35 ifcont35: ; preds = %else34, %then33 - %172 = load %array*, %array** %c, align 8 - %173 = getelementptr %array, %array* %172, i32 0, i32 0 - %174 = load i32*, i32** %173, align 8 - %175 = ptrtoint i32* %174 to i64 - %176 = icmp ne i64 %175, 0 - %177 = xor i1 %176, true - br i1 %177, label %then36, label %else37 + %176 = load %array*, %array** %c, align 8 + %177 = getelementptr %array, %array* %176, i32 0, i32 0 + %178 = load i32*, i32** %177, align 8 + %179 = ptrtoint i32* %178 to i64 + %180 = icmp ne i64 %179, 0 + %181 = xor i1 %180, true + br i1 %181, label %then36, label %else37 then36: ; preds = %ifcont35 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @114, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @113, i32 0, i32 0)) @@ -516,23 +517,23 @@ else37: ; preds = %ifcont35 br label %ifcont38 ifcont38: ; preds = %else37, %then36 - %178 = getelementptr %array, %array* %172, i32 0, i32 2 - %179 = load %dimension_descriptor*, %dimension_descriptor** %178, align 8 - %180 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %179, i32 0 - %181 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 1 - %182 = load i32, i32* %181, align 4 - %183 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 2 - %184 = load i32, i32* %183, align 4 - %185 = sub i32 1, %182 - %186 = add i32 %182, %184 - %187 = sub i32 %186, 1 - %188 = icmp slt i32 1, %182 - %189 = icmp sgt i32 1, %187 - %190 = or i1 %188, %189 - br i1 %190, label %then39, label %else40 + %182 = getelementptr %array, %array* %176, i32 0, i32 2 + %183 = load %dimension_descriptor*, %dimension_descriptor** %182, align 8 + %184 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %183, i32 0 + %185 = getelementptr %dimension_descriptor, %dimension_descriptor* %184, i32 0, i32 1 + %186 = load i32, i32* %185, align 4 + %187 = getelementptr %dimension_descriptor, %dimension_descriptor* %184, i32 0, i32 2 + %188 = load i32, i32* %187, align 4 + %189 = sub i32 1, %186 + %190 = add i32 %186, %188 + %191 = sub i32 %190, 1 + %192 = icmp slt i32 1, %186 + %193 = icmp sgt i32 1, %191 + %194 = or i1 %192, %193 + br i1 %194, label %then39, label %else40 then39: ; preds = %ifcont38 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @116, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @115, i32 0, i32 0), i32 1, i32 1, i32 %182, i32 %187) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @116, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @115, i32 0, i32 0), i32 1, i32 1, i32 %186, i32 %191) call void @exit(i32 1) br label %ifcont41 @@ -540,25 +541,25 @@ else40: ; preds = %ifcont38 br label %ifcont41 ifcont41: ; preds = %else40, %then39 - %191 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 0 - %192 = load i32, i32* %191, align 4 - %193 = mul i32 %192, %185 - %194 = add i32 0, %193 - %195 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %179, i32 1 - %196 = getelementptr %dimension_descriptor, %dimension_descriptor* %195, i32 0, i32 1 - %197 = load i32, i32* %196, align 4 - %198 = getelementptr %dimension_descriptor, %dimension_descriptor* %195, i32 0, i32 2 - %199 = load i32, i32* %198, align 4 - %200 = sub i32 1, %197 - %201 = add i32 %197, %199 - %202 = sub i32 %201, 1 - %203 = icmp slt i32 1, %197 - %204 = icmp sgt i32 1, %202 - %205 = or i1 %203, %204 - br i1 %205, label %then42, label %else43 + %195 = getelementptr %dimension_descriptor, %dimension_descriptor* %184, i32 0, i32 0 + %196 = load i32, i32* %195, align 4 + %197 = mul i32 %196, %189 + %198 = add i32 0, %197 + %199 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %183, i32 1 + %200 = getelementptr %dimension_descriptor, %dimension_descriptor* %199, i32 0, i32 1 + %201 = load i32, i32* %200, align 4 + %202 = getelementptr %dimension_descriptor, %dimension_descriptor* %199, i32 0, i32 2 + %203 = load i32, i32* %202, align 4 + %204 = sub i32 1, %201 + %205 = add i32 %201, %203 + %206 = sub i32 %205, 1 + %207 = icmp slt i32 1, %201 + %208 = icmp sgt i32 1, %206 + %209 = or i1 %207, %208 + br i1 %209, label %then42, label %else43 then42: ; preds = %ifcont41 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @118, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @117, i32 0, i32 0), i32 1, i32 2, i32 %197, i32 %202) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @118, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @117, i32 0, i32 0), i32 1, i32 2, i32 %201, i32 %206) call void @exit(i32 1) br label %ifcont44 @@ -566,25 +567,25 @@ else43: ; preds = %ifcont41 br label %ifcont44 ifcont44: ; preds = %else43, %then42 - %206 = getelementptr %dimension_descriptor, %dimension_descriptor* %195, i32 0, i32 0 - %207 = load i32, i32* %206, align 4 - %208 = mul i32 %207, %200 - %209 = add i32 %194, %208 - %210 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %179, i32 2 - %211 = getelementptr %dimension_descriptor, %dimension_descriptor* %210, i32 0, i32 1 - %212 = load i32, i32* %211, align 4 - %213 = getelementptr %dimension_descriptor, %dimension_descriptor* %210, i32 0, i32 2 - %214 = load i32, i32* %213, align 4 - %215 = sub i32 1, %212 - %216 = add i32 %212, %214 - %217 = sub i32 %216, 1 - %218 = icmp slt i32 1, %212 - %219 = icmp sgt i32 1, %217 - %220 = or i1 %218, %219 - br i1 %220, label %then45, label %else46 + %210 = getelementptr %dimension_descriptor, %dimension_descriptor* %199, i32 0, i32 0 + %211 = load i32, i32* %210, align 4 + %212 = mul i32 %211, %204 + %213 = add i32 %198, %212 + %214 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %183, i32 2 + %215 = getelementptr %dimension_descriptor, %dimension_descriptor* %214, i32 0, i32 1 + %216 = load i32, i32* %215, align 4 + %217 = getelementptr %dimension_descriptor, %dimension_descriptor* %214, i32 0, i32 2 + %218 = load i32, i32* %217, align 4 + %219 = sub i32 1, %216 + %220 = add i32 %216, %218 + %221 = sub i32 %220, 1 + %222 = icmp slt i32 1, %216 + %223 = icmp sgt i32 1, %221 + %224 = or i1 %222, %223 + br i1 %224, label %then45, label %else46 then45: ; preds = %ifcont44 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @120, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @119, i32 0, i32 0), i32 1, i32 3, i32 %212, i32 %217) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @120, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @119, i32 0, i32 0), i32 1, i32 3, i32 %216, i32 %221) call void @exit(i32 1) br label %ifcont47 @@ -592,38 +593,38 @@ else46: ; preds = %ifcont44 br label %ifcont47 ifcont47: ; preds = %else46, %then45 - %221 = getelementptr %dimension_descriptor, %dimension_descriptor* %210, i32 0, i32 0 - %222 = load i32, i32* %221, align 4 - %223 = mul i32 %222, %215 - %224 = add i32 %209, %223 - %225 = getelementptr %array, %array* %172, i32 0, i32 1 + %225 = getelementptr %dimension_descriptor, %dimension_descriptor* %214, i32 0, i32 0 %226 = load i32, i32* %225, align 4 - %227 = add i32 %224, %226 - %228 = getelementptr %array, %array* %172, i32 0, i32 0 - %229 = load i32*, i32** %228, align 8 - %230 = getelementptr inbounds i32, i32* %229, i32 %227 - %231 = load i32, i32* %230, align 4 - %232 = alloca i32, align 4 - store i32 %231, i32* %232, align 4 - %233 = call i8* (i8*, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.3, i32 0, i32 0), i32 0, i32 0, i32* %232) - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @121, i32 0, i32 0), i8* %233, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0)) - %234 = load %array*, %array** %c, align 8 - %235 = getelementptr %array, %array* %234, i32 0, i32 0 - %236 = load i32*, i32** %235, align 8 - %237 = ptrtoint i32* %236 to i64 - %238 = icmp ne i64 %237, 0 - br i1 %238, label %then48, label %else49 + %227 = mul i32 %226, %219 + %228 = add i32 %213, %227 + %229 = getelementptr %array, %array* %176, i32 0, i32 1 + %230 = load i32, i32* %229, align 4 + %231 = add i32 %228, %230 + %232 = getelementptr %array, %array* %176, i32 0, i32 0 + %233 = load i32*, i32** %232, align 8 + %234 = getelementptr inbounds i32, i32* %233, i32 %231 + %235 = load i32, i32* %234, align 4 + %236 = alloca i32, align 4 + store i32 %235, i32* %236, align 4 + %237 = call i8* (i8*, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.3, i32 0, i32 0), i32 0, i32 0, i32* %236) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @121, i32 0, i32 0), i8* %237, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0)) + %238 = load %array*, %array** %c, align 8 + %239 = getelementptr %array, %array* %238, i32 0, i32 0 + %240 = load i32*, i32** %239, align 8 + %241 = ptrtoint i32* %240 to i64 + %242 = icmp ne i64 %241, 0 + br i1 %242, label %then48, label %else49 then48: ; preds = %ifcont47 - %239 = getelementptr %array, %array* %234, i32 0, i32 0 - %240 = load i32*, i32** %239, align 8 - %241 = alloca i8*, align 8 - %242 = bitcast i32* %240 to i8* - store i8* %242, i8** %241, align 8 - %243 = load i8*, i8** %241, align 8 - call void @_lfortran_free(i8* %243) - %244 = getelementptr %array, %array* %234, i32 0, i32 0 - store i32* null, i32** %244, align 8 + %243 = getelementptr %array, %array* %238, i32 0, i32 0 + %244 = load i32*, i32** %243, align 8 + %245 = alloca i8*, align 8 + %246 = bitcast i32* %244 to i8* + store i8* %246, i8** %245, align 8 + %247 = load i8*, i8** %245, align 8 + call void @_lfortran_free(i8* %247) + %248 = getelementptr %array, %array* %238, i32 0, i32 0 + store i32* null, i32** %248, align 8 br label %ifcont50 else49: ; preds = %ifcont47 @@ -651,9 +652,13 @@ then: ; preds = %.entry store i32 3, i32* %5, align 4 %6 = load i32, i32* %5, align 4 %7 = alloca %dimension_descriptor, i32 %6, align 8 + %8 = getelementptr %dimension_descriptor, %dimension_descriptor* %7, i32 0, i32 1 + store i32 1, i32* %8, align 4 + %9 = getelementptr %dimension_descriptor, %dimension_descriptor* %7, i32 0, i32 2 + store i32 1, i32* %9, align 4 store %dimension_descriptor* %7, %dimension_descriptor** %4, align 8 - %8 = getelementptr %array, %array* %3, i32 0, i32 4 - store i32 3, i32* %8, align 4 + %10 = getelementptr %array, %array* %3, i32 0, i32 4 + store i32 3, i32* %10, align 4 store %array* %3, %array** %c, align 8 br label %ifcont @@ -661,24 +666,22 @@ else: ; preds = %.entry br label %ifcont ifcont: ; preds = %else, %then - %9 = load %array*, %array** %c, align 8 - %10 = getelementptr %array, %array* %9, i32 0, i32 1 - store i32 0, i32* %10, align 4 - %11 = getelementptr %array, %array* %9, i32 0, i32 2 - %12 = load %dimension_descriptor*, %dimension_descriptor** %11, align 8 - %13 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %12, i32 0 - %14 = getelementptr %dimension_descriptor, %dimension_descriptor* %13, i32 0, i32 0 - %15 = getelementptr %dimension_descriptor, %dimension_descriptor* %13, i32 0, i32 1 - %16 = getelementptr %dimension_descriptor, %dimension_descriptor* %13, i32 0, i32 2 - store i32 1, i32* %14, align 4 - store i32 1, i32* %15, align 4 - store i32 3, i32* %16, align 4 - %17 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %12, i32 1 - %18 = getelementptr %dimension_descriptor, %dimension_descriptor* %17, i32 0, i32 0 - %19 = getelementptr %dimension_descriptor, %dimension_descriptor* %17, i32 0, i32 1 - %20 = getelementptr %dimension_descriptor, %dimension_descriptor* %17, i32 0, i32 2 + %11 = load %array*, %array** %c, align 8 + %12 = getelementptr %array, %array* %11, i32 0, i32 1 + store i32 0, i32* %12, align 4 + %13 = getelementptr %array, %array* %11, i32 0, i32 2 + %14 = load %dimension_descriptor*, %dimension_descriptor** %13, align 8 + %15 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %14, i32 0 + %16 = getelementptr %dimension_descriptor, %dimension_descriptor* %15, i32 0, i32 0 + %17 = getelementptr %dimension_descriptor, %dimension_descriptor* %15, i32 0, i32 1 + %18 = getelementptr %dimension_descriptor, %dimension_descriptor* %15, i32 0, i32 2 + store i32 1, i32* %16, align 4 + store i32 1, i32* %17, align 4 store i32 3, i32* %18, align 4 - store i32 1, i32* %19, align 4 + %19 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %14, i32 1 + %20 = getelementptr %dimension_descriptor, %dimension_descriptor* %19, i32 0, i32 0 + %21 = getelementptr %dimension_descriptor, %dimension_descriptor* %19, i32 0, i32 1 + %22 = getelementptr %dimension_descriptor, %dimension_descriptor* %19, i32 0, i32 2 store i32 3, i32* %20, align 4 %21 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %12, i32 2 %22 = getelementptr %dimension_descriptor, %dimension_descriptor* %21, i32 0, i32 0 From 850091e7ff3f2743bbd57bffb8a10895d46f1d32 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 24 Jul 2025 07:16:24 +0000 Subject: [PATCH 084/119] feat: force ArrayPhysicalCast to have dimensions if not in a call --- src/libasr/asr_verify.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index 2a5cea57fa7..dabd118068d 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -57,6 +57,8 @@ class VerifyVisitor : public BaseWalkVisitor bool non_global_symbol_visited; bool _return_var_or_intent_out = false; bool _processing_dims = false; + bool _inside_call = false; + bool _inside_array_physical_cast_type = false; const ASR::expr_t* current_expr {}; // current expression being visited public: @@ -979,11 +981,14 @@ class VerifyVisitor : public BaseWalkVisitor } } + bool _inside_call_copy = _inside_call; + _inside_call = true; for (size_t i=0; i require(x.m_old == ASRUtils::extract_physical_type(ASRUtils::expr_type(x.m_arg)), "Old physical type conflicts with the physical type of argument " + std::to_string(x.m_old) + " " + std::to_string(ASRUtils::extract_physical_type(ASRUtils::expr_type(x.m_arg)))); + bool _inside_array_physical_cast_type_copy = _inside_array_physical_cast_type; + _inside_array_physical_cast_type = true; + visit_ttype(*x.m_type); + _inside_array_physical_cast_type = _inside_array_physical_cast_type_copy; } } @@ -1103,7 +1112,10 @@ class VerifyVisitor : public BaseWalkVisitor ::get_verify_function(x.m_intrinsic_id); LCOMPILERS_ASSERT(verify_ != nullptr); verify_(x, diagnostics); + bool _inside_call_copy = _inside_call; + _inside_call = true; BaseWalkVisitor::visit_IntrinsicElementalFunction(x); + _inside_call = _inside_call_copy; } void visit_IntrinsicArrayFunction(const ASR::IntrinsicArrayFunction_t& x) { @@ -1115,7 +1127,10 @@ class VerifyVisitor : public BaseWalkVisitor ::get_verify_function(x.m_arr_intrinsic_id); LCOMPILERS_ASSERT(verify_ != nullptr); verify_(x, diagnostics); + bool _inside_call_copy = _inside_call; + _inside_call = true; BaseWalkVisitor::visit_IntrinsicArrayFunction(x); + _inside_call = _inside_call_copy; } void visit_FunctionCall(const FunctionCall_t &x) { @@ -1206,6 +1221,11 @@ class VerifyVisitor : public BaseWalkVisitor } void visit_dimension(const dimension_t &x) { + if (_inside_array_physical_cast_type && !_inside_call) { + require_with_loc(x.m_length != nullptr && x.m_start != nullptr, + "Dimensions in ArrayPhysicalCast must be present if not inside a call", + x.loc); + } if (x.m_start) { if(check_external){ require_with_loc(ASRUtils::is_integer( From 138bd0ed50f4820d30b9b237eff62f65a6538514 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 24 Jul 2025 09:59:04 +0000 Subject: [PATCH 085/119] tests: skip bounds checking in some openmp tests --- integration_tests/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index c561ec0b2bf..47dfcc9db6b 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2505,11 +2505,11 @@ RUN(NAME openmp_60 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_61 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_62 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_63 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) -RUN(NAME openmp_64 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) -RUN(NAME openmp_65 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) +RUN(NAME openmp_64 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME openmp_65 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp EXTRA_ARGS --no-array-bounds-checking) RUN(NAME openmp_66 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_67 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) -RUN(NAME openmp_68 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) +RUN(NAME openmp_68 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp EXTRA_ARGS --no-array-bounds-checking) RUN(NAME openmp_69 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_70 LABELS target_offload) RUN(NAME openmp_71 LABELS target_offload) From 72e2d1ce072417a08172d13624d87d8014067fcb Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 24 Jul 2025 11:48:08 +0000 Subject: [PATCH 086/119] tests: uncomment tests which fail with bounds checking --- integration_tests/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 47dfcc9db6b..786962d206e 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -987,8 +987,8 @@ RUN(NAME intrinsics_144 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # RUN(NAME intrinsics_145 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # dot_product RUN(NAME intrinsics_146 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # dprod RUN(NAME intrinsics_147 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack -# FIXME: Multi dimensional ArrayConstant is not supported -# RUN(NAME intrinsics_148 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack +# FIXME: Fails with array bounds checking. Multi dimensional ArrayConstant is not supported. +RUN(NAME intrinsics_148 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) # pack RUN(NAME intrinsics_149 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # unpack RUN(NAME intrinsics_150 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # maskr RUN(NAME intrinsics_151 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # maskl @@ -1129,7 +1129,7 @@ RUN(NAME intrinsics_284 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # acosh RUN(NAME intrinsics_285 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # real RUN(NAME intrinsics_286 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # atanh # FIXME:Fix this test with --array-bounds-checking (https://github.com/lfortran/lfortran/pull/7955#issuecomment-3036967309) -# RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # spread +RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran EXTRA_ARGS --no-array-bounds-checking) # spread RUN(NAME intrinsics_289 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # ishftc RUN(NAME intrinsics_290 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # log10 RUN(NAME intrinsics_291 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # gamma From b1789b69315d7c85ecee7d0a10dbd0adca319a58 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Fri, 25 Jul 2025 06:16:50 +0000 Subject: [PATCH 087/119] tests: update references after rebase --- tests/reference/llvm-allocate_03-495d621.json | 2 +- .../reference/llvm-allocate_03-495d621.stdout | 2195 +++++++++++------ tests/reference/llvm-arrays_01-91893af.json | 2 +- tests/reference/llvm-arrays_01-91893af.stdout | 524 ++-- .../llvm-arrays_01_complex-c90dbdd.json | 2 +- .../llvm-arrays_01_complex-c90dbdd.stdout | 1808 ++++++++------ .../llvm-arrays_01_logical-f19a63d.json | 2 +- .../llvm-arrays_01_logical-f19a63d.stdout | 942 ++++--- .../llvm-arrays_01_real-6c5e850.json | 2 +- .../llvm-arrays_01_real-6c5e850.stdout | 772 +++--- .../llvm-arrays_01_size-aaed99f.json | 2 +- .../llvm-arrays_01_size-aaed99f.stdout | 544 ++-- .../llvm-implicit_interface_04-9b6786e.json | 2 +- .../llvm-implicit_interface_04-9b6786e.stdout | 154 +- tests/reference/llvm-modules_36-53c9a79.json | 2 +- .../reference/llvm-modules_36-53c9a79.stdout | 95 +- 16 files changed, 3998 insertions(+), 3052 deletions(-) diff --git a/tests/reference/llvm-allocate_03-495d621.json b/tests/reference/llvm-allocate_03-495d621.json index c76af6f0ff1..147101ec475 100644 --- a/tests/reference/llvm-allocate_03-495d621.json +++ b/tests/reference/llvm-allocate_03-495d621.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-allocate_03-495d621.stdout", - "stdout_hash": "7e9dfde5e4c77377cbcd57070d3c2b1fd806824df8f2519febbd6202", + "stdout_hash": "001b1c61316bee5096e87ac97fc71b11d4b5c21bcbf576415a185832", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-allocate_03-495d621.stdout b/tests/reference/llvm-allocate_03-495d621.stdout index 48db306b8f8..2b86745d65d 100644 --- a/tests/reference/llvm-allocate_03-495d621.stdout +++ b/tests/reference/llvm-allocate_03-495d621.stdout @@ -5,48 +5,144 @@ source_filename = "LFortran" %array = type { i32*, i32, %dimension_descriptor*, i1, i32 } %dimension_descriptor = type { i32, i32, i32 } -@0 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@0 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@1 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@2 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@3 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@5 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@6 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@7 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@8 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 @serialization_info = private unnamed_addr constant [3 x i8] c"I4\00", align 1 -@1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@9 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@10 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@11 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@12 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@13 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@14 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@15 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@16 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@17 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@18 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@19 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@20 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@21 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@22 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@23 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@24 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@25 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data = private constant [11 x i8] c"ERROR STOP\00" @string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data, i32 0, i32 0), i64 10 }> @string_const_data.1 = private constant [2 x i8] c"\0A\00" @string_const.2 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.1, i32 0, i32 0), i64 1 }> -@2 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 -@3 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@26 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@27 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 @serialization_info.3 = private unnamed_addr constant [3 x i8] c"I4\00", align 1 -@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@28 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@29 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@30 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@31 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@32 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@33 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@34 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@35 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@36 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@37 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@38 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@39 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@40 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@41 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@42 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@43 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@44 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.4 = private constant [11 x i8] c"ERROR STOP\00" @string_const.5 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.4, i32 0, i32 0), i64 10 }> @string_const_data.6 = private constant [2 x i8] c"\0A\00" @string_const.7 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.6, i32 0, i32 0), i64 1 }> -@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@45 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@46 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@47 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@48 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@49 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@50 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@51 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@52 = private unnamed_addr constant [2 x i8] c"x\00", align 1 +@53 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.8 = private constant [11 x i8] c"ERROR STOP\00" @string_const.9 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.8, i32 0, i32 0), i64 10 }> @string_const_data.10 = private constant [2 x i8] c"\0A\00" @string_const.11 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.10, i32 0, i32 0), i64 1 }> -@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 -@7 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@54 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@55 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 @serialization_info.12 = private unnamed_addr constant [3 x i8] c"I4\00", align 1 -@8 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@56 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@57 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@58 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@59 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@60 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@61 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@62 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@63 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@64 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@65 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@66 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@67 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@68 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@69 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@70 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@71 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@72 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.13 = private constant [11 x i8] c"ERROR STOP\00" @string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.13, i32 0, i32 0), i64 10 }> @string_const_data.15 = private constant [2 x i8] c"\0A\00" @string_const.16 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.15, i32 0, i32 0), i64 1 }> -@9 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@73 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@74 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@75 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@76 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@77 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@78 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@79 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@80 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@81 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.17 = private constant [11 x i8] c"ERROR STOP\00" @string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.17, i32 0, i32 0), i64 10 }> @string_const_data.19 = private constant [2 x i8] c"\0A\00" @string_const.20 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.19, i32 0, i32 0), i64 1 }> -@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@82 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@83 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@84 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@85 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@86 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@87 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@88 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@89 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@90 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@91 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@92 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@93 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@94 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@95 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@96 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@97 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@98 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.21 = private constant [11 x i8] c"ERROR STOP\00" @string_const.22 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.21, i32 0, i32 0), i64 10 }> @string_const_data.23 = private constant [2 x i8] c"\0A\00" @string_const.24 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.23, i32 0, i32 0), i64 1 }> -@11 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 -@12 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@99 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@100 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 @serialization_info.25 = private unnamed_addr constant [3 x i8] c"I4\00", align 1 -@13 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@101 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@102 = private unnamed_addr constant [45 x i8] c"Runtime Error: Array '%s' is not allocated.\0A\00", align 1 +@103 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@104 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@105 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@106 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@107 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@108 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@109 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -119,23 +215,30 @@ ifcont: ; preds = %else, %then store i32 3, i32* %30, align 4 store i32 1, i32* %31, align 4 store i32 3, i32* %32, align 4 - %33 = getelementptr %array, %array* %17, i32 0, i32 0 - %34 = alloca i32, align 4 - store i32 108, i32* %34, align 4 - %35 = load i32, i32* %34, align 4 - %36 = sext i32 %35 to i64 - %37 = call i8* @_lfortran_malloc(i64 %36) - %38 = bitcast i8* %37 to i32* - store i32* %38, i32** %33, align 8 + %33 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %24, i32 2 + %34 = getelementptr %dimension_descriptor, %dimension_descriptor* %33, i32 0, i32 0 + %35 = getelementptr %dimension_descriptor, %dimension_descriptor* %33, i32 0, i32 1 + %36 = getelementptr %dimension_descriptor, %dimension_descriptor* %33, i32 0, i32 2 + store i32 9, i32* %34, align 4 + store i32 1, i32* %35, align 4 + store i32 3, i32* %36, align 4 + %37 = getelementptr %array, %array* %21, i32 0, i32 0 + %38 = alloca i32, align 4 + store i32 108, i32* %38, align 4 + %39 = load i32, i32* %38, align 4 + %40 = sext i32 %39 to i64 + %41 = call i8* @_lfortran_malloc(i64 %40) + %42 = bitcast i8* %41 to i32* + store i32* %42, i32** %37, align 8 store i32 0, i32* %stat2, align 4 - %39 = load i32, i32* %stat2, align 4 - %40 = icmp ne i32 %39, 0 - br i1 %40, label %then3, label %else4 + %43 = load i32, i32* %stat2, align 4 + %44 = icmp ne i32 %43, 0 + br i1 %44, label %then3, label %else4 then3: ; preds = %ifcont - %41 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 - %42 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %41, i8* %42) + %45 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 + %46 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @82, i32 0, i32 0), i8* %45, i8* %46) call void @exit(i32 1) br label %ifcont5 @@ -143,107 +246,40 @@ else4: ; preds = %ifcont br label %ifcont5 ifcont5: ; preds = %else4, %then3 - %43 = load %array*, %array** %c, align 8 - %44 = getelementptr %array, %array* %43, i32 0, i32 2 - %45 = load %dimension_descriptor*, %dimension_descriptor** %44, align 8 - %46 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %45, i32 0 - %47 = getelementptr %dimension_descriptor, %dimension_descriptor* %46, i32 0, i32 1 - %48 = load i32, i32* %47, align 4 - %49 = sub i32 1, %48 - %50 = getelementptr %dimension_descriptor, %dimension_descriptor* %46, i32 0, i32 0 - %51 = load i32, i32* %50, align 4 - %52 = mul i32 %51, %49 - %53 = add i32 0, %52 - %54 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %45, i32 1 - %55 = getelementptr %dimension_descriptor, %dimension_descriptor* %54, i32 0, i32 1 - %56 = load i32, i32* %55, align 4 - %57 = sub i32 1, %56 - %58 = getelementptr %dimension_descriptor, %dimension_descriptor* %54, i32 0, i32 0 - %59 = load i32, i32* %58, align 4 - %60 = mul i32 %59, %57 - %61 = add i32 %53, %60 - %62 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %45, i32 2 - %63 = getelementptr %dimension_descriptor, %dimension_descriptor* %62, i32 0, i32 1 - %64 = load i32, i32* %63, align 4 - %65 = sub i32 1, %64 - %66 = getelementptr %dimension_descriptor, %dimension_descriptor* %62, i32 0, i32 0 - %67 = load i32, i32* %66, align 4 - %68 = mul i32 %67, %65 - %69 = add i32 %61, %68 - %70 = getelementptr %array, %array* %43, i32 0, i32 1 - %71 = load i32, i32* %70, align 4 - %72 = add i32 %69, %71 - %73 = getelementptr %array, %array* %43, i32 0, i32 0 - %74 = load i32*, i32** %73, align 8 - %75 = getelementptr inbounds i32, i32* %74, i32 %72 - store i32 3, i32* %75, align 4 - %76 = load %array*, %array** %c, align 8 - %77 = getelementptr %array, %array* %76, i32 0, i32 0 - %78 = load i32*, i32** %77, align 8 - %79 = ptrtoint i32* %78 to i64 - %80 = icmp ne i64 %79, 0 - br i1 %80, label %then6, label %else7 + %47 = load %array*, %array** %c, align 8 + %48 = getelementptr %array, %array* %47, i32 0, i32 0 + %49 = load i32*, i32** %48, align 8 + %50 = ptrtoint i32* %49 to i64 + %51 = icmp ne i64 %50, 0 + %52 = xor i1 %51, true + br i1 %52, label %then6, label %else7 then6: ; preds = %ifcont5 - %81 = getelementptr %array, %array* %76, i32 0, i32 0 - %82 = load i32*, i32** %81, align 8 - %83 = alloca i8*, align 8 - %84 = bitcast i32* %82 to i8* - store i8* %84, i8** %83, align 8 - %85 = load i8*, i8** %83, align 8 - call void @_lfortran_free(i8* %85) - %86 = getelementptr %array, %array* %76, i32 0, i32 0 - store i32* null, i32** %86, align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @84, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @83, i32 0, i32 0)) + call void @exit(i32 1) br label %ifcont8 else7: ; preds = %ifcont5 br label %ifcont8 ifcont8: ; preds = %else7, %then6 - call void @h(%array** %c) - %87 = call i32 @g(%array** %c) - store i32 %87, i32* %r1, align 4 - %88 = load %array*, %array** %c, align 8 - %89 = getelementptr %array, %array* %88, i32 0, i32 2 - %90 = load %dimension_descriptor*, %dimension_descriptor** %89, align 8 - %91 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %90, i32 0 - %92 = getelementptr %dimension_descriptor, %dimension_descriptor* %91, i32 0, i32 1 - %93 = load i32, i32* %92, align 4 - %94 = sub i32 1, %93 - %95 = getelementptr %dimension_descriptor, %dimension_descriptor* %91, i32 0, i32 0 - %96 = load i32, i32* %95, align 4 - %97 = mul i32 %96, %94 - %98 = add i32 0, %97 - %99 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %90, i32 1 - %100 = getelementptr %dimension_descriptor, %dimension_descriptor* %99, i32 0, i32 1 - %101 = load i32, i32* %100, align 4 - %102 = sub i32 1, %101 - %103 = getelementptr %dimension_descriptor, %dimension_descriptor* %99, i32 0, i32 0 - %104 = load i32, i32* %103, align 4 - %105 = mul i32 %104, %102 - %106 = add i32 %98, %105 - %107 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %90, i32 2 - %108 = getelementptr %dimension_descriptor, %dimension_descriptor* %107, i32 0, i32 1 - %109 = load i32, i32* %108, align 4 - %110 = sub i32 1, %109 - %111 = getelementptr %dimension_descriptor, %dimension_descriptor* %107, i32 0, i32 0 - %112 = load i32, i32* %111, align 4 - %113 = mul i32 %112, %110 - %114 = add i32 %106, %113 - %115 = getelementptr %array, %array* %88, i32 0, i32 1 - %116 = load i32, i32* %115, align 4 - %117 = add i32 %114, %116 - %118 = getelementptr %array, %array* %88, i32 0, i32 0 - %119 = load i32*, i32** %118, align 8 - %120 = getelementptr inbounds i32, i32* %119, i32 %117 - %121 = load i32, i32* %120, align 4 - %122 = icmp ne i32 %121, 8 - br i1 %122, label %then9, label %else10 + %53 = getelementptr %array, %array* %47, i32 0, i32 2 + %54 = load %dimension_descriptor*, %dimension_descriptor** %53, align 8 + %55 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %54, i32 0 + %56 = getelementptr %dimension_descriptor, %dimension_descriptor* %55, i32 0, i32 1 + %57 = load i32, i32* %56, align 4 + %58 = getelementptr %dimension_descriptor, %dimension_descriptor* %55, i32 0, i32 2 + %59 = load i32, i32* %58, align 4 + %60 = sub i32 1, %57 + %61 = add i32 %57, %59 + %62 = sub i32 %61, 1 + %63 = icmp slt i32 1, %57 + %64 = icmp sgt i32 1, %62 + %65 = or i1 %63, %64 + br i1 %65, label %then9, label %else10 then9: ; preds = %ifcont8 - %123 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 - %124 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %123, i8* %124) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @86, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @85, i32 0, i32 0), i32 1, i32 1, i32 %57, i32 %62) call void @exit(i32 1) br label %ifcont11 @@ -251,95 +287,51 @@ else10: ; preds = %ifcont8 br label %ifcont11 ifcont11: ; preds = %else10, %then9 - %125 = load %array*, %array** %c, align 8 - %126 = getelementptr %array, %array* %125, i32 0, i32 2 - %127 = load %dimension_descriptor*, %dimension_descriptor** %126, align 8 - %128 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %127, i32 0 - %129 = getelementptr %dimension_descriptor, %dimension_descriptor* %128, i32 0, i32 1 - %130 = load i32, i32* %129, align 4 - %131 = sub i32 1, %130 - %132 = getelementptr %dimension_descriptor, %dimension_descriptor* %128, i32 0, i32 0 - %133 = load i32, i32* %132, align 4 - %134 = mul i32 %133, %131 - %135 = add i32 0, %134 - %136 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %127, i32 1 - %137 = getelementptr %dimension_descriptor, %dimension_descriptor* %136, i32 0, i32 1 - %138 = load i32, i32* %137, align 4 - %139 = sub i32 1, %138 - %140 = getelementptr %dimension_descriptor, %dimension_descriptor* %136, i32 0, i32 0 - %141 = load i32, i32* %140, align 4 - %142 = mul i32 %141, %139 - %143 = add i32 %135, %142 - %144 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %127, i32 2 - %145 = getelementptr %dimension_descriptor, %dimension_descriptor* %144, i32 0, i32 1 - %146 = load i32, i32* %145, align 4 - %147 = sub i32 1, %146 - %148 = getelementptr %dimension_descriptor, %dimension_descriptor* %144, i32 0, i32 0 - %149 = load i32, i32* %148, align 4 - %150 = mul i32 %149, %147 - %151 = add i32 %143, %150 - %152 = getelementptr %array, %array* %125, i32 0, i32 1 - %153 = load i32, i32* %152, align 4 - %154 = add i32 %151, %153 - %155 = getelementptr %array, %array* %125, i32 0, i32 0 - %156 = load i32*, i32** %155, align 8 - %157 = getelementptr inbounds i32, i32* %156, i32 %154 - %158 = load i32, i32* %157, align 4 - %159 = alloca i32, align 4 - store i32 %158, i32* %159, align 4 - %160 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.25, i32 0, i32 0), i32 0, i32 0, i32* %159) - %161 = call i64 @_lfortran_str_len(i8* %160) - %162 = call i8* @_lfortran_malloc(i64 16) - %stringFormat_desc = bitcast i8* %162 to %string_descriptor* - %163 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 - store i8* %160, i8** %163, align 8 - %164 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 1 - store i64 %161, i64* %164, align 4 - %165 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 - %166 = load i8*, i8** %165, align 8 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0), i8* %166, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @12, i32 0, i32 0)) - %167 = load %array*, %array** %c, align 8 - %168 = getelementptr %array, %array* %167, i32 0, i32 0 - %169 = load i32*, i32** %168, align 8 - %170 = ptrtoint i32* %169 to i64 - %171 = icmp ne i64 %170, 0 - br i1 %171, label %then12, label %else13 + %66 = getelementptr %dimension_descriptor, %dimension_descriptor* %55, i32 0, i32 0 + %67 = load i32, i32* %66, align 4 + %68 = mul i32 %67, %60 + %69 = add i32 0, %68 + %70 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %54, i32 1 + %71 = getelementptr %dimension_descriptor, %dimension_descriptor* %70, i32 0, i32 1 + %72 = load i32, i32* %71, align 4 + %73 = getelementptr %dimension_descriptor, %dimension_descriptor* %70, i32 0, i32 2 + %74 = load i32, i32* %73, align 4 + %75 = sub i32 1, %72 + %76 = add i32 %72, %74 + %77 = sub i32 %76, 1 + %78 = icmp slt i32 1, %72 + %79 = icmp sgt i32 1, %77 + %80 = or i1 %78, %79 + br i1 %80, label %then12, label %else13 then12: ; preds = %ifcont11 - %172 = getelementptr %array, %array* %167, i32 0, i32 0 - %173 = load i32*, i32** %172, align 8 - %174 = alloca i8*, align 8 - %175 = bitcast i32* %173 to i8* - store i8* %175, i8** %174, align 8 - %176 = load i8*, i8** %174, align 8 - call void @_lfortran_free(i8* %176) - %177 = getelementptr %array, %array* %167, i32 0, i32 0 - store i32* null, i32** %177, align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @88, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @87, i32 0, i32 0), i32 1, i32 2, i32 %72, i32 %77) + call void @exit(i32 1) br label %ifcont14 else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 - %78 = getelementptr %dimension_descriptor, %dimension_descriptor* %67, i32 0, i32 0 - %79 = load i32, i32* %78, align 4 - %80 = mul i32 %79, %72 - %81 = add i32 %66, %80 - %82 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %51, i32 2 - %83 = getelementptr %dimension_descriptor, %dimension_descriptor* %82, i32 0, i32 1 - %84 = load i32, i32* %83, align 4 - %85 = getelementptr %dimension_descriptor, %dimension_descriptor* %82, i32 0, i32 2 - %86 = load i32, i32* %85, align 4 - %87 = sub i32 1, %84 - %88 = add i32 %84, %86 - %89 = sub i32 %88, 1 - %90 = icmp slt i32 1, %84 - %91 = icmp sgt i32 1, %89 - %92 = or i1 %90, %91 - br i1 %92, label %then15, label %else16 + %81 = getelementptr %dimension_descriptor, %dimension_descriptor* %70, i32 0, i32 0 + %82 = load i32, i32* %81, align 4 + %83 = mul i32 %82, %75 + %84 = add i32 %69, %83 + %85 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %54, i32 2 + %86 = getelementptr %dimension_descriptor, %dimension_descriptor* %85, i32 0, i32 1 + %87 = load i32, i32* %86, align 4 + %88 = getelementptr %dimension_descriptor, %dimension_descriptor* %85, i32 0, i32 2 + %89 = load i32, i32* %88, align 4 + %90 = sub i32 1, %87 + %91 = add i32 %87, %89 + %92 = sub i32 %91, 1 + %93 = icmp slt i32 1, %87 + %94 = icmp sgt i32 1, %92 + %95 = or i1 %93, %94 + br i1 %95, label %then15, label %else16 then15: ; preds = %ifcont14 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @100, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @99, i32 0, i32 0), i32 1, i32 3, i32 %84, i32 %89) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @90, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @89, i32 0, i32 0), i32 1, i32 3, i32 %87, i32 %92) call void @exit(i32 1) br label %ifcont17 @@ -347,34 +339,34 @@ else16: ; preds = %ifcont14 br label %ifcont17 ifcont17: ; preds = %else16, %then15 - %93 = getelementptr %dimension_descriptor, %dimension_descriptor* %82, i32 0, i32 0 - %94 = load i32, i32* %93, align 4 - %95 = mul i32 %94, %87 - %96 = add i32 %81, %95 - %97 = getelementptr %array, %array* %44, i32 0, i32 1 - %98 = load i32, i32* %97, align 4 - %99 = add i32 %96, %98 - %100 = getelementptr %array, %array* %44, i32 0, i32 0 - %101 = load i32*, i32** %100, align 8 - %102 = getelementptr inbounds i32, i32* %101, i32 %99 - store i32 3, i32* %102, align 4 - %103 = load %array*, %array** %c, align 8 - %104 = getelementptr %array, %array* %103, i32 0, i32 0 - %105 = load i32*, i32** %104, align 8 - %106 = ptrtoint i32* %105 to i64 - %107 = icmp ne i64 %106, 0 - br i1 %107, label %then18, label %else19 + %96 = getelementptr %dimension_descriptor, %dimension_descriptor* %85, i32 0, i32 0 + %97 = load i32, i32* %96, align 4 + %98 = mul i32 %97, %90 + %99 = add i32 %84, %98 + %100 = getelementptr %array, %array* %47, i32 0, i32 1 + %101 = load i32, i32* %100, align 4 + %102 = add i32 %99, %101 + %103 = getelementptr %array, %array* %47, i32 0, i32 0 + %104 = load i32*, i32** %103, align 8 + %105 = getelementptr inbounds i32, i32* %104, i32 %102 + store i32 3, i32* %105, align 4 + %106 = load %array*, %array** %c, align 8 + %107 = getelementptr %array, %array* %106, i32 0, i32 0 + %108 = load i32*, i32** %107, align 8 + %109 = ptrtoint i32* %108 to i64 + %110 = icmp ne i64 %109, 0 + br i1 %110, label %then18, label %else19 then18: ; preds = %ifcont17 - %108 = getelementptr %array, %array* %103, i32 0, i32 0 - %109 = load i32*, i32** %108, align 8 - %110 = alloca i8*, align 8 - %111 = bitcast i32* %109 to i8* - store i8* %111, i8** %110, align 8 - %112 = load i8*, i8** %110, align 8 - call void @_lfortran_free(i8* %112) - %113 = getelementptr %array, %array* %103, i32 0, i32 0 - store i32* null, i32** %113, align 8 + %111 = getelementptr %array, %array* %106, i32 0, i32 0 + %112 = load i32*, i32** %111, align 8 + %113 = alloca i8*, align 8 + %114 = bitcast i32* %112 to i8* + store i8* %114, i8** %113, align 8 + %115 = load i8*, i8** %113, align 8 + call void @_lfortran_free(i8* %115) + %116 = getelementptr %array, %array* %106, i32 0, i32 0 + store i32* null, i32** %116, align 8 br label %ifcont20 else19: ; preds = %ifcont17 @@ -382,18 +374,18 @@ else19: ; preds = %ifcont17 ifcont20: ; preds = %else19, %then18 call void @h(%array** %c) - %114 = call i32 @g(%array** %c) - store i32 %114, i32* %r1, align 4 - %115 = load %array*, %array** %c, align 8 - %116 = getelementptr %array, %array* %115, i32 0, i32 0 - %117 = load i32*, i32** %116, align 8 - %118 = ptrtoint i32* %117 to i64 - %119 = icmp ne i64 %118, 0 - %120 = xor i1 %119, true - br i1 %120, label %then21, label %else22 + %117 = call i32 @g(%array** %c) + store i32 %117, i32* %r1, align 4 + %118 = load %array*, %array** %c, align 8 + %119 = getelementptr %array, %array* %118, i32 0, i32 0 + %120 = load i32*, i32** %119, align 8 + %121 = ptrtoint i32* %120 to i64 + %122 = icmp ne i64 %121, 0 + %123 = xor i1 %122, true + br i1 %123, label %then21, label %else22 then21: ; preds = %ifcont20 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @102, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @101, i32 0, i32 0)) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @92, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @91, i32 0, i32 0)) call void @exit(i32 1) br label %ifcont23 @@ -401,23 +393,23 @@ else22: ; preds = %ifcont20 br label %ifcont23 ifcont23: ; preds = %else22, %then21 - %121 = getelementptr %array, %array* %115, i32 0, i32 2 - %122 = load %dimension_descriptor*, %dimension_descriptor** %121, align 8 - %123 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %122, i32 0 - %124 = getelementptr %dimension_descriptor, %dimension_descriptor* %123, i32 0, i32 1 - %125 = load i32, i32* %124, align 4 - %126 = getelementptr %dimension_descriptor, %dimension_descriptor* %123, i32 0, i32 2 - %127 = load i32, i32* %126, align 4 - %128 = sub i32 1, %125 - %129 = add i32 %125, %127 - %130 = sub i32 %129, 1 - %131 = icmp slt i32 1, %125 - %132 = icmp sgt i32 1, %130 - %133 = or i1 %131, %132 - br i1 %133, label %then24, label %else25 + %124 = getelementptr %array, %array* %118, i32 0, i32 2 + %125 = load %dimension_descriptor*, %dimension_descriptor** %124, align 8 + %126 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %125, i32 0 + %127 = getelementptr %dimension_descriptor, %dimension_descriptor* %126, i32 0, i32 1 + %128 = load i32, i32* %127, align 4 + %129 = getelementptr %dimension_descriptor, %dimension_descriptor* %126, i32 0, i32 2 + %130 = load i32, i32* %129, align 4 + %131 = sub i32 1, %128 + %132 = add i32 %128, %130 + %133 = sub i32 %132, 1 + %134 = icmp slt i32 1, %128 + %135 = icmp sgt i32 1, %133 + %136 = or i1 %134, %135 + br i1 %136, label %then24, label %else25 then24: ; preds = %ifcont23 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @103, i32 0, i32 0), i32 1, i32 1, i32 %125, i32 %130) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @94, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @93, i32 0, i32 0), i32 1, i32 1, i32 %128, i32 %133) call void @exit(i32 1) br label %ifcont26 @@ -425,25 +417,25 @@ else25: ; preds = %ifcont23 br label %ifcont26 ifcont26: ; preds = %else25, %then24 - %134 = getelementptr %dimension_descriptor, %dimension_descriptor* %123, i32 0, i32 0 - %135 = load i32, i32* %134, align 4 - %136 = mul i32 %135, %128 - %137 = add i32 0, %136 - %138 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %122, i32 1 - %139 = getelementptr %dimension_descriptor, %dimension_descriptor* %138, i32 0, i32 1 - %140 = load i32, i32* %139, align 4 - %141 = getelementptr %dimension_descriptor, %dimension_descriptor* %138, i32 0, i32 2 - %142 = load i32, i32* %141, align 4 - %143 = sub i32 1, %140 - %144 = add i32 %140, %142 - %145 = sub i32 %144, 1 - %146 = icmp slt i32 1, %140 - %147 = icmp sgt i32 1, %145 - %148 = or i1 %146, %147 - br i1 %148, label %then27, label %else28 + %137 = getelementptr %dimension_descriptor, %dimension_descriptor* %126, i32 0, i32 0 + %138 = load i32, i32* %137, align 4 + %139 = mul i32 %138, %131 + %140 = add i32 0, %139 + %141 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %125, i32 1 + %142 = getelementptr %dimension_descriptor, %dimension_descriptor* %141, i32 0, i32 1 + %143 = load i32, i32* %142, align 4 + %144 = getelementptr %dimension_descriptor, %dimension_descriptor* %141, i32 0, i32 2 + %145 = load i32, i32* %144, align 4 + %146 = sub i32 1, %143 + %147 = add i32 %143, %145 + %148 = sub i32 %147, 1 + %149 = icmp slt i32 1, %143 + %150 = icmp sgt i32 1, %148 + %151 = or i1 %149, %150 + br i1 %151, label %then27, label %else28 then27: ; preds = %ifcont26 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0), i32 1, i32 2, i32 %140, i32 %145) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @96, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @95, i32 0, i32 0), i32 1, i32 2, i32 %143, i32 %148) call void @exit(i32 1) br label %ifcont29 @@ -451,25 +443,25 @@ else28: ; preds = %ifcont26 br label %ifcont29 ifcont29: ; preds = %else28, %then27 - %149 = getelementptr %dimension_descriptor, %dimension_descriptor* %138, i32 0, i32 0 - %150 = load i32, i32* %149, align 4 - %151 = mul i32 %150, %143 - %152 = add i32 %137, %151 - %153 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %122, i32 2 - %154 = getelementptr %dimension_descriptor, %dimension_descriptor* %153, i32 0, i32 1 - %155 = load i32, i32* %154, align 4 - %156 = getelementptr %dimension_descriptor, %dimension_descriptor* %153, i32 0, i32 2 - %157 = load i32, i32* %156, align 4 - %158 = sub i32 1, %155 - %159 = add i32 %155, %157 - %160 = sub i32 %159, 1 - %161 = icmp slt i32 1, %155 - %162 = icmp sgt i32 1, %160 - %163 = or i1 %161, %162 - br i1 %163, label %then30, label %else31 + %152 = getelementptr %dimension_descriptor, %dimension_descriptor* %141, i32 0, i32 0 + %153 = load i32, i32* %152, align 4 + %154 = mul i32 %153, %146 + %155 = add i32 %140, %154 + %156 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %125, i32 2 + %157 = getelementptr %dimension_descriptor, %dimension_descriptor* %156, i32 0, i32 1 + %158 = load i32, i32* %157, align 4 + %159 = getelementptr %dimension_descriptor, %dimension_descriptor* %156, i32 0, i32 2 + %160 = load i32, i32* %159, align 4 + %161 = sub i32 1, %158 + %162 = add i32 %158, %160 + %163 = sub i32 %162, 1 + %164 = icmp slt i32 1, %158 + %165 = icmp sgt i32 1, %163 + %166 = or i1 %164, %165 + br i1 %166, label %then30, label %else31 then30: ; preds = %ifcont29 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 1, i32 3, i32 %155, i32 %160) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @98, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @97, i32 0, i32 0), i32 1, i32 3, i32 %158, i32 %163) call void @exit(i32 1) br label %ifcont32 @@ -477,22 +469,24 @@ else31: ; preds = %ifcont29 br label %ifcont32 ifcont32: ; preds = %else31, %then30 - %164 = getelementptr %dimension_descriptor, %dimension_descriptor* %153, i32 0, i32 0 - %165 = load i32, i32* %164, align 4 - %166 = mul i32 %165, %158 - %167 = add i32 %152, %166 - %168 = getelementptr %array, %array* %115, i32 0, i32 1 - %169 = load i32, i32* %168, align 4 - %170 = add i32 %167, %169 - %171 = getelementptr %array, %array* %115, i32 0, i32 0 - %172 = load i32*, i32** %171, align 8 - %173 = getelementptr inbounds i32, i32* %172, i32 %170 - %174 = load i32, i32* %173, align 4 - %175 = icmp ne i32 %174, 8 - br i1 %175, label %then33, label %else34 + %167 = getelementptr %dimension_descriptor, %dimension_descriptor* %156, i32 0, i32 0 + %168 = load i32, i32* %167, align 4 + %169 = mul i32 %168, %161 + %170 = add i32 %155, %169 + %171 = getelementptr %array, %array* %118, i32 0, i32 1 + %172 = load i32, i32* %171, align 4 + %173 = add i32 %170, %172 + %174 = getelementptr %array, %array* %118, i32 0, i32 0 + %175 = load i32*, i32** %174, align 8 + %176 = getelementptr inbounds i32, i32* %175, i32 %173 + %177 = load i32, i32* %176, align 4 + %178 = icmp ne i32 %177, 8 + br i1 %178, label %then33, label %else34 then33: ; preds = %ifcont32 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @109, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @110, i32 0, i32 0)) + %179 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 + %180 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @99, i32 0, i32 0), i8* %179, i8* %180) call void @exit(i32 1) br label %ifcont35 @@ -500,16 +494,16 @@ else34: ; preds = %ifcont32 br label %ifcont35 ifcont35: ; preds = %else34, %then33 - %176 = load %array*, %array** %c, align 8 - %177 = getelementptr %array, %array* %176, i32 0, i32 0 - %178 = load i32*, i32** %177, align 8 - %179 = ptrtoint i32* %178 to i64 - %180 = icmp ne i64 %179, 0 - %181 = xor i1 %180, true - br i1 %181, label %then36, label %else37 + %181 = load %array*, %array** %c, align 8 + %182 = getelementptr %array, %array* %181, i32 0, i32 0 + %183 = load i32*, i32** %182, align 8 + %184 = ptrtoint i32* %183 to i64 + %185 = icmp ne i64 %184, 0 + %186 = xor i1 %185, true + br i1 %186, label %then36, label %else37 then36: ; preds = %ifcont35 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @114, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @113, i32 0, i32 0)) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @102, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @101, i32 0, i32 0)) call void @exit(i32 1) br label %ifcont38 @@ -517,23 +511,23 @@ else37: ; preds = %ifcont35 br label %ifcont38 ifcont38: ; preds = %else37, %then36 - %182 = getelementptr %array, %array* %176, i32 0, i32 2 - %183 = load %dimension_descriptor*, %dimension_descriptor** %182, align 8 - %184 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %183, i32 0 - %185 = getelementptr %dimension_descriptor, %dimension_descriptor* %184, i32 0, i32 1 - %186 = load i32, i32* %185, align 4 - %187 = getelementptr %dimension_descriptor, %dimension_descriptor* %184, i32 0, i32 2 - %188 = load i32, i32* %187, align 4 - %189 = sub i32 1, %186 - %190 = add i32 %186, %188 - %191 = sub i32 %190, 1 - %192 = icmp slt i32 1, %186 - %193 = icmp sgt i32 1, %191 - %194 = or i1 %192, %193 - br i1 %194, label %then39, label %else40 + %187 = getelementptr %array, %array* %181, i32 0, i32 2 + %188 = load %dimension_descriptor*, %dimension_descriptor** %187, align 8 + %189 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %188, i32 0 + %190 = getelementptr %dimension_descriptor, %dimension_descriptor* %189, i32 0, i32 1 + %191 = load i32, i32* %190, align 4 + %192 = getelementptr %dimension_descriptor, %dimension_descriptor* %189, i32 0, i32 2 + %193 = load i32, i32* %192, align 4 + %194 = sub i32 1, %191 + %195 = add i32 %191, %193 + %196 = sub i32 %195, 1 + %197 = icmp slt i32 1, %191 + %198 = icmp sgt i32 1, %196 + %199 = or i1 %197, %198 + br i1 %199, label %then39, label %else40 then39: ; preds = %ifcont38 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @116, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @115, i32 0, i32 0), i32 1, i32 1, i32 %186, i32 %191) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @103, i32 0, i32 0), i32 1, i32 1, i32 %191, i32 %196) call void @exit(i32 1) br label %ifcont41 @@ -541,25 +535,25 @@ else40: ; preds = %ifcont38 br label %ifcont41 ifcont41: ; preds = %else40, %then39 - %195 = getelementptr %dimension_descriptor, %dimension_descriptor* %184, i32 0, i32 0 - %196 = load i32, i32* %195, align 4 - %197 = mul i32 %196, %189 - %198 = add i32 0, %197 - %199 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %183, i32 1 - %200 = getelementptr %dimension_descriptor, %dimension_descriptor* %199, i32 0, i32 1 + %200 = getelementptr %dimension_descriptor, %dimension_descriptor* %189, i32 0, i32 0 %201 = load i32, i32* %200, align 4 - %202 = getelementptr %dimension_descriptor, %dimension_descriptor* %199, i32 0, i32 2 - %203 = load i32, i32* %202, align 4 - %204 = sub i32 1, %201 - %205 = add i32 %201, %203 - %206 = sub i32 %205, 1 - %207 = icmp slt i32 1, %201 - %208 = icmp sgt i32 1, %206 - %209 = or i1 %207, %208 - br i1 %209, label %then42, label %else43 + %202 = mul i32 %201, %194 + %203 = add i32 0, %202 + %204 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %188, i32 1 + %205 = getelementptr %dimension_descriptor, %dimension_descriptor* %204, i32 0, i32 1 + %206 = load i32, i32* %205, align 4 + %207 = getelementptr %dimension_descriptor, %dimension_descriptor* %204, i32 0, i32 2 + %208 = load i32, i32* %207, align 4 + %209 = sub i32 1, %206 + %210 = add i32 %206, %208 + %211 = sub i32 %210, 1 + %212 = icmp slt i32 1, %206 + %213 = icmp sgt i32 1, %211 + %214 = or i1 %212, %213 + br i1 %214, label %then42, label %else43 then42: ; preds = %ifcont41 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @118, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @117, i32 0, i32 0), i32 1, i32 2, i32 %201, i32 %206) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0), i32 1, i32 2, i32 %206, i32 %211) call void @exit(i32 1) br label %ifcont44 @@ -567,25 +561,25 @@ else43: ; preds = %ifcont41 br label %ifcont44 ifcont44: ; preds = %else43, %then42 - %210 = getelementptr %dimension_descriptor, %dimension_descriptor* %199, i32 0, i32 0 - %211 = load i32, i32* %210, align 4 - %212 = mul i32 %211, %204 - %213 = add i32 %198, %212 - %214 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %183, i32 2 - %215 = getelementptr %dimension_descriptor, %dimension_descriptor* %214, i32 0, i32 1 + %215 = getelementptr %dimension_descriptor, %dimension_descriptor* %204, i32 0, i32 0 %216 = load i32, i32* %215, align 4 - %217 = getelementptr %dimension_descriptor, %dimension_descriptor* %214, i32 0, i32 2 - %218 = load i32, i32* %217, align 4 - %219 = sub i32 1, %216 - %220 = add i32 %216, %218 - %221 = sub i32 %220, 1 - %222 = icmp slt i32 1, %216 - %223 = icmp sgt i32 1, %221 - %224 = or i1 %222, %223 - br i1 %224, label %then45, label %else46 + %217 = mul i32 %216, %209 + %218 = add i32 %203, %217 + %219 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %188, i32 2 + %220 = getelementptr %dimension_descriptor, %dimension_descriptor* %219, i32 0, i32 1 + %221 = load i32, i32* %220, align 4 + %222 = getelementptr %dimension_descriptor, %dimension_descriptor* %219, i32 0, i32 2 + %223 = load i32, i32* %222, align 4 + %224 = sub i32 1, %221 + %225 = add i32 %221, %223 + %226 = sub i32 %225, 1 + %227 = icmp slt i32 1, %221 + %228 = icmp sgt i32 1, %226 + %229 = or i1 %227, %228 + br i1 %229, label %then45, label %else46 then45: ; preds = %ifcont44 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @120, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @119, i32 0, i32 0), i32 1, i32 3, i32 %216, i32 %221) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 1, i32 3, i32 %221, i32 %226) call void @exit(i32 1) br label %ifcont47 @@ -593,38 +587,47 @@ else46: ; preds = %ifcont44 br label %ifcont47 ifcont47: ; preds = %else46, %then45 - %225 = getelementptr %dimension_descriptor, %dimension_descriptor* %214, i32 0, i32 0 - %226 = load i32, i32* %225, align 4 - %227 = mul i32 %226, %219 - %228 = add i32 %213, %227 - %229 = getelementptr %array, %array* %176, i32 0, i32 1 - %230 = load i32, i32* %229, align 4 - %231 = add i32 %228, %230 - %232 = getelementptr %array, %array* %176, i32 0, i32 0 - %233 = load i32*, i32** %232, align 8 - %234 = getelementptr inbounds i32, i32* %233, i32 %231 + %230 = getelementptr %dimension_descriptor, %dimension_descriptor* %219, i32 0, i32 0 + %231 = load i32, i32* %230, align 4 + %232 = mul i32 %231, %224 + %233 = add i32 %218, %232 + %234 = getelementptr %array, %array* %181, i32 0, i32 1 %235 = load i32, i32* %234, align 4 - %236 = alloca i32, align 4 - store i32 %235, i32* %236, align 4 - %237 = call i8* (i8*, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.3, i32 0, i32 0), i32 0, i32 0, i32* %236) - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @121, i32 0, i32 0), i8* %237, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0)) - %238 = load %array*, %array** %c, align 8 - %239 = getelementptr %array, %array* %238, i32 0, i32 0 - %240 = load i32*, i32** %239, align 8 - %241 = ptrtoint i32* %240 to i64 - %242 = icmp ne i64 %241, 0 - br i1 %242, label %then48, label %else49 + %236 = add i32 %233, %235 + %237 = getelementptr %array, %array* %181, i32 0, i32 0 + %238 = load i32*, i32** %237, align 8 + %239 = getelementptr inbounds i32, i32* %238, i32 %236 + %240 = load i32, i32* %239, align 4 + %241 = alloca i32, align 4 + store i32 %240, i32* %241, align 4 + %242 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.25, i32 0, i32 0), i32 0, i32 0, i32* %241) + %243 = call i64 @_lfortran_str_len(i8* %242) + %244 = call i8* @_lfortran_malloc(i64 16) + %stringFormat_desc = bitcast i8* %244 to %string_descriptor* + %245 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 + store i8* %242, i8** %245, align 8 + %246 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 1 + store i64 %243, i64* %246, align 4 + %247 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 + %248 = load i8*, i8** %247, align 8 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @109, i32 0, i32 0), i8* %248, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @100, i32 0, i32 0)) + %249 = load %array*, %array** %c, align 8 + %250 = getelementptr %array, %array* %249, i32 0, i32 0 + %251 = load i32*, i32** %250, align 8 + %252 = ptrtoint i32* %251 to i64 + %253 = icmp ne i64 %252, 0 + br i1 %253, label %then48, label %else49 then48: ; preds = %ifcont47 - %243 = getelementptr %array, %array* %238, i32 0, i32 0 - %244 = load i32*, i32** %243, align 8 - %245 = alloca i8*, align 8 - %246 = bitcast i32* %244 to i8* - store i8* %246, i8** %245, align 8 - %247 = load i8*, i8** %245, align 8 - call void @_lfortran_free(i8* %247) - %248 = getelementptr %array, %array* %238, i32 0, i32 0 - store i32* null, i32** %248, align 8 + %254 = getelementptr %array, %array* %249, i32 0, i32 0 + %255 = load i32*, i32** %254, align 8 + %256 = alloca i8*, align 8 + %257 = bitcast i32* %255 to i8* + store i8* %257, i8** %256, align 8 + %258 = load i8*, i8** %256, align 8 + call void @_lfortran_free(i8* %258) + %259 = getelementptr %array, %array* %249, i32 0, i32 0 + store i32* null, i32** %259, align 8 br label %ifcont50 else49: ; preds = %ifcont47 @@ -683,58 +686,130 @@ ifcont: ; preds = %else, %then %21 = getelementptr %dimension_descriptor, %dimension_descriptor* %19, i32 0, i32 1 %22 = getelementptr %dimension_descriptor, %dimension_descriptor* %19, i32 0, i32 2 store i32 3, i32* %20, align 4 - %21 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %12, i32 2 - %22 = getelementptr %dimension_descriptor, %dimension_descriptor* %21, i32 0, i32 0 - %23 = getelementptr %dimension_descriptor, %dimension_descriptor* %21, i32 0, i32 1 - %24 = getelementptr %dimension_descriptor, %dimension_descriptor* %21, i32 0, i32 2 - store i32 9, i32* %22, align 4 - store i32 1, i32* %23, align 4 - store i32 3, i32* %24, align 4 - %25 = getelementptr %array, %array* %9, i32 0, i32 0 - %26 = alloca i32, align 4 - store i32 108, i32* %26, align 4 - %27 = load i32, i32* %26, align 4 - %28 = sext i32 %27 to i64 - %29 = call i8* @_lfortran_malloc(i64 %28) - %30 = bitcast i8* %29 to i32* - store i32* %30, i32** %25, align 8 - %31 = load %array*, %array** %c, align 8 - %32 = getelementptr %array, %array* %31, i32 0, i32 2 - %33 = load %dimension_descriptor*, %dimension_descriptor** %32, align 8 - %34 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %33, i32 0 - %35 = getelementptr %dimension_descriptor, %dimension_descriptor* %34, i32 0, i32 1 - %36 = load i32, i32* %35, align 4 - %37 = sub i32 1, %36 - %38 = getelementptr %dimension_descriptor, %dimension_descriptor* %34, i32 0, i32 0 - %39 = load i32, i32* %38, align 4 - %40 = mul i32 %39, %37 - %41 = add i32 0, %40 - %42 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %33, i32 1 - %43 = getelementptr %dimension_descriptor, %dimension_descriptor* %42, i32 0, i32 1 - %44 = load i32, i32* %43, align 4 - %45 = sub i32 1, %44 - %46 = getelementptr %dimension_descriptor, %dimension_descriptor* %42, i32 0, i32 0 - %47 = load i32, i32* %46, align 4 - %48 = mul i32 %47, %45 - %49 = add i32 %41, %48 - %50 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %33, i32 2 - %51 = getelementptr %dimension_descriptor, %dimension_descriptor* %50, i32 0, i32 1 - %52 = load i32, i32* %51, align 4 - %53 = sub i32 1, %52 - %54 = getelementptr %dimension_descriptor, %dimension_descriptor* %50, i32 0, i32 0 - %55 = load i32, i32* %54, align 4 - %56 = mul i32 %55, %53 - %57 = add i32 %49, %56 - %58 = getelementptr %array, %array* %31, i32 0, i32 1 - %59 = load i32, i32* %58, align 4 - %60 = add i32 %57, %59 - %61 = getelementptr %array, %array* %31, i32 0, i32 0 - %62 = load i32*, i32** %61, align 8 - %63 = getelementptr inbounds i32, i32* %62, i32 %60 - store i32 99, i32* %63, align 4 + store i32 1, i32* %21, align 4 + store i32 3, i32* %22, align 4 + %23 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %14, i32 2 + %24 = getelementptr %dimension_descriptor, %dimension_descriptor* %23, i32 0, i32 0 + %25 = getelementptr %dimension_descriptor, %dimension_descriptor* %23, i32 0, i32 1 + %26 = getelementptr %dimension_descriptor, %dimension_descriptor* %23, i32 0, i32 2 + store i32 9, i32* %24, align 4 + store i32 1, i32* %25, align 4 + store i32 3, i32* %26, align 4 + %27 = getelementptr %array, %array* %11, i32 0, i32 0 + %28 = alloca i32, align 4 + store i32 108, i32* %28, align 4 + %29 = load i32, i32* %28, align 4 + %30 = sext i32 %29 to i64 + %31 = call i8* @_lfortran_malloc(i64 %30) + %32 = bitcast i8* %31 to i32* + store i32* %32, i32** %27, align 8 + %33 = load %array*, %array** %c, align 8 + %34 = getelementptr %array, %array* %33, i32 0, i32 0 + %35 = load i32*, i32** %34, align 8 + %36 = ptrtoint i32* %35 to i64 + %37 = icmp ne i64 %36, 0 + %38 = xor i1 %37, true + br i1 %38, label %then1, label %else2 + +then1: ; preds = %ifcont + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont3 + +else2: ; preds = %ifcont + br label %ifcont3 + +ifcont3: ; preds = %else2, %then1 + %39 = getelementptr %array, %array* %33, i32 0, i32 2 + %40 = load %dimension_descriptor*, %dimension_descriptor** %39, align 8 + %41 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %40, i32 0 + %42 = getelementptr %dimension_descriptor, %dimension_descriptor* %41, i32 0, i32 1 + %43 = load i32, i32* %42, align 4 + %44 = getelementptr %dimension_descriptor, %dimension_descriptor* %41, i32 0, i32 2 + %45 = load i32, i32* %44, align 4 + %46 = sub i32 1, %43 + %47 = add i32 %43, %45 + %48 = sub i32 %47, 1 + %49 = icmp slt i32 1, %43 + %50 = icmp sgt i32 1, %48 + %51 = or i1 %49, %50 + br i1 %51, label %then4, label %else5 + +then4: ; preds = %ifcont3 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 1, i32 1, i32 %43, i32 %48) + call void @exit(i32 1) + br label %ifcont6 + +else5: ; preds = %ifcont3 + br label %ifcont6 + +ifcont6: ; preds = %else5, %then4 + %52 = getelementptr %dimension_descriptor, %dimension_descriptor* %41, i32 0, i32 0 + %53 = load i32, i32* %52, align 4 + %54 = mul i32 %53, %46 + %55 = add i32 0, %54 + %56 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %40, i32 1 + %57 = getelementptr %dimension_descriptor, %dimension_descriptor* %56, i32 0, i32 1 + %58 = load i32, i32* %57, align 4 + %59 = getelementptr %dimension_descriptor, %dimension_descriptor* %56, i32 0, i32 2 + %60 = load i32, i32* %59, align 4 + %61 = sub i32 1, %58 + %62 = add i32 %58, %60 + %63 = sub i32 %62, 1 + %64 = icmp slt i32 1, %58 + %65 = icmp sgt i32 1, %63 + %66 = or i1 %64, %65 + br i1 %66, label %then7, label %else8 + +then7: ; preds = %ifcont6 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0), i32 1, i32 2, i32 %58, i32 %63) + call void @exit(i32 1) + br label %ifcont9 + +else8: ; preds = %ifcont6 + br label %ifcont9 + +ifcont9: ; preds = %else8, %then7 + %67 = getelementptr %dimension_descriptor, %dimension_descriptor* %56, i32 0, i32 0 + %68 = load i32, i32* %67, align 4 + %69 = mul i32 %68, %61 + %70 = add i32 %55, %69 + %71 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %40, i32 2 + %72 = getelementptr %dimension_descriptor, %dimension_descriptor* %71, i32 0, i32 1 + %73 = load i32, i32* %72, align 4 + %74 = getelementptr %dimension_descriptor, %dimension_descriptor* %71, i32 0, i32 2 + %75 = load i32, i32* %74, align 4 + %76 = sub i32 1, %73 + %77 = add i32 %73, %75 + %78 = sub i32 %77, 1 + %79 = icmp slt i32 1, %73 + %80 = icmp sgt i32 1, %78 + %81 = or i1 %79, %80 + br i1 %81, label %then10, label %else11 + +then10: ; preds = %ifcont9 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @6, i32 0, i32 0), i32 1, i32 3, i32 %73, i32 %78) + call void @exit(i32 1) + br label %ifcont12 + +else11: ; preds = %ifcont9 + br label %ifcont12 + +ifcont12: ; preds = %else11, %then10 + %82 = getelementptr %dimension_descriptor, %dimension_descriptor* %71, i32 0, i32 0 + %83 = load i32, i32* %82, align 4 + %84 = mul i32 %83, %76 + %85 = add i32 %70, %84 + %86 = getelementptr %array, %array* %33, i32 0, i32 1 + %87 = load i32, i32* %86, align 4 + %88 = add i32 %85, %87 + %89 = getelementptr %array, %array* %33, i32 0, i32 0 + %90 = load i32*, i32** %89, align 8 + %91 = getelementptr inbounds i32, i32* %90, i32 %88 + store i32 99, i32* %91, align 4 br label %return -return: ; preds = %ifcont +return: ; preds = %ifcont12 ret void } @@ -742,93 +817,15 @@ define i32 @g(%array** %x) { .entry: %r = alloca i32, align 4 %0 = load %array*, %array** %x, align 8 - %1 = getelementptr %array, %array* %0, i32 0, i32 2 - %2 = load %dimension_descriptor*, %dimension_descriptor** %1, align 8 - %3 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %2, i32 0 - %4 = getelementptr %dimension_descriptor, %dimension_descriptor* %3, i32 0, i32 1 - %5 = load i32, i32* %4, align 4 - %6 = sub i32 1, %5 - %7 = getelementptr %dimension_descriptor, %dimension_descriptor* %3, i32 0, i32 0 - %8 = load i32, i32* %7, align 4 - %9 = mul i32 %8, %6 - %10 = add i32 0, %9 - %11 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %2, i32 1 - %12 = getelementptr %dimension_descriptor, %dimension_descriptor* %11, i32 0, i32 1 - %13 = load i32, i32* %12, align 4 - %14 = sub i32 1, %13 - %15 = getelementptr %dimension_descriptor, %dimension_descriptor* %11, i32 0, i32 0 - %16 = load i32, i32* %15, align 4 - %17 = mul i32 %16, %14 - %18 = add i32 %10, %17 - %19 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %2, i32 2 - %20 = getelementptr %dimension_descriptor, %dimension_descriptor* %19, i32 0, i32 1 - %21 = load i32, i32* %20, align 4 - %22 = sub i32 1, %21 - %23 = getelementptr %dimension_descriptor, %dimension_descriptor* %19, i32 0, i32 0 - %24 = load i32, i32* %23, align 4 - %25 = mul i32 %24, %22 - %26 = add i32 %18, %25 - %27 = getelementptr %array, %array* %0, i32 0, i32 1 - %28 = load i32, i32* %27, align 4 - %29 = add i32 %26, %28 - %30 = getelementptr %array, %array* %0, i32 0, i32 0 - %31 = load i32*, i32** %30, align 8 - %32 = getelementptr inbounds i32, i32* %31, i32 %29 - %33 = load i32, i32* %32, align 4 - %34 = alloca i32, align 4 - store i32 %33, i32* %34, align 4 - %35 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info, i32 0, i32 0), i32 0, i32 0, i32* %34) - %36 = call i64 @_lfortran_str_len(i8* %35) - %37 = call i8* @_lfortran_malloc(i64 16) - %stringFormat_desc = bitcast i8* %37 to %string_descriptor* - %38 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 - store i8* %35, i8** %38, align 8 - %39 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 1 - store i64 %36, i64* %39, align 4 - %40 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 - %41 = load i8*, i8** %40, align 8 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0)) - %42 = load %array*, %array** %x, align 8 - %43 = getelementptr %array, %array* %42, i32 0, i32 2 - %44 = load %dimension_descriptor*, %dimension_descriptor** %43, align 8 - %45 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %44, i32 0 - %46 = getelementptr %dimension_descriptor, %dimension_descriptor* %45, i32 0, i32 1 - %47 = load i32, i32* %46, align 4 - %48 = sub i32 1, %47 - %49 = getelementptr %dimension_descriptor, %dimension_descriptor* %45, i32 0, i32 0 - %50 = load i32, i32* %49, align 4 - %51 = mul i32 %50, %48 - %52 = add i32 0, %51 - %53 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %44, i32 1 - %54 = getelementptr %dimension_descriptor, %dimension_descriptor* %53, i32 0, i32 1 - %55 = load i32, i32* %54, align 4 - %56 = sub i32 1, %55 - %57 = getelementptr %dimension_descriptor, %dimension_descriptor* %53, i32 0, i32 0 - %58 = load i32, i32* %57, align 4 - %59 = mul i32 %58, %56 - %60 = add i32 %52, %59 - %61 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %44, i32 2 - %62 = getelementptr %dimension_descriptor, %dimension_descriptor* %61, i32 0, i32 1 - %63 = load i32, i32* %62, align 4 - %64 = sub i32 1, %63 - %65 = getelementptr %dimension_descriptor, %dimension_descriptor* %61, i32 0, i32 0 - %66 = load i32, i32* %65, align 4 - %67 = mul i32 %66, %64 - %68 = add i32 %60, %67 - %69 = getelementptr %array, %array* %42, i32 0, i32 1 - %70 = load i32, i32* %69, align 4 - %71 = add i32 %68, %70 - %72 = getelementptr %array, %array* %42, i32 0, i32 0 - %73 = load i32*, i32** %72, align 8 - %74 = getelementptr inbounds i32, i32* %73, i32 %71 - %75 = load i32, i32* %74, align 4 - %76 = icmp ne i32 %75, 8 - br i1 %76, label %then, label %else + %1 = getelementptr %array, %array* %0, i32 0, i32 0 + %2 = load i32*, i32** %1, align 8 + %3 = ptrtoint i32* %2 to i64 + %4 = icmp ne i64 %3, 0 + %5 = xor i1 %4, true + br i1 %5, label %then, label %else then: ; preds = %.entry - %77 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 - %78 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i8* %77, i8* %78) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @10, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @9, i32 0, i32 0)) call void @exit(i32 1) br label %ifcont @@ -836,165 +833,593 @@ else: ; preds = %.entry br label %ifcont ifcont: ; preds = %else, %then - %79 = load %array*, %array** %x, align 8 - %80 = getelementptr %array, %array* %79, i32 0, i32 0 - %81 = load i32*, i32** %80, align 8 - %82 = ptrtoint i32* %81 to i64 - %83 = icmp ne i64 %82, 0 - br i1 %83, label %then1, label %else2 + %6 = getelementptr %array, %array* %0, i32 0, i32 2 + %7 = load %dimension_descriptor*, %dimension_descriptor** %6, align 8 + %8 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %7, i32 0 + %9 = getelementptr %dimension_descriptor, %dimension_descriptor* %8, i32 0, i32 1 + %10 = load i32, i32* %9, align 4 + %11 = getelementptr %dimension_descriptor, %dimension_descriptor* %8, i32 0, i32 2 + %12 = load i32, i32* %11, align 4 + %13 = sub i32 1, %10 + %14 = add i32 %10, %12 + %15 = sub i32 %14, 1 + %16 = icmp slt i32 1, %10 + %17 = icmp sgt i32 1, %15 + %18 = or i1 %16, %17 + br i1 %18, label %then1, label %else2 then1: ; preds = %ifcont - %84 = getelementptr %array, %array* %79, i32 0, i32 0 - %85 = load i32*, i32** %84, align 8 - %86 = alloca i8*, align 8 - %87 = bitcast i32* %85 to i8* - store i8* %87, i8** %86, align 8 - %88 = load i8*, i8** %86, align 8 - call void @_lfortran_free(i8* %88) - %89 = getelementptr %array, %array* %79, i32 0, i32 0 - store i32* null, i32** %89, align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i32 1, i32 1, i32 %10, i32 %15) + call void @exit(i32 1) br label %ifcont3 else2: ; preds = %ifcont br label %ifcont3 ifcont3: ; preds = %else2, %then1 - call void @f(%array** %x) - %90 = load %array*, %array** %x, align 8 - %91 = getelementptr %array, %array* %90, i32 0, i32 2 - %92 = load %dimension_descriptor*, %dimension_descriptor** %91, align 8 - %93 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %92, i32 0 - %94 = getelementptr %dimension_descriptor, %dimension_descriptor* %93, i32 0, i32 1 + %19 = getelementptr %dimension_descriptor, %dimension_descriptor* %8, i32 0, i32 0 + %20 = load i32, i32* %19, align 4 + %21 = mul i32 %20, %13 + %22 = add i32 0, %21 + %23 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %7, i32 1 + %24 = getelementptr %dimension_descriptor, %dimension_descriptor* %23, i32 0, i32 1 + %25 = load i32, i32* %24, align 4 + %26 = getelementptr %dimension_descriptor, %dimension_descriptor* %23, i32 0, i32 2 + %27 = load i32, i32* %26, align 4 + %28 = sub i32 1, %25 + %29 = add i32 %25, %27 + %30 = sub i32 %29, 1 + %31 = icmp slt i32 1, %25 + %32 = icmp sgt i32 1, %30 + %33 = or i1 %31, %32 + br i1 %33, label %then4, label %else5 + +then4: ; preds = %ifcont3 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 1, i32 2, i32 %25, i32 %30) + call void @exit(i32 1) + br label %ifcont6 + +else5: ; preds = %ifcont3 + br label %ifcont6 + +ifcont6: ; preds = %else5, %then4 + %34 = getelementptr %dimension_descriptor, %dimension_descriptor* %23, i32 0, i32 0 + %35 = load i32, i32* %34, align 4 + %36 = mul i32 %35, %28 + %37 = add i32 %22, %36 + %38 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %7, i32 2 + %39 = getelementptr %dimension_descriptor, %dimension_descriptor* %38, i32 0, i32 1 + %40 = load i32, i32* %39, align 4 + %41 = getelementptr %dimension_descriptor, %dimension_descriptor* %38, i32 0, i32 2 + %42 = load i32, i32* %41, align 4 + %43 = sub i32 1, %40 + %44 = add i32 %40, %42 + %45 = sub i32 %44, 1 + %46 = icmp slt i32 1, %40 + %47 = icmp sgt i32 1, %45 + %48 = or i1 %46, %47 + br i1 %48, label %then7, label %else8 + +then7: ; preds = %ifcont6 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 1, i32 3, i32 %40, i32 %45) + call void @exit(i32 1) + br label %ifcont9 + +else8: ; preds = %ifcont6 + br label %ifcont9 + +ifcont9: ; preds = %else8, %then7 + %49 = getelementptr %dimension_descriptor, %dimension_descriptor* %38, i32 0, i32 0 + %50 = load i32, i32* %49, align 4 + %51 = mul i32 %50, %43 + %52 = add i32 %37, %51 + %53 = getelementptr %array, %array* %0, i32 0, i32 1 + %54 = load i32, i32* %53, align 4 + %55 = add i32 %52, %54 + %56 = getelementptr %array, %array* %0, i32 0, i32 0 + %57 = load i32*, i32** %56, align 8 + %58 = getelementptr inbounds i32, i32* %57, i32 %55 + %59 = load i32, i32* %58, align 4 + %60 = alloca i32, align 4 + store i32 %59, i32* %60, align 4 + %61 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info, i32 0, i32 0), i32 0, i32 0, i32* %60) + %62 = call i64 @_lfortran_str_len(i8* %61) + %63 = call i8* @_lfortran_malloc(i64 16) + %stringFormat_desc = bitcast i8* %63 to %string_descriptor* + %64 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 + store i8* %61, i8** %64, align 8 + %65 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 1 + store i64 %62, i64* %65, align 4 + %66 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 + %67 = load i8*, i8** %66, align 8 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @17, i32 0, i32 0), i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @8, i32 0, i32 0)) + %68 = load %array*, %array** %x, align 8 + %69 = getelementptr %array, %array* %68, i32 0, i32 0 + %70 = load i32*, i32** %69, align 8 + %71 = ptrtoint i32* %70 to i64 + %72 = icmp ne i64 %71, 0 + %73 = xor i1 %72, true + br i1 %73, label %then10, label %else11 + +then10: ; preds = %ifcont9 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @19, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @18, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont12 + +else11: ; preds = %ifcont9 + br label %ifcont12 + +ifcont12: ; preds = %else11, %then10 + %74 = getelementptr %array, %array* %68, i32 0, i32 2 + %75 = load %dimension_descriptor*, %dimension_descriptor** %74, align 8 + %76 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %75, i32 0 + %77 = getelementptr %dimension_descriptor, %dimension_descriptor* %76, i32 0, i32 1 + %78 = load i32, i32* %77, align 4 + %79 = getelementptr %dimension_descriptor, %dimension_descriptor* %76, i32 0, i32 2 + %80 = load i32, i32* %79, align 4 + %81 = sub i32 1, %78 + %82 = add i32 %78, %80 + %83 = sub i32 %82, 1 + %84 = icmp slt i32 1, %78 + %85 = icmp sgt i32 1, %83 + %86 = or i1 %84, %85 + br i1 %86, label %then13, label %else14 + +then13: ; preds = %ifcont12 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @21, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @20, i32 0, i32 0), i32 1, i32 1, i32 %78, i32 %83) + call void @exit(i32 1) + br label %ifcont15 + +else14: ; preds = %ifcont12 + br label %ifcont15 + +ifcont15: ; preds = %else14, %then13 + %87 = getelementptr %dimension_descriptor, %dimension_descriptor* %76, i32 0, i32 0 + %88 = load i32, i32* %87, align 4 + %89 = mul i32 %88, %81 + %90 = add i32 0, %89 + %91 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %75, i32 1 + %92 = getelementptr %dimension_descriptor, %dimension_descriptor* %91, i32 0, i32 1 + %93 = load i32, i32* %92, align 4 + %94 = getelementptr %dimension_descriptor, %dimension_descriptor* %91, i32 0, i32 2 %95 = load i32, i32* %94, align 4 - %96 = sub i32 1, %95 - %97 = getelementptr %dimension_descriptor, %dimension_descriptor* %93, i32 0, i32 0 - %98 = load i32, i32* %97, align 4 - %99 = mul i32 %98, %96 - %100 = add i32 0, %99 - %101 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %92, i32 1 - %102 = getelementptr %dimension_descriptor, %dimension_descriptor* %101, i32 0, i32 1 + %96 = sub i32 1, %93 + %97 = add i32 %93, %95 + %98 = sub i32 %97, 1 + %99 = icmp slt i32 1, %93 + %100 = icmp sgt i32 1, %98 + %101 = or i1 %99, %100 + br i1 %101, label %then16, label %else17 + +then16: ; preds = %ifcont15 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @22, i32 0, i32 0), i32 1, i32 2, i32 %93, i32 %98) + call void @exit(i32 1) + br label %ifcont18 + +else17: ; preds = %ifcont15 + br label %ifcont18 + +ifcont18: ; preds = %else17, %then16 + %102 = getelementptr %dimension_descriptor, %dimension_descriptor* %91, i32 0, i32 0 %103 = load i32, i32* %102, align 4 - %104 = sub i32 1, %103 - %105 = getelementptr %dimension_descriptor, %dimension_descriptor* %101, i32 0, i32 0 - %106 = load i32, i32* %105, align 4 - %107 = mul i32 %106, %104 - %108 = add i32 %100, %107 - %109 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %92, i32 2 - %110 = getelementptr %dimension_descriptor, %dimension_descriptor* %109, i32 0, i32 1 - %111 = load i32, i32* %110, align 4 - %112 = sub i32 1, %111 - %113 = getelementptr %dimension_descriptor, %dimension_descriptor* %109, i32 0, i32 0 - %114 = load i32, i32* %113, align 4 - %115 = mul i32 %114, %112 - %116 = add i32 %108, %115 - %117 = getelementptr %array, %array* %90, i32 0, i32 1 + %104 = mul i32 %103, %96 + %105 = add i32 %90, %104 + %106 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %75, i32 2 + %107 = getelementptr %dimension_descriptor, %dimension_descriptor* %106, i32 0, i32 1 + %108 = load i32, i32* %107, align 4 + %109 = getelementptr %dimension_descriptor, %dimension_descriptor* %106, i32 0, i32 2 + %110 = load i32, i32* %109, align 4 + %111 = sub i32 1, %108 + %112 = add i32 %108, %110 + %113 = sub i32 %112, 1 + %114 = icmp slt i32 1, %108 + %115 = icmp sgt i32 1, %113 + %116 = or i1 %114, %115 + br i1 %116, label %then19, label %else20 + +then19: ; preds = %ifcont18 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @25, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @24, i32 0, i32 0), i32 1, i32 3, i32 %108, i32 %113) + call void @exit(i32 1) + br label %ifcont21 + +else20: ; preds = %ifcont18 + br label %ifcont21 + +ifcont21: ; preds = %else20, %then19 + %117 = getelementptr %dimension_descriptor, %dimension_descriptor* %106, i32 0, i32 0 %118 = load i32, i32* %117, align 4 - %119 = add i32 %116, %118 - %120 = getelementptr %array, %array* %90, i32 0, i32 0 - %121 = load i32*, i32** %120, align 8 - %122 = getelementptr inbounds i32, i32* %121, i32 %119 - %123 = load i32, i32* %122, align 4 - %124 = alloca i32, align 4 - store i32 %123, i32* %124, align 4 - %125 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.3, i32 0, i32 0), i32 0, i32 0, i32* %124) - %126 = call i64 @_lfortran_str_len(i8* %125) - %127 = call i8* @_lfortran_malloc(i64 16) - %stringFormat_desc4 = bitcast i8* %127 to %string_descriptor* - %128 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc4, i32 0, i32 0 - store i8* %125, i8** %128, align 8 - %129 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc4, i32 0, i32 1 - store i64 %126, i64* %129, align 4 - %130 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc4, i32 0, i32 0 - %131 = load i8*, i8** %130, align 8 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %131, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @3, i32 0, i32 0)) - %132 = load %array*, %array** %x, align 8 - %133 = getelementptr %array, %array* %132, i32 0, i32 2 - %134 = load %dimension_descriptor*, %dimension_descriptor** %133, align 8 - %135 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %134, i32 0 - %136 = getelementptr %dimension_descriptor, %dimension_descriptor* %135, i32 0, i32 1 - %137 = load i32, i32* %136, align 4 - %138 = sub i32 1, %137 - %139 = getelementptr %dimension_descriptor, %dimension_descriptor* %135, i32 0, i32 0 - %140 = load i32, i32* %139, align 4 - %141 = mul i32 %140, %138 - %142 = add i32 0, %141 - %143 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %134, i32 1 - %144 = getelementptr %dimension_descriptor, %dimension_descriptor* %143, i32 0, i32 1 - %145 = load i32, i32* %144, align 4 - %146 = sub i32 1, %145 - %147 = getelementptr %dimension_descriptor, %dimension_descriptor* %143, i32 0, i32 0 - %148 = load i32, i32* %147, align 4 - %149 = mul i32 %148, %146 - %150 = add i32 %142, %149 - %151 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %134, i32 2 - %152 = getelementptr %dimension_descriptor, %dimension_descriptor* %151, i32 0, i32 1 - %153 = load i32, i32* %152, align 4 - %154 = sub i32 1, %153 - %155 = getelementptr %dimension_descriptor, %dimension_descriptor* %151, i32 0, i32 0 - %156 = load i32, i32* %155, align 4 - %157 = mul i32 %156, %154 - %158 = add i32 %150, %157 - %159 = getelementptr %array, %array* %132, i32 0, i32 1 - %160 = load i32, i32* %159, align 4 - %161 = add i32 %158, %160 - %162 = getelementptr %array, %array* %132, i32 0, i32 0 - %163 = load i32*, i32** %162, align 8 - %164 = getelementptr inbounds i32, i32* %163, i32 %161 - %165 = load i32, i32* %164, align 4 - %166 = icmp ne i32 %165, 99 - br i1 %166, label %then5, label %else6 - -then5: ; preds = %ifcont3 - %167 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.5, i32 0, i32 0), align 8 - %168 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.7, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %167, i8* %168) + %119 = mul i32 %118, %111 + %120 = add i32 %105, %119 + %121 = getelementptr %array, %array* %68, i32 0, i32 1 + %122 = load i32, i32* %121, align 4 + %123 = add i32 %120, %122 + %124 = getelementptr %array, %array* %68, i32 0, i32 0 + %125 = load i32*, i32** %124, align 8 + %126 = getelementptr inbounds i32, i32* %125, i32 %123 + %127 = load i32, i32* %126, align 4 + %128 = icmp ne i32 %127, 8 + br i1 %128, label %then22, label %else23 + +then22: ; preds = %ifcont21 + %129 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 + %130 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @26, i32 0, i32 0), i8* %129, i8* %130) + call void @exit(i32 1) + br label %ifcont24 + +else23: ; preds = %ifcont21 + br label %ifcont24 + +ifcont24: ; preds = %else23, %then22 + %131 = load %array*, %array** %x, align 8 + %132 = getelementptr %array, %array* %131, i32 0, i32 0 + %133 = load i32*, i32** %132, align 8 + %134 = ptrtoint i32* %133 to i64 + %135 = icmp ne i64 %134, 0 + br i1 %135, label %then25, label %else26 + +then25: ; preds = %ifcont24 + %136 = getelementptr %array, %array* %131, i32 0, i32 0 + %137 = load i32*, i32** %136, align 8 + %138 = alloca i8*, align 8 + %139 = bitcast i32* %137 to i8* + store i8* %139, i8** %138, align 8 + %140 = load i8*, i8** %138, align 8 + call void @_lfortran_free(i8* %140) + %141 = getelementptr %array, %array* %131, i32 0, i32 0 + store i32* null, i32** %141, align 8 + br label %ifcont27 + +else26: ; preds = %ifcont24 + br label %ifcont27 + +ifcont27: ; preds = %else26, %then25 + call void @f(%array** %x) + %142 = load %array*, %array** %x, align 8 + %143 = getelementptr %array, %array* %142, i32 0, i32 0 + %144 = load i32*, i32** %143, align 8 + %145 = ptrtoint i32* %144 to i64 + %146 = icmp ne i64 %145, 0 + %147 = xor i1 %146, true + br i1 %147, label %then28, label %else29 + +then28: ; preds = %ifcont27 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @29, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @28, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont7 - -else6: ; preds = %ifcont3 - br label %ifcont7 - -ifcont7: ; preds = %else6, %then5 - %169 = load %array*, %array** %x, align 8 - %170 = getelementptr %array, %array* %169, i32 0, i32 2 - %171 = load %dimension_descriptor*, %dimension_descriptor** %170, align 8 - %172 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %171, i32 0 - %173 = getelementptr %dimension_descriptor, %dimension_descriptor* %172, i32 0, i32 1 - %174 = load i32, i32* %173, align 4 - %175 = sub i32 1, %174 - %176 = getelementptr %dimension_descriptor, %dimension_descriptor* %172, i32 0, i32 0 + br label %ifcont30 + +else29: ; preds = %ifcont27 + br label %ifcont30 + +ifcont30: ; preds = %else29, %then28 + %148 = getelementptr %array, %array* %142, i32 0, i32 2 + %149 = load %dimension_descriptor*, %dimension_descriptor** %148, align 8 + %150 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %149, i32 0 + %151 = getelementptr %dimension_descriptor, %dimension_descriptor* %150, i32 0, i32 1 + %152 = load i32, i32* %151, align 4 + %153 = getelementptr %dimension_descriptor, %dimension_descriptor* %150, i32 0, i32 2 + %154 = load i32, i32* %153, align 4 + %155 = sub i32 1, %152 + %156 = add i32 %152, %154 + %157 = sub i32 %156, 1 + %158 = icmp slt i32 1, %152 + %159 = icmp sgt i32 1, %157 + %160 = or i1 %158, %159 + br i1 %160, label %then31, label %else32 + +then31: ; preds = %ifcont30 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @31, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @30, i32 0, i32 0), i32 1, i32 1, i32 %152, i32 %157) + call void @exit(i32 1) + br label %ifcont33 + +else32: ; preds = %ifcont30 + br label %ifcont33 + +ifcont33: ; preds = %else32, %then31 + %161 = getelementptr %dimension_descriptor, %dimension_descriptor* %150, i32 0, i32 0 + %162 = load i32, i32* %161, align 4 + %163 = mul i32 %162, %155 + %164 = add i32 0, %163 + %165 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %149, i32 1 + %166 = getelementptr %dimension_descriptor, %dimension_descriptor* %165, i32 0, i32 1 + %167 = load i32, i32* %166, align 4 + %168 = getelementptr %dimension_descriptor, %dimension_descriptor* %165, i32 0, i32 2 + %169 = load i32, i32* %168, align 4 + %170 = sub i32 1, %167 + %171 = add i32 %167, %169 + %172 = sub i32 %171, 1 + %173 = icmp slt i32 1, %167 + %174 = icmp sgt i32 1, %172 + %175 = or i1 %173, %174 + br i1 %175, label %then34, label %else35 + +then34: ; preds = %ifcont33 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0), i32 1, i32 2, i32 %167, i32 %172) + call void @exit(i32 1) + br label %ifcont36 + +else35: ; preds = %ifcont33 + br label %ifcont36 + +ifcont36: ; preds = %else35, %then34 + %176 = getelementptr %dimension_descriptor, %dimension_descriptor* %165, i32 0, i32 0 %177 = load i32, i32* %176, align 4 - %178 = mul i32 %177, %175 - %179 = add i32 0, %178 - %180 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %171, i32 1 + %178 = mul i32 %177, %170 + %179 = add i32 %164, %178 + %180 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %149, i32 2 %181 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 1 %182 = load i32, i32* %181, align 4 - %183 = sub i32 1, %182 - %184 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 0 - %185 = load i32, i32* %184, align 4 - %186 = mul i32 %185, %183 - %187 = add i32 %179, %186 - %188 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %171, i32 2 - %189 = getelementptr %dimension_descriptor, %dimension_descriptor* %188, i32 0, i32 1 - %190 = load i32, i32* %189, align 4 - %191 = sub i32 1, %190 - %192 = getelementptr %dimension_descriptor, %dimension_descriptor* %188, i32 0, i32 0 - %193 = load i32, i32* %192, align 4 - %194 = mul i32 %193, %191 - %195 = add i32 %187, %194 - %196 = getelementptr %array, %array* %169, i32 0, i32 1 - %197 = load i32, i32* %196, align 4 - %198 = add i32 %195, %197 - %199 = getelementptr %array, %array* %169, i32 0, i32 0 - %200 = load i32*, i32** %199, align 8 - %201 = getelementptr inbounds i32, i32* %200, i32 %198 - store i32 8, i32* %201, align 4 + %183 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 2 + %184 = load i32, i32* %183, align 4 + %185 = sub i32 1, %182 + %186 = add i32 %182, %184 + %187 = sub i32 %186, 1 + %188 = icmp slt i32 1, %182 + %189 = icmp sgt i32 1, %187 + %190 = or i1 %188, %189 + br i1 %190, label %then37, label %else38 + +then37: ; preds = %ifcont36 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @35, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @34, i32 0, i32 0), i32 1, i32 3, i32 %182, i32 %187) + call void @exit(i32 1) + br label %ifcont39 + +else38: ; preds = %ifcont36 + br label %ifcont39 + +ifcont39: ; preds = %else38, %then37 + %191 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 0 + %192 = load i32, i32* %191, align 4 + %193 = mul i32 %192, %185 + %194 = add i32 %179, %193 + %195 = getelementptr %array, %array* %142, i32 0, i32 1 + %196 = load i32, i32* %195, align 4 + %197 = add i32 %194, %196 + %198 = getelementptr %array, %array* %142, i32 0, i32 0 + %199 = load i32*, i32** %198, align 8 + %200 = getelementptr inbounds i32, i32* %199, i32 %197 + %201 = load i32, i32* %200, align 4 + %202 = alloca i32, align 4 + store i32 %201, i32* %202, align 4 + %203 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.3, i32 0, i32 0), i32 0, i32 0, i32* %202) + %204 = call i64 @_lfortran_str_len(i8* %203) + %205 = call i8* @_lfortran_malloc(i64 16) + %stringFormat_desc40 = bitcast i8* %205 to %string_descriptor* + %206 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc40, i32 0, i32 0 + store i8* %203, i8** %206, align 8 + %207 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc40, i32 0, i32 1 + store i64 %204, i64* %207, align 4 + %208 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc40, i32 0, i32 0 + %209 = load i8*, i8** %208, align 8 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @36, i32 0, i32 0), i8* %209, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0)) + %210 = load %array*, %array** %x, align 8 + %211 = getelementptr %array, %array* %210, i32 0, i32 0 + %212 = load i32*, i32** %211, align 8 + %213 = ptrtoint i32* %212 to i64 + %214 = icmp ne i64 %213, 0 + %215 = xor i1 %214, true + br i1 %215, label %then41, label %else42 + +then41: ; preds = %ifcont39 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @38, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @37, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont43 + +else42: ; preds = %ifcont39 + br label %ifcont43 + +ifcont43: ; preds = %else42, %then41 + %216 = getelementptr %array, %array* %210, i32 0, i32 2 + %217 = load %dimension_descriptor*, %dimension_descriptor** %216, align 8 + %218 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %217, i32 0 + %219 = getelementptr %dimension_descriptor, %dimension_descriptor* %218, i32 0, i32 1 + %220 = load i32, i32* %219, align 4 + %221 = getelementptr %dimension_descriptor, %dimension_descriptor* %218, i32 0, i32 2 + %222 = load i32, i32* %221, align 4 + %223 = sub i32 1, %220 + %224 = add i32 %220, %222 + %225 = sub i32 %224, 1 + %226 = icmp slt i32 1, %220 + %227 = icmp sgt i32 1, %225 + %228 = or i1 %226, %227 + br i1 %228, label %then44, label %else45 + +then44: ; preds = %ifcont43 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @40, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @39, i32 0, i32 0), i32 1, i32 1, i32 %220, i32 %225) + call void @exit(i32 1) + br label %ifcont46 + +else45: ; preds = %ifcont43 + br label %ifcont46 + +ifcont46: ; preds = %else45, %then44 + %229 = getelementptr %dimension_descriptor, %dimension_descriptor* %218, i32 0, i32 0 + %230 = load i32, i32* %229, align 4 + %231 = mul i32 %230, %223 + %232 = add i32 0, %231 + %233 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %217, i32 1 + %234 = getelementptr %dimension_descriptor, %dimension_descriptor* %233, i32 0, i32 1 + %235 = load i32, i32* %234, align 4 + %236 = getelementptr %dimension_descriptor, %dimension_descriptor* %233, i32 0, i32 2 + %237 = load i32, i32* %236, align 4 + %238 = sub i32 1, %235 + %239 = add i32 %235, %237 + %240 = sub i32 %239, 1 + %241 = icmp slt i32 1, %235 + %242 = icmp sgt i32 1, %240 + %243 = or i1 %241, %242 + br i1 %243, label %then47, label %else48 + +then47: ; preds = %ifcont46 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @42, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @41, i32 0, i32 0), i32 1, i32 2, i32 %235, i32 %240) + call void @exit(i32 1) + br label %ifcont49 + +else48: ; preds = %ifcont46 + br label %ifcont49 + +ifcont49: ; preds = %else48, %then47 + %244 = getelementptr %dimension_descriptor, %dimension_descriptor* %233, i32 0, i32 0 + %245 = load i32, i32* %244, align 4 + %246 = mul i32 %245, %238 + %247 = add i32 %232, %246 + %248 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %217, i32 2 + %249 = getelementptr %dimension_descriptor, %dimension_descriptor* %248, i32 0, i32 1 + %250 = load i32, i32* %249, align 4 + %251 = getelementptr %dimension_descriptor, %dimension_descriptor* %248, i32 0, i32 2 + %252 = load i32, i32* %251, align 4 + %253 = sub i32 1, %250 + %254 = add i32 %250, %252 + %255 = sub i32 %254, 1 + %256 = icmp slt i32 1, %250 + %257 = icmp sgt i32 1, %255 + %258 = or i1 %256, %257 + br i1 %258, label %then50, label %else51 + +then50: ; preds = %ifcont49 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @44, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @43, i32 0, i32 0), i32 1, i32 3, i32 %250, i32 %255) + call void @exit(i32 1) + br label %ifcont52 + +else51: ; preds = %ifcont49 + br label %ifcont52 + +ifcont52: ; preds = %else51, %then50 + %259 = getelementptr %dimension_descriptor, %dimension_descriptor* %248, i32 0, i32 0 + %260 = load i32, i32* %259, align 4 + %261 = mul i32 %260, %253 + %262 = add i32 %247, %261 + %263 = getelementptr %array, %array* %210, i32 0, i32 1 + %264 = load i32, i32* %263, align 4 + %265 = add i32 %262, %264 + %266 = getelementptr %array, %array* %210, i32 0, i32 0 + %267 = load i32*, i32** %266, align 8 + %268 = getelementptr inbounds i32, i32* %267, i32 %265 + %269 = load i32, i32* %268, align 4 + %270 = icmp ne i32 %269, 99 + br i1 %270, label %then53, label %else54 + +then53: ; preds = %ifcont52 + %271 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.5, i32 0, i32 0), align 8 + %272 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.7, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @45, i32 0, i32 0), i8* %271, i8* %272) + call void @exit(i32 1) + br label %ifcont55 + +else54: ; preds = %ifcont52 + br label %ifcont55 + +ifcont55: ; preds = %else54, %then53 + %273 = load %array*, %array** %x, align 8 + %274 = getelementptr %array, %array* %273, i32 0, i32 0 + %275 = load i32*, i32** %274, align 8 + %276 = ptrtoint i32* %275 to i64 + %277 = icmp ne i64 %276, 0 + %278 = xor i1 %277, true + br i1 %278, label %then56, label %else57 + +then56: ; preds = %ifcont55 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont58 + +else57: ; preds = %ifcont55 + br label %ifcont58 + +ifcont58: ; preds = %else57, %then56 + %279 = getelementptr %array, %array* %273, i32 0, i32 2 + %280 = load %dimension_descriptor*, %dimension_descriptor** %279, align 8 + %281 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %280, i32 0 + %282 = getelementptr %dimension_descriptor, %dimension_descriptor* %281, i32 0, i32 1 + %283 = load i32, i32* %282, align 4 + %284 = getelementptr %dimension_descriptor, %dimension_descriptor* %281, i32 0, i32 2 + %285 = load i32, i32* %284, align 4 + %286 = sub i32 1, %283 + %287 = add i32 %283, %285 + %288 = sub i32 %287, 1 + %289 = icmp slt i32 1, %283 + %290 = icmp sgt i32 1, %288 + %291 = or i1 %289, %290 + br i1 %291, label %then59, label %else60 + +then59: ; preds = %ifcont58 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 1, i32 1, i32 %283, i32 %288) + call void @exit(i32 1) + br label %ifcont61 + +else60: ; preds = %ifcont58 + br label %ifcont61 + +ifcont61: ; preds = %else60, %then59 + %292 = getelementptr %dimension_descriptor, %dimension_descriptor* %281, i32 0, i32 0 + %293 = load i32, i32* %292, align 4 + %294 = mul i32 %293, %286 + %295 = add i32 0, %294 + %296 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %280, i32 1 + %297 = getelementptr %dimension_descriptor, %dimension_descriptor* %296, i32 0, i32 1 + %298 = load i32, i32* %297, align 4 + %299 = getelementptr %dimension_descriptor, %dimension_descriptor* %296, i32 0, i32 2 + %300 = load i32, i32* %299, align 4 + %301 = sub i32 1, %298 + %302 = add i32 %298, %300 + %303 = sub i32 %302, 1 + %304 = icmp slt i32 1, %298 + %305 = icmp sgt i32 1, %303 + %306 = or i1 %304, %305 + br i1 %306, label %then62, label %else63 + +then62: ; preds = %ifcont61 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @51, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @50, i32 0, i32 0), i32 1, i32 2, i32 %298, i32 %303) + call void @exit(i32 1) + br label %ifcont64 + +else63: ; preds = %ifcont61 + br label %ifcont64 + +ifcont64: ; preds = %else63, %then62 + %307 = getelementptr %dimension_descriptor, %dimension_descriptor* %296, i32 0, i32 0 + %308 = load i32, i32* %307, align 4 + %309 = mul i32 %308, %301 + %310 = add i32 %295, %309 + %311 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %280, i32 2 + %312 = getelementptr %dimension_descriptor, %dimension_descriptor* %311, i32 0, i32 1 + %313 = load i32, i32* %312, align 4 + %314 = getelementptr %dimension_descriptor, %dimension_descriptor* %311, i32 0, i32 2 + %315 = load i32, i32* %314, align 4 + %316 = sub i32 1, %313 + %317 = add i32 %313, %315 + %318 = sub i32 %317, 1 + %319 = icmp slt i32 1, %313 + %320 = icmp sgt i32 1, %318 + %321 = or i1 %319, %320 + br i1 %321, label %then65, label %else66 + +then65: ; preds = %ifcont64 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @53, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @52, i32 0, i32 0), i32 1, i32 3, i32 %313, i32 %318) + call void @exit(i32 1) + br label %ifcont67 + +else66: ; preds = %ifcont64 + br label %ifcont67 + +ifcont67: ; preds = %else66, %then65 + %322 = getelementptr %dimension_descriptor, %dimension_descriptor* %311, i32 0, i32 0 + %323 = load i32, i32* %322, align 4 + %324 = mul i32 %323, %316 + %325 = add i32 %310, %324 + %326 = getelementptr %array, %array* %273, i32 0, i32 1 + %327 = load i32, i32* %326, align 4 + %328 = add i32 %325, %327 + %329 = getelementptr %array, %array* %273, i32 0, i32 0 + %330 = load i32*, i32** %329, align 8 + %331 = getelementptr inbounds i32, i32* %330, i32 %328 + store i32 8, i32* %331, align 4 store i32 0, i32* %r, align 4 br label %return -return: ; preds = %ifcont7 - %202 = load i32, i32* %r, align 4 - ret i32 %202 +return: ; preds = %ifcont67 + %332 = load i32, i32* %r, align 4 + ret i32 %332 } define void @h(%array** %c) { @@ -1010,7 +1435,7 @@ define void @h(%array** %c) { then: ; preds = %.entry %6 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.9, i32 0, i32 0), align 8 %7 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.11, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %6, i8* %7) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @54, i32 0, i32 0), i8* %6, i8* %7) call void @exit(i32 1) br label %ifcont @@ -1043,93 +1468,15 @@ else2: ; preds = %ifcont ifcont3: ; preds = %else2, %then1 call void @f(%array** %c) %19 = load %array*, %array** %c, align 8 - %20 = getelementptr %array, %array* %19, i32 0, i32 2 - %21 = load %dimension_descriptor*, %dimension_descriptor** %20, align 8 - %22 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %21, i32 0 - %23 = getelementptr %dimension_descriptor, %dimension_descriptor* %22, i32 0, i32 1 - %24 = load i32, i32* %23, align 4 - %25 = sub i32 1, %24 - %26 = getelementptr %dimension_descriptor, %dimension_descriptor* %22, i32 0, i32 0 - %27 = load i32, i32* %26, align 4 - %28 = mul i32 %27, %25 - %29 = add i32 0, %28 - %30 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %21, i32 1 - %31 = getelementptr %dimension_descriptor, %dimension_descriptor* %30, i32 0, i32 1 - %32 = load i32, i32* %31, align 4 - %33 = sub i32 1, %32 - %34 = getelementptr %dimension_descriptor, %dimension_descriptor* %30, i32 0, i32 0 - %35 = load i32, i32* %34, align 4 - %36 = mul i32 %35, %33 - %37 = add i32 %29, %36 - %38 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %21, i32 2 - %39 = getelementptr %dimension_descriptor, %dimension_descriptor* %38, i32 0, i32 1 - %40 = load i32, i32* %39, align 4 - %41 = sub i32 1, %40 - %42 = getelementptr %dimension_descriptor, %dimension_descriptor* %38, i32 0, i32 0 - %43 = load i32, i32* %42, align 4 - %44 = mul i32 %43, %41 - %45 = add i32 %37, %44 - %46 = getelementptr %array, %array* %19, i32 0, i32 1 - %47 = load i32, i32* %46, align 4 - %48 = add i32 %45, %47 - %49 = getelementptr %array, %array* %19, i32 0, i32 0 - %50 = load i32*, i32** %49, align 8 - %51 = getelementptr inbounds i32, i32* %50, i32 %48 - %52 = load i32, i32* %51, align 4 - %53 = alloca i32, align 4 - store i32 %52, i32* %53, align 4 - %54 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.12, i32 0, i32 0), i32 0, i32 0, i32* %53) - %55 = call i64 @_lfortran_str_len(i8* %54) - %56 = call i8* @_lfortran_malloc(i64 16) - %stringFormat_desc = bitcast i8* %56 to %string_descriptor* - %57 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 - store i8* %54, i8** %57, align 8 - %58 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 1 - store i64 %55, i64* %58, align 4 - %59 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 - %60 = load i8*, i8** %59, align 8 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %60, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @7, i32 0, i32 0)) - %61 = load %array*, %array** %c, align 8 - %62 = getelementptr %array, %array* %61, i32 0, i32 2 - %63 = load %dimension_descriptor*, %dimension_descriptor** %62, align 8 - %64 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %63, i32 0 - %65 = getelementptr %dimension_descriptor, %dimension_descriptor* %64, i32 0, i32 1 - %66 = load i32, i32* %65, align 4 - %67 = sub i32 1, %66 - %68 = getelementptr %dimension_descriptor, %dimension_descriptor* %64, i32 0, i32 0 - %69 = load i32, i32* %68, align 4 - %70 = mul i32 %69, %67 - %71 = add i32 0, %70 - %72 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %63, i32 1 - %73 = getelementptr %dimension_descriptor, %dimension_descriptor* %72, i32 0, i32 1 - %74 = load i32, i32* %73, align 4 - %75 = sub i32 1, %74 - %76 = getelementptr %dimension_descriptor, %dimension_descriptor* %72, i32 0, i32 0 - %77 = load i32, i32* %76, align 4 - %78 = mul i32 %77, %75 - %79 = add i32 %71, %78 - %80 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %63, i32 2 - %81 = getelementptr %dimension_descriptor, %dimension_descriptor* %80, i32 0, i32 1 - %82 = load i32, i32* %81, align 4 - %83 = sub i32 1, %82 - %84 = getelementptr %dimension_descriptor, %dimension_descriptor* %80, i32 0, i32 0 - %85 = load i32, i32* %84, align 4 - %86 = mul i32 %85, %83 - %87 = add i32 %79, %86 - %88 = getelementptr %array, %array* %61, i32 0, i32 1 - %89 = load i32, i32* %88, align 4 - %90 = add i32 %87, %89 - %91 = getelementptr %array, %array* %61, i32 0, i32 0 - %92 = load i32*, i32** %91, align 8 - %93 = getelementptr inbounds i32, i32* %92, i32 %90 - %94 = load i32, i32* %93, align 4 - %95 = icmp ne i32 %94, 99 - br i1 %95, label %then4, label %else5 + %20 = getelementptr %array, %array* %19, i32 0, i32 0 + %21 = load i32*, i32** %20, align 8 + %22 = ptrtoint i32* %21 to i64 + %23 = icmp ne i64 %22, 0 + %24 = xor i1 %23, true + br i1 %24, label %then4, label %else5 then4: ; preds = %ifcont3 - %96 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 - %97 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %96, i8* %97) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0)) call void @exit(i32 1) br label %ifcont6 @@ -1137,40 +1484,328 @@ else5: ; preds = %ifcont3 br label %ifcont6 ifcont6: ; preds = %else5, %then4 - %98 = load %array*, %array** %c, align 8 - %99 = getelementptr %array, %array* %98, i32 0, i32 2 - %100 = load %dimension_descriptor*, %dimension_descriptor** %99, align 8 - %101 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %100, i32 0 - %102 = getelementptr %dimension_descriptor, %dimension_descriptor* %101, i32 0, i32 1 - %103 = load i32, i32* %102, align 4 - %104 = sub i32 1, %103 - %105 = getelementptr %dimension_descriptor, %dimension_descriptor* %101, i32 0, i32 0 - %106 = load i32, i32* %105, align 4 - %107 = mul i32 %106, %104 - %108 = add i32 0, %107 - %109 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %100, i32 1 - %110 = getelementptr %dimension_descriptor, %dimension_descriptor* %109, i32 0, i32 1 - %111 = load i32, i32* %110, align 4 - %112 = sub i32 1, %111 - %113 = getelementptr %dimension_descriptor, %dimension_descriptor* %109, i32 0, i32 0 + %25 = getelementptr %array, %array* %19, i32 0, i32 2 + %26 = load %dimension_descriptor*, %dimension_descriptor** %25, align 8 + %27 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %26, i32 0 + %28 = getelementptr %dimension_descriptor, %dimension_descriptor* %27, i32 0, i32 1 + %29 = load i32, i32* %28, align 4 + %30 = getelementptr %dimension_descriptor, %dimension_descriptor* %27, i32 0, i32 2 + %31 = load i32, i32* %30, align 4 + %32 = sub i32 1, %29 + %33 = add i32 %29, %31 + %34 = sub i32 %33, 1 + %35 = icmp slt i32 1, %29 + %36 = icmp sgt i32 1, %34 + %37 = or i1 %35, %36 + br i1 %37, label %then7, label %else8 + +then7: ; preds = %ifcont6 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 1, i32 1, i32 %29, i32 %34) + call void @exit(i32 1) + br label %ifcont9 + +else8: ; preds = %ifcont6 + br label %ifcont9 + +ifcont9: ; preds = %else8, %then7 + %38 = getelementptr %dimension_descriptor, %dimension_descriptor* %27, i32 0, i32 0 + %39 = load i32, i32* %38, align 4 + %40 = mul i32 %39, %32 + %41 = add i32 0, %40 + %42 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %26, i32 1 + %43 = getelementptr %dimension_descriptor, %dimension_descriptor* %42, i32 0, i32 1 + %44 = load i32, i32* %43, align 4 + %45 = getelementptr %dimension_descriptor, %dimension_descriptor* %42, i32 0, i32 2 + %46 = load i32, i32* %45, align 4 + %47 = sub i32 1, %44 + %48 = add i32 %44, %46 + %49 = sub i32 %48, 1 + %50 = icmp slt i32 1, %44 + %51 = icmp sgt i32 1, %49 + %52 = or i1 %50, %51 + br i1 %52, label %then10, label %else11 + +then10: ; preds = %ifcont9 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 1, i32 2, i32 %44, i32 %49) + call void @exit(i32 1) + br label %ifcont12 + +else11: ; preds = %ifcont9 + br label %ifcont12 + +ifcont12: ; preds = %else11, %then10 + %53 = getelementptr %dimension_descriptor, %dimension_descriptor* %42, i32 0, i32 0 + %54 = load i32, i32* %53, align 4 + %55 = mul i32 %54, %47 + %56 = add i32 %41, %55 + %57 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %26, i32 2 + %58 = getelementptr %dimension_descriptor, %dimension_descriptor* %57, i32 0, i32 1 + %59 = load i32, i32* %58, align 4 + %60 = getelementptr %dimension_descriptor, %dimension_descriptor* %57, i32 0, i32 2 + %61 = load i32, i32* %60, align 4 + %62 = sub i32 1, %59 + %63 = add i32 %59, %61 + %64 = sub i32 %63, 1 + %65 = icmp slt i32 1, %59 + %66 = icmp sgt i32 1, %64 + %67 = or i1 %65, %66 + br i1 %67, label %then13, label %else14 + +then13: ; preds = %ifcont12 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 1, i32 3, i32 %59, i32 %64) + call void @exit(i32 1) + br label %ifcont15 + +else14: ; preds = %ifcont12 + br label %ifcont15 + +ifcont15: ; preds = %else14, %then13 + %68 = getelementptr %dimension_descriptor, %dimension_descriptor* %57, i32 0, i32 0 + %69 = load i32, i32* %68, align 4 + %70 = mul i32 %69, %62 + %71 = add i32 %56, %70 + %72 = getelementptr %array, %array* %19, i32 0, i32 1 + %73 = load i32, i32* %72, align 4 + %74 = add i32 %71, %73 + %75 = getelementptr %array, %array* %19, i32 0, i32 0 + %76 = load i32*, i32** %75, align 8 + %77 = getelementptr inbounds i32, i32* %76, i32 %74 + %78 = load i32, i32* %77, align 4 + %79 = alloca i32, align 4 + store i32 %78, i32* %79, align 4 + %80 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.12, i32 0, i32 0), i32 0, i32 0, i32* %79) + %81 = call i64 @_lfortran_str_len(i8* %80) + %82 = call i8* @_lfortran_malloc(i64 16) + %stringFormat_desc = bitcast i8* %82 to %string_descriptor* + %83 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 + store i8* %80, i8** %83, align 8 + %84 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 1 + store i64 %81, i64* %84, align 4 + %85 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 + %86 = load i8*, i8** %85, align 8 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @64, i32 0, i32 0), i8* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0)) + %87 = load %array*, %array** %c, align 8 + %88 = getelementptr %array, %array* %87, i32 0, i32 0 + %89 = load i32*, i32** %88, align 8 + %90 = ptrtoint i32* %89 to i64 + %91 = icmp ne i64 %90, 0 + %92 = xor i1 %91, true + br i1 %92, label %then16, label %else17 + +then16: ; preds = %ifcont15 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @66, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @65, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont18 + +else17: ; preds = %ifcont15 + br label %ifcont18 + +ifcont18: ; preds = %else17, %then16 + %93 = getelementptr %array, %array* %87, i32 0, i32 2 + %94 = load %dimension_descriptor*, %dimension_descriptor** %93, align 8 + %95 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %94, i32 0 + %96 = getelementptr %dimension_descriptor, %dimension_descriptor* %95, i32 0, i32 1 + %97 = load i32, i32* %96, align 4 + %98 = getelementptr %dimension_descriptor, %dimension_descriptor* %95, i32 0, i32 2 + %99 = load i32, i32* %98, align 4 + %100 = sub i32 1, %97 + %101 = add i32 %97, %99 + %102 = sub i32 %101, 1 + %103 = icmp slt i32 1, %97 + %104 = icmp sgt i32 1, %102 + %105 = or i1 %103, %104 + br i1 %105, label %then19, label %else20 + +then19: ; preds = %ifcont18 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @68, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @67, i32 0, i32 0), i32 1, i32 1, i32 %97, i32 %102) + call void @exit(i32 1) + br label %ifcont21 + +else20: ; preds = %ifcont18 + br label %ifcont21 + +ifcont21: ; preds = %else20, %then19 + %106 = getelementptr %dimension_descriptor, %dimension_descriptor* %95, i32 0, i32 0 + %107 = load i32, i32* %106, align 4 + %108 = mul i32 %107, %100 + %109 = add i32 0, %108 + %110 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %94, i32 1 + %111 = getelementptr %dimension_descriptor, %dimension_descriptor* %110, i32 0, i32 1 + %112 = load i32, i32* %111, align 4 + %113 = getelementptr %dimension_descriptor, %dimension_descriptor* %110, i32 0, i32 2 %114 = load i32, i32* %113, align 4 - %115 = mul i32 %114, %112 - %116 = add i32 %108, %115 - %117 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %100, i32 2 - %118 = getelementptr %dimension_descriptor, %dimension_descriptor* %117, i32 0, i32 1 - %119 = load i32, i32* %118, align 4 - %120 = sub i32 1, %119 - %121 = getelementptr %dimension_descriptor, %dimension_descriptor* %117, i32 0, i32 0 + %115 = sub i32 1, %112 + %116 = add i32 %112, %114 + %117 = sub i32 %116, 1 + %118 = icmp slt i32 1, %112 + %119 = icmp sgt i32 1, %117 + %120 = or i1 %118, %119 + br i1 %120, label %then22, label %else23 + +then22: ; preds = %ifcont21 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @69, i32 0, i32 0), i32 1, i32 2, i32 %112, i32 %117) + call void @exit(i32 1) + br label %ifcont24 + +else23: ; preds = %ifcont21 + br label %ifcont24 + +ifcont24: ; preds = %else23, %then22 + %121 = getelementptr %dimension_descriptor, %dimension_descriptor* %110, i32 0, i32 0 %122 = load i32, i32* %121, align 4 - %123 = mul i32 %122, %120 - %124 = add i32 %116, %123 - %125 = getelementptr %array, %array* %98, i32 0, i32 1 - %126 = load i32, i32* %125, align 4 - %127 = add i32 %124, %126 - %128 = getelementptr %array, %array* %98, i32 0, i32 0 - %129 = load i32*, i32** %128, align 8 - %130 = getelementptr inbounds i32, i32* %129, i32 %127 - store i32 8, i32* %130, align 4 + %123 = mul i32 %122, %115 + %124 = add i32 %109, %123 + %125 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %94, i32 2 + %126 = getelementptr %dimension_descriptor, %dimension_descriptor* %125, i32 0, i32 1 + %127 = load i32, i32* %126, align 4 + %128 = getelementptr %dimension_descriptor, %dimension_descriptor* %125, i32 0, i32 2 + %129 = load i32, i32* %128, align 4 + %130 = sub i32 1, %127 + %131 = add i32 %127, %129 + %132 = sub i32 %131, 1 + %133 = icmp slt i32 1, %127 + %134 = icmp sgt i32 1, %132 + %135 = or i1 %133, %134 + br i1 %135, label %then25, label %else26 + +then25: ; preds = %ifcont24 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @72, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @71, i32 0, i32 0), i32 1, i32 3, i32 %127, i32 %132) + call void @exit(i32 1) + br label %ifcont27 + +else26: ; preds = %ifcont24 + br label %ifcont27 + +ifcont27: ; preds = %else26, %then25 + %136 = getelementptr %dimension_descriptor, %dimension_descriptor* %125, i32 0, i32 0 + %137 = load i32, i32* %136, align 4 + %138 = mul i32 %137, %130 + %139 = add i32 %124, %138 + %140 = getelementptr %array, %array* %87, i32 0, i32 1 + %141 = load i32, i32* %140, align 4 + %142 = add i32 %139, %141 + %143 = getelementptr %array, %array* %87, i32 0, i32 0 + %144 = load i32*, i32** %143, align 8 + %145 = getelementptr inbounds i32, i32* %144, i32 %142 + %146 = load i32, i32* %145, align 4 + %147 = icmp ne i32 %146, 99 + br i1 %147, label %then28, label %else29 + +then28: ; preds = %ifcont27 + %148 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 + %149 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @73, i32 0, i32 0), i8* %148, i8* %149) + call void @exit(i32 1) + br label %ifcont30 + +else29: ; preds = %ifcont27 + br label %ifcont30 + +ifcont30: ; preds = %else29, %then28 + %150 = load %array*, %array** %c, align 8 + %151 = getelementptr %array, %array* %150, i32 0, i32 0 + %152 = load i32*, i32** %151, align 8 + %153 = ptrtoint i32* %152 to i64 + %154 = icmp ne i64 %153, 0 + %155 = xor i1 %154, true + br i1 %155, label %then31, label %else32 + +then31: ; preds = %ifcont30 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0)) + call void @exit(i32 1) + br label %ifcont33 + +else32: ; preds = %ifcont30 + br label %ifcont33 + +ifcont33: ; preds = %else32, %then31 + %156 = getelementptr %array, %array* %150, i32 0, i32 2 + %157 = load %dimension_descriptor*, %dimension_descriptor** %156, align 8 + %158 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %157, i32 0 + %159 = getelementptr %dimension_descriptor, %dimension_descriptor* %158, i32 0, i32 1 + %160 = load i32, i32* %159, align 4 + %161 = getelementptr %dimension_descriptor, %dimension_descriptor* %158, i32 0, i32 2 + %162 = load i32, i32* %161, align 4 + %163 = sub i32 1, %160 + %164 = add i32 %160, %162 + %165 = sub i32 %164, 1 + %166 = icmp slt i32 1, %160 + %167 = icmp sgt i32 1, %165 + %168 = or i1 %166, %167 + br i1 %168, label %then34, label %else35 + +then34: ; preds = %ifcont33 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @77, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @76, i32 0, i32 0), i32 1, i32 1, i32 %160, i32 %165) + call void @exit(i32 1) + br label %ifcont36 + +else35: ; preds = %ifcont33 + br label %ifcont36 + +ifcont36: ; preds = %else35, %then34 + %169 = getelementptr %dimension_descriptor, %dimension_descriptor* %158, i32 0, i32 0 + %170 = load i32, i32* %169, align 4 + %171 = mul i32 %170, %163 + %172 = add i32 0, %171 + %173 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %157, i32 1 + %174 = getelementptr %dimension_descriptor, %dimension_descriptor* %173, i32 0, i32 1 + %175 = load i32, i32* %174, align 4 + %176 = getelementptr %dimension_descriptor, %dimension_descriptor* %173, i32 0, i32 2 + %177 = load i32, i32* %176, align 4 + %178 = sub i32 1, %175 + %179 = add i32 %175, %177 + %180 = sub i32 %179, 1 + %181 = icmp slt i32 1, %175 + %182 = icmp sgt i32 1, %180 + %183 = or i1 %181, %182 + br i1 %183, label %then37, label %else38 + +then37: ; preds = %ifcont36 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @79, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @78, i32 0, i32 0), i32 1, i32 2, i32 %175, i32 %180) + call void @exit(i32 1) + br label %ifcont39 + +else38: ; preds = %ifcont36 + br label %ifcont39 + +ifcont39: ; preds = %else38, %then37 + %184 = getelementptr %dimension_descriptor, %dimension_descriptor* %173, i32 0, i32 0 + %185 = load i32, i32* %184, align 4 + %186 = mul i32 %185, %178 + %187 = add i32 %172, %186 + %188 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %157, i32 2 + %189 = getelementptr %dimension_descriptor, %dimension_descriptor* %188, i32 0, i32 1 + %190 = load i32, i32* %189, align 4 + %191 = getelementptr %dimension_descriptor, %dimension_descriptor* %188, i32 0, i32 2 + %192 = load i32, i32* %191, align 4 + %193 = sub i32 1, %190 + %194 = add i32 %190, %192 + %195 = sub i32 %194, 1 + %196 = icmp slt i32 1, %190 + %197 = icmp sgt i32 1, %195 + %198 = or i1 %196, %197 + br i1 %198, label %then40, label %else41 + +then40: ; preds = %ifcont39 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @81, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @80, i32 0, i32 0), i32 1, i32 3, i32 %190, i32 %195) + call void @exit(i32 1) + br label %ifcont42 + +else41: ; preds = %ifcont39 + br label %ifcont42 + +ifcont42: ; preds = %else41, %then40 + %199 = getelementptr %dimension_descriptor, %dimension_descriptor* %188, i32 0, i32 0 + %200 = load i32, i32* %199, align 4 + %201 = mul i32 %200, %193 + %202 = add i32 %187, %201 + %203 = getelementptr %array, %array* %150, i32 0, i32 1 + %204 = load i32, i32* %203, align 4 + %205 = add i32 %202, %204 + %206 = getelementptr %array, %array* %150, i32 0, i32 0 + %207 = load i32*, i32** %206, align 8 + %208 = getelementptr inbounds i32, i32* %207, i32 %205 + store i32 8, i32* %208, align 4 br label %return return: ; preds = %ifcont42 @@ -1179,17 +1814,13 @@ return: ; preds = %ifcont42 declare i8* @_lfortran_malloc(i64) -declare i8* @_lcompilers_string_format_fortran(i8*, i64, i8*, i32, i32, ...) - -declare i64 @_lfortran_str_len(i8*) - -declare void @_lfortran_printf(i8*, ...) - declare void @_lcompilers_print_error(i8*, ...) declare void @exit(i32) -declare i8* @_lcompilers_string_format_fortran(i8*, i8*, i32, i32, ...) +declare i8* @_lcompilers_string_format_fortran(i8*, i64, i8*, i32, i32, ...) + +declare i64 @_lfortran_str_len(i8*) declare void @_lfortran_printf(i8*, ...) diff --git a/tests/reference/llvm-arrays_01-91893af.json b/tests/reference/llvm-arrays_01-91893af.json index 0c6d59f5813..3031d65c27d 100644 --- a/tests/reference/llvm-arrays_01-91893af.json +++ b/tests/reference/llvm-arrays_01-91893af.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01-91893af.stdout", - "stdout_hash": "519edf069901f00ac8cffe1f8bd2bfa6c9f6e3b6b7d8fab112169b1d", + "stdout_hash": "7e6eaf20854bb55c7e2206f4019bd183338fb937cc68c2dc25149b86", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01-91893af.stdout b/tests/reference/llvm-arrays_01-91893af.stdout index bd931560f8e..fcf3db18f55 100644 --- a/tests/reference/llvm-arrays_01-91893af.stdout +++ b/tests/reference/llvm-arrays_01-91893af.stdout @@ -3,66 +3,112 @@ source_filename = "LFortran" %string_descriptor = type <{ i8*, i64 }> +@0 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@1 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@2 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@3 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data = private constant [11 x i8] c"ERROR STOP\00" @string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data, i32 0, i32 0), i64 10 }> @string_const_data.1 = private constant [2 x i8] c"\0A\00" @string_const.2 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.1, i32 0, i32 0), i64 1 }> -@0 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@5 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@6 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.3 = private constant [11 x i8] c"ERROR STOP\00" @string_const.4 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.3, i32 0, i32 0), i64 10 }> @string_const_data.5 = private constant [2 x i8] c"\0A\00" @string_const.6 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.5, i32 0, i32 0), i64 1 }> -@1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@8 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@9 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.7 = private constant [11 x i8] c"ERROR STOP\00" @string_const.8 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.7, i32 0, i32 0), i64 10 }> @string_const_data.9 = private constant [2 x i8] c"\0A\00" @string_const.10 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.9, i32 0, i32 0), i64 1 }> -@2 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@11 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@12 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@13 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@14 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.11 = private constant [11 x i8] c"ERROR STOP\00" @string_const.12 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.11, i32 0, i32 0), i64 10 }> @string_const_data.13 = private constant [2 x i8] c"\0A\00" @string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.13, i32 0, i32 0), i64 1 }> -@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@15 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@16 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@17 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.15 = private constant [11 x i8] c"ERROR STOP\00" @string_const.16 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.15, i32 0, i32 0), i64 10 }> @string_const_data.17 = private constant [2 x i8] c"\0A\00" @string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.17, i32 0, i32 0), i64 1 }> -@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@18 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@19 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@20 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.19 = private constant [11 x i8] c"ERROR STOP\00" @string_const.20 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.19, i32 0, i32 0), i64 10 }> @string_const_data.21 = private constant [2 x i8] c"\0A\00" @string_const.22 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.21, i32 0, i32 0), i64 1 }> -@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@21 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@22 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@23 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.23 = private constant [11 x i8] c"ERROR STOP\00" @string_const.24 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.23, i32 0, i32 0), i64 10 }> @string_const_data.25 = private constant [2 x i8] c"\0A\00" @string_const.26 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.25, i32 0, i32 0), i64 1 }> -@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@24 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@25 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@26 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@27 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@28 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@29 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@30 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.27 = private constant [11 x i8] c"ERROR STOP\00" @string_const.28 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.27, i32 0, i32 0), i64 10 }> @string_const_data.29 = private constant [2 x i8] c"\0A\00" @string_const.30 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.29, i32 0, i32 0), i64 1 }> -@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@31 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@32 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@33 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.31 = private constant [11 x i8] c"ERROR STOP\00" @string_const.32 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.31, i32 0, i32 0), i64 10 }> @string_const_data.33 = private constant [2 x i8] c"\0A\00" @string_const.34 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.33, i32 0, i32 0), i64 1 }> -@8 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@34 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@35 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@36 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.35 = private constant [11 x i8] c"ERROR STOP\00" @string_const.36 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.35, i32 0, i32 0), i64 10 }> @string_const_data.37 = private constant [2 x i8] c"\0A\00" @string_const.38 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.37, i32 0, i32 0), i64 1 }> -@9 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@37 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@38 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@39 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@40 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@41 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@42 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@43 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@44 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@45 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@46 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@47 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@48 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@49 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.39 = private constant [11 x i8] c"ERROR STOP\00" @string_const.40 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.39, i32 0, i32 0), i64 10 }> @string_const_data.41 = private constant [2 x i8] c"\0A\00" @string_const.42 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.41, i32 0, i32 0), i64 1 }> -@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@50 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@51 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@52 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@53 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@54 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@55 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@56 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.43 = private constant [11 x i8] c"ERROR STOP\00" @string_const.44 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.43, i32 0, i32 0), i64 10 }> @string_const_data.45 = private constant [2 x i8] c"\0A\00" @string_const.46 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.45, i32 0, i32 0), i64 1 }> -@11 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@57 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -93,16 +139,8 @@ loop.body: ; preds = %loop.head %13 = or i1 %11, %12 br i1 %13, label %then, label %else -loop.end: ; preds = %loop.head - %14 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %15 = load i32, i32* %14, align 4 - %16 = icmp ne i32 %15, 11 - br i1 %16, label %then, label %else - -then: ; preds = %loop.end - %17 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 - %18 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8* %17, i8* %18) +then: ; preds = %loop.body + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 %7, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont @@ -110,15 +148,17 @@ else: ; preds = %loop.body br label %ifcont ifcont: ; preds = %else, %then - %19 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 1 - %20 = load i32, i32* %19, align 4 - %21 = icmp ne i32 %20, 12 - br i1 %21, label %then2, label %else3 + %14 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %10 + %15 = load i32, i32* %i1, align 4 + %16 = add i32 %15, 10 + store i32 %16, i32* %14, align 4 + br label %loop.head + +loop.end: ; preds = %loop.head + br i1 false, label %then2, label %else3 -then2: ; preds = %ifcont - %22 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 - %23 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %22, i8* %23) +then2: ; preds = %loop.end + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont4 @@ -126,15 +166,15 @@ else3: ; preds = %loop.end br label %ifcont4 ifcont4: ; preds = %else3, %then2 - %24 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 2 - %25 = load i32, i32* %24, align 4 - %26 = icmp ne i32 %25, 13 - br i1 %26, label %then5, label %else6 + %17 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %18 = load i32, i32* %17, align 4 + %19 = icmp ne i32 %18, 11 + br i1 %19, label %then5, label %else6 then5: ; preds = %ifcont4 - %27 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 - %28 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i8* %27, i8* %28) + %20 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 + %21 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %20, i8* %21) call void @exit(i32 1) br label %ifcont7 @@ -144,36 +184,24 @@ else6: ; preds = %ifcont4 ifcont7: ; preds = %else6, %then5 br i1 false, label %then8, label %else9 -loop.head8: ; preds = %loop.body9, %ifcont7 - %29 = load i32, i32* %i1, align 4 - %30 = add i32 %29, 1 - %31 = icmp sle i32 %30, 14 - br i1 %31, label %loop.body9, label %loop.end10 +then8: ; preds = %ifcont7 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @5, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont10 -loop.body9: ; preds = %loop.head8 - %32 = load i32, i32* %i1, align 4 - %33 = add i32 %32, 1 - store i32 %33, i32* %i1, align 4 - %34 = load i32, i32* %i1, align 4 - %35 = sub i32 %34, 10 - %36 = sub i32 %35, 1 - %37 = mul i32 1, %36 - %38 = add i32 0, %37 - %39 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %38 - %40 = load i32, i32* %i1, align 4 - store i32 %40, i32* %39, align 4 - br label %loop.head8 - -loop.end10: ; preds = %loop.head8 - %41 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %42 = load i32, i32* %41, align 4 - %43 = icmp ne i32 %42, 11 - br i1 %43, label %then11, label %else12 - -then11: ; preds = %loop.end10 - %44 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 - %45 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %44, i8* %45) +else9: ; preds = %ifcont7 + br label %ifcont10 + +ifcont10: ; preds = %else9, %then8 + %22 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 1 + %23 = load i32, i32* %22, align 4 + %24 = icmp ne i32 %23, 12 + br i1 %24, label %then11, label %else12 + +then11: ; preds = %ifcont10 + %25 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 + %26 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %25, i8* %26) call void @exit(i32 1) br label %ifcont13 @@ -181,15 +209,10 @@ else12: ; preds = %ifcont10 br label %ifcont13 ifcont13: ; preds = %else12, %then11 - %46 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %47 = load i32, i32* %46, align 4 - %48 = icmp ne i32 %47, 12 - br i1 %48, label %then14, label %else15 + br i1 false, label %then14, label %else15 then14: ; preds = %ifcont13 - %49 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 - %50 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %49, i8* %50) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @9, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @8, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont16 @@ -197,15 +220,15 @@ else15: ; preds = %ifcont13 br label %ifcont16 ifcont16: ; preds = %else15, %then14 - %51 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %52 = load i32, i32* %51, align 4 - %53 = icmp ne i32 %52, 13 - br i1 %53, label %then17, label %else18 + %27 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 2 + %28 = load i32, i32* %27, align 4 + %29 = icmp ne i32 %28, 13 + br i1 %29, label %then17, label %else18 then17: ; preds = %ifcont16 - %54 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 - %55 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %54, i8* %55) + %30 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 + %31 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %30, i8* %31) call void @exit(i32 1) br label %ifcont19 @@ -213,15 +236,31 @@ else18: ; preds = %ifcont16 br label %ifcont19 ifcont19: ; preds = %else18, %then17 - %56 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %57 = load i32, i32* %56, align 4 - %58 = icmp ne i32 %57, 14 - br i1 %58, label %then20, label %else21 + store i32 10, i32* %i1, align 4 + br label %loop.head20 -then20: ; preds = %ifcont19 - %59 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 - %60 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %59, i8* %60) +loop.head20: ; preds = %ifcont24, %ifcont19 + %32 = load i32, i32* %i1, align 4 + %33 = add i32 %32, 1 + %34 = icmp sle i32 %33, 14 + br i1 %34, label %loop.body21, label %loop.end25 + +loop.body21: ; preds = %loop.head20 + %35 = load i32, i32* %i1, align 4 + %36 = add i32 %35, 1 + store i32 %36, i32* %i1, align 4 + %37 = load i32, i32* %i1, align 4 + %38 = sub i32 %37, 10 + %39 = sub i32 %38, 1 + %40 = mul i32 1, %39 + %41 = add i32 0, %40 + %42 = icmp slt i32 %38, 1 + %43 = icmp sgt i32 %38, 4 + %44 = or i1 %42, %43 + br i1 %44, label %then22, label %else23 + +then22: ; preds = %loop.body21 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i32 %38, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont24 @@ -229,46 +268,16 @@ else23: ; preds = %loop.body21 br label %ifcont24 ifcont24: ; preds = %else23, %then22 - %39 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %35 - %40 = load i32, i32* %i1, align 4 - store i32 %40, i32* %39, align 4 + %45 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %41 + %46 = load i32, i32* %i1, align 4 + store i32 %46, i32* %45, align 4 br label %loop.head20 -loop.head23: ; preds = %loop.body24, %ifcont22 - %61 = load i32, i32* %i1, align 4 - %62 = add i32 %61, 1 - %63 = icmp sle i32 %62, 3 - br i1 %63, label %loop.body24, label %loop.end25 - -loop.body24: ; preds = %loop.head23 - %64 = load i32, i32* %i1, align 4 - %65 = add i32 %64, 1 - store i32 %65, i32* %i1, align 4 - %66 = load i32, i32* %i1, align 4 - %67 = sub i32 %66, 1 - %68 = mul i32 1, %67 - %69 = add i32 0, %68 - %70 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %69 - %71 = load i32, i32* %i1, align 4 - %72 = sub i32 %71, 1 - %73 = mul i32 1, %72 - %74 = add i32 0, %73 - %75 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %74 - %76 = load i32, i32* %75, align 4 - %77 = sub i32 %76, 10 - store i32 %77, i32* %70, align 4 - br label %loop.head23 - -loop.end25: ; preds = %loop.head23 - %78 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %79 = load i32, i32* %78, align 4 - %80 = icmp ne i32 %79, 1 - br i1 %80, label %then26, label %else27 +loop.end25: ; preds = %loop.head20 + br i1 false, label %then26, label %else27 then26: ; preds = %loop.end25 - %81 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 - %82 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %81, i8* %82) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont28 @@ -276,15 +285,15 @@ else27: ; preds = %loop.end25 br label %ifcont28 ifcont28: ; preds = %else27, %then26 - %83 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %84 = load i32, i32* %83, align 4 - %85 = icmp ne i32 %84, 2 - br i1 %85, label %then29, label %else30 + %47 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %48 = load i32, i32* %47, align 4 + %49 = icmp ne i32 %48, 11 + br i1 %49, label %then29, label %else30 then29: ; preds = %ifcont28 - %86 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 - %87 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %86, i8* %87) + %50 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 + %51 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %50, i8* %51) call void @exit(i32 1) br label %ifcont31 @@ -292,15 +301,10 @@ else30: ; preds = %ifcont28 br label %ifcont31 ifcont31: ; preds = %else30, %then29 - %88 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %89 = load i32, i32* %88, align 4 - %90 = icmp ne i32 %89, 3 - br i1 %90, label %then32, label %else33 + br i1 false, label %then32, label %else33 then32: ; preds = %ifcont31 - %91 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 - %92 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %91, i8* %92) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @16, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont34 @@ -308,28 +312,15 @@ else33: ; preds = %ifcont31 br label %ifcont34 ifcont34: ; preds = %else33, %then32 - %93 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %94 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %95 = load i32, i32* %94, align 4 - %96 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %97 = load i32, i32* %96, align 4 - %98 = add i32 %95, %97 - %99 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %100 = load i32, i32* %99, align 4 - %101 = add i32 %98, %100 - %102 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %103 = load i32, i32* %102, align 4 - %104 = add i32 %101, %103 - store i32 %104, i32* %93, align 4 - %105 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %106 = load i32, i32* %105, align 4 - %107 = icmp ne i32 %106, 17 - br i1 %107, label %then35, label %else36 + %52 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %53 = load i32, i32* %52, align 4 + %54 = icmp ne i32 %53, 12 + br i1 %54, label %then35, label %else36 then35: ; preds = %ifcont34 - %108 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 - %109 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %108, i8* %109) + %55 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 + %56 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @18, i32 0, i32 0), i8* %55, i8* %56) call void @exit(i32 1) br label %ifcont37 @@ -337,19 +328,10 @@ else36: ; preds = %ifcont34 br label %ifcont37 ifcont37: ; preds = %else36, %then35 - %110 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %111 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %112 = load i32, i32* %111, align 4 - store i32 %112, i32* %110, align 4 - %113 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %114 = load i32, i32* %113, align 4 - %115 = icmp ne i32 %114, 11 - br i1 %115, label %then38, label %else39 + br i1 false, label %then38, label %else39 then38: ; preds = %ifcont37 - %116 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 - %117 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %116, i8* %117) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont40 @@ -357,13 +339,15 @@ else39: ; preds = %ifcont37 br label %ifcont40 ifcont40: ; preds = %else39, %then38 - %47 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %48 = load i32, i32* %47, align 4 - %49 = icmp ne i32 %48, 13 - br i1 %49, label %then41, label %else42 + %57 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %58 = load i32, i32* %57, align 4 + %59 = icmp ne i32 %58, 13 + br i1 %59, label %then41, label %else42 then41: ; preds = %ifcont40 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @31, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0)) + %60 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 + %61 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @21, i32 0, i32 0), i8* %60, i8* %61) call void @exit(i32 1) br label %ifcont43 @@ -374,7 +358,7 @@ ifcont43: ; preds = %else42, %then41 br i1 false, label %then44, label %else45 then44: ; preds = %ifcont43 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @35, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @34, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @22, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont46 @@ -382,13 +366,15 @@ else45: ; preds = %ifcont43 br label %ifcont46 ifcont46: ; preds = %else45, %then44 - %50 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %51 = load i32, i32* %50, align 4 - %52 = icmp ne i32 %51, 14 - br i1 %52, label %then47, label %else48 + %62 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %63 = load i32, i32* %62, align 4 + %64 = icmp ne i32 %63, 14 + br i1 %64, label %then47, label %else48 then47: ; preds = %ifcont46 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @38, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @37, i32 0, i32 0)) + %65 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 + %66 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @24, i32 0, i32 0), i8* %65, i8* %66) call void @exit(i32 1) br label %ifcont49 @@ -400,26 +386,26 @@ ifcont49: ; preds = %else48, %then47 br label %loop.head50 loop.head50: ; preds = %ifcont57, %ifcont49 - %53 = load i32, i32* %i1, align 4 - %54 = add i32 %53, 1 - %55 = icmp sle i32 %54, 3 - br i1 %55, label %loop.body51, label %loop.end58 + %67 = load i32, i32* %i1, align 4 + %68 = add i32 %67, 1 + %69 = icmp sle i32 %68, 3 + br i1 %69, label %loop.body51, label %loop.end58 loop.body51: ; preds = %loop.head50 - %56 = load i32, i32* %i1, align 4 - %57 = add i32 %56, 1 - store i32 %57, i32* %i1, align 4 - %58 = load i32, i32* %i1, align 4 - %59 = sub i32 %58, 1 - %60 = mul i32 1, %59 - %61 = add i32 0, %60 - %62 = icmp slt i32 %58, 1 - %63 = icmp sgt i32 %58, 4 - %64 = or i1 %62, %63 - br i1 %64, label %then52, label %else53 + %70 = load i32, i32* %i1, align 4 + %71 = add i32 %70, 1 + store i32 %71, i32* %i1, align 4 + %72 = load i32, i32* %i1, align 4 + %73 = sub i32 %72, 1 + %74 = mul i32 1, %73 + %75 = add i32 0, %74 + %76 = icmp slt i32 %72, 1 + %77 = icmp sgt i32 %72, 4 + %78 = or i1 %76, %77 + br i1 %78, label %then52, label %else53 then52: ; preds = %loop.body51 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @40, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @39, i32 0, i32 0), i32 %58, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @26, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @25, i32 0, i32 0), i32 %72, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont54 @@ -427,18 +413,18 @@ else53: ; preds = %loop.body51 br label %ifcont54 ifcont54: ; preds = %else53, %then52 - %65 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %61 - %66 = load i32, i32* %i1, align 4 - %67 = sub i32 %66, 1 - %68 = mul i32 1, %67 - %69 = add i32 0, %68 - %70 = icmp slt i32 %66, 1 - %71 = icmp sgt i32 %66, 3 - %72 = or i1 %70, %71 - br i1 %72, label %then55, label %else56 + %79 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %75 + %80 = load i32, i32* %i1, align 4 + %81 = sub i32 %80, 1 + %82 = mul i32 1, %81 + %83 = add i32 0, %82 + %84 = icmp slt i32 %80, 1 + %85 = icmp sgt i32 %80, 3 + %86 = or i1 %84, %85 + br i1 %86, label %then55, label %else56 then55: ; preds = %ifcont54 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @42, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @41, i32 0, i32 0), i32 %66, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %80, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont57 @@ -446,17 +432,17 @@ else56: ; preds = %ifcont54 br label %ifcont57 ifcont57: ; preds = %else56, %then55 - %73 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %69 - %74 = load i32, i32* %73, align 4 - %75 = sub i32 %74, 10 - store i32 %75, i32* %65, align 4 + %87 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %83 + %88 = load i32, i32* %87, align 4 + %89 = sub i32 %88, 10 + store i32 %89, i32* %79, align 4 br label %loop.head50 loop.end58: ; preds = %loop.head50 br i1 false, label %then59, label %else60 then59: ; preds = %loop.end58 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @44, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @43, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont61 @@ -464,13 +450,15 @@ else60: ; preds = %loop.end58 br label %ifcont61 ifcont61: ; preds = %else60, %then59 - %76 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %77 = load i32, i32* %76, align 4 - %78 = icmp ne i32 %77, 1 - br i1 %78, label %then62, label %else63 + %90 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %91 = load i32, i32* %90, align 4 + %92 = icmp ne i32 %91, 1 + br i1 %92, label %then62, label %else63 then62: ; preds = %ifcont61 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0)) + %93 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 + %94 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @31, i32 0, i32 0), i8* %93, i8* %94) call void @exit(i32 1) br label %ifcont64 @@ -481,7 +469,7 @@ ifcont64: ; preds = %else63, %then62 br i1 false, label %then65, label %else66 then65: ; preds = %ifcont64 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont67 @@ -489,13 +477,15 @@ else66: ; preds = %ifcont64 br label %ifcont67 ifcont67: ; preds = %else66, %then65 - %79 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %80 = load i32, i32* %79, align 4 - %81 = icmp ne i32 %80, 2 - br i1 %81, label %then68, label %else69 + %95 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %96 = load i32, i32* %95, align 4 + %97 = icmp ne i32 %96, 2 + br i1 %97, label %then68, label %else69 then68: ; preds = %ifcont67 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @50, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0)) + %98 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 + %99 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @34, i32 0, i32 0), i8* %98, i8* %99) call void @exit(i32 1) br label %ifcont70 @@ -506,7 +496,7 @@ ifcont70: ; preds = %else69, %then68 br i1 false, label %then71, label %else72 then71: ; preds = %ifcont70 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont73 @@ -514,13 +504,15 @@ else72: ; preds = %ifcont70 br label %ifcont73 ifcont73: ; preds = %else72, %then71 - %82 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %83 = load i32, i32* %82, align 4 - %84 = icmp ne i32 %83, 3 - br i1 %84, label %then74, label %else75 + %100 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %101 = load i32, i32* %100, align 4 + %102 = icmp ne i32 %101, 3 + br i1 %102, label %then74, label %else75 then74: ; preds = %ifcont73 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0)) + %103 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 + %104 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @37, i32 0, i32 0), i8* %103, i8* %104) call void @exit(i32 1) br label %ifcont76 @@ -531,7 +523,7 @@ ifcont76: ; preds = %else75, %then74 br i1 false, label %then77, label %else78 then77: ; preds = %ifcont76 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @39, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @38, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont79 @@ -539,11 +531,11 @@ else78: ; preds = %ifcont76 br label %ifcont79 ifcont79: ; preds = %else78, %then77 - %85 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %105 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 br i1 false, label %then80, label %else81 then80: ; preds = %ifcont79 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont82 @@ -551,12 +543,12 @@ else81: ; preds = %ifcont79 br label %ifcont82 ifcont82: ; preds = %else81, %then80 - %86 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %87 = load i32, i32* %86, align 4 + %106 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %107 = load i32, i32* %106, align 4 br i1 false, label %then83, label %else84 then83: ; preds = %ifcont82 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @43, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @42, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont85 @@ -564,13 +556,13 @@ else84: ; preds = %ifcont82 br label %ifcont85 ifcont85: ; preds = %else84, %then83 - %88 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %89 = load i32, i32* %88, align 4 - %90 = add i32 %87, %89 + %108 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %109 = load i32, i32* %108, align 4 + %110 = add i32 %107, %109 br i1 false, label %then86, label %else87 then86: ; preds = %ifcont85 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @44, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont88 @@ -578,13 +570,13 @@ else87: ; preds = %ifcont85 br label %ifcont88 ifcont88: ; preds = %else87, %then86 - %91 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %92 = load i32, i32* %91, align 4 - %93 = add i32 %90, %92 + %111 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %112 = load i32, i32* %111, align 4 + %113 = add i32 %110, %112 br i1 false, label %then89, label %else90 then89: ; preds = %ifcont88 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont91 @@ -592,14 +584,14 @@ else90: ; preds = %ifcont88 br label %ifcont91 ifcont91: ; preds = %else90, %then89 - %94 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %95 = load i32, i32* %94, align 4 - %96 = add i32 %93, %95 - store i32 %96, i32* %85, align 4 + %114 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %115 = load i32, i32* %114, align 4 + %116 = add i32 %113, %115 + store i32 %116, i32* %105, align 4 br i1 false, label %then92, label %else93 then92: ; preds = %ifcont91 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont94 @@ -607,13 +599,15 @@ else93: ; preds = %ifcont91 br label %ifcont94 ifcont94: ; preds = %else93, %then92 - %97 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %98 = load i32, i32* %97, align 4 - %99 = icmp ne i32 %98, 17 - br i1 %99, label %then95, label %else96 + %117 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %118 = load i32, i32* %117, align 4 + %119 = icmp ne i32 %118, 17 + br i1 %119, label %then95, label %else96 then95: ; preds = %ifcont94 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @72, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @71, i32 0, i32 0)) + %120 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 + %121 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @50, i32 0, i32 0), i8* %120, i8* %121) call void @exit(i32 1) br label %ifcont97 @@ -624,7 +618,7 @@ ifcont97: ; preds = %else96, %then95 br i1 false, label %then98, label %else99 then98: ; preds = %ifcont97 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @74, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @73, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont100 @@ -632,11 +626,11 @@ else99: ; preds = %ifcont97 br label %ifcont100 ifcont100: ; preds = %else99, %then98 - %100 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %122 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 br i1 false, label %then101, label %else102 then101: ; preds = %ifcont100 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @76, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @75, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont103 @@ -644,13 +638,13 @@ else102: ; preds = %ifcont100 br label %ifcont103 ifcont103: ; preds = %else102, %then101 - %101 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %102 = load i32, i32* %101, align 4 - store i32 %102, i32* %100, align 4 + %123 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %124 = load i32, i32* %123, align 4 + store i32 %124, i32* %122, align 4 br i1 false, label %then104, label %else105 then104: ; preds = %ifcont103 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont106 @@ -658,13 +652,15 @@ else105: ; preds = %ifcont103 br label %ifcont106 ifcont106: ; preds = %else105, %then104 - %103 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %104 = load i32, i32* %103, align 4 - %105 = icmp ne i32 %104, 11 - br i1 %105, label %then107, label %else108 + %125 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %126 = load i32, i32* %125, align 4 + %127 = icmp ne i32 %126, 11 + br i1 %127, label %then107, label %else108 then107: ; preds = %ifcont106 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @79, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @80, i32 0, i32 0)) + %128 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 + %129 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* %128, i8* %129) call void @exit(i32 1) br label %ifcont109 diff --git a/tests/reference/llvm-arrays_01_complex-c90dbdd.json b/tests/reference/llvm-arrays_01_complex-c90dbdd.json index 9a397fec8e8..a2c7844096a 100644 --- a/tests/reference/llvm-arrays_01_complex-c90dbdd.json +++ b/tests/reference/llvm-arrays_01_complex-c90dbdd.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01_complex-c90dbdd.stdout", - "stdout_hash": "d945df036c4c5db8cf6d089dbda27573a4cd9b896e0d707175f125b7", + "stdout_hash": "add8a39604ffcbebcd738b81c6eedaff27b95028aaf1aeef14ba72b0", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout b/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout index 0b820a9a816..ad81718e0ee 100644 --- a/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout +++ b/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout @@ -4,86 +4,152 @@ source_filename = "LFortran" %string_descriptor = type <{ i8*, i64 }> %complex_4 = type <{ float, float }> +@0 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@1 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@2 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@3 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data = private constant [11 x i8] c"ERROR STOP\00" @string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data, i32 0, i32 0), i64 10 }> @string_const_data.1 = private constant [2 x i8] c"\0A\00" @string_const.2 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.1, i32 0, i32 0), i64 1 }> -@0 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@5 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@6 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.3 = private constant [11 x i8] c"ERROR STOP\00" @string_const.4 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.3, i32 0, i32 0), i64 10 }> @string_const_data.5 = private constant [2 x i8] c"\0A\00" @string_const.6 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.5, i32 0, i32 0), i64 1 }> -@1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@8 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@9 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.7 = private constant [11 x i8] c"ERROR STOP\00" @string_const.8 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.7, i32 0, i32 0), i64 10 }> @string_const_data.9 = private constant [2 x i8] c"\0A\00" @string_const.10 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.9, i32 0, i32 0), i64 1 }> -@2 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@11 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@12 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@13 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@14 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.11 = private constant [11 x i8] c"ERROR STOP\00" @string_const.12 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.11, i32 0, i32 0), i64 10 }> @string_const_data.13 = private constant [2 x i8] c"\0A\00" @string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.13, i32 0, i32 0), i64 1 }> -@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@15 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@16 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@17 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.15 = private constant [11 x i8] c"ERROR STOP\00" @string_const.16 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.15, i32 0, i32 0), i64 10 }> @string_const_data.17 = private constant [2 x i8] c"\0A\00" @string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.17, i32 0, i32 0), i64 1 }> -@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@18 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@19 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@20 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.19 = private constant [11 x i8] c"ERROR STOP\00" @string_const.20 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.19, i32 0, i32 0), i64 10 }> @string_const_data.21 = private constant [2 x i8] c"\0A\00" @string_const.22 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.21, i32 0, i32 0), i64 1 }> -@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@21 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@22 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@23 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.23 = private constant [11 x i8] c"ERROR STOP\00" @string_const.24 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.23, i32 0, i32 0), i64 10 }> @string_const_data.25 = private constant [2 x i8] c"\0A\00" @string_const.26 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.25, i32 0, i32 0), i64 1 }> -@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@24 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@25 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@26 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@27 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@28 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@29 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@30 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.27 = private constant [11 x i8] c"ERROR STOP\00" @string_const.28 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.27, i32 0, i32 0), i64 10 }> @string_const_data.29 = private constant [2 x i8] c"\0A\00" @string_const.30 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.29, i32 0, i32 0), i64 1 }> -@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@31 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@32 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@33 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.31 = private constant [11 x i8] c"ERROR STOP\00" @string_const.32 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.31, i32 0, i32 0), i64 10 }> @string_const_data.33 = private constant [2 x i8] c"\0A\00" @string_const.34 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.33, i32 0, i32 0), i64 1 }> -@8 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@34 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@35 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@36 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.35 = private constant [11 x i8] c"ERROR STOP\00" @string_const.36 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.35, i32 0, i32 0), i64 10 }> @string_const_data.37 = private constant [2 x i8] c"\0A\00" @string_const.38 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.37, i32 0, i32 0), i64 1 }> -@9 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@37 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@38 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@39 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@40 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@41 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@42 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@43 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@44 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@45 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@46 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@47 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@48 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@49 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.39 = private constant [11 x i8] c"ERROR STOP\00" @string_const.40 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.39, i32 0, i32 0), i64 10 }> @string_const_data.41 = private constant [2 x i8] c"\0A\00" @string_const.42 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.41, i32 0, i32 0), i64 1 }> -@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@50 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@51 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@52 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@53 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@54 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@55 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@56 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.43 = private constant [11 x i8] c"ERROR STOP\00" @string_const.44 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.43, i32 0, i32 0), i64 10 }> @string_const_data.45 = private constant [2 x i8] c"\0A\00" @string_const.46 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.45, i32 0, i32 0), i64 1 }> -@11 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@57 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@58 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@59 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@60 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@61 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@62 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@63 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@64 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@65 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.47 = private constant [11 x i8] c"ERROR STOP\00" @string_const.48 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.47, i32 0, i32 0), i64 10 }> @string_const_data.49 = private constant [2 x i8] c"\0A\00" @string_const.50 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.49, i32 0, i32 0), i64 1 }> -@12 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@66 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@67 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@68 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@69 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@70 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.51 = private constant [11 x i8] c"ERROR STOP\00" @string_const.52 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.51, i32 0, i32 0), i64 10 }> @string_const_data.53 = private constant [2 x i8] c"\0A\00" @string_const.54 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.53, i32 0, i32 0), i64 1 }> -@13 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@71 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@72 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@73 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@74 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@75 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.55 = private constant [11 x i8] c"ERROR STOP\00" @string_const.56 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.55, i32 0, i32 0), i64 10 }> @string_const_data.57 = private constant [2 x i8] c"\0A\00" @string_const.58 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.57, i32 0, i32 0), i64 1 }> -@14 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@76 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@77 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@78 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@79 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@80 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.59 = private constant [11 x i8] c"ERROR STOP\00" @string_const.60 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.59, i32 0, i32 0), i64 10 }> @string_const_data.61 = private constant [2 x i8] c"\0A\00" @string_const.62 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.61, i32 0, i32 0), i64 1 }> -@15 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@81 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -117,40 +183,8 @@ loop.body: ; preds = %loop.head %13 = or i1 %11, %12 br i1 %13, label %then, label %else -loop.end: ; preds = %loop.head - %19 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 - %20 = load %complex_4, %complex_4* %19, align 1 - %21 = alloca %complex_4, align 8 - %22 = getelementptr %complex_4, %complex_4* %21, i32 0, i32 0 - %23 = getelementptr %complex_4, %complex_4* %21, i32 0, i32 1 - store float 1.100000e+01, float* %22, align 4 - store float 0.000000e+00, float* %23, align 4 - %24 = load %complex_4, %complex_4* %21, align 1 - %25 = alloca %complex_4, align 8 - store %complex_4 %20, %complex_4* %25, align 1 - %26 = getelementptr %complex_4, %complex_4* %25, i32 0, i32 0 - %27 = load float, float* %26, align 4 - %28 = alloca %complex_4, align 8 - store %complex_4 %24, %complex_4* %28, align 1 - %29 = getelementptr %complex_4, %complex_4* %28, i32 0, i32 0 - %30 = load float, float* %29, align 4 - %31 = alloca %complex_4, align 8 - store %complex_4 %20, %complex_4* %31, align 1 - %32 = getelementptr %complex_4, %complex_4* %31, i32 0, i32 1 - %33 = load float, float* %32, align 4 - %34 = alloca %complex_4, align 8 - store %complex_4 %24, %complex_4* %34, align 1 - %35 = getelementptr %complex_4, %complex_4* %34, i32 0, i32 1 - %36 = load float, float* %35, align 4 - %37 = fcmp one float %27, %30 - %38 = fcmp one float %33, %36 - %39 = or i1 %37, %38 - br i1 %39, label %then, label %else - -then: ; preds = %loop.end - %40 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 - %41 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8* %40, i8* %41) +then: ; preds = %loop.body + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 %7, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont @@ -158,39 +192,24 @@ else: ; preds = %loop.body br label %ifcont ifcont: ; preds = %else, %then - %42 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 1 - %43 = load %complex_4, %complex_4* %42, align 1 - %44 = alloca %complex_4, align 8 - %45 = getelementptr %complex_4, %complex_4* %44, i32 0, i32 0 - %46 = getelementptr %complex_4, %complex_4* %44, i32 0, i32 1 - store float 1.200000e+01, float* %45, align 4 - store float 0.000000e+00, float* %46, align 4 - %47 = load %complex_4, %complex_4* %44, align 1 - %48 = alloca %complex_4, align 8 - store %complex_4 %43, %complex_4* %48, align 1 - %49 = getelementptr %complex_4, %complex_4* %48, i32 0, i32 0 - %50 = load float, float* %49, align 4 - %51 = alloca %complex_4, align 8 - store %complex_4 %47, %complex_4* %51, align 1 - %52 = getelementptr %complex_4, %complex_4* %51, i32 0, i32 0 - %53 = load float, float* %52, align 4 - %54 = alloca %complex_4, align 8 - store %complex_4 %43, %complex_4* %54, align 1 - %55 = getelementptr %complex_4, %complex_4* %54, i32 0, i32 1 - %56 = load float, float* %55, align 4 - %57 = alloca %complex_4, align 8 - store %complex_4 %47, %complex_4* %57, align 1 - %58 = getelementptr %complex_4, %complex_4* %57, i32 0, i32 1 - %59 = load float, float* %58, align 4 - %60 = fcmp one float %50, %53 - %61 = fcmp one float %56, %59 - %62 = or i1 %60, %61 - br i1 %62, label %then3, label %else4 - -then3: ; preds = %ifcont - %63 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 - %64 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %63, i8* %64) + %14 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 %10 + %15 = load i32, i32* %i1, align 4 + %16 = add i32 %15, 10 + %17 = sitofp i32 %16 to float + %18 = alloca %complex_4, align 8 + %19 = getelementptr %complex_4, %complex_4* %18, i32 0, i32 0 + %20 = getelementptr %complex_4, %complex_4* %18, i32 0, i32 1 + store float %17, float* %19, align 4 + store float 0.000000e+00, float* %20, align 4 + %21 = load %complex_4, %complex_4* %18, align 1 + store %complex_4 %21, %complex_4* %14, align 1 + br label %loop.head + +loop.end: ; preds = %loop.head + br i1 false, label %then3, label %else4 + +then3: ; preds = %loop.end + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont5 @@ -198,39 +217,39 @@ else4: ; preds = %loop.end br label %ifcont5 ifcont5: ; preds = %else4, %then3 - %65 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 2 - %66 = load %complex_4, %complex_4* %65, align 1 - %67 = alloca %complex_4, align 8 - %68 = getelementptr %complex_4, %complex_4* %67, i32 0, i32 0 - %69 = getelementptr %complex_4, %complex_4* %67, i32 0, i32 1 - store float 1.300000e+01, float* %68, align 4 - store float 0.000000e+00, float* %69, align 4 - %70 = load %complex_4, %complex_4* %67, align 1 - %71 = alloca %complex_4, align 8 - store %complex_4 %66, %complex_4* %71, align 1 - %72 = getelementptr %complex_4, %complex_4* %71, i32 0, i32 0 - %73 = load float, float* %72, align 4 - %74 = alloca %complex_4, align 8 - store %complex_4 %70, %complex_4* %74, align 1 - %75 = getelementptr %complex_4, %complex_4* %74, i32 0, i32 0 - %76 = load float, float* %75, align 4 - %77 = alloca %complex_4, align 8 - store %complex_4 %66, %complex_4* %77, align 1 - %78 = getelementptr %complex_4, %complex_4* %77, i32 0, i32 1 - %79 = load float, float* %78, align 4 - %80 = alloca %complex_4, align 8 - store %complex_4 %70, %complex_4* %80, align 1 - %81 = getelementptr %complex_4, %complex_4* %80, i32 0, i32 1 - %82 = load float, float* %81, align 4 - %83 = fcmp one float %73, %76 - %84 = fcmp one float %79, %82 - %85 = or i1 %83, %84 - br i1 %85, label %then6, label %else7 + %22 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 + %23 = load %complex_4, %complex_4* %22, align 1 + %24 = alloca %complex_4, align 8 + %25 = getelementptr %complex_4, %complex_4* %24, i32 0, i32 0 + %26 = getelementptr %complex_4, %complex_4* %24, i32 0, i32 1 + store float 1.100000e+01, float* %25, align 4 + store float 0.000000e+00, float* %26, align 4 + %27 = load %complex_4, %complex_4* %24, align 1 + %28 = alloca %complex_4, align 8 + store %complex_4 %23, %complex_4* %28, align 1 + %29 = getelementptr %complex_4, %complex_4* %28, i32 0, i32 0 + %30 = load float, float* %29, align 4 + %31 = alloca %complex_4, align 8 + store %complex_4 %27, %complex_4* %31, align 1 + %32 = getelementptr %complex_4, %complex_4* %31, i32 0, i32 0 + %33 = load float, float* %32, align 4 + %34 = alloca %complex_4, align 8 + store %complex_4 %23, %complex_4* %34, align 1 + %35 = getelementptr %complex_4, %complex_4* %34, i32 0, i32 1 + %36 = load float, float* %35, align 4 + %37 = alloca %complex_4, align 8 + store %complex_4 %27, %complex_4* %37, align 1 + %38 = getelementptr %complex_4, %complex_4* %37, i32 0, i32 1 + %39 = load float, float* %38, align 4 + %40 = fcmp one float %30, %33 + %41 = fcmp one float %36, %39 + %42 = or i1 %40, %41 + br i1 %42, label %then6, label %else7 then6: ; preds = %ifcont5 - %86 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 - %87 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i8* %86, i8* %87) + %43 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 + %44 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %43, i8* %44) call void @exit(i32 1) br label %ifcont8 @@ -240,67 +259,48 @@ else7: ; preds = %ifcont5 ifcont8: ; preds = %else7, %then6 br i1 false, label %then9, label %else10 -loop.head9: ; preds = %loop.body10, %ifcont8 - %88 = load i32, i32* %i1, align 4 - %89 = add i32 %88, 1 - %90 = icmp sle i32 %89, 14 - br i1 %90, label %loop.body10, label %loop.end11 - -loop.body10: ; preds = %loop.head9 - %91 = load i32, i32* %i1, align 4 - %92 = add i32 %91, 1 - store i32 %92, i32* %i1, align 4 - %93 = load i32, i32* %i1, align 4 - %94 = sub i32 %93, 10 - %95 = sub i32 %94, 1 - %96 = mul i32 1, %95 - %97 = add i32 0, %96 - %98 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 %97 - %99 = load i32, i32* %i1, align 4 - %100 = sitofp i32 %99 to float - %101 = alloca %complex_4, align 8 - %102 = getelementptr %complex_4, %complex_4* %101, i32 0, i32 0 - %103 = getelementptr %complex_4, %complex_4* %101, i32 0, i32 1 - store float %100, float* %102, align 4 - store float 0.000000e+00, float* %103, align 4 - %104 = load %complex_4, %complex_4* %101, align 1 - store %complex_4 %104, %complex_4* %98, align 1 - br label %loop.head9 - -loop.end11: ; preds = %loop.head9 - %105 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 - %106 = load %complex_4, %complex_4* %105, align 1 - %107 = alloca %complex_4, align 8 - %108 = getelementptr %complex_4, %complex_4* %107, i32 0, i32 0 - %109 = getelementptr %complex_4, %complex_4* %107, i32 0, i32 1 - store float 1.100000e+01, float* %108, align 4 - store float 0.000000e+00, float* %109, align 4 - %110 = load %complex_4, %complex_4* %107, align 1 - %111 = alloca %complex_4, align 8 - store %complex_4 %106, %complex_4* %111, align 1 - %112 = getelementptr %complex_4, %complex_4* %111, i32 0, i32 0 - %113 = load float, float* %112, align 4 - %114 = alloca %complex_4, align 8 - store %complex_4 %110, %complex_4* %114, align 1 - %115 = getelementptr %complex_4, %complex_4* %114, i32 0, i32 0 - %116 = load float, float* %115, align 4 - %117 = alloca %complex_4, align 8 - store %complex_4 %106, %complex_4* %117, align 1 - %118 = getelementptr %complex_4, %complex_4* %117, i32 0, i32 1 - %119 = load float, float* %118, align 4 - %120 = alloca %complex_4, align 8 - store %complex_4 %110, %complex_4* %120, align 1 - %121 = getelementptr %complex_4, %complex_4* %120, i32 0, i32 1 - %122 = load float, float* %121, align 4 - %123 = fcmp one float %113, %116 - %124 = fcmp one float %119, %122 - %125 = or i1 %123, %124 - br i1 %125, label %then12, label %else13 - -then12: ; preds = %loop.end11 - %126 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 - %127 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %126, i8* %127) +then9: ; preds = %ifcont8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @5, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont11 + +else10: ; preds = %ifcont8 + br label %ifcont11 + +ifcont11: ; preds = %else10, %then9 + %45 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 1 + %46 = load %complex_4, %complex_4* %45, align 1 + %47 = alloca %complex_4, align 8 + %48 = getelementptr %complex_4, %complex_4* %47, i32 0, i32 0 + %49 = getelementptr %complex_4, %complex_4* %47, i32 0, i32 1 + store float 1.200000e+01, float* %48, align 4 + store float 0.000000e+00, float* %49, align 4 + %50 = load %complex_4, %complex_4* %47, align 1 + %51 = alloca %complex_4, align 8 + store %complex_4 %46, %complex_4* %51, align 1 + %52 = getelementptr %complex_4, %complex_4* %51, i32 0, i32 0 + %53 = load float, float* %52, align 4 + %54 = alloca %complex_4, align 8 + store %complex_4 %50, %complex_4* %54, align 1 + %55 = getelementptr %complex_4, %complex_4* %54, i32 0, i32 0 + %56 = load float, float* %55, align 4 + %57 = alloca %complex_4, align 8 + store %complex_4 %46, %complex_4* %57, align 1 + %58 = getelementptr %complex_4, %complex_4* %57, i32 0, i32 1 + %59 = load float, float* %58, align 4 + %60 = alloca %complex_4, align 8 + store %complex_4 %50, %complex_4* %60, align 1 + %61 = getelementptr %complex_4, %complex_4* %60, i32 0, i32 1 + %62 = load float, float* %61, align 4 + %63 = fcmp one float %53, %56 + %64 = fcmp one float %59, %62 + %65 = or i1 %63, %64 + br i1 %65, label %then12, label %else13 + +then12: ; preds = %ifcont11 + %66 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 + %67 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %66, i8* %67) call void @exit(i32 1) br label %ifcont14 @@ -308,39 +308,10 @@ else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 - %128 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 - %129 = load %complex_4, %complex_4* %128, align 1 - %130 = alloca %complex_4, align 8 - %131 = getelementptr %complex_4, %complex_4* %130, i32 0, i32 0 - %132 = getelementptr %complex_4, %complex_4* %130, i32 0, i32 1 - store float 1.200000e+01, float* %131, align 4 - store float 0.000000e+00, float* %132, align 4 - %133 = load %complex_4, %complex_4* %130, align 1 - %134 = alloca %complex_4, align 8 - store %complex_4 %129, %complex_4* %134, align 1 - %135 = getelementptr %complex_4, %complex_4* %134, i32 0, i32 0 - %136 = load float, float* %135, align 4 - %137 = alloca %complex_4, align 8 - store %complex_4 %133, %complex_4* %137, align 1 - %138 = getelementptr %complex_4, %complex_4* %137, i32 0, i32 0 - %139 = load float, float* %138, align 4 - %140 = alloca %complex_4, align 8 - store %complex_4 %129, %complex_4* %140, align 1 - %141 = getelementptr %complex_4, %complex_4* %140, i32 0, i32 1 - %142 = load float, float* %141, align 4 - %143 = alloca %complex_4, align 8 - store %complex_4 %133, %complex_4* %143, align 1 - %144 = getelementptr %complex_4, %complex_4* %143, i32 0, i32 1 - %145 = load float, float* %144, align 4 - %146 = fcmp one float %136, %139 - %147 = fcmp one float %142, %145 - %148 = or i1 %146, %147 - br i1 %148, label %then15, label %else16 + br i1 false, label %then15, label %else16 then15: ; preds = %ifcont14 - %149 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 - %150 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %149, i8* %150) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @9, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @8, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont17 @@ -348,39 +319,39 @@ else16: ; preds = %ifcont14 br label %ifcont17 ifcont17: ; preds = %else16, %then15 - %151 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 - %152 = load %complex_4, %complex_4* %151, align 1 - %153 = alloca %complex_4, align 8 - %154 = getelementptr %complex_4, %complex_4* %153, i32 0, i32 0 - %155 = getelementptr %complex_4, %complex_4* %153, i32 0, i32 1 - store float 1.300000e+01, float* %154, align 4 - store float 0.000000e+00, float* %155, align 4 - %156 = load %complex_4, %complex_4* %153, align 1 - %157 = alloca %complex_4, align 8 - store %complex_4 %152, %complex_4* %157, align 1 - %158 = getelementptr %complex_4, %complex_4* %157, i32 0, i32 0 - %159 = load float, float* %158, align 4 - %160 = alloca %complex_4, align 8 - store %complex_4 %156, %complex_4* %160, align 1 - %161 = getelementptr %complex_4, %complex_4* %160, i32 0, i32 0 - %162 = load float, float* %161, align 4 - %163 = alloca %complex_4, align 8 - store %complex_4 %152, %complex_4* %163, align 1 - %164 = getelementptr %complex_4, %complex_4* %163, i32 0, i32 1 - %165 = load float, float* %164, align 4 - %166 = alloca %complex_4, align 8 - store %complex_4 %156, %complex_4* %166, align 1 - %167 = getelementptr %complex_4, %complex_4* %166, i32 0, i32 1 - %168 = load float, float* %167, align 4 - %169 = fcmp one float %159, %162 - %170 = fcmp one float %165, %168 - %171 = or i1 %169, %170 - br i1 %171, label %then18, label %else19 + %68 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 2 + %69 = load %complex_4, %complex_4* %68, align 1 + %70 = alloca %complex_4, align 8 + %71 = getelementptr %complex_4, %complex_4* %70, i32 0, i32 0 + %72 = getelementptr %complex_4, %complex_4* %70, i32 0, i32 1 + store float 1.300000e+01, float* %71, align 4 + store float 0.000000e+00, float* %72, align 4 + %73 = load %complex_4, %complex_4* %70, align 1 + %74 = alloca %complex_4, align 8 + store %complex_4 %69, %complex_4* %74, align 1 + %75 = getelementptr %complex_4, %complex_4* %74, i32 0, i32 0 + %76 = load float, float* %75, align 4 + %77 = alloca %complex_4, align 8 + store %complex_4 %73, %complex_4* %77, align 1 + %78 = getelementptr %complex_4, %complex_4* %77, i32 0, i32 0 + %79 = load float, float* %78, align 4 + %80 = alloca %complex_4, align 8 + store %complex_4 %69, %complex_4* %80, align 1 + %81 = getelementptr %complex_4, %complex_4* %80, i32 0, i32 1 + %82 = load float, float* %81, align 4 + %83 = alloca %complex_4, align 8 + store %complex_4 %73, %complex_4* %83, align 1 + %84 = getelementptr %complex_4, %complex_4* %83, i32 0, i32 1 + %85 = load float, float* %84, align 4 + %86 = fcmp one float %76, %79 + %87 = fcmp one float %82, %85 + %88 = or i1 %86, %87 + br i1 %88, label %then18, label %else19 then18: ; preds = %ifcont17 - %172 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 - %173 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %172, i8* %173) + %89 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 + %90 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %89, i8* %90) call void @exit(i32 1) br label %ifcont20 @@ -388,39 +359,31 @@ else19: ; preds = %ifcont17 br label %ifcont20 ifcont20: ; preds = %else19, %then18 - %174 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 - %175 = load %complex_4, %complex_4* %174, align 1 - %176 = alloca %complex_4, align 8 - %177 = getelementptr %complex_4, %complex_4* %176, i32 0, i32 0 - %178 = getelementptr %complex_4, %complex_4* %176, i32 0, i32 1 - store float 1.400000e+01, float* %177, align 4 - store float 0.000000e+00, float* %178, align 4 - %179 = load %complex_4, %complex_4* %176, align 1 - %180 = alloca %complex_4, align 8 - store %complex_4 %175, %complex_4* %180, align 1 - %181 = getelementptr %complex_4, %complex_4* %180, i32 0, i32 0 - %182 = load float, float* %181, align 4 - %183 = alloca %complex_4, align 8 - store %complex_4 %179, %complex_4* %183, align 1 - %184 = getelementptr %complex_4, %complex_4* %183, i32 0, i32 0 - %185 = load float, float* %184, align 4 - %186 = alloca %complex_4, align 8 - store %complex_4 %175, %complex_4* %186, align 1 - %187 = getelementptr %complex_4, %complex_4* %186, i32 0, i32 1 - %188 = load float, float* %187, align 4 - %189 = alloca %complex_4, align 8 - store %complex_4 %179, %complex_4* %189, align 1 - %190 = getelementptr %complex_4, %complex_4* %189, i32 0, i32 1 - %191 = load float, float* %190, align 4 - %192 = fcmp one float %182, %185 - %193 = fcmp one float %188, %191 - %194 = or i1 %192, %193 - br i1 %194, label %then21, label %else22 - -then21: ; preds = %ifcont20 - %195 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 - %196 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %195, i8* %196) + store i32 10, i32* %i1, align 4 + br label %loop.head21 + +loop.head21: ; preds = %ifcont25, %ifcont20 + %91 = load i32, i32* %i1, align 4 + %92 = add i32 %91, 1 + %93 = icmp sle i32 %92, 14 + br i1 %93, label %loop.body22, label %loop.end26 + +loop.body22: ; preds = %loop.head21 + %94 = load i32, i32* %i1, align 4 + %95 = add i32 %94, 1 + store i32 %95, i32* %i1, align 4 + %96 = load i32, i32* %i1, align 4 + %97 = sub i32 %96, 10 + %98 = sub i32 %97, 1 + %99 = mul i32 1, %98 + %100 = add i32 0, %99 + %101 = icmp slt i32 %97, 1 + %102 = icmp sgt i32 %97, 4 + %103 = or i1 %101, %102 + br i1 %103, label %then23, label %else24 + +then23: ; preds = %loop.body22 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i32 %97, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont25 @@ -428,89 +391,23 @@ else24: ; preds = %loop.body22 br label %ifcont25 ifcont25: ; preds = %else24, %then23 - %98 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 %94 - %99 = load i32, i32* %i1, align 4 - %100 = sitofp i32 %99 to float - %101 = alloca %complex_4, align 8 - %102 = getelementptr %complex_4, %complex_4* %101, i32 0, i32 0 - %103 = getelementptr %complex_4, %complex_4* %101, i32 0, i32 1 - store float %100, float* %102, align 4 - store float 0.000000e+00, float* %103, align 4 - %104 = load %complex_4, %complex_4* %101, align 1 - store %complex_4 %104, %complex_4* %98, align 1 + %104 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 %100 + %105 = load i32, i32* %i1, align 4 + %106 = sitofp i32 %105 to float + %107 = alloca %complex_4, align 8 + %108 = getelementptr %complex_4, %complex_4* %107, i32 0, i32 0 + %109 = getelementptr %complex_4, %complex_4* %107, i32 0, i32 1 + store float %106, float* %108, align 4 + store float 0.000000e+00, float* %109, align 4 + %110 = load %complex_4, %complex_4* %107, align 1 + store %complex_4 %110, %complex_4* %104, align 1 br label %loop.head21 -loop.head24: ; preds = %loop.body25, %ifcont23 - %197 = load i32, i32* %i1, align 4 - %198 = add i32 %197, 1 - %199 = icmp sle i32 %198, 3 - br i1 %199, label %loop.body25, label %loop.end26 - -loop.body25: ; preds = %loop.head24 - %200 = load i32, i32* %i1, align 4 - %201 = add i32 %200, 1 - store i32 %201, i32* %i1, align 4 - %202 = load i32, i32* %i1, align 4 - %203 = sub i32 %202, 1 - %204 = mul i32 1, %203 - %205 = add i32 0, %204 - %206 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 %205 - %207 = load i32, i32* %i1, align 4 - %208 = sub i32 %207, 1 - %209 = mul i32 1, %208 - %210 = add i32 0, %209 - %211 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 %210 - %212 = load %complex_4, %complex_4* %211, align 1 - %213 = alloca %complex_4, align 8 - %214 = getelementptr %complex_4, %complex_4* %213, i32 0, i32 0 - %215 = getelementptr %complex_4, %complex_4* %213, i32 0, i32 1 - store float 1.000000e+01, float* %214, align 4 - store float 0.000000e+00, float* %215, align 4 - %216 = load %complex_4, %complex_4* %213, align 1 - %217 = alloca %complex_4, align 8 - store %complex_4 %212, %complex_4* %217, align 1 - %218 = alloca %complex_4, align 8 - store %complex_4 %216, %complex_4* %218, align 1 - %219 = alloca %complex_4, align 8 - call void @_lfortran_complex_sub_32(%complex_4* %217, %complex_4* %218, %complex_4* %219) - %220 = load %complex_4, %complex_4* %219, align 1 - store %complex_4 %220, %complex_4* %206, align 1 - br label %loop.head24 - -loop.end26: ; preds = %loop.head24 - %221 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 - %222 = load %complex_4, %complex_4* %221, align 1 - %223 = alloca %complex_4, align 8 - %224 = getelementptr %complex_4, %complex_4* %223, i32 0, i32 0 - %225 = getelementptr %complex_4, %complex_4* %223, i32 0, i32 1 - store float 1.000000e+00, float* %224, align 4 - store float 0.000000e+00, float* %225, align 4 - %226 = load %complex_4, %complex_4* %223, align 1 - %227 = alloca %complex_4, align 8 - store %complex_4 %222, %complex_4* %227, align 1 - %228 = getelementptr %complex_4, %complex_4* %227, i32 0, i32 0 - %229 = load float, float* %228, align 4 - %230 = alloca %complex_4, align 8 - store %complex_4 %226, %complex_4* %230, align 1 - %231 = getelementptr %complex_4, %complex_4* %230, i32 0, i32 0 - %232 = load float, float* %231, align 4 - %233 = alloca %complex_4, align 8 - store %complex_4 %222, %complex_4* %233, align 1 - %234 = getelementptr %complex_4, %complex_4* %233, i32 0, i32 1 - %235 = load float, float* %234, align 4 - %236 = alloca %complex_4, align 8 - store %complex_4 %226, %complex_4* %236, align 1 - %237 = getelementptr %complex_4, %complex_4* %236, i32 0, i32 1 - %238 = load float, float* %237, align 4 - %239 = fcmp one float %229, %232 - %240 = fcmp one float %235, %238 - %241 = or i1 %239, %240 - br i1 %241, label %then27, label %else28 +loop.end26: ; preds = %loop.head21 + br i1 false, label %then27, label %else28 then27: ; preds = %loop.end26 - %242 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 - %243 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %242, i8* %243) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont29 @@ -518,39 +415,39 @@ else28: ; preds = %loop.end26 br label %ifcont29 ifcont29: ; preds = %else28, %then27 - %244 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 - %245 = load %complex_4, %complex_4* %244, align 1 - %246 = alloca %complex_4, align 8 - %247 = getelementptr %complex_4, %complex_4* %246, i32 0, i32 0 - %248 = getelementptr %complex_4, %complex_4* %246, i32 0, i32 1 - store float 2.000000e+00, float* %247, align 4 - store float 0.000000e+00, float* %248, align 4 - %249 = load %complex_4, %complex_4* %246, align 1 - %250 = alloca %complex_4, align 8 - store %complex_4 %245, %complex_4* %250, align 1 - %251 = getelementptr %complex_4, %complex_4* %250, i32 0, i32 0 - %252 = load float, float* %251, align 4 - %253 = alloca %complex_4, align 8 - store %complex_4 %249, %complex_4* %253, align 1 - %254 = getelementptr %complex_4, %complex_4* %253, i32 0, i32 0 - %255 = load float, float* %254, align 4 - %256 = alloca %complex_4, align 8 - store %complex_4 %245, %complex_4* %256, align 1 - %257 = getelementptr %complex_4, %complex_4* %256, i32 0, i32 1 - %258 = load float, float* %257, align 4 - %259 = alloca %complex_4, align 8 - store %complex_4 %249, %complex_4* %259, align 1 - %260 = getelementptr %complex_4, %complex_4* %259, i32 0, i32 1 - %261 = load float, float* %260, align 4 - %262 = fcmp one float %252, %255 - %263 = fcmp one float %258, %261 - %264 = or i1 %262, %263 - br i1 %264, label %then30, label %else31 + %111 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 + %112 = load %complex_4, %complex_4* %111, align 1 + %113 = alloca %complex_4, align 8 + %114 = getelementptr %complex_4, %complex_4* %113, i32 0, i32 0 + %115 = getelementptr %complex_4, %complex_4* %113, i32 0, i32 1 + store float 1.100000e+01, float* %114, align 4 + store float 0.000000e+00, float* %115, align 4 + %116 = load %complex_4, %complex_4* %113, align 1 + %117 = alloca %complex_4, align 8 + store %complex_4 %112, %complex_4* %117, align 1 + %118 = getelementptr %complex_4, %complex_4* %117, i32 0, i32 0 + %119 = load float, float* %118, align 4 + %120 = alloca %complex_4, align 8 + store %complex_4 %116, %complex_4* %120, align 1 + %121 = getelementptr %complex_4, %complex_4* %120, i32 0, i32 0 + %122 = load float, float* %121, align 4 + %123 = alloca %complex_4, align 8 + store %complex_4 %112, %complex_4* %123, align 1 + %124 = getelementptr %complex_4, %complex_4* %123, i32 0, i32 1 + %125 = load float, float* %124, align 4 + %126 = alloca %complex_4, align 8 + store %complex_4 %116, %complex_4* %126, align 1 + %127 = getelementptr %complex_4, %complex_4* %126, i32 0, i32 1 + %128 = load float, float* %127, align 4 + %129 = fcmp one float %119, %122 + %130 = fcmp one float %125, %128 + %131 = or i1 %129, %130 + br i1 %131, label %then30, label %else31 then30: ; preds = %ifcont29 - %265 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 - %266 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %265, i8* %266) + %132 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 + %133 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %132, i8* %133) call void @exit(i32 1) br label %ifcont32 @@ -558,39 +455,10 @@ else31: ; preds = %ifcont29 br label %ifcont32 ifcont32: ; preds = %else31, %then30 - %267 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 - %268 = load %complex_4, %complex_4* %267, align 1 - %269 = alloca %complex_4, align 8 - %270 = getelementptr %complex_4, %complex_4* %269, i32 0, i32 0 - %271 = getelementptr %complex_4, %complex_4* %269, i32 0, i32 1 - store float 3.000000e+00, float* %270, align 4 - store float 0.000000e+00, float* %271, align 4 - %272 = load %complex_4, %complex_4* %269, align 1 - %273 = alloca %complex_4, align 8 - store %complex_4 %268, %complex_4* %273, align 1 - %274 = getelementptr %complex_4, %complex_4* %273, i32 0, i32 0 - %275 = load float, float* %274, align 4 - %276 = alloca %complex_4, align 8 - store %complex_4 %272, %complex_4* %276, align 1 - %277 = getelementptr %complex_4, %complex_4* %276, i32 0, i32 0 - %278 = load float, float* %277, align 4 - %279 = alloca %complex_4, align 8 - store %complex_4 %268, %complex_4* %279, align 1 - %280 = getelementptr %complex_4, %complex_4* %279, i32 0, i32 1 - %281 = load float, float* %280, align 4 - %282 = alloca %complex_4, align 8 - store %complex_4 %272, %complex_4* %282, align 1 - %283 = getelementptr %complex_4, %complex_4* %282, i32 0, i32 1 - %284 = load float, float* %283, align 4 - %285 = fcmp one float %275, %278 - %286 = fcmp one float %281, %284 - %287 = or i1 %285, %286 - br i1 %287, label %then33, label %else34 + br i1 false, label %then33, label %else34 then33: ; preds = %ifcont32 - %288 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 - %289 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %288, i8* %289) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @16, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont35 @@ -598,28 +466,407 @@ else34: ; preds = %ifcont32 br label %ifcont35 ifcont35: ; preds = %else34, %then33 - %290 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 - %291 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 - %292 = load %complex_4, %complex_4* %291, align 1 - %293 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 - %294 = load %complex_4, %complex_4* %293, align 1 - %295 = alloca %complex_4, align 8 - store %complex_4 %292, %complex_4* %295, align 1 - %296 = alloca %complex_4, align 8 - store %complex_4 %294, %complex_4* %296, align 1 - %297 = alloca %complex_4, align 8 - call void @_lfortran_complex_add_32(%complex_4* %295, %complex_4* %296, %complex_4* %297) - %298 = load %complex_4, %complex_4* %297, align 1 - %299 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 - %300 = load %complex_4, %complex_4* %299, align 1 - %301 = alloca %complex_4, align 8 - store %complex_4 %298, %complex_4* %301, align 1 - %302 = alloca %complex_4, align 8 - store %complex_4 %300, %complex_4* %302, align 1 - %303 = alloca %complex_4, align 8 - call void @_lfortran_complex_add_32(%complex_4* %301, %complex_4* %302, %complex_4* %303) + %134 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 + %135 = load %complex_4, %complex_4* %134, align 1 + %136 = alloca %complex_4, align 8 + %137 = getelementptr %complex_4, %complex_4* %136, i32 0, i32 0 + %138 = getelementptr %complex_4, %complex_4* %136, i32 0, i32 1 + store float 1.200000e+01, float* %137, align 4 + store float 0.000000e+00, float* %138, align 4 + %139 = load %complex_4, %complex_4* %136, align 1 + %140 = alloca %complex_4, align 8 + store %complex_4 %135, %complex_4* %140, align 1 + %141 = getelementptr %complex_4, %complex_4* %140, i32 0, i32 0 + %142 = load float, float* %141, align 4 + %143 = alloca %complex_4, align 8 + store %complex_4 %139, %complex_4* %143, align 1 + %144 = getelementptr %complex_4, %complex_4* %143, i32 0, i32 0 + %145 = load float, float* %144, align 4 + %146 = alloca %complex_4, align 8 + store %complex_4 %135, %complex_4* %146, align 1 + %147 = getelementptr %complex_4, %complex_4* %146, i32 0, i32 1 + %148 = load float, float* %147, align 4 + %149 = alloca %complex_4, align 8 + store %complex_4 %139, %complex_4* %149, align 1 + %150 = getelementptr %complex_4, %complex_4* %149, i32 0, i32 1 + %151 = load float, float* %150, align 4 + %152 = fcmp one float %142, %145 + %153 = fcmp one float %148, %151 + %154 = or i1 %152, %153 + br i1 %154, label %then36, label %else37 + +then36: ; preds = %ifcont35 + %155 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 + %156 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @18, i32 0, i32 0), i8* %155, i8* %156) + call void @exit(i32 1) + br label %ifcont38 + +else37: ; preds = %ifcont35 + br label %ifcont38 + +ifcont38: ; preds = %else37, %then36 + br i1 false, label %then39, label %else40 + +then39: ; preds = %ifcont38 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont41 + +else40: ; preds = %ifcont38 + br label %ifcont41 + +ifcont41: ; preds = %else40, %then39 + %157 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 + %158 = load %complex_4, %complex_4* %157, align 1 + %159 = alloca %complex_4, align 8 + %160 = getelementptr %complex_4, %complex_4* %159, i32 0, i32 0 + %161 = getelementptr %complex_4, %complex_4* %159, i32 0, i32 1 + store float 1.300000e+01, float* %160, align 4 + store float 0.000000e+00, float* %161, align 4 + %162 = load %complex_4, %complex_4* %159, align 1 + %163 = alloca %complex_4, align 8 + store %complex_4 %158, %complex_4* %163, align 1 + %164 = getelementptr %complex_4, %complex_4* %163, i32 0, i32 0 + %165 = load float, float* %164, align 4 + %166 = alloca %complex_4, align 8 + store %complex_4 %162, %complex_4* %166, align 1 + %167 = getelementptr %complex_4, %complex_4* %166, i32 0, i32 0 + %168 = load float, float* %167, align 4 + %169 = alloca %complex_4, align 8 + store %complex_4 %158, %complex_4* %169, align 1 + %170 = getelementptr %complex_4, %complex_4* %169, i32 0, i32 1 + %171 = load float, float* %170, align 4 + %172 = alloca %complex_4, align 8 + store %complex_4 %162, %complex_4* %172, align 1 + %173 = getelementptr %complex_4, %complex_4* %172, i32 0, i32 1 + %174 = load float, float* %173, align 4 + %175 = fcmp one float %165, %168 + %176 = fcmp one float %171, %174 + %177 = or i1 %175, %176 + br i1 %177, label %then42, label %else43 + +then42: ; preds = %ifcont41 + %178 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 + %179 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @21, i32 0, i32 0), i8* %178, i8* %179) + call void @exit(i32 1) + br label %ifcont44 + +else43: ; preds = %ifcont41 + br label %ifcont44 + +ifcont44: ; preds = %else43, %then42 + br i1 false, label %then45, label %else46 + +then45: ; preds = %ifcont44 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @22, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont47 + +else46: ; preds = %ifcont44 + br label %ifcont47 + +ifcont47: ; preds = %else46, %then45 + %180 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 + %181 = load %complex_4, %complex_4* %180, align 1 + %182 = alloca %complex_4, align 8 + %183 = getelementptr %complex_4, %complex_4* %182, i32 0, i32 0 + %184 = getelementptr %complex_4, %complex_4* %182, i32 0, i32 1 + store float 1.400000e+01, float* %183, align 4 + store float 0.000000e+00, float* %184, align 4 + %185 = load %complex_4, %complex_4* %182, align 1 + %186 = alloca %complex_4, align 8 + store %complex_4 %181, %complex_4* %186, align 1 + %187 = getelementptr %complex_4, %complex_4* %186, i32 0, i32 0 + %188 = load float, float* %187, align 4 + %189 = alloca %complex_4, align 8 + store %complex_4 %185, %complex_4* %189, align 1 + %190 = getelementptr %complex_4, %complex_4* %189, i32 0, i32 0 + %191 = load float, float* %190, align 4 + %192 = alloca %complex_4, align 8 + store %complex_4 %181, %complex_4* %192, align 1 + %193 = getelementptr %complex_4, %complex_4* %192, i32 0, i32 1 + %194 = load float, float* %193, align 4 + %195 = alloca %complex_4, align 8 + store %complex_4 %185, %complex_4* %195, align 1 + %196 = getelementptr %complex_4, %complex_4* %195, i32 0, i32 1 + %197 = load float, float* %196, align 4 + %198 = fcmp one float %188, %191 + %199 = fcmp one float %194, %197 + %200 = or i1 %198, %199 + br i1 %200, label %then48, label %else49 + +then48: ; preds = %ifcont47 + %201 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 + %202 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @24, i32 0, i32 0), i8* %201, i8* %202) + call void @exit(i32 1) + br label %ifcont50 + +else49: ; preds = %ifcont47 + br label %ifcont50 + +ifcont50: ; preds = %else49, %then48 + store i32 0, i32* %i1, align 4 + br label %loop.head51 + +loop.head51: ; preds = %ifcont58, %ifcont50 + %203 = load i32, i32* %i1, align 4 + %204 = add i32 %203, 1 + %205 = icmp sle i32 %204, 3 + br i1 %205, label %loop.body52, label %loop.end59 + +loop.body52: ; preds = %loop.head51 + %206 = load i32, i32* %i1, align 4 + %207 = add i32 %206, 1 + store i32 %207, i32* %i1, align 4 + %208 = load i32, i32* %i1, align 4 + %209 = sub i32 %208, 1 + %210 = mul i32 1, %209 + %211 = add i32 0, %210 + %212 = icmp slt i32 %208, 1 + %213 = icmp sgt i32 %208, 4 + %214 = or i1 %212, %213 + br i1 %214, label %then53, label %else54 + +then53: ; preds = %loop.body52 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @26, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @25, i32 0, i32 0), i32 %208, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont55 + +else54: ; preds = %loop.body52 + br label %ifcont55 + +ifcont55: ; preds = %else54, %then53 + %215 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 %211 + %216 = load i32, i32* %i1, align 4 + %217 = sub i32 %216, 1 + %218 = mul i32 1, %217 + %219 = add i32 0, %218 + %220 = icmp slt i32 %216, 1 + %221 = icmp sgt i32 %216, 3 + %222 = or i1 %220, %221 + br i1 %222, label %then56, label %else57 + +then56: ; preds = %ifcont55 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %216, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont58 + +else57: ; preds = %ifcont55 + br label %ifcont58 + +ifcont58: ; preds = %else57, %then56 + %223 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 %219 + %224 = load %complex_4, %complex_4* %223, align 1 + %225 = alloca %complex_4, align 8 + %226 = getelementptr %complex_4, %complex_4* %225, i32 0, i32 0 + %227 = getelementptr %complex_4, %complex_4* %225, i32 0, i32 1 + store float 1.000000e+01, float* %226, align 4 + store float 0.000000e+00, float* %227, align 4 + %228 = load %complex_4, %complex_4* %225, align 1 + %229 = alloca %complex_4, align 8 + store %complex_4 %224, %complex_4* %229, align 1 + %230 = alloca %complex_4, align 8 + store %complex_4 %228, %complex_4* %230, align 1 + %231 = alloca %complex_4, align 8 + call void @_lfortran_complex_sub_32(%complex_4* %229, %complex_4* %230, %complex_4* %231) + %232 = load %complex_4, %complex_4* %231, align 1 + store %complex_4 %232, %complex_4* %215, align 1 + br label %loop.head51 + +loop.end59: ; preds = %loop.head51 + br i1 false, label %then60, label %else61 + +then60: ; preds = %loop.end59 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont62 + +else61: ; preds = %loop.end59 + br label %ifcont62 + +ifcont62: ; preds = %else61, %then60 + %233 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 + %234 = load %complex_4, %complex_4* %233, align 1 + %235 = alloca %complex_4, align 8 + %236 = getelementptr %complex_4, %complex_4* %235, i32 0, i32 0 + %237 = getelementptr %complex_4, %complex_4* %235, i32 0, i32 1 + store float 1.000000e+00, float* %236, align 4 + store float 0.000000e+00, float* %237, align 4 + %238 = load %complex_4, %complex_4* %235, align 1 + %239 = alloca %complex_4, align 8 + store %complex_4 %234, %complex_4* %239, align 1 + %240 = getelementptr %complex_4, %complex_4* %239, i32 0, i32 0 + %241 = load float, float* %240, align 4 + %242 = alloca %complex_4, align 8 + store %complex_4 %238, %complex_4* %242, align 1 + %243 = getelementptr %complex_4, %complex_4* %242, i32 0, i32 0 + %244 = load float, float* %243, align 4 + %245 = alloca %complex_4, align 8 + store %complex_4 %234, %complex_4* %245, align 1 + %246 = getelementptr %complex_4, %complex_4* %245, i32 0, i32 1 + %247 = load float, float* %246, align 4 + %248 = alloca %complex_4, align 8 + store %complex_4 %238, %complex_4* %248, align 1 + %249 = getelementptr %complex_4, %complex_4* %248, i32 0, i32 1 + %250 = load float, float* %249, align 4 + %251 = fcmp one float %241, %244 + %252 = fcmp one float %247, %250 + %253 = or i1 %251, %252 + br i1 %253, label %then63, label %else64 + +then63: ; preds = %ifcont62 + %254 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 + %255 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @31, i32 0, i32 0), i8* %254, i8* %255) + call void @exit(i32 1) + br label %ifcont65 + +else64: ; preds = %ifcont62 + br label %ifcont65 + +ifcont65: ; preds = %else64, %then63 + br i1 false, label %then66, label %else67 + +then66: ; preds = %ifcont65 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont68 + +else67: ; preds = %ifcont65 + br label %ifcont68 + +ifcont68: ; preds = %else67, %then66 + %256 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 + %257 = load %complex_4, %complex_4* %256, align 1 + %258 = alloca %complex_4, align 8 + %259 = getelementptr %complex_4, %complex_4* %258, i32 0, i32 0 + %260 = getelementptr %complex_4, %complex_4* %258, i32 0, i32 1 + store float 2.000000e+00, float* %259, align 4 + store float 0.000000e+00, float* %260, align 4 + %261 = load %complex_4, %complex_4* %258, align 1 + %262 = alloca %complex_4, align 8 + store %complex_4 %257, %complex_4* %262, align 1 + %263 = getelementptr %complex_4, %complex_4* %262, i32 0, i32 0 + %264 = load float, float* %263, align 4 + %265 = alloca %complex_4, align 8 + store %complex_4 %261, %complex_4* %265, align 1 + %266 = getelementptr %complex_4, %complex_4* %265, i32 0, i32 0 + %267 = load float, float* %266, align 4 + %268 = alloca %complex_4, align 8 + store %complex_4 %257, %complex_4* %268, align 1 + %269 = getelementptr %complex_4, %complex_4* %268, i32 0, i32 1 + %270 = load float, float* %269, align 4 + %271 = alloca %complex_4, align 8 + store %complex_4 %261, %complex_4* %271, align 1 + %272 = getelementptr %complex_4, %complex_4* %271, i32 0, i32 1 + %273 = load float, float* %272, align 4 + %274 = fcmp one float %264, %267 + %275 = fcmp one float %270, %273 + %276 = or i1 %274, %275 + br i1 %276, label %then69, label %else70 + +then69: ; preds = %ifcont68 + %277 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 + %278 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @34, i32 0, i32 0), i8* %277, i8* %278) + call void @exit(i32 1) + br label %ifcont71 + +else70: ; preds = %ifcont68 + br label %ifcont71 + +ifcont71: ; preds = %else70, %then69 + br i1 false, label %then72, label %else73 + +then72: ; preds = %ifcont71 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont74 + +else73: ; preds = %ifcont71 + br label %ifcont74 + +ifcont74: ; preds = %else73, %then72 + %279 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 + %280 = load %complex_4, %complex_4* %279, align 1 + %281 = alloca %complex_4, align 8 + %282 = getelementptr %complex_4, %complex_4* %281, i32 0, i32 0 + %283 = getelementptr %complex_4, %complex_4* %281, i32 0, i32 1 + store float 3.000000e+00, float* %282, align 4 + store float 0.000000e+00, float* %283, align 4 + %284 = load %complex_4, %complex_4* %281, align 1 + %285 = alloca %complex_4, align 8 + store %complex_4 %280, %complex_4* %285, align 1 + %286 = getelementptr %complex_4, %complex_4* %285, i32 0, i32 0 + %287 = load float, float* %286, align 4 + %288 = alloca %complex_4, align 8 + store %complex_4 %284, %complex_4* %288, align 1 + %289 = getelementptr %complex_4, %complex_4* %288, i32 0, i32 0 + %290 = load float, float* %289, align 4 + %291 = alloca %complex_4, align 8 + store %complex_4 %280, %complex_4* %291, align 1 + %292 = getelementptr %complex_4, %complex_4* %291, i32 0, i32 1 + %293 = load float, float* %292, align 4 + %294 = alloca %complex_4, align 8 + store %complex_4 %284, %complex_4* %294, align 1 + %295 = getelementptr %complex_4, %complex_4* %294, i32 0, i32 1 + %296 = load float, float* %295, align 4 + %297 = fcmp one float %287, %290 + %298 = fcmp one float %293, %296 + %299 = or i1 %297, %298 + br i1 %299, label %then75, label %else76 + +then75: ; preds = %ifcont74 + %300 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 + %301 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @37, i32 0, i32 0), i8* %300, i8* %301) + call void @exit(i32 1) + br label %ifcont77 + +else76: ; preds = %ifcont74 + br label %ifcont77 + +ifcont77: ; preds = %else76, %then75 + br i1 false, label %then78, label %else79 + +then78: ; preds = %ifcont77 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @39, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @38, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont80 + +else79: ; preds = %ifcont77 + br label %ifcont80 + +ifcont80: ; preds = %else79, %then78 + %302 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 + br i1 false, label %then81, label %else82 + +then81: ; preds = %ifcont80 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont83 + +else82: ; preds = %ifcont80 + br label %ifcont83 + +ifcont83: ; preds = %else82, %then81 + %303 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 %304 = load %complex_4, %complex_4* %303, align 1 - %305 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 + br i1 false, label %then84, label %else85 + +then84: ; preds = %ifcont83 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @43, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @42, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont86 + +else85: ; preds = %ifcont83 + br label %ifcont86 + +ifcont86: ; preds = %else85, %then84 + %305 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 %306 = load %complex_4, %complex_4* %305, align 1 %307 = alloca %complex_4, align 8 store %complex_4 %304, %complex_4* %307, align 1 @@ -628,84 +875,91 @@ ifcont35: ; preds = %else34, %then33 %309 = alloca %complex_4, align 8 call void @_lfortran_complex_add_32(%complex_4* %307, %complex_4* %308, %complex_4* %309) %310 = load %complex_4, %complex_4* %309, align 1 - store %complex_4 %310, %complex_4* %290, align 1 - %311 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 + br i1 false, label %then87, label %else88 + +then87: ; preds = %ifcont86 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @44, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont89 + +else88: ; preds = %ifcont86 + br label %ifcont89 + +ifcont89: ; preds = %else88, %then87 + %311 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 %312 = load %complex_4, %complex_4* %311, align 1 %313 = alloca %complex_4, align 8 - %314 = getelementptr %complex_4, %complex_4* %313, i32 0, i32 0 - %315 = getelementptr %complex_4, %complex_4* %313, i32 0, i32 1 - store float 1.700000e+01, float* %314, align 4 - store float 0.000000e+00, float* %315, align 4 - %316 = load %complex_4, %complex_4* %313, align 1 - %317 = alloca %complex_4, align 8 - store %complex_4 %312, %complex_4* %317, align 1 - %318 = getelementptr %complex_4, %complex_4* %317, i32 0, i32 0 - %319 = load float, float* %318, align 4 - %320 = alloca %complex_4, align 8 - store %complex_4 %316, %complex_4* %320, align 1 - %321 = getelementptr %complex_4, %complex_4* %320, i32 0, i32 0 - %322 = load float, float* %321, align 4 - %323 = alloca %complex_4, align 8 - store %complex_4 %312, %complex_4* %323, align 1 - %324 = getelementptr %complex_4, %complex_4* %323, i32 0, i32 1 - %325 = load float, float* %324, align 4 - %326 = alloca %complex_4, align 8 - store %complex_4 %316, %complex_4* %326, align 1 - %327 = getelementptr %complex_4, %complex_4* %326, i32 0, i32 1 - %328 = load float, float* %327, align 4 - %329 = fcmp one float %319, %322 - %330 = fcmp one float %325, %328 - %331 = or i1 %329, %330 - br i1 %331, label %then36, label %else37 + store %complex_4 %310, %complex_4* %313, align 1 + %314 = alloca %complex_4, align 8 + store %complex_4 %312, %complex_4* %314, align 1 + %315 = alloca %complex_4, align 8 + call void @_lfortran_complex_add_32(%complex_4* %313, %complex_4* %314, %complex_4* %315) + %316 = load %complex_4, %complex_4* %315, align 1 + br i1 false, label %then90, label %else91 + +then90: ; preds = %ifcont89 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont92 -then36: ; preds = %ifcont35 - %332 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 - %333 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %332, i8* %333) +else91: ; preds = %ifcont89 + br label %ifcont92 + +ifcont92: ; preds = %else91, %then90 + %317 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 + %318 = load %complex_4, %complex_4* %317, align 1 + %319 = alloca %complex_4, align 8 + store %complex_4 %316, %complex_4* %319, align 1 + %320 = alloca %complex_4, align 8 + store %complex_4 %318, %complex_4* %320, align 1 + %321 = alloca %complex_4, align 8 + call void @_lfortran_complex_add_32(%complex_4* %319, %complex_4* %320, %complex_4* %321) + %322 = load %complex_4, %complex_4* %321, align 1 + store %complex_4 %322, %complex_4* %302, align 1 + br i1 false, label %then93, label %else94 + +then93: ; preds = %ifcont92 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont95 else94: ; preds = %ifcont92 br label %ifcont95 -ifcont38: ; preds = %else37, %then36 - %334 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 - %335 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 - %336 = load %complex_4, %complex_4* %335, align 1 - store %complex_4 %336, %complex_4* %334, align 1 - %337 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 - %338 = load %complex_4, %complex_4* %337, align 1 - %339 = alloca %complex_4, align 8 - %340 = getelementptr %complex_4, %complex_4* %339, i32 0, i32 0 - %341 = getelementptr %complex_4, %complex_4* %339, i32 0, i32 1 - store float 1.100000e+01, float* %340, align 4 - store float 0.000000e+00, float* %341, align 4 - %342 = load %complex_4, %complex_4* %339, align 1 - %343 = alloca %complex_4, align 8 - store %complex_4 %338, %complex_4* %343, align 1 - %344 = getelementptr %complex_4, %complex_4* %343, i32 0, i32 0 - %345 = load float, float* %344, align 4 - %346 = alloca %complex_4, align 8 - store %complex_4 %342, %complex_4* %346, align 1 - %347 = getelementptr %complex_4, %complex_4* %346, i32 0, i32 0 - %348 = load float, float* %347, align 4 - %349 = alloca %complex_4, align 8 - store %complex_4 %338, %complex_4* %349, align 1 - %350 = getelementptr %complex_4, %complex_4* %349, i32 0, i32 1 - %351 = load float, float* %350, align 4 - %352 = alloca %complex_4, align 8 - store %complex_4 %342, %complex_4* %352, align 1 - %353 = getelementptr %complex_4, %complex_4* %352, i32 0, i32 1 - %354 = load float, float* %353, align 4 - %355 = fcmp one float %345, %348 - %356 = fcmp one float %351, %354 - %357 = or i1 %355, %356 - br i1 %357, label %then39, label %else40 - -then39: ; preds = %ifcont38 - %358 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 - %359 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %358, i8* %359) +ifcont95: ; preds = %else94, %then93 + %323 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 + %324 = load %complex_4, %complex_4* %323, align 1 + %325 = alloca %complex_4, align 8 + %326 = getelementptr %complex_4, %complex_4* %325, i32 0, i32 0 + %327 = getelementptr %complex_4, %complex_4* %325, i32 0, i32 1 + store float 1.700000e+01, float* %326, align 4 + store float 0.000000e+00, float* %327, align 4 + %328 = load %complex_4, %complex_4* %325, align 1 + %329 = alloca %complex_4, align 8 + store %complex_4 %324, %complex_4* %329, align 1 + %330 = getelementptr %complex_4, %complex_4* %329, i32 0, i32 0 + %331 = load float, float* %330, align 4 + %332 = alloca %complex_4, align 8 + store %complex_4 %328, %complex_4* %332, align 1 + %333 = getelementptr %complex_4, %complex_4* %332, i32 0, i32 0 + %334 = load float, float* %333, align 4 + %335 = alloca %complex_4, align 8 + store %complex_4 %324, %complex_4* %335, align 1 + %336 = getelementptr %complex_4, %complex_4* %335, i32 0, i32 1 + %337 = load float, float* %336, align 4 + %338 = alloca %complex_4, align 8 + store %complex_4 %328, %complex_4* %338, align 1 + %339 = getelementptr %complex_4, %complex_4* %338, i32 0, i32 1 + %340 = load float, float* %339, align 4 + %341 = fcmp one float %331, %334 + %342 = fcmp one float %337, %340 + %343 = or i1 %341, %342 + br i1 %343, label %then96, label %else97 + +then96: ; preds = %ifcont95 + %344 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 + %345 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @50, i32 0, i32 0), i8* %344, i8* %345) call void @exit(i32 1) br label %ifcont98 @@ -716,7 +970,7 @@ ifcont98: ; preds = %else97, %then96 br i1 false, label %then99, label %else100 then99: ; preds = %ifcont98 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @74, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @73, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont101 @@ -724,11 +978,11 @@ else100: ; preds = %ifcont98 br label %ifcont101 ifcont101: ; preds = %else100, %then99 - %324 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 + %346 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 br i1 false, label %then102, label %else103 then102: ; preds = %ifcont101 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @76, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @75, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont104 @@ -736,13 +990,13 @@ else103: ; preds = %ifcont101 br label %ifcont104 ifcont104: ; preds = %else103, %then102 - %325 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 - %326 = load %complex_4, %complex_4* %325, align 1 - store %complex_4 %326, %complex_4* %324, align 1 + %347 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 + %348 = load %complex_4, %complex_4* %347, align 1 + store %complex_4 %348, %complex_4* %346, align 1 br i1 false, label %then105, label %else106 then105: ; preds = %ifcont104 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont107 @@ -750,37 +1004,39 @@ else106: ; preds = %ifcont104 br label %ifcont107 ifcont107: ; preds = %else106, %then105 - %327 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 - %328 = load %complex_4, %complex_4* %327, align 1 - %329 = alloca %complex_4, align 8 - %330 = getelementptr %complex_4, %complex_4* %329, i32 0, i32 0 - %331 = getelementptr %complex_4, %complex_4* %329, i32 0, i32 1 - store float 1.100000e+01, float* %330, align 4 - store float 0.000000e+00, float* %331, align 4 - %332 = load %complex_4, %complex_4* %329, align 1 - %333 = alloca %complex_4, align 8 - store %complex_4 %328, %complex_4* %333, align 1 - %334 = getelementptr %complex_4, %complex_4* %333, i32 0, i32 0 - %335 = load float, float* %334, align 4 - %336 = alloca %complex_4, align 8 - store %complex_4 %332, %complex_4* %336, align 1 - %337 = getelementptr %complex_4, %complex_4* %336, i32 0, i32 0 - %338 = load float, float* %337, align 4 - %339 = alloca %complex_4, align 8 - store %complex_4 %328, %complex_4* %339, align 1 - %340 = getelementptr %complex_4, %complex_4* %339, i32 0, i32 1 - %341 = load float, float* %340, align 4 - %342 = alloca %complex_4, align 8 - store %complex_4 %332, %complex_4* %342, align 1 - %343 = getelementptr %complex_4, %complex_4* %342, i32 0, i32 1 - %344 = load float, float* %343, align 4 - %345 = fcmp one float %335, %338 - %346 = fcmp one float %341, %344 - %347 = or i1 %345, %346 - br i1 %347, label %then108, label %else109 + %349 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 + %350 = load %complex_4, %complex_4* %349, align 1 + %351 = alloca %complex_4, align 8 + %352 = getelementptr %complex_4, %complex_4* %351, i32 0, i32 0 + %353 = getelementptr %complex_4, %complex_4* %351, i32 0, i32 1 + store float 1.100000e+01, float* %352, align 4 + store float 0.000000e+00, float* %353, align 4 + %354 = load %complex_4, %complex_4* %351, align 1 + %355 = alloca %complex_4, align 8 + store %complex_4 %350, %complex_4* %355, align 1 + %356 = getelementptr %complex_4, %complex_4* %355, i32 0, i32 0 + %357 = load float, float* %356, align 4 + %358 = alloca %complex_4, align 8 + store %complex_4 %354, %complex_4* %358, align 1 + %359 = getelementptr %complex_4, %complex_4* %358, i32 0, i32 0 + %360 = load float, float* %359, align 4 + %361 = alloca %complex_4, align 8 + store %complex_4 %350, %complex_4* %361, align 1 + %362 = getelementptr %complex_4, %complex_4* %361, i32 0, i32 1 + %363 = load float, float* %362, align 4 + %364 = alloca %complex_4, align 8 + store %complex_4 %354, %complex_4* %364, align 1 + %365 = getelementptr %complex_4, %complex_4* %364, i32 0, i32 1 + %366 = load float, float* %365, align 4 + %367 = fcmp one float %357, %360 + %368 = fcmp one float %363, %366 + %369 = or i1 %367, %368 + br i1 %369, label %then108, label %else109 then108: ; preds = %ifcont107 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @79, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @80, i32 0, i32 0)) + %370 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 + %371 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* %370, i8* %371) call void @exit(i32 1) br label %ifcont110 @@ -791,209 +1047,263 @@ ifcont110: ; preds = %else109, %then108 store i32 0, i32* %i1, align 4 br label %loop.head111 -loop.head42: ; preds = %loop.end46, %ifcont41 - %360 = load i32, i32* %i1, align 4 - %361 = add i32 %360, 1 - %362 = icmp sle i32 %361, 2 - br i1 %362, label %loop.body43, label %loop.end47 +loop.head111: ; preds = %loop.end121, %ifcont110 + %372 = load i32, i32* %i1, align 4 + %373 = add i32 %372, 1 + %374 = icmp sle i32 %373, 2 + br i1 %374, label %loop.body112, label %loop.end122 -loop.body43: ; preds = %loop.head42 - %363 = load i32, i32* %i1, align 4 - %364 = add i32 %363, 1 - store i32 %364, i32* %i1, align 4 +loop.body112: ; preds = %loop.head111 + %375 = load i32, i32* %i1, align 4 + %376 = add i32 %375, 1 + store i32 %376, i32* %i1, align 4 store i32 0, i32* %j2, align 4 br label %loop.head113 -loop.head44: ; preds = %loop.body45, %loop.body43 - %365 = load i32, i32* %j2, align 4 - %366 = add i32 %365, 1 - %367 = icmp sle i32 %366, 2 - br i1 %367, label %loop.body45, label %loop.end46 - -loop.body45: ; preds = %loop.head44 - %368 = load i32, i32* %j2, align 4 - %369 = add i32 %368, 1 - store i32 %369, i32* %j2, align 4 - %370 = load i32, i32* %i1, align 4 - %371 = load i32, i32* %j2, align 4 - %372 = sub i32 %370, 1 - %373 = mul i32 1, %372 - %374 = add i32 0, %373 - %375 = sub i32 %371, 1 - %376 = mul i32 2, %375 - %377 = add i32 %374, %376 - %378 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 %377 - %379 = load i32, i32* %i1, align 4 +loop.head113: ; preds = %ifcont120, %loop.body112 + %377 = load i32, i32* %j2, align 4 + %378 = add i32 %377, 1 + %379 = icmp sle i32 %378, 2 + br i1 %379, label %loop.body114, label %loop.end121 + +loop.body114: ; preds = %loop.head113 %380 = load i32, i32* %j2, align 4 - %381 = add i32 %379, %380 - %382 = add i32 %381, 10 - %383 = sitofp i32 %382 to float - %384 = alloca %complex_4, align 8 - %385 = getelementptr %complex_4, %complex_4* %384, i32 0, i32 0 - %386 = getelementptr %complex_4, %complex_4* %384, i32 0, i32 1 - store float %383, float* %385, align 4 - store float 0.000000e+00, float* %386, align 4 - %387 = load %complex_4, %complex_4* %384, align 1 - store %complex_4 %387, %complex_4* %378, align 1 - br label %loop.head44 - -loop.end46: ; preds = %loop.head44 - br label %loop.head42 - -loop.end47: ; preds = %loop.head42 - %388 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 0 - %389 = load %complex_4, %complex_4* %388, align 1 - %390 = alloca %complex_4, align 8 - %391 = getelementptr %complex_4, %complex_4* %390, i32 0, i32 0 - %392 = getelementptr %complex_4, %complex_4* %390, i32 0, i32 1 - store float 1.200000e+01, float* %391, align 4 - store float 0.000000e+00, float* %392, align 4 - %393 = load %complex_4, %complex_4* %390, align 1 - %394 = alloca %complex_4, align 8 - store %complex_4 %389, %complex_4* %394, align 1 - %395 = getelementptr %complex_4, %complex_4* %394, i32 0, i32 0 - %396 = load float, float* %395, align 4 - %397 = alloca %complex_4, align 8 - store %complex_4 %393, %complex_4* %397, align 1 - %398 = getelementptr %complex_4, %complex_4* %397, i32 0, i32 0 - %399 = load float, float* %398, align 4 - %400 = alloca %complex_4, align 8 - store %complex_4 %389, %complex_4* %400, align 1 - %401 = getelementptr %complex_4, %complex_4* %400, i32 0, i32 1 - %402 = load float, float* %401, align 4 - %403 = alloca %complex_4, align 8 - store %complex_4 %393, %complex_4* %403, align 1 - %404 = getelementptr %complex_4, %complex_4* %403, i32 0, i32 1 - %405 = load float, float* %404, align 4 - %406 = fcmp one float %396, %399 - %407 = fcmp one float %402, %405 - %408 = or i1 %406, %407 - br i1 %408, label %then48, label %else49 - -then48: ; preds = %loop.end47 - %409 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 - %410 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i8* %409, i8* %410) + %381 = add i32 %380, 1 + store i32 %381, i32* %j2, align 4 + %382 = load i32, i32* %i1, align 4 + %383 = load i32, i32* %j2, align 4 + %384 = sub i32 %382, 1 + %385 = mul i32 1, %384 + %386 = add i32 0, %385 + %387 = icmp slt i32 %382, 1 + %388 = icmp sgt i32 %382, 2 + %389 = or i1 %387, %388 + br i1 %389, label %then115, label %else116 + +then115: ; preds = %loop.body114 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 %382, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont117 else116: ; preds = %loop.body114 br label %ifcont117 -ifcont50: ; preds = %else49, %then48 - %411 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 2 - %412 = load %complex_4, %complex_4* %411, align 1 - %413 = alloca %complex_4, align 8 - %414 = getelementptr %complex_4, %complex_4* %413, i32 0, i32 0 - %415 = getelementptr %complex_4, %complex_4* %413, i32 0, i32 1 - store float 1.300000e+01, float* %414, align 4 - store float 0.000000e+00, float* %415, align 4 - %416 = load %complex_4, %complex_4* %413, align 1 - %417 = alloca %complex_4, align 8 - store %complex_4 %412, %complex_4* %417, align 1 - %418 = getelementptr %complex_4, %complex_4* %417, i32 0, i32 0 - %419 = load float, float* %418, align 4 - %420 = alloca %complex_4, align 8 - store %complex_4 %416, %complex_4* %420, align 1 - %421 = getelementptr %complex_4, %complex_4* %420, i32 0, i32 0 - %422 = load float, float* %421, align 4 - %423 = alloca %complex_4, align 8 - store %complex_4 %412, %complex_4* %423, align 1 - %424 = getelementptr %complex_4, %complex_4* %423, i32 0, i32 1 - %425 = load float, float* %424, align 4 - %426 = alloca %complex_4, align 8 - store %complex_4 %416, %complex_4* %426, align 1 - %427 = getelementptr %complex_4, %complex_4* %426, i32 0, i32 1 - %428 = load float, float* %427, align 4 - %429 = fcmp one float %419, %422 - %430 = fcmp one float %425, %428 - %431 = or i1 %429, %430 - br i1 %431, label %then51, label %else52 - -then51: ; preds = %ifcont50 - %432 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 - %433 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0), i8* %432, i8* %433) +ifcont117: ; preds = %else116, %then115 + %390 = sub i32 %383, 1 + %391 = mul i32 2, %390 + %392 = add i32 %386, %391 + %393 = icmp slt i32 %383, 1 + %394 = icmp sgt i32 %383, 2 + %395 = or i1 %393, %394 + br i1 %395, label %then118, label %else119 + +then118: ; preds = %ifcont117 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 %383, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont120 + +else119: ; preds = %ifcont117 + br label %ifcont120 + +ifcont120: ; preds = %else119, %then118 + %396 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 %392 + %397 = load i32, i32* %i1, align 4 + %398 = load i32, i32* %j2, align 4 + %399 = add i32 %397, %398 + %400 = add i32 %399, 10 + %401 = sitofp i32 %400 to float + %402 = alloca %complex_4, align 8 + %403 = getelementptr %complex_4, %complex_4* %402, i32 0, i32 0 + %404 = getelementptr %complex_4, %complex_4* %402, i32 0, i32 1 + store float %401, float* %403, align 4 + store float 0.000000e+00, float* %404, align 4 + %405 = load %complex_4, %complex_4* %402, align 1 + store %complex_4 %405, %complex_4* %396, align 1 + br label %loop.head113 + +loop.end121: ; preds = %loop.head113 + br label %loop.head111 + +loop.end122: ; preds = %loop.head111 + br i1 false, label %then123, label %else124 + +then123: ; preds = %loop.end122 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont125 + +else124: ; preds = %loop.end122 + br label %ifcont125 + +ifcont125: ; preds = %else124, %then123 + br i1 false, label %then126, label %else127 + +then126: ; preds = %ifcont125 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont128 + +else127: ; preds = %ifcont125 + br label %ifcont128 + +ifcont128: ; preds = %else127, %then126 + %406 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 0 + %407 = load %complex_4, %complex_4* %406, align 1 + %408 = alloca %complex_4, align 8 + %409 = getelementptr %complex_4, %complex_4* %408, i32 0, i32 0 + %410 = getelementptr %complex_4, %complex_4* %408, i32 0, i32 1 + store float 1.200000e+01, float* %409, align 4 + store float 0.000000e+00, float* %410, align 4 + %411 = load %complex_4, %complex_4* %408, align 1 + %412 = alloca %complex_4, align 8 + store %complex_4 %407, %complex_4* %412, align 1 + %413 = getelementptr %complex_4, %complex_4* %412, i32 0, i32 0 + %414 = load float, float* %413, align 4 + %415 = alloca %complex_4, align 8 + store %complex_4 %411, %complex_4* %415, align 1 + %416 = getelementptr %complex_4, %complex_4* %415, i32 0, i32 0 + %417 = load float, float* %416, align 4 + %418 = alloca %complex_4, align 8 + store %complex_4 %407, %complex_4* %418, align 1 + %419 = getelementptr %complex_4, %complex_4* %418, i32 0, i32 1 + %420 = load float, float* %419, align 4 + %421 = alloca %complex_4, align 8 + store %complex_4 %411, %complex_4* %421, align 1 + %422 = getelementptr %complex_4, %complex_4* %421, i32 0, i32 1 + %423 = load float, float* %422, align 4 + %424 = fcmp one float %414, %417 + %425 = fcmp one float %420, %423 + %426 = or i1 %424, %425 + br i1 %426, label %then129, label %else130 + +then129: ; preds = %ifcont128 + %427 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 + %428 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @66, i32 0, i32 0), i8* %427, i8* %428) call void @exit(i32 1) br label %ifcont131 else130: ; preds = %ifcont128 br label %ifcont131 -ifcont53: ; preds = %else52, %then51 - %434 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 1 - %435 = load %complex_4, %complex_4* %434, align 1 - %436 = alloca %complex_4, align 8 - %437 = getelementptr %complex_4, %complex_4* %436, i32 0, i32 0 - %438 = getelementptr %complex_4, %complex_4* %436, i32 0, i32 1 - store float 1.300000e+01, float* %437, align 4 - store float 0.000000e+00, float* %438, align 4 - %439 = load %complex_4, %complex_4* %436, align 1 - %440 = alloca %complex_4, align 8 - store %complex_4 %435, %complex_4* %440, align 1 - %441 = getelementptr %complex_4, %complex_4* %440, i32 0, i32 0 - %442 = load float, float* %441, align 4 - %443 = alloca %complex_4, align 8 - store %complex_4 %439, %complex_4* %443, align 1 - %444 = getelementptr %complex_4, %complex_4* %443, i32 0, i32 0 - %445 = load float, float* %444, align 4 - %446 = alloca %complex_4, align 8 - store %complex_4 %435, %complex_4* %446, align 1 - %447 = getelementptr %complex_4, %complex_4* %446, i32 0, i32 1 - %448 = load float, float* %447, align 4 - %449 = alloca %complex_4, align 8 - store %complex_4 %439, %complex_4* %449, align 1 - %450 = getelementptr %complex_4, %complex_4* %449, i32 0, i32 1 - %451 = load float, float* %450, align 4 - %452 = fcmp one float %442, %445 - %453 = fcmp one float %448, %451 - %454 = or i1 %452, %453 - br i1 %454, label %then54, label %else55 - -then54: ; preds = %ifcont53 - %455 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 - %456 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %455, i8* %456) +ifcont131: ; preds = %else130, %then129 + br i1 false, label %then132, label %else133 + +then132: ; preds = %ifcont131 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @68, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @67, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont134 + +else133: ; preds = %ifcont131 + br label %ifcont134 + +ifcont134: ; preds = %else133, %then132 + br i1 false, label %then135, label %else136 + +then135: ; preds = %ifcont134 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @69, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont137 + +else136: ; preds = %ifcont134 + br label %ifcont137 + +ifcont137: ; preds = %else136, %then135 + %429 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 2 + %430 = load %complex_4, %complex_4* %429, align 1 + %431 = alloca %complex_4, align 8 + %432 = getelementptr %complex_4, %complex_4* %431, i32 0, i32 0 + %433 = getelementptr %complex_4, %complex_4* %431, i32 0, i32 1 + store float 1.300000e+01, float* %432, align 4 + store float 0.000000e+00, float* %433, align 4 + %434 = load %complex_4, %complex_4* %431, align 1 + %435 = alloca %complex_4, align 8 + store %complex_4 %430, %complex_4* %435, align 1 + %436 = getelementptr %complex_4, %complex_4* %435, i32 0, i32 0 + %437 = load float, float* %436, align 4 + %438 = alloca %complex_4, align 8 + store %complex_4 %434, %complex_4* %438, align 1 + %439 = getelementptr %complex_4, %complex_4* %438, i32 0, i32 0 + %440 = load float, float* %439, align 4 + %441 = alloca %complex_4, align 8 + store %complex_4 %430, %complex_4* %441, align 1 + %442 = getelementptr %complex_4, %complex_4* %441, i32 0, i32 1 + %443 = load float, float* %442, align 4 + %444 = alloca %complex_4, align 8 + store %complex_4 %434, %complex_4* %444, align 1 + %445 = getelementptr %complex_4, %complex_4* %444, i32 0, i32 1 + %446 = load float, float* %445, align 4 + %447 = fcmp one float %437, %440 + %448 = fcmp one float %443, %446 + %449 = or i1 %447, %448 + br i1 %449, label %then138, label %else139 + +then138: ; preds = %ifcont137 + %450 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 + %451 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @71, i32 0, i32 0), i8* %450, i8* %451) call void @exit(i32 1) br label %ifcont140 else139: ; preds = %ifcont137 br label %ifcont140 -ifcont56: ; preds = %else55, %then54 - %457 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 3 - %458 = load %complex_4, %complex_4* %457, align 1 - %459 = alloca %complex_4, align 8 - %460 = getelementptr %complex_4, %complex_4* %459, i32 0, i32 0 - %461 = getelementptr %complex_4, %complex_4* %459, i32 0, i32 1 - store float 1.400000e+01, float* %460, align 4 - store float 0.000000e+00, float* %461, align 4 - %462 = load %complex_4, %complex_4* %459, align 1 - %463 = alloca %complex_4, align 8 - store %complex_4 %458, %complex_4* %463, align 1 - %464 = getelementptr %complex_4, %complex_4* %463, i32 0, i32 0 - %465 = load float, float* %464, align 4 - %466 = alloca %complex_4, align 8 - store %complex_4 %462, %complex_4* %466, align 1 - %467 = getelementptr %complex_4, %complex_4* %466, i32 0, i32 0 - %468 = load float, float* %467, align 4 - %469 = alloca %complex_4, align 8 - store %complex_4 %458, %complex_4* %469, align 1 - %470 = getelementptr %complex_4, %complex_4* %469, i32 0, i32 1 - %471 = load float, float* %470, align 4 - %472 = alloca %complex_4, align 8 - store %complex_4 %462, %complex_4* %472, align 1 - %473 = getelementptr %complex_4, %complex_4* %472, i32 0, i32 1 - %474 = load float, float* %473, align 4 - %475 = fcmp one float %465, %468 - %476 = fcmp one float %471, %474 - %477 = or i1 %475, %476 - br i1 %477, label %then57, label %else58 - -then57: ; preds = %ifcont56 - %478 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 - %479 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %478, i8* %479) +ifcont140: ; preds = %else139, %then138 + br i1 false, label %then141, label %else142 + +then141: ; preds = %ifcont140 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont143 + +else142: ; preds = %ifcont140 + br label %ifcont143 + +ifcont143: ; preds = %else142, %then141 + br i1 false, label %then144, label %else145 + +then144: ; preds = %ifcont143 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void @exit(i32 1) + br label %ifcont146 + +else145: ; preds = %ifcont143 + br label %ifcont146 + +ifcont146: ; preds = %else145, %then144 + %452 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 1 + %453 = load %complex_4, %complex_4* %452, align 1 + %454 = alloca %complex_4, align 8 + %455 = getelementptr %complex_4, %complex_4* %454, i32 0, i32 0 + %456 = getelementptr %complex_4, %complex_4* %454, i32 0, i32 1 + store float 1.300000e+01, float* %455, align 4 + store float 0.000000e+00, float* %456, align 4 + %457 = load %complex_4, %complex_4* %454, align 1 + %458 = alloca %complex_4, align 8 + store %complex_4 %453, %complex_4* %458, align 1 + %459 = getelementptr %complex_4, %complex_4* %458, i32 0, i32 0 + %460 = load float, float* %459, align 4 + %461 = alloca %complex_4, align 8 + store %complex_4 %457, %complex_4* %461, align 1 + %462 = getelementptr %complex_4, %complex_4* %461, i32 0, i32 0 + %463 = load float, float* %462, align 4 + %464 = alloca %complex_4, align 8 + store %complex_4 %453, %complex_4* %464, align 1 + %465 = getelementptr %complex_4, %complex_4* %464, i32 0, i32 1 + %466 = load float, float* %465, align 4 + %467 = alloca %complex_4, align 8 + store %complex_4 %457, %complex_4* %467, align 1 + %468 = getelementptr %complex_4, %complex_4* %467, i32 0, i32 1 + %469 = load float, float* %468, align 4 + %470 = fcmp one float %460, %463 + %471 = fcmp one float %466, %469 + %472 = or i1 %470, %471 + br i1 %472, label %then147, label %else148 + +then147: ; preds = %ifcont146 + %473 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 + %474 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @76, i32 0, i32 0), i8* %473, i8* %474) call void @exit(i32 1) br label %ifcont149 @@ -1004,7 +1314,7 @@ ifcont149: ; preds = %else148, %then147 br i1 false, label %then150, label %else151 then150: ; preds = %ifcont149 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont152 @@ -1015,7 +1325,7 @@ ifcont152: ; preds = %else151, %then150 br i1 false, label %then153, label %else154 then153: ; preds = %ifcont152 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @110, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @109, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont155 @@ -1023,37 +1333,39 @@ else154: ; preds = %ifcont152 br label %ifcont155 ifcont155: ; preds = %else154, %then153 - %445 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 3 - %446 = load %complex_4, %complex_4* %445, align 1 - %447 = alloca %complex_4, align 8 - %448 = getelementptr %complex_4, %complex_4* %447, i32 0, i32 0 - %449 = getelementptr %complex_4, %complex_4* %447, i32 0, i32 1 - store float 1.400000e+01, float* %448, align 4 - store float 0.000000e+00, float* %449, align 4 - %450 = load %complex_4, %complex_4* %447, align 1 - %451 = alloca %complex_4, align 8 - store %complex_4 %446, %complex_4* %451, align 1 - %452 = getelementptr %complex_4, %complex_4* %451, i32 0, i32 0 - %453 = load float, float* %452, align 4 - %454 = alloca %complex_4, align 8 - store %complex_4 %450, %complex_4* %454, align 1 - %455 = getelementptr %complex_4, %complex_4* %454, i32 0, i32 0 - %456 = load float, float* %455, align 4 - %457 = alloca %complex_4, align 8 - store %complex_4 %446, %complex_4* %457, align 1 - %458 = getelementptr %complex_4, %complex_4* %457, i32 0, i32 1 - %459 = load float, float* %458, align 4 - %460 = alloca %complex_4, align 8 - store %complex_4 %450, %complex_4* %460, align 1 - %461 = getelementptr %complex_4, %complex_4* %460, i32 0, i32 1 - %462 = load float, float* %461, align 4 - %463 = fcmp one float %453, %456 - %464 = fcmp one float %459, %462 - %465 = or i1 %463, %464 - br i1 %465, label %then156, label %else157 + %475 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 3 + %476 = load %complex_4, %complex_4* %475, align 1 + %477 = alloca %complex_4, align 8 + %478 = getelementptr %complex_4, %complex_4* %477, i32 0, i32 0 + %479 = getelementptr %complex_4, %complex_4* %477, i32 0, i32 1 + store float 1.400000e+01, float* %478, align 4 + store float 0.000000e+00, float* %479, align 4 + %480 = load %complex_4, %complex_4* %477, align 1 + %481 = alloca %complex_4, align 8 + store %complex_4 %476, %complex_4* %481, align 1 + %482 = getelementptr %complex_4, %complex_4* %481, i32 0, i32 0 + %483 = load float, float* %482, align 4 + %484 = alloca %complex_4, align 8 + store %complex_4 %480, %complex_4* %484, align 1 + %485 = getelementptr %complex_4, %complex_4* %484, i32 0, i32 0 + %486 = load float, float* %485, align 4 + %487 = alloca %complex_4, align 8 + store %complex_4 %476, %complex_4* %487, align 1 + %488 = getelementptr %complex_4, %complex_4* %487, i32 0, i32 1 + %489 = load float, float* %488, align 4 + %490 = alloca %complex_4, align 8 + store %complex_4 %480, %complex_4* %490, align 1 + %491 = getelementptr %complex_4, %complex_4* %490, i32 0, i32 1 + %492 = load float, float* %491, align 4 + %493 = fcmp one float %483, %486 + %494 = fcmp one float %489, %492 + %495 = or i1 %493, %494 + br i1 %495, label %then156, label %else157 then156: ; preds = %ifcont155 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @113, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0)) + %496 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 + %497 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* %496, i8* %497) call void @exit(i32 1) br label %ifcont158 diff --git a/tests/reference/llvm-arrays_01_logical-f19a63d.json b/tests/reference/llvm-arrays_01_logical-f19a63d.json index bc044e343d0..9250651f3e6 100644 --- a/tests/reference/llvm-arrays_01_logical-f19a63d.json +++ b/tests/reference/llvm-arrays_01_logical-f19a63d.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01_logical-f19a63d.stdout", - "stdout_hash": "7f356e0290aab42274c5b224bc2bf402e34da57fe1676a04eae2f9c2", + "stdout_hash": "1ef5064c26b1b2d0b850070ba4f041d98a9dfb18f945d84eee3efb0f", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01_logical-f19a63d.stdout b/tests/reference/llvm-arrays_01_logical-f19a63d.stdout index 6f8e5b49778..d8bace63a9b 100644 --- a/tests/reference/llvm-arrays_01_logical-f19a63d.stdout +++ b/tests/reference/llvm-arrays_01_logical-f19a63d.stdout @@ -3,86 +3,164 @@ source_filename = "LFortran" %string_descriptor = type <{ i8*, i64 }> +@0 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@1 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@2 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@3 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@5 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@6 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@7 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data = private constant [11 x i8] c"ERROR STOP\00" @string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data, i32 0, i32 0), i64 10 }> @string_const_data.1 = private constant [2 x i8] c"\0A\00" @string_const.2 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.1, i32 0, i32 0), i64 1 }> -@0 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@8 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@9 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@10 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.3 = private constant [11 x i8] c"ERROR STOP\00" @string_const.4 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.3, i32 0, i32 0), i64 10 }> @string_const_data.5 = private constant [2 x i8] c"\0A\00" @string_const.6 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.5, i32 0, i32 0), i64 1 }> -@1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@11 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@12 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@13 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.7 = private constant [11 x i8] c"ERROR STOP\00" @string_const.8 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.7, i32 0, i32 0), i64 10 }> @string_const_data.9 = private constant [2 x i8] c"\0A\00" @string_const.10 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.9, i32 0, i32 0), i64 1 }> -@2 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@14 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@15 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@16 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@17 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@18 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@19 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@20 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@21 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@22 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.11 = private constant [11 x i8] c"ERROR STOP\00" @string_const.12 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.11, i32 0, i32 0), i64 10 }> @string_const_data.13 = private constant [2 x i8] c"\0A\00" @string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.13, i32 0, i32 0), i64 1 }> -@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@23 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@24 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@25 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.15 = private constant [11 x i8] c"ERROR STOP\00" @string_const.16 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.15, i32 0, i32 0), i64 10 }> @string_const_data.17 = private constant [2 x i8] c"\0A\00" @string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.17, i32 0, i32 0), i64 1 }> -@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@26 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@27 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@28 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.19 = private constant [11 x i8] c"ERROR STOP\00" @string_const.20 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.19, i32 0, i32 0), i64 10 }> @string_const_data.21 = private constant [2 x i8] c"\0A\00" @string_const.22 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.21, i32 0, i32 0), i64 1 }> -@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@29 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@30 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@31 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.23 = private constant [11 x i8] c"ERROR STOP\00" @string_const.24 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.23, i32 0, i32 0), i64 10 }> @string_const_data.25 = private constant [2 x i8] c"\0A\00" @string_const.26 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.25, i32 0, i32 0), i64 1 }> -@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@32 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@33 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@34 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@35 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@36 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@37 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@38 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.27 = private constant [11 x i8] c"ERROR STOP\00" @string_const.28 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.27, i32 0, i32 0), i64 10 }> @string_const_data.29 = private constant [2 x i8] c"\0A\00" @string_const.30 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.29, i32 0, i32 0), i64 1 }> -@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@39 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@40 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@41 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.31 = private constant [11 x i8] c"ERROR STOP\00" @string_const.32 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.31, i32 0, i32 0), i64 10 }> @string_const_data.33 = private constant [2 x i8] c"\0A\00" @string_const.34 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.33, i32 0, i32 0), i64 1 }> -@8 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@42 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@43 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@44 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.35 = private constant [11 x i8] c"ERROR STOP\00" @string_const.36 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.35, i32 0, i32 0), i64 10 }> @string_const_data.37 = private constant [2 x i8] c"\0A\00" @string_const.38 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.37, i32 0, i32 0), i64 1 }> -@9 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@45 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@46 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@47 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@48 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@49 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@50 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@51 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@52 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@53 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@54 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@55 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@56 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@57 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.39 = private constant [11 x i8] c"ERROR STOP\00" @string_const.40 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.39, i32 0, i32 0), i64 10 }> @string_const_data.41 = private constant [2 x i8] c"\0A\00" @string_const.42 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.41, i32 0, i32 0), i64 1 }> -@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@58 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@59 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@60 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@61 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@62 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@63 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@64 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.43 = private constant [11 x i8] c"ERROR STOP\00" @string_const.44 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.43, i32 0, i32 0), i64 10 }> @string_const_data.45 = private constant [2 x i8] c"\0A\00" @string_const.46 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.45, i32 0, i32 0), i64 1 }> -@11 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@65 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@66 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@67 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@68 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@69 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@70 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@71 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@72 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@73 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@74 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@75 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@76 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@77 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.47 = private constant [11 x i8] c"ERROR STOP\00" @string_const.48 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.47, i32 0, i32 0), i64 10 }> @string_const_data.49 = private constant [2 x i8] c"\0A\00" @string_const.50 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.49, i32 0, i32 0), i64 1 }> -@12 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@78 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@79 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@80 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@81 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@82 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.51 = private constant [11 x i8] c"ERROR STOP\00" @string_const.52 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.51, i32 0, i32 0), i64 10 }> @string_const_data.53 = private constant [2 x i8] c"\0A\00" @string_const.54 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.53, i32 0, i32 0), i64 1 }> -@13 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@83 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@84 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@85 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@86 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@87 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.55 = private constant [11 x i8] c"ERROR STOP\00" @string_const.56 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.55, i32 0, i32 0), i64 10 }> @string_const_data.57 = private constant [2 x i8] c"\0A\00" @string_const.58 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.57, i32 0, i32 0), i64 1 }> -@14 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@88 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@89 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@90 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@91 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@92 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.59 = private constant [11 x i8] c"ERROR STOP\00" @string_const.60 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.59, i32 0, i32 0), i64 10 }> @string_const_data.61 = private constant [2 x i8] c"\0A\00" @string_const.62 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.61, i32 0, i32 0), i64 1 }> -@15 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@93 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -129,31 +207,8 @@ loop.body: ; preds = %loop.head %14 = or i1 %12, %13 br i1 %14, label %then3, label %else4 -loop.end: ; preds = %loop.head - %21 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 - %22 = load i1, i1* %21, align 1 - %23 = xor i1 %22, true - br i1 %23, label %then, label %else - -then: ; preds = %loop.end - %24 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 - %25 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8* %24, i8* %25) - call void @exit(i32 1) - br label %ifcont - -else: ; preds = %loop.end - br label %ifcont - -ifcont: ; preds = %else, %then - %26 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 1 - %27 = load i1, i1* %26, align 1 - br i1 %27, label %then3, label %else4 - -then3: ; preds = %ifcont - %28 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 - %29 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %28, i8* %29) +then3: ; preds = %loop.body + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 %8, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont5 @@ -161,15 +216,19 @@ else4: ; preds = %loop.body br label %ifcont5 ifcont5: ; preds = %else4, %then3 - %30 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 2 - %31 = load i1, i1* %30, align 1 - %32 = xor i1 %31, true - br i1 %32, label %then6, label %else7 + %15 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %11 + %16 = load i32, i32* %i1, align 4 + %17 = sub i32 %16, 1 + %18 = sub i32 %17, 1 + %19 = mul i32 1, %18 + %20 = add i32 0, %19 + %21 = icmp slt i32 %17, 1 + %22 = icmp sgt i32 %17, 3 + %23 = or i1 %21, %22 + br i1 %23, label %then6, label %else7 then6: ; preds = %ifcont5 - %33 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 - %34 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i8* %33, i8* %34) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0), i32 %17, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont8 @@ -177,48 +236,33 @@ else7: ; preds = %ifcont5 br label %ifcont8 ifcont8: ; preds = %else7, %then6 - %35 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 - store i1 false, i1* %35, align 1 - store i32 11, i32* %i1, align 4 - br label %loop.head9 - -loop.head9: ; preds = %loop.body10, %ifcont8 - %36 = load i32, i32* %i1, align 4 - %37 = add i32 %36, 1 - %38 = icmp sle i32 %37, 14 - br i1 %38, label %loop.body10, label %loop.end11 - -loop.body10: ; preds = %loop.head9 - %39 = load i32, i32* %i1, align 4 - %40 = add i32 %39, 1 - store i32 %40, i32* %i1, align 4 - %41 = load i32, i32* %i1, align 4 - %42 = sub i32 %41, 10 - %43 = sub i32 %42, 1 - %44 = mul i32 1, %43 - %45 = add i32 0, %44 - %46 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %45 - %47 = load i32, i32* %i1, align 4 - %48 = sub i32 %47, 10 - %49 = sub i32 %48, 1 - %50 = sub i32 %49, 1 - %51 = mul i32 1, %50 - %52 = add i32 0, %51 - %53 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %52 - %54 = load i1, i1* %53, align 1 - %55 = xor i1 %54, true - store i1 %55, i1* %46, align 1 - br label %loop.head9 - -loop.end11: ; preds = %loop.head9 - %56 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 - %57 = load i1, i1* %56, align 1 - br i1 %57, label %then12, label %else13 - -then12: ; preds = %loop.end11 - %58 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 - %59 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %58, i8* %59) + %24 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %20 + %25 = load i1, i1* %24, align 1 + %26 = xor i1 %25, true + store i1 %26, i1* %15, align 1 + br label %loop.head + +loop.end: ; preds = %loop.head + br i1 false, label %then9, label %else10 + +then9: ; preds = %loop.end + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @6, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont11 + +else10: ; preds = %loop.end + br label %ifcont11 + +ifcont11: ; preds = %else10, %then9 + %27 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 + %28 = load i1, i1* %27, align 1 + %29 = xor i1 %28, true + br i1 %29, label %then12, label %else13 + +then12: ; preds = %ifcont11 + %30 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 + %31 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %30, i8* %31) call void @exit(i32 1) br label %ifcont14 @@ -226,15 +270,10 @@ else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 - %60 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 - %61 = load i1, i1* %60, align 1 - %62 = xor i1 %61, true - br i1 %62, label %then15, label %else16 + br i1 false, label %then15, label %else16 then15: ; preds = %ifcont14 - %63 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 - %64 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %63, i8* %64) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @10, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @9, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont17 @@ -242,14 +281,14 @@ else16: ; preds = %ifcont14 br label %ifcont17 ifcont17: ; preds = %else16, %then15 - %65 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 - %66 = load i1, i1* %65, align 1 - br i1 %66, label %then18, label %else19 + %32 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 1 + %33 = load i1, i1* %32, align 1 + br i1 %33, label %then18, label %else19 then18: ; preds = %ifcont17 - %67 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 - %68 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %67, i8* %68) + %34 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 + %35 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %34, i8* %35) call void @exit(i32 1) br label %ifcont20 @@ -257,15 +296,10 @@ else19: ; preds = %ifcont17 br label %ifcont20 ifcont20: ; preds = %else19, %then18 - %69 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - %70 = load i1, i1* %69, align 1 - %71 = xor i1 %70, true - br i1 %71, label %then21, label %else22 + br i1 false, label %then21, label %else22 then21: ; preds = %ifcont20 - %72 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 - %73 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %72, i8* %73) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @13, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @12, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont23 @@ -273,46 +307,26 @@ else22: ; preds = %ifcont20 br label %ifcont23 ifcont23: ; preds = %else22, %then21 - %32 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 2 - %33 = load i1, i1* %32, align 1 - %34 = xor i1 %33, true - br i1 %34, label %then24, label %else25 - -loop.head24: ; preds = %loop.body25, %ifcont23 - %74 = load i32, i32* %i1, align 4 - %75 = add i32 %74, 1 - %76 = icmp sle i32 %75, 3 - br i1 %76, label %loop.body25, label %loop.end26 - -loop.body25: ; preds = %loop.head24 - %77 = load i32, i32* %i1, align 4 - %78 = add i32 %77, 1 - store i32 %78, i32* %i1, align 4 - %79 = load i32, i32* %i1, align 4 - %80 = sub i32 %79, 1 - %81 = mul i32 1, %80 - %82 = add i32 0, %81 - %83 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %82 - %84 = load i32, i32* %i1, align 4 - %85 = sub i32 %84, 1 - %86 = mul i32 1, %85 - %87 = add i32 0, %86 - %88 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %87 - %89 = load i1, i1* %88, align 1 - %90 = icmp eq i1 %89, false - %91 = select i1 %90, i1 %89, i1 false - store i1 %91, i1* %83, align 1 - br label %loop.head24 - -loop.end26: ; preds = %loop.head24 - %92 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 - %93 = load i1, i1* %92, align 1 - br i1 %93, label %then27, label %else28 - -then27: ; preds = %loop.end26 - %94 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 - %95 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %94, i8* %95) + %36 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 2 + %37 = load i1, i1* %36, align 1 + %38 = xor i1 %37, true + br i1 %38, label %then24, label %else25 + +then24: ; preds = %ifcont23 + %39 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 + %40 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %39, i8* %40) + call void @exit(i32 1) + br label %ifcont26 + +else25: ; preds = %ifcont23 + br label %ifcont26 + +ifcont26: ; preds = %else25, %then24 + br i1 false, label %then27, label %else28 + +then27: ; preds = %ifcont26 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont29 @@ -320,81 +334,72 @@ else28: ; preds = %ifcont26 br label %ifcont29 ifcont29: ; preds = %else28, %then27 - %96 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 - %97 = load i1, i1* %96, align 1 - br i1 %97, label %then30, label %else31 - -then30: ; preds = %ifcont29 - %98 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 - %99 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %98, i8* %99) + %41 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 + store i1 false, i1* %41, align 1 + store i32 11, i32* %i1, align 4 + br label %loop.head30 + +loop.head30: ; preds = %ifcont37, %ifcont29 + %42 = load i32, i32* %i1, align 4 + %43 = add i32 %42, 1 + %44 = icmp sle i32 %43, 14 + br i1 %44, label %loop.body31, label %loop.end38 + +loop.body31: ; preds = %loop.head30 + %45 = load i32, i32* %i1, align 4 + %46 = add i32 %45, 1 + store i32 %46, i32* %i1, align 4 + %47 = load i32, i32* %i1, align 4 + %48 = sub i32 %47, 10 + %49 = sub i32 %48, 1 + %50 = mul i32 1, %49 + %51 = add i32 0, %50 + %52 = icmp slt i32 %48, 1 + %53 = icmp sgt i32 %48, 4 + %54 = or i1 %52, %53 + br i1 %54, label %then32, label %else33 + +then32: ; preds = %loop.body31 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @18, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @17, i32 0, i32 0), i32 %48, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont34 else33: ; preds = %loop.body31 br label %ifcont34 -ifcont32: ; preds = %else31, %then30 - %100 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 - %101 = load i1, i1* %100, align 1 - br i1 %101, label %then33, label %else34 - -then33: ; preds = %ifcont32 - %102 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 - %103 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %102, i8* %103) +ifcont34: ; preds = %else33, %then32 + %55 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %51 + %56 = load i32, i32* %i1, align 4 + %57 = sub i32 %56, 10 + %58 = sub i32 %57, 1 + %59 = sub i32 %58, 1 + %60 = mul i32 1, %59 + %61 = add i32 0, %60 + %62 = icmp slt i32 %58, 1 + %63 = icmp sgt i32 %58, 4 + %64 = or i1 %62, %63 + br i1 %64, label %then35, label %else36 + +then35: ; preds = %ifcont34 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 %58, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont37 else36: ; preds = %ifcont34 br label %ifcont37 -ifcont35: ; preds = %else34, %then33 - %104 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - %105 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 - %106 = load i1, i1* %105, align 1 - %107 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 - %108 = load i1, i1* %107, align 1 - %109 = icmp eq i1 %106, false - %110 = select i1 %109, i1 %108, i1 %106 - %111 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 - %112 = load i1, i1* %111, align 1 - %113 = icmp eq i1 %110, false - %114 = select i1 %113, i1 %112, i1 %110 - %115 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 - %116 = load i1, i1* %115, align 1 - %117 = icmp eq i1 %114, false - %118 = select i1 %117, i1 %116, i1 %114 - store i1 %118, i1* %104, align 1 - %119 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - %120 = load i1, i1* %119, align 1 - %121 = xor i1 %120, true - br i1 %121, label %then36, label %else37 - -then36: ; preds = %ifcont35 - %122 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 - %123 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %122, i8* %123) - call void @exit(i32 1) - br label %ifcont38 +ifcont37: ; preds = %else36, %then35 + %65 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %61 + %66 = load i1, i1* %65, align 1 + %67 = xor i1 %66, true + store i1 %67, i1* %55, align 1 + br label %loop.head30 -else37: ; preds = %ifcont35 - br label %ifcont38 +loop.end38: ; preds = %loop.head30 + br i1 false, label %then39, label %else40 -ifcont38: ; preds = %else37, %then36 - %124 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - %125 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 - %126 = load i1, i1* %125, align 1 - store i1 %126, i1* %124, align 1 - %127 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - %128 = load i1, i1* %127, align 1 - %129 = xor i1 %128, true - br i1 %129, label %then39, label %else40 - -then39: ; preds = %ifcont38 - %130 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 - %131 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %130, i8* %131) +then39: ; preds = %loop.end38 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @22, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @21, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont41 @@ -402,88 +407,52 @@ else40: ; preds = %loop.end38 br label %ifcont41 ifcont41: ; preds = %else40, %then39 - %62 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 - %63 = load i1, i1* %62, align 1 - br i1 %63, label %then42, label %else43 - -loop.head42: ; preds = %loop.end49, %ifcont41 - %132 = load i32, i32* %i1, align 4 - %133 = add i32 %132, 1 - %134 = icmp sle i32 %133, 2 - br i1 %134, label %loop.body43, label %loop.end50 - -loop.body43: ; preds = %loop.head42 - %135 = load i32, i32* %i1, align 4 - %136 = add i32 %135, 1 - store i32 %136, i32* %i1, align 4 - store i32 0, i32* %j2, align 4 - br label %loop.head44 - -loop.head44: ; preds = %ifcont48, %loop.body43 - %137 = load i32, i32* %j2, align 4 - %138 = add i32 %137, 1 - %139 = icmp sle i32 %138, 2 - br i1 %139, label %loop.body45, label %loop.end49 - -loop.body45: ; preds = %loop.head44 - %140 = load i32, i32* %j2, align 4 - %141 = add i32 %140, 1 - store i32 %141, i32* %j2, align 4 - %142 = load i32, i32* %i1, align 4 - %143 = load i32, i32* %j2, align 4 - %144 = add i32 %142, %143 - %145 = load i32, i32* %i1, align 4 - %146 = load i32, i32* %j2, align 4 - %147 = add i32 %145, %146 - %148 = sdiv i32 %147, 2 - %149 = mul i32 2, %148 - %150 = sub i32 %144, %149 - %151 = icmp eq i32 %150, 1 - br i1 %151, label %then46, label %else47 - -then46: ; preds = %loop.body45 - %152 = load i32, i32* %i1, align 4 - %153 = load i32, i32* %j2, align 4 - %154 = sub i32 %152, 1 - %155 = mul i32 1, %154 - %156 = add i32 0, %155 - %157 = sub i32 %153, 1 - %158 = mul i32 2, %157 - %159 = add i32 %156, %158 - %160 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %159 - store i1 true, i1* %160, align 1 - br label %ifcont48 - -else47: ; preds = %loop.body45 - %161 = load i32, i32* %i1, align 4 - %162 = load i32, i32* %j2, align 4 - %163 = sub i32 %161, 1 - %164 = mul i32 1, %163 - %165 = add i32 0, %164 - %166 = sub i32 %162, 1 - %167 = mul i32 2, %166 - %168 = add i32 %165, %167 - %169 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %168 - store i1 false, i1* %169, align 1 - br label %ifcont48 + %68 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 + %69 = load i1, i1* %68, align 1 + br i1 %69, label %then42, label %else43 + +then42: ; preds = %ifcont41 + %70 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 + %71 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @23, i32 0, i32 0), i8* %70, i8* %71) + call void @exit(i32 1) + br label %ifcont44 + +else43: ; preds = %ifcont41 + br label %ifcont44 + +ifcont44: ; preds = %else43, %then42 + br i1 false, label %then45, label %else46 + +then45: ; preds = %ifcont44 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @25, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @24, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont47 + +else46: ; preds = %ifcont44 + br label %ifcont47 + +ifcont47: ; preds = %else46, %then45 + %72 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 + %73 = load i1, i1* %72, align 1 + %74 = xor i1 %73, true + br i1 %74, label %then48, label %else49 then48: ; preds = %ifcont47 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @34, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0)) + %75 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 + %76 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @26, i32 0, i32 0), i8* %75, i8* %76) call void @exit(i32 1) br label %ifcont50 else49: ; preds = %ifcont47 br label %ifcont50 -loop.end50: ; preds = %loop.head42 - %170 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 0 - %171 = load i1, i1* %170, align 1 - br i1 %171, label %then51, label %else52 +ifcont50: ; preds = %else49, %then48 + br i1 false, label %then51, label %else52 -then51: ; preds = %loop.end50 - %172 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 - %173 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i8* %172, i8* %173) +then51: ; preds = %ifcont50 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont53 @@ -491,15 +460,14 @@ else52: ; preds = %ifcont50 br label %ifcont53 ifcont53: ; preds = %else52, %then51 - %174 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 2 - %175 = load i1, i1* %174, align 1 - %176 = xor i1 %175, true - br i1 %176, label %then54, label %else55 + %77 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 + %78 = load i1, i1* %77, align 1 + br i1 %78, label %then54, label %else55 then54: ; preds = %ifcont53 - %177 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 - %178 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0), i8* %177, i8* %178) + %79 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 + %80 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @29, i32 0, i32 0), i8* %79, i8* %80) call void @exit(i32 1) br label %ifcont56 @@ -507,15 +475,10 @@ else55: ; preds = %ifcont53 br label %ifcont56 ifcont56: ; preds = %else55, %then54 - %179 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 1 - %180 = load i1, i1* %179, align 1 - %181 = xor i1 %180, true - br i1 %181, label %then57, label %else58 + br i1 false, label %then57, label %else58 then57: ; preds = %ifcont56 - %182 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 - %183 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %182, i8* %183) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @31, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @30, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont59 @@ -523,14 +486,15 @@ else58: ; preds = %ifcont56 br label %ifcont59 ifcont59: ; preds = %else58, %then57 - %184 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 3 - %185 = load i1, i1* %184, align 1 - br i1 %185, label %then60, label %else61 + %81 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + %82 = load i1, i1* %81, align 1 + %83 = xor i1 %82, true + br i1 %83, label %then60, label %else61 then60: ; preds = %ifcont59 - %186 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 - %187 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %186, i8* %187) + %84 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 + %85 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @32, i32 0, i32 0), i8* %84, i8* %85) call void @exit(i32 1) br label %ifcont62 @@ -542,26 +506,26 @@ ifcont62: ; preds = %else61, %then60 br label %loop.head63 loop.head63: ; preds = %ifcont70, %ifcont62 - %72 = load i32, i32* %i1, align 4 - %73 = add i32 %72, 1 - %74 = icmp sle i32 %73, 3 - br i1 %74, label %loop.body64, label %loop.end71 + %86 = load i32, i32* %i1, align 4 + %87 = add i32 %86, 1 + %88 = icmp sle i32 %87, 3 + br i1 %88, label %loop.body64, label %loop.end71 loop.body64: ; preds = %loop.head63 - %75 = load i32, i32* %i1, align 4 - %76 = add i32 %75, 1 - store i32 %76, i32* %i1, align 4 - %77 = load i32, i32* %i1, align 4 - %78 = sub i32 %77, 1 - %79 = mul i32 1, %78 - %80 = add i32 0, %79 - %81 = icmp slt i32 %77, 1 - %82 = icmp sgt i32 %77, 4 - %83 = or i1 %81, %82 - br i1 %83, label %then65, label %else66 + %89 = load i32, i32* %i1, align 4 + %90 = add i32 %89, 1 + store i32 %90, i32* %i1, align 4 + %91 = load i32, i32* %i1, align 4 + %92 = sub i32 %91, 1 + %93 = mul i32 1, %92 + %94 = add i32 0, %93 + %95 = icmp slt i32 %91, 1 + %96 = icmp sgt i32 %91, 4 + %97 = or i1 %95, %96 + br i1 %97, label %then65, label %else66 then65: ; preds = %loop.body64 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @48, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @47, i32 0, i32 0), i32 %77, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @34, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @33, i32 0, i32 0), i32 %91, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont67 @@ -569,18 +533,18 @@ else66: ; preds = %loop.body64 br label %ifcont67 ifcont67: ; preds = %else66, %then65 - %84 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %80 - %85 = load i32, i32* %i1, align 4 - %86 = sub i32 %85, 1 - %87 = mul i32 1, %86 - %88 = add i32 0, %87 - %89 = icmp slt i32 %85, 1 - %90 = icmp sgt i32 %85, 3 - %91 = or i1 %89, %90 - br i1 %91, label %then68, label %else69 + %98 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %94 + %99 = load i32, i32* %i1, align 4 + %100 = sub i32 %99, 1 + %101 = mul i32 1, %100 + %102 = add i32 0, %101 + %103 = icmp slt i32 %99, 1 + %104 = icmp sgt i32 %99, 3 + %105 = or i1 %103, %104 + br i1 %105, label %then68, label %else69 then68: ; preds = %ifcont67 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @50, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @49, i32 0, i32 0), i32 %85, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0), i32 %99, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont70 @@ -588,18 +552,18 @@ else69: ; preds = %ifcont67 br label %ifcont70 ifcont70: ; preds = %else69, %then68 - %92 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %88 - %93 = load i1, i1* %92, align 1 - %94 = icmp eq i1 %93, false - %95 = select i1 %94, i1 %93, i1 false - store i1 %95, i1* %84, align 1 + %106 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %102 + %107 = load i1, i1* %106, align 1 + %108 = icmp eq i1 %107, false + %109 = select i1 %108, i1 %107, i1 false + store i1 %109, i1* %98, align 1 br label %loop.head63 loop.end71: ; preds = %loop.head63 br i1 false, label %then72, label %else73 then72: ; preds = %loop.end71 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @38, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @37, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont74 @@ -607,12 +571,14 @@ else73: ; preds = %loop.end71 br label %ifcont74 ifcont74: ; preds = %else73, %then72 - %96 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 - %97 = load i1, i1* %96, align 1 - br i1 %97, label %then75, label %else76 + %110 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 + %111 = load i1, i1* %110, align 1 + br i1 %111, label %then75, label %else76 then75: ; preds = %ifcont74 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @53, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @54, i32 0, i32 0)) + %112 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 + %113 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @39, i32 0, i32 0), i8* %112, i8* %113) call void @exit(i32 1) br label %ifcont77 @@ -623,7 +589,7 @@ ifcont77: ; preds = %else76, %then75 br i1 false, label %then78, label %else79 then78: ; preds = %ifcont77 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont80 @@ -631,12 +597,14 @@ else79: ; preds = %ifcont77 br label %ifcont80 ifcont80: ; preds = %else79, %then78 - %98 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 - %99 = load i1, i1* %98, align 1 - br i1 %99, label %then81, label %else82 + %114 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 + %115 = load i1, i1* %114, align 1 + br i1 %115, label %then81, label %else82 then81: ; preds = %ifcont80 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @60, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @58, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @59, i32 0, i32 0)) + %116 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 + %117 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @42, i32 0, i32 0), i8* %116, i8* %117) call void @exit(i32 1) br label %ifcont83 @@ -647,7 +615,7 @@ ifcont83: ; preds = %else82, %then81 br i1 false, label %then84, label %else85 then84: ; preds = %ifcont83 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @62, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @61, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @44, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @43, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont86 @@ -655,12 +623,14 @@ else85: ; preds = %ifcont83 br label %ifcont86 ifcont86: ; preds = %else85, %then84 - %100 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 - %101 = load i1, i1* %100, align 1 - br i1 %101, label %then87, label %else88 + %118 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 + %119 = load i1, i1* %118, align 1 + br i1 %119, label %then87, label %else88 then87: ; preds = %ifcont86 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0)) + %120 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 + %121 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @45, i32 0, i32 0), i8* %120, i8* %121) call void @exit(i32 1) br label %ifcont89 @@ -671,7 +641,7 @@ ifcont89: ; preds = %else88, %then87 br i1 false, label %then90, label %else91 then90: ; preds = %ifcont89 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont92 @@ -679,11 +649,11 @@ else91: ; preds = %ifcont89 br label %ifcont92 ifcont92: ; preds = %else91, %then90 - %102 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + %122 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 br i1 false, label %then93, label %else94 then93: ; preds = %ifcont92 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont95 @@ -691,12 +661,12 @@ else94: ; preds = %ifcont92 br label %ifcont95 ifcont95: ; preds = %else94, %then93 - %103 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 - %104 = load i1, i1* %103, align 1 + %123 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 + %124 = load i1, i1* %123, align 1 br i1 false, label %then96, label %else97 then96: ; preds = %ifcont95 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @71, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @70, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @51, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @50, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont98 @@ -704,14 +674,14 @@ else97: ; preds = %ifcont95 br label %ifcont98 ifcont98: ; preds = %else97, %then96 - %105 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 - %106 = load i1, i1* %105, align 1 - %107 = icmp eq i1 %104, false - %108 = select i1 %107, i1 %106, i1 %104 + %125 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 + %126 = load i1, i1* %125, align 1 + %127 = icmp eq i1 %124, false + %128 = select i1 %127, i1 %126, i1 %124 br i1 false, label %then99, label %else100 then99: ; preds = %ifcont98 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @53, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @52, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont101 @@ -719,14 +689,14 @@ else100: ; preds = %ifcont98 br label %ifcont101 ifcont101: ; preds = %else100, %then99 - %109 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 - %110 = load i1, i1* %109, align 1 - %111 = icmp eq i1 %108, false - %112 = select i1 %111, i1 %110, i1 %108 + %129 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 + %130 = load i1, i1* %129, align 1 + %131 = icmp eq i1 %128, false + %132 = select i1 %131, i1 %130, i1 %128 br i1 false, label %then102, label %else103 then102: ; preds = %ifcont101 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @54, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont104 @@ -734,15 +704,15 @@ else103: ; preds = %ifcont101 br label %ifcont104 ifcont104: ; preds = %else103, %then102 - %113 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 - %114 = load i1, i1* %113, align 1 - %115 = icmp eq i1 %112, false - %116 = select i1 %115, i1 %114, i1 %112 - store i1 %116, i1* %102, align 1 + %133 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 + %134 = load i1, i1* %133, align 1 + %135 = icmp eq i1 %132, false + %136 = select i1 %135, i1 %134, i1 %132 + store i1 %136, i1* %122, align 1 br i1 false, label %then105, label %else106 then105: ; preds = %ifcont104 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @77, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @76, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont107 @@ -750,13 +720,15 @@ else106: ; preds = %ifcont104 br label %ifcont107 ifcont107: ; preds = %else106, %then105 - %117 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - %118 = load i1, i1* %117, align 1 - %119 = xor i1 %118, true - br i1 %119, label %then108, label %else109 + %137 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + %138 = load i1, i1* %137, align 1 + %139 = xor i1 %138, true + br i1 %139, label %then108, label %else109 then108: ; preds = %ifcont107 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0)) + %140 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 + %141 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @58, i32 0, i32 0), i8* %140, i8* %141) call void @exit(i32 1) br label %ifcont110 @@ -767,7 +739,7 @@ ifcont110: ; preds = %else109, %then108 br i1 false, label %then111, label %else112 then111: ; preds = %ifcont110 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @82, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @81, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @60, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @59, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont113 @@ -775,11 +747,11 @@ else112: ; preds = %ifcont110 br label %ifcont113 ifcont113: ; preds = %else112, %then111 - %120 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + %142 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 br i1 false, label %then114, label %else115 then114: ; preds = %ifcont113 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @84, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @83, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @62, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @61, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont116 @@ -787,13 +759,13 @@ else115: ; preds = %ifcont113 br label %ifcont116 ifcont116: ; preds = %else115, %then114 - %121 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 - %122 = load i1, i1* %121, align 1 - store i1 %122, i1* %120, align 1 + %143 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 + %144 = load i1, i1* %143, align 1 + store i1 %144, i1* %142, align 1 br i1 false, label %then117, label %else118 then117: ; preds = %ifcont116 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @86, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @85, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @64, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @63, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont119 @@ -801,13 +773,15 @@ else118: ; preds = %ifcont116 br label %ifcont119 ifcont119: ; preds = %else118, %then117 - %123 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - %124 = load i1, i1* %123, align 1 - %125 = xor i1 %124, true - br i1 %125, label %then120, label %else121 + %145 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 + %146 = load i1, i1* %145, align 1 + %147 = xor i1 %146, true + br i1 %147, label %then120, label %else121 then120: ; preds = %ifcont119 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @89, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @87, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @88, i32 0, i32 0)) + %148 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 + %149 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @65, i32 0, i32 0), i8* %148, i8* %149) call void @exit(i32 1) br label %ifcont122 @@ -819,53 +793,53 @@ ifcont122: ; preds = %else121, %then120 br label %loop.head123 loop.head123: ; preds = %loop.end142, %ifcont122 - %126 = load i32, i32* %i1, align 4 - %127 = add i32 %126, 1 - %128 = icmp sle i32 %127, 2 - br i1 %128, label %loop.body124, label %loop.end143 + %150 = load i32, i32* %i1, align 4 + %151 = add i32 %150, 1 + %152 = icmp sle i32 %151, 2 + br i1 %152, label %loop.body124, label %loop.end143 loop.body124: ; preds = %loop.head123 - %129 = load i32, i32* %i1, align 4 - %130 = add i32 %129, 1 - store i32 %130, i32* %i1, align 4 + %153 = load i32, i32* %i1, align 4 + %154 = add i32 %153, 1 + store i32 %154, i32* %i1, align 4 store i32 0, i32* %j2, align 4 br label %loop.head125 loop.head125: ; preds = %ifcont141, %loop.body124 - %131 = load i32, i32* %j2, align 4 - %132 = add i32 %131, 1 - %133 = icmp sle i32 %132, 2 - br i1 %133, label %loop.body126, label %loop.end142 + %155 = load i32, i32* %j2, align 4 + %156 = add i32 %155, 1 + %157 = icmp sle i32 %156, 2 + br i1 %157, label %loop.body126, label %loop.end142 loop.body126: ; preds = %loop.head125 - %134 = load i32, i32* %j2, align 4 - %135 = add i32 %134, 1 - store i32 %135, i32* %j2, align 4 - %136 = load i32, i32* %i1, align 4 - %137 = load i32, i32* %j2, align 4 - %138 = add i32 %136, %137 - %139 = load i32, i32* %i1, align 4 - %140 = load i32, i32* %j2, align 4 - %141 = add i32 %139, %140 - %142 = sdiv i32 %141, 2 - %143 = mul i32 2, %142 - %144 = sub i32 %138, %143 - %145 = icmp eq i32 %144, 1 - br i1 %145, label %then127, label %else134 + %158 = load i32, i32* %j2, align 4 + %159 = add i32 %158, 1 + store i32 %159, i32* %j2, align 4 + %160 = load i32, i32* %i1, align 4 + %161 = load i32, i32* %j2, align 4 + %162 = add i32 %160, %161 + %163 = load i32, i32* %i1, align 4 + %164 = load i32, i32* %j2, align 4 + %165 = add i32 %163, %164 + %166 = sdiv i32 %165, 2 + %167 = mul i32 2, %166 + %168 = sub i32 %162, %167 + %169 = icmp eq i32 %168, 1 + br i1 %169, label %then127, label %else134 then127: ; preds = %loop.body126 - %146 = load i32, i32* %i1, align 4 - %147 = load i32, i32* %j2, align 4 - %148 = sub i32 %146, 1 - %149 = mul i32 1, %148 - %150 = add i32 0, %149 - %151 = icmp slt i32 %146, 1 - %152 = icmp sgt i32 %146, 2 - %153 = or i1 %151, %152 - br i1 %153, label %then128, label %else129 + %170 = load i32, i32* %i1, align 4 + %171 = load i32, i32* %j2, align 4 + %172 = sub i32 %170, 1 + %173 = mul i32 1, %172 + %174 = add i32 0, %173 + %175 = icmp slt i32 %170, 1 + %176 = icmp sgt i32 %170, 2 + %177 = or i1 %175, %176 + br i1 %177, label %then128, label %else129 then128: ; preds = %then127 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @91, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @90, i32 0, i32 0), i32 %146, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 %170, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont130 @@ -873,16 +847,16 @@ else129: ; preds = %then127 br label %ifcont130 ifcont130: ; preds = %else129, %then128 - %154 = sub i32 %147, 1 - %155 = mul i32 2, %154 - %156 = add i32 %150, %155 - %157 = icmp slt i32 %147, 1 - %158 = icmp sgt i32 %147, 2 - %159 = or i1 %157, %158 - br i1 %159, label %then131, label %else132 + %178 = sub i32 %171, 1 + %179 = mul i32 2, %178 + %180 = add i32 %174, %179 + %181 = icmp slt i32 %171, 1 + %182 = icmp sgt i32 %171, 2 + %183 = or i1 %181, %182 + br i1 %183, label %then131, label %else132 then131: ; preds = %ifcont130 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @93, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @92, i32 0, i32 0), i32 %147, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 %171, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont133 @@ -890,23 +864,23 @@ else132: ; preds = %ifcont130 br label %ifcont133 ifcont133: ; preds = %else132, %then131 - %160 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %156 - store i1 true, i1* %160, align 1 + %184 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %180 + store i1 true, i1* %184, align 1 br label %ifcont141 else134: ; preds = %loop.body126 - %161 = load i32, i32* %i1, align 4 - %162 = load i32, i32* %j2, align 4 - %163 = sub i32 %161, 1 - %164 = mul i32 1, %163 - %165 = add i32 0, %164 - %166 = icmp slt i32 %161, 1 - %167 = icmp sgt i32 %161, 2 - %168 = or i1 %166, %167 - br i1 %168, label %then135, label %else136 + %185 = load i32, i32* %i1, align 4 + %186 = load i32, i32* %j2, align 4 + %187 = sub i32 %185, 1 + %188 = mul i32 1, %187 + %189 = add i32 0, %188 + %190 = icmp slt i32 %185, 1 + %191 = icmp sgt i32 %185, 2 + %192 = or i1 %190, %191 + br i1 %192, label %then135, label %else136 then135: ; preds = %else134 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @95, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @94, i32 0, i32 0), i32 %161, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @71, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @70, i32 0, i32 0), i32 %185, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont137 @@ -914,16 +888,16 @@ else136: ; preds = %else134 br label %ifcont137 ifcont137: ; preds = %else136, %then135 - %169 = sub i32 %162, 1 - %170 = mul i32 2, %169 - %171 = add i32 %165, %170 - %172 = icmp slt i32 %162, 1 - %173 = icmp sgt i32 %162, 2 - %174 = or i1 %172, %173 - br i1 %174, label %then138, label %else139 + %193 = sub i32 %186, 1 + %194 = mul i32 2, %193 + %195 = add i32 %189, %194 + %196 = icmp slt i32 %186, 1 + %197 = icmp sgt i32 %186, 2 + %198 = or i1 %196, %197 + br i1 %198, label %then138, label %else139 then138: ; preds = %ifcont137 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @97, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @96, i32 0, i32 0), i32 %162, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 %186, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont140 @@ -931,8 +905,8 @@ else139: ; preds = %ifcont137 br label %ifcont140 ifcont140: ; preds = %else139, %then138 - %175 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %171 - store i1 false, i1* %175, align 1 + %199 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %195 + store i1 false, i1* %199, align 1 br label %ifcont141 ifcont141: ; preds = %ifcont140, %ifcont133 @@ -945,7 +919,7 @@ loop.end143: ; preds = %loop.head123 br i1 false, label %then144, label %else145 then144: ; preds = %loop.end143 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @99, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @98, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont146 @@ -956,7 +930,7 @@ ifcont146: ; preds = %else145, %then144 br i1 false, label %then147, label %else148 then147: ; preds = %ifcont146 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @101, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @100, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @77, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @76, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont149 @@ -964,12 +938,14 @@ else148: ; preds = %ifcont146 br label %ifcont149 ifcont149: ; preds = %else148, %then147 - %176 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 0 - %177 = load i1, i1* %176, align 1 - br i1 %177, label %then150, label %else151 + %200 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 0 + %201 = load i1, i1* %200, align 1 + br i1 %201, label %then150, label %else151 then150: ; preds = %ifcont149 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @102, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @103, i32 0, i32 0)) + %202 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 + %203 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @78, i32 0, i32 0), i8* %202, i8* %203) call void @exit(i32 1) br label %ifcont152 @@ -980,7 +956,7 @@ ifcont152: ; preds = %else151, %then150 br i1 false, label %then153, label %else154 then153: ; preds = %ifcont152 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont155 @@ -991,7 +967,7 @@ ifcont155: ; preds = %else154, %then153 br i1 false, label %then156, label %else157 then156: ; preds = %ifcont155 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @82, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @81, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont158 @@ -999,13 +975,15 @@ else157: ; preds = %ifcont155 br label %ifcont158 ifcont158: ; preds = %else157, %then156 - %178 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 2 - %179 = load i1, i1* %178, align 1 - %180 = xor i1 %179, true - br i1 %180, label %then159, label %else160 + %204 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 2 + %205 = load i1, i1* %204, align 1 + %206 = xor i1 %205, true + br i1 %206, label %then159, label %else160 then159: ; preds = %ifcont158 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @109, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @110, i32 0, i32 0)) + %207 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 + %208 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @83, i32 0, i32 0), i8* %207, i8* %208) call void @exit(i32 1) br label %ifcont161 @@ -1016,7 +994,7 @@ ifcont161: ; preds = %else160, %then159 br i1 false, label %then162, label %else163 then162: ; preds = %ifcont161 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @113, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @85, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @84, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont164 @@ -1027,7 +1005,7 @@ ifcont164: ; preds = %else163, %then162 br i1 false, label %then165, label %else166 then165: ; preds = %ifcont164 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @115, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @114, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @87, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @86, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont167 @@ -1035,13 +1013,15 @@ else166: ; preds = %ifcont164 br label %ifcont167 ifcont167: ; preds = %else166, %then165 - %181 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 1 - %182 = load i1, i1* %181, align 1 - %183 = xor i1 %182, true - br i1 %183, label %then168, label %else169 + %209 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 1 + %210 = load i1, i1* %209, align 1 + %211 = xor i1 %210, true + br i1 %211, label %then168, label %else169 then168: ; preds = %ifcont167 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @118, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @116, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @117, i32 0, i32 0)) + %212 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 + %213 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @88, i32 0, i32 0), i8* %212, i8* %213) call void @exit(i32 1) br label %ifcont170 @@ -1052,7 +1032,7 @@ ifcont170: ; preds = %else169, %then168 br i1 false, label %then171, label %else172 then171: ; preds = %ifcont170 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @120, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @119, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @90, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @89, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont173 @@ -1063,7 +1043,7 @@ ifcont173: ; preds = %else172, %then171 br i1 false, label %then174, label %else175 then174: ; preds = %ifcont173 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @122, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @121, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @92, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @91, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont176 @@ -1071,12 +1051,14 @@ else175: ; preds = %ifcont173 br label %ifcont176 ifcont176: ; preds = %else175, %then174 - %184 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 3 - %185 = load i1, i1* %184, align 1 - br i1 %185, label %then177, label %else178 + %214 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 3 + %215 = load i1, i1* %214, align 1 + br i1 %215, label %then177, label %else178 then177: ; preds = %ifcont176 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @125, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @123, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @124, i32 0, i32 0)) + %216 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 + %217 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @93, i32 0, i32 0), i8* %216, i8* %217) call void @exit(i32 1) br label %ifcont179 diff --git a/tests/reference/llvm-arrays_01_real-6c5e850.json b/tests/reference/llvm-arrays_01_real-6c5e850.json index 560de827d6b..717239515b5 100644 --- a/tests/reference/llvm-arrays_01_real-6c5e850.json +++ b/tests/reference/llvm-arrays_01_real-6c5e850.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01_real-6c5e850.stdout", - "stdout_hash": "48edf18a0d5d0b28a65e76d73964d34687a78430d24603453fd8ca98", + "stdout_hash": "347a9f038653343d85246444f9aa200ed00f5415749c1583505d9721", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01_real-6c5e850.stdout b/tests/reference/llvm-arrays_01_real-6c5e850.stdout index 8ca179ba2a7..8277192e969 100644 --- a/tests/reference/llvm-arrays_01_real-6c5e850.stdout +++ b/tests/reference/llvm-arrays_01_real-6c5e850.stdout @@ -3,86 +3,152 @@ source_filename = "LFortran" %string_descriptor = type <{ i8*, i64 }> +@0 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@1 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@2 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@3 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data = private constant [11 x i8] c"ERROR STOP\00" @string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data, i32 0, i32 0), i64 10 }> @string_const_data.1 = private constant [2 x i8] c"\0A\00" @string_const.2 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.1, i32 0, i32 0), i64 1 }> -@0 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@5 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@6 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.3 = private constant [11 x i8] c"ERROR STOP\00" @string_const.4 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.3, i32 0, i32 0), i64 10 }> @string_const_data.5 = private constant [2 x i8] c"\0A\00" @string_const.6 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.5, i32 0, i32 0), i64 1 }> -@1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@8 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@9 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.7 = private constant [11 x i8] c"ERROR STOP\00" @string_const.8 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.7, i32 0, i32 0), i64 10 }> @string_const_data.9 = private constant [2 x i8] c"\0A\00" @string_const.10 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.9, i32 0, i32 0), i64 1 }> -@2 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@11 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@12 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@13 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@14 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.11 = private constant [11 x i8] c"ERROR STOP\00" @string_const.12 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.11, i32 0, i32 0), i64 10 }> @string_const_data.13 = private constant [2 x i8] c"\0A\00" @string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.13, i32 0, i32 0), i64 1 }> -@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@15 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@16 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@17 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.15 = private constant [11 x i8] c"ERROR STOP\00" @string_const.16 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.15, i32 0, i32 0), i64 10 }> @string_const_data.17 = private constant [2 x i8] c"\0A\00" @string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.17, i32 0, i32 0), i64 1 }> -@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@18 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@19 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@20 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.19 = private constant [11 x i8] c"ERROR STOP\00" @string_const.20 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.19, i32 0, i32 0), i64 10 }> @string_const_data.21 = private constant [2 x i8] c"\0A\00" @string_const.22 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.21, i32 0, i32 0), i64 1 }> -@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@21 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@22 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@23 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.23 = private constant [11 x i8] c"ERROR STOP\00" @string_const.24 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.23, i32 0, i32 0), i64 10 }> @string_const_data.25 = private constant [2 x i8] c"\0A\00" @string_const.26 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.25, i32 0, i32 0), i64 1 }> -@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@24 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@25 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@26 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@27 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@28 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@29 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@30 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.27 = private constant [11 x i8] c"ERROR STOP\00" @string_const.28 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.27, i32 0, i32 0), i64 10 }> @string_const_data.29 = private constant [2 x i8] c"\0A\00" @string_const.30 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.29, i32 0, i32 0), i64 1 }> -@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@31 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@32 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@33 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.31 = private constant [11 x i8] c"ERROR STOP\00" @string_const.32 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.31, i32 0, i32 0), i64 10 }> @string_const_data.33 = private constant [2 x i8] c"\0A\00" @string_const.34 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.33, i32 0, i32 0), i64 1 }> -@8 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@34 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@35 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@36 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.35 = private constant [11 x i8] c"ERROR STOP\00" @string_const.36 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.35, i32 0, i32 0), i64 10 }> @string_const_data.37 = private constant [2 x i8] c"\0A\00" @string_const.38 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.37, i32 0, i32 0), i64 1 }> -@9 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@37 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@38 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@39 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@40 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@41 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@42 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@43 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@44 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@45 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@46 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@47 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@48 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@49 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.39 = private constant [11 x i8] c"ERROR STOP\00" @string_const.40 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.39, i32 0, i32 0), i64 10 }> @string_const_data.41 = private constant [2 x i8] c"\0A\00" @string_const.42 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.41, i32 0, i32 0), i64 1 }> -@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@50 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@51 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@52 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@53 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@54 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@55 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@56 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.43 = private constant [11 x i8] c"ERROR STOP\00" @string_const.44 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.43, i32 0, i32 0), i64 10 }> @string_const_data.45 = private constant [2 x i8] c"\0A\00" @string_const.46 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.45, i32 0, i32 0), i64 1 }> -@11 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@57 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@58 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@59 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@60 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@61 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@62 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@63 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@64 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@65 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.47 = private constant [11 x i8] c"ERROR STOP\00" @string_const.48 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.47, i32 0, i32 0), i64 10 }> @string_const_data.49 = private constant [2 x i8] c"\0A\00" @string_const.50 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.49, i32 0, i32 0), i64 1 }> -@12 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@66 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@67 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@68 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@69 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@70 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.51 = private constant [11 x i8] c"ERROR STOP\00" @string_const.52 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.51, i32 0, i32 0), i64 10 }> @string_const_data.53 = private constant [2 x i8] c"\0A\00" @string_const.54 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.53, i32 0, i32 0), i64 1 }> -@13 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@71 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@72 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@73 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@74 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@75 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.55 = private constant [11 x i8] c"ERROR STOP\00" @string_const.56 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.55, i32 0, i32 0), i64 10 }> @string_const_data.57 = private constant [2 x i8] c"\0A\00" @string_const.58 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.57, i32 0, i32 0), i64 1 }> -@14 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@76 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@77 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@78 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@79 = private unnamed_addr constant [2 x i8] c"c\00", align 1 +@80 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.59 = private constant [11 x i8] c"ERROR STOP\00" @string_const.60 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.59, i32 0, i32 0), i64 10 }> @string_const_data.61 = private constant [2 x i8] c"\0A\00" @string_const.62 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.61, i32 0, i32 0), i64 1 }> -@15 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@81 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -116,16 +182,8 @@ loop.body: ; preds = %loop.head %13 = or i1 %11, %12 br i1 %13, label %then, label %else -loop.end: ; preds = %loop.head - %15 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 - %16 = load double, double* %15, align 8 - %17 = fcmp une double %16, 1.100000e+01 - br i1 %17, label %then, label %else - -then: ; preds = %loop.end - %18 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 - %19 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8* %18, i8* %19) +then: ; preds = %loop.body + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 %7, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont @@ -133,15 +191,18 @@ else: ; preds = %loop.body br label %ifcont ifcont: ; preds = %else, %then - %20 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 1 - %21 = load double, double* %20, align 8 - %22 = fcmp une double %21, 1.200000e+01 - br i1 %22, label %then3, label %else4 + %14 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 %10 + %15 = load i32, i32* %i1, align 4 + %16 = add i32 %15, 10 + %17 = sitofp i32 %16 to double + store double %17, double* %14, align 8 + br label %loop.head -then3: ; preds = %ifcont - %23 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 - %24 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %23, i8* %24) +loop.end: ; preds = %loop.head + br i1 false, label %then3, label %else4 + +then3: ; preds = %loop.end + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont5 @@ -149,15 +210,15 @@ else4: ; preds = %loop.end br label %ifcont5 ifcont5: ; preds = %else4, %then3 - %25 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 2 - %26 = load double, double* %25, align 8 - %27 = fcmp une double %26, 1.300000e+01 - br i1 %27, label %then6, label %else7 + %18 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 + %19 = load double, double* %18, align 8 + %20 = fcmp une double %19, 1.100000e+01 + br i1 %20, label %then6, label %else7 then6: ; preds = %ifcont5 - %28 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 - %29 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i8* %28, i8* %29) + %21 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 + %22 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %21, i8* %22) call void @exit(i32 1) br label %ifcont8 @@ -167,37 +228,24 @@ else7: ; preds = %ifcont5 ifcont8: ; preds = %else7, %then6 br i1 false, label %then9, label %else10 -loop.head9: ; preds = %loop.body10, %ifcont8 - %30 = load i32, i32* %i1, align 4 - %31 = add i32 %30, 1 - %32 = icmp sle i32 %31, 14 - br i1 %32, label %loop.body10, label %loop.end11 +then9: ; preds = %ifcont8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @5, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont11 + +else10: ; preds = %ifcont8 + br label %ifcont11 -loop.body10: ; preds = %loop.head9 - %33 = load i32, i32* %i1, align 4 - %34 = add i32 %33, 1 - store i32 %34, i32* %i1, align 4 - %35 = load i32, i32* %i1, align 4 - %36 = sub i32 %35, 10 - %37 = sub i32 %36, 1 - %38 = mul i32 1, %37 - %39 = add i32 0, %38 - %40 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 %39 - %41 = load i32, i32* %i1, align 4 - %42 = sitofp i32 %41 to double - store double %42, double* %40, align 8 - br label %loop.head9 - -loop.end11: ; preds = %loop.head9 - %43 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 - %44 = load double, double* %43, align 8 - %45 = fcmp une double %44, 1.100000e+01 - br i1 %45, label %then12, label %else13 - -then12: ; preds = %loop.end11 - %46 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 - %47 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %46, i8* %47) +ifcont11: ; preds = %else10, %then9 + %23 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 1 + %24 = load double, double* %23, align 8 + %25 = fcmp une double %24, 1.200000e+01 + br i1 %25, label %then12, label %else13 + +then12: ; preds = %ifcont11 + %26 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 + %27 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %26, i8* %27) call void @exit(i32 1) br label %ifcont14 @@ -205,15 +253,10 @@ else13: ; preds = %ifcont11 br label %ifcont14 ifcont14: ; preds = %else13, %then12 - %48 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 - %49 = load double, double* %48, align 8 - %50 = fcmp une double %49, 1.200000e+01 - br i1 %50, label %then15, label %else16 + br i1 false, label %then15, label %else16 then15: ; preds = %ifcont14 - %51 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 - %52 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %51, i8* %52) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @9, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @8, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont17 @@ -221,15 +264,15 @@ else16: ; preds = %ifcont14 br label %ifcont17 ifcont17: ; preds = %else16, %then15 - %53 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 - %54 = load double, double* %53, align 8 - %55 = fcmp une double %54, 1.300000e+01 - br i1 %55, label %then18, label %else19 + %28 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 2 + %29 = load double, double* %28, align 8 + %30 = fcmp une double %29, 1.300000e+01 + br i1 %30, label %then18, label %else19 then18: ; preds = %ifcont17 - %56 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 - %57 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %56, i8* %57) + %31 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 + %32 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %31, i8* %32) call void @exit(i32 1) br label %ifcont20 @@ -237,15 +280,31 @@ else19: ; preds = %ifcont17 br label %ifcont20 ifcont20: ; preds = %else19, %then18 - %58 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - %59 = load double, double* %58, align 8 - %60 = fcmp une double %59, 1.400000e+01 - br i1 %60, label %then21, label %else22 + store i32 10, i32* %i1, align 4 + br label %loop.head21 -then21: ; preds = %ifcont20 - %61 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 - %62 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %61, i8* %62) +loop.head21: ; preds = %ifcont25, %ifcont20 + %33 = load i32, i32* %i1, align 4 + %34 = add i32 %33, 1 + %35 = icmp sle i32 %34, 14 + br i1 %35, label %loop.body22, label %loop.end26 + +loop.body22: ; preds = %loop.head21 + %36 = load i32, i32* %i1, align 4 + %37 = add i32 %36, 1 + store i32 %37, i32* %i1, align 4 + %38 = load i32, i32* %i1, align 4 + %39 = sub i32 %38, 10 + %40 = sub i32 %39, 1 + %41 = mul i32 1, %40 + %42 = add i32 0, %41 + %43 = icmp slt i32 %39, 1 + %44 = icmp sgt i32 %39, 4 + %45 = or i1 %43, %44 + br i1 %45, label %then23, label %else24 + +then23: ; preds = %loop.body22 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i32 %39, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont25 @@ -253,47 +312,17 @@ else24: ; preds = %loop.body22 br label %ifcont25 ifcont25: ; preds = %else24, %then23 - %40 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 %36 - %41 = load i32, i32* %i1, align 4 - %42 = sitofp i32 %41 to double - store double %42, double* %40, align 8 + %46 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 %42 + %47 = load i32, i32* %i1, align 4 + %48 = sitofp i32 %47 to double + store double %48, double* %46, align 8 br label %loop.head21 -loop.head24: ; preds = %loop.body25, %ifcont23 - %63 = load i32, i32* %i1, align 4 - %64 = add i32 %63, 1 - %65 = icmp sle i32 %64, 3 - br i1 %65, label %loop.body25, label %loop.end26 - -loop.body25: ; preds = %loop.head24 - %66 = load i32, i32* %i1, align 4 - %67 = add i32 %66, 1 - store i32 %67, i32* %i1, align 4 - %68 = load i32, i32* %i1, align 4 - %69 = sub i32 %68, 1 - %70 = mul i32 1, %69 - %71 = add i32 0, %70 - %72 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 %71 - %73 = load i32, i32* %i1, align 4 - %74 = sub i32 %73, 1 - %75 = mul i32 1, %74 - %76 = add i32 0, %75 - %77 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 %76 - %78 = load double, double* %77, align 8 - %79 = fsub double %78, 1.000000e+01 - store double %79, double* %72, align 8 - br label %loop.head24 - -loop.end26: ; preds = %loop.head24 - %80 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 - %81 = load double, double* %80, align 8 - %82 = fcmp une double %81, 1.000000e+00 - br i1 %82, label %then27, label %else28 +loop.end26: ; preds = %loop.head21 + br i1 false, label %then27, label %else28 then27: ; preds = %loop.end26 - %83 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 - %84 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %83, i8* %84) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont29 @@ -301,15 +330,15 @@ else28: ; preds = %loop.end26 br label %ifcont29 ifcont29: ; preds = %else28, %then27 - %85 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 - %86 = load double, double* %85, align 8 - %87 = fcmp une double %86, 2.000000e+00 - br i1 %87, label %then30, label %else31 + %49 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 + %50 = load double, double* %49, align 8 + %51 = fcmp une double %50, 1.100000e+01 + br i1 %51, label %then30, label %else31 then30: ; preds = %ifcont29 - %88 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 - %89 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %88, i8* %89) + %52 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 + %53 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %52, i8* %53) call void @exit(i32 1) br label %ifcont32 @@ -317,15 +346,10 @@ else31: ; preds = %ifcont29 br label %ifcont32 ifcont32: ; preds = %else31, %then30 - %90 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 - %91 = load double, double* %90, align 8 - %92 = fcmp une double %91, 3.000000e+00 - br i1 %92, label %then33, label %else34 + br i1 false, label %then33, label %else34 then33: ; preds = %ifcont32 - %93 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 - %94 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %93, i8* %94) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @16, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont35 @@ -333,28 +357,15 @@ else34: ; preds = %ifcont32 br label %ifcont35 ifcont35: ; preds = %else34, %then33 - %95 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - %96 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 - %97 = load double, double* %96, align 8 - %98 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 - %99 = load double, double* %98, align 8 - %100 = fadd double %97, %99 - %101 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 - %102 = load double, double* %101, align 8 - %103 = fadd double %100, %102 - %104 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 - %105 = load double, double* %104, align 8 - %106 = fadd double %103, %105 - store double %106, double* %95, align 8 - %107 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - %108 = load double, double* %107, align 8 - %109 = fcmp une double %108, 1.700000e+01 - br i1 %109, label %then36, label %else37 + %54 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 + %55 = load double, double* %54, align 8 + %56 = fcmp une double %55, 1.200000e+01 + br i1 %56, label %then36, label %else37 then36: ; preds = %ifcont35 - %110 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 - %111 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %110, i8* %111) + %57 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 + %58 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @18, i32 0, i32 0), i8* %57, i8* %58) call void @exit(i32 1) br label %ifcont38 @@ -362,19 +373,10 @@ else37: ; preds = %ifcont35 br label %ifcont38 ifcont38: ; preds = %else37, %then36 - %112 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - %113 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 - %114 = load double, double* %113, align 8 - store double %114, double* %112, align 8 - %115 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - %116 = load double, double* %115, align 8 - %117 = fcmp une double %116, 1.100000e+01 - br i1 %117, label %then39, label %else40 + br i1 false, label %then39, label %else40 then39: ; preds = %ifcont38 - %118 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 - %119 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %118, i8* %119) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont41 @@ -382,64 +384,42 @@ else40: ; preds = %ifcont38 br label %ifcont41 ifcont41: ; preds = %else40, %then39 - %49 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 - %50 = load double, double* %49, align 8 - %51 = fcmp une double %50, 1.300000e+01 - br i1 %51, label %then42, label %else43 - -loop.head42: ; preds = %loop.end46, %ifcont41 - %120 = load i32, i32* %i1, align 4 - %121 = add i32 %120, 1 - %122 = icmp sle i32 %121, 2 - br i1 %122, label %loop.body43, label %loop.end47 - -loop.body43: ; preds = %loop.head42 - %123 = load i32, i32* %i1, align 4 - %124 = add i32 %123, 1 - store i32 %124, i32* %i1, align 4 - store i32 0, i32* %j2, align 4 - br label %loop.head44 - -loop.head44: ; preds = %loop.body45, %loop.body43 - %125 = load i32, i32* %j2, align 4 - %126 = add i32 %125, 1 - %127 = icmp sle i32 %126, 2 - br i1 %127, label %loop.body45, label %loop.end46 - -loop.body45: ; preds = %loop.head44 - %128 = load i32, i32* %j2, align 4 - %129 = add i32 %128, 1 - store i32 %129, i32* %j2, align 4 - %130 = load i32, i32* %i1, align 4 - %131 = load i32, i32* %j2, align 4 - %132 = sub i32 %130, 1 - %133 = mul i32 1, %132 - %134 = add i32 0, %133 - %135 = sub i32 %131, 1 - %136 = mul i32 2, %135 - %137 = add i32 %134, %136 - %138 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 %137 - %139 = load i32, i32* %i1, align 4 - %140 = load i32, i32* %j2, align 4 - %141 = add i32 %139, %140 - %142 = add i32 %141, 10 - %143 = sitofp i32 %142 to double - store double %143, double* %138, align 8 - br label %loop.head44 + %59 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 + %60 = load double, double* %59, align 8 + %61 = fcmp une double %60, 1.300000e+01 + br i1 %61, label %then42, label %else43 + +then42: ; preds = %ifcont41 + %62 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 + %63 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @21, i32 0, i32 0), i8* %62, i8* %63) + call void @exit(i32 1) + br label %ifcont44 + +else43: ; preds = %ifcont41 + br label %ifcont44 + +ifcont44: ; preds = %else43, %then42 + br i1 false, label %then45, label %else46 + +then45: ; preds = %ifcont44 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @22, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont47 else46: ; preds = %ifcont44 br label %ifcont47 -loop.end47: ; preds = %loop.head42 - %144 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 0 - %145 = load double, double* %144, align 8 - %146 = fcmp une double %145, 1.200000e+01 - br i1 %146, label %then48, label %else49 +ifcont47: ; preds = %else46, %then45 + %64 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + %65 = load double, double* %64, align 8 + %66 = fcmp une double %65, 1.400000e+01 + br i1 %66, label %then48, label %else49 -then48: ; preds = %loop.end47 - %147 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 - %148 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i8* %147, i8* %148) +then48: ; preds = %ifcont47 + %67 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 + %68 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @24, i32 0, i32 0), i8* %67, i8* %68) call void @exit(i32 1) br label %ifcont50 @@ -447,47 +427,83 @@ else49: ; preds = %ifcont47 br label %ifcont50 ifcont50: ; preds = %else49, %then48 - %149 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 2 - %150 = load double, double* %149, align 8 - %151 = fcmp une double %150, 1.300000e+01 - br i1 %151, label %then51, label %else52 - -then51: ; preds = %ifcont50 - %152 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 - %153 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0), i8* %152, i8* %153) + store i32 0, i32* %i1, align 4 + br label %loop.head51 + +loop.head51: ; preds = %ifcont58, %ifcont50 + %69 = load i32, i32* %i1, align 4 + %70 = add i32 %69, 1 + %71 = icmp sle i32 %70, 3 + br i1 %71, label %loop.body52, label %loop.end59 + +loop.body52: ; preds = %loop.head51 + %72 = load i32, i32* %i1, align 4 + %73 = add i32 %72, 1 + store i32 %73, i32* %i1, align 4 + %74 = load i32, i32* %i1, align 4 + %75 = sub i32 %74, 1 + %76 = mul i32 1, %75 + %77 = add i32 0, %76 + %78 = icmp slt i32 %74, 1 + %79 = icmp sgt i32 %74, 4 + %80 = or i1 %78, %79 + br i1 %80, label %then53, label %else54 + +then53: ; preds = %loop.body52 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @26, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @25, i32 0, i32 0), i32 %74, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont55 else54: ; preds = %loop.body52 br label %ifcont55 -ifcont53: ; preds = %else52, %then51 - %154 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 1 - %155 = load double, double* %154, align 8 - %156 = fcmp une double %155, 1.300000e+01 - br i1 %156, label %then54, label %else55 +ifcont55: ; preds = %else54, %then53 + %81 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 %77 + %82 = load i32, i32* %i1, align 4 + %83 = sub i32 %82, 1 + %84 = mul i32 1, %83 + %85 = add i32 0, %84 + %86 = icmp slt i32 %82, 1 + %87 = icmp sgt i32 %82, 3 + %88 = or i1 %86, %87 + br i1 %88, label %then56, label %else57 -then54: ; preds = %ifcont53 - %157 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 - %158 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %157, i8* %158) +then56: ; preds = %ifcont55 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %82, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont58 else57: ; preds = %ifcont55 br label %ifcont58 -ifcont56: ; preds = %else55, %then54 - %159 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 3 - %160 = load double, double* %159, align 8 - %161 = fcmp une double %160, 1.400000e+01 - br i1 %161, label %then57, label %else58 +ifcont58: ; preds = %else57, %then56 + %89 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 %85 + %90 = load double, double* %89, align 8 + %91 = fsub double %90, 1.000000e+01 + store double %91, double* %81, align 8 + br label %loop.head51 -then57: ; preds = %ifcont56 - %162 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 - %163 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %162, i8* %163) +loop.end59: ; preds = %loop.head51 + br i1 false, label %then60, label %else61 + +then60: ; preds = %loop.end59 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void @exit(i32 1) + br label %ifcont62 + +else61: ; preds = %loop.end59 + br label %ifcont62 + +ifcont62: ; preds = %else61, %then60 + %92 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 + %93 = load double, double* %92, align 8 + %94 = fcmp une double %93, 1.000000e+00 + br i1 %94, label %then63, label %else64 + +then63: ; preds = %ifcont62 + %95 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 + %96 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @31, i32 0, i32 0), i8* %95, i8* %96) call void @exit(i32 1) br label %ifcont65 @@ -498,7 +514,7 @@ ifcont65: ; preds = %else64, %then63 br i1 false, label %then66, label %else67 then66: ; preds = %ifcont65 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont68 @@ -506,13 +522,15 @@ else67: ; preds = %ifcont65 br label %ifcont68 ifcont68: ; preds = %else67, %then66 - %81 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 - %82 = load double, double* %81, align 8 - %83 = fcmp une double %82, 2.000000e+00 - br i1 %83, label %then69, label %else70 + %97 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 + %98 = load double, double* %97, align 8 + %99 = fcmp une double %98, 2.000000e+00 + br i1 %99, label %then69, label %else70 then69: ; preds = %ifcont68 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @50, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0)) + %100 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 + %101 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @34, i32 0, i32 0), i8* %100, i8* %101) call void @exit(i32 1) br label %ifcont71 @@ -523,7 +541,7 @@ ifcont71: ; preds = %else70, %then69 br i1 false, label %then72, label %else73 then72: ; preds = %ifcont71 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont74 @@ -531,13 +549,15 @@ else73: ; preds = %ifcont71 br label %ifcont74 ifcont74: ; preds = %else73, %then72 - %84 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 - %85 = load double, double* %84, align 8 - %86 = fcmp une double %85, 3.000000e+00 - br i1 %86, label %then75, label %else76 + %102 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 + %103 = load double, double* %102, align 8 + %104 = fcmp une double %103, 3.000000e+00 + br i1 %104, label %then75, label %else76 then75: ; preds = %ifcont74 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0)) + %105 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 + %106 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @37, i32 0, i32 0), i8* %105, i8* %106) call void @exit(i32 1) br label %ifcont77 @@ -548,7 +568,7 @@ ifcont77: ; preds = %else76, %then75 br i1 false, label %then78, label %else79 then78: ; preds = %ifcont77 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @39, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @38, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont80 @@ -556,11 +576,11 @@ else79: ; preds = %ifcont77 br label %ifcont80 ifcont80: ; preds = %else79, %then78 - %87 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + %107 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 br i1 false, label %then81, label %else82 then81: ; preds = %ifcont80 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont83 @@ -568,12 +588,12 @@ else82: ; preds = %ifcont80 br label %ifcont83 ifcont83: ; preds = %else82, %then81 - %88 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 - %89 = load double, double* %88, align 8 + %108 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 + %109 = load double, double* %108, align 8 br i1 false, label %then84, label %else85 then84: ; preds = %ifcont83 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @43, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @42, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont86 @@ -581,13 +601,13 @@ else85: ; preds = %ifcont83 br label %ifcont86 ifcont86: ; preds = %else85, %then84 - %90 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 - %91 = load double, double* %90, align 8 - %92 = fadd double %89, %91 + %110 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 + %111 = load double, double* %110, align 8 + %112 = fadd double %109, %111 br i1 false, label %then87, label %else88 then87: ; preds = %ifcont86 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @44, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont89 @@ -595,13 +615,13 @@ else88: ; preds = %ifcont86 br label %ifcont89 ifcont89: ; preds = %else88, %then87 - %93 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 - %94 = load double, double* %93, align 8 - %95 = fadd double %92, %94 + %113 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 + %114 = load double, double* %113, align 8 + %115 = fadd double %112, %114 br i1 false, label %then90, label %else91 then90: ; preds = %ifcont89 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont92 @@ -609,14 +629,14 @@ else91: ; preds = %ifcont89 br label %ifcont92 ifcont92: ; preds = %else91, %then90 - %96 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 - %97 = load double, double* %96, align 8 - %98 = fadd double %95, %97 - store double %98, double* %87, align 8 + %116 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 + %117 = load double, double* %116, align 8 + %118 = fadd double %115, %117 + store double %118, double* %107, align 8 br i1 false, label %then93, label %else94 then93: ; preds = %ifcont92 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont95 @@ -624,13 +644,15 @@ else94: ; preds = %ifcont92 br label %ifcont95 ifcont95: ; preds = %else94, %then93 - %99 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - %100 = load double, double* %99, align 8 - %101 = fcmp une double %100, 1.700000e+01 - br i1 %101, label %then96, label %else97 + %119 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + %120 = load double, double* %119, align 8 + %121 = fcmp une double %120, 1.700000e+01 + br i1 %121, label %then96, label %else97 then96: ; preds = %ifcont95 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @72, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @71, i32 0, i32 0)) + %122 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 + %123 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @50, i32 0, i32 0), i8* %122, i8* %123) call void @exit(i32 1) br label %ifcont98 @@ -641,7 +663,7 @@ ifcont98: ; preds = %else97, %then96 br i1 false, label %then99, label %else100 then99: ; preds = %ifcont98 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @74, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @73, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont101 @@ -649,11 +671,11 @@ else100: ; preds = %ifcont98 br label %ifcont101 ifcont101: ; preds = %else100, %then99 - %102 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + %124 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 br i1 false, label %then102, label %else103 then102: ; preds = %ifcont101 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @76, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @75, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont104 @@ -661,13 +683,13 @@ else103: ; preds = %ifcont101 br label %ifcont104 ifcont104: ; preds = %else103, %then102 - %103 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 - %104 = load double, double* %103, align 8 - store double %104, double* %102, align 8 + %125 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 + %126 = load double, double* %125, align 8 + store double %126, double* %124, align 8 br i1 false, label %then105, label %else106 then105: ; preds = %ifcont104 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont107 @@ -675,13 +697,15 @@ else106: ; preds = %ifcont104 br label %ifcont107 ifcont107: ; preds = %else106, %then105 - %105 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - %106 = load double, double* %105, align 8 - %107 = fcmp une double %106, 1.100000e+01 - br i1 %107, label %then108, label %else109 + %127 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 + %128 = load double, double* %127, align 8 + %129 = fcmp une double %128, 1.100000e+01 + br i1 %129, label %then108, label %else109 then108: ; preds = %ifcont107 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @79, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @80, i32 0, i32 0)) + %130 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 + %131 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* %130, i8* %131) call void @exit(i32 1) br label %ifcont110 @@ -693,40 +717,40 @@ ifcont110: ; preds = %else109, %then108 br label %loop.head111 loop.head111: ; preds = %loop.end121, %ifcont110 - %108 = load i32, i32* %i1, align 4 - %109 = add i32 %108, 1 - %110 = icmp sle i32 %109, 2 - br i1 %110, label %loop.body112, label %loop.end122 + %132 = load i32, i32* %i1, align 4 + %133 = add i32 %132, 1 + %134 = icmp sle i32 %133, 2 + br i1 %134, label %loop.body112, label %loop.end122 loop.body112: ; preds = %loop.head111 - %111 = load i32, i32* %i1, align 4 - %112 = add i32 %111, 1 - store i32 %112, i32* %i1, align 4 + %135 = load i32, i32* %i1, align 4 + %136 = add i32 %135, 1 + store i32 %136, i32* %i1, align 4 store i32 0, i32* %j2, align 4 br label %loop.head113 loop.head113: ; preds = %ifcont120, %loop.body112 - %113 = load i32, i32* %j2, align 4 - %114 = add i32 %113, 1 - %115 = icmp sle i32 %114, 2 - br i1 %115, label %loop.body114, label %loop.end121 + %137 = load i32, i32* %j2, align 4 + %138 = add i32 %137, 1 + %139 = icmp sle i32 %138, 2 + br i1 %139, label %loop.body114, label %loop.end121 loop.body114: ; preds = %loop.head113 - %116 = load i32, i32* %j2, align 4 - %117 = add i32 %116, 1 - store i32 %117, i32* %j2, align 4 - %118 = load i32, i32* %i1, align 4 - %119 = load i32, i32* %j2, align 4 - %120 = sub i32 %118, 1 - %121 = mul i32 1, %120 - %122 = add i32 0, %121 - %123 = icmp slt i32 %118, 1 - %124 = icmp sgt i32 %118, 2 - %125 = or i1 %123, %124 - br i1 %125, label %then115, label %else116 + %140 = load i32, i32* %j2, align 4 + %141 = add i32 %140, 1 + store i32 %141, i32* %j2, align 4 + %142 = load i32, i32* %i1, align 4 + %143 = load i32, i32* %j2, align 4 + %144 = sub i32 %142, 1 + %145 = mul i32 1, %144 + %146 = add i32 0, %145 + %147 = icmp slt i32 %142, 1 + %148 = icmp sgt i32 %142, 2 + %149 = or i1 %147, %148 + br i1 %149, label %then115, label %else116 then115: ; preds = %loop.body114 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @83, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @82, i32 0, i32 0), i32 %118, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 %142, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont117 @@ -734,16 +758,16 @@ else116: ; preds = %loop.body114 br label %ifcont117 ifcont117: ; preds = %else116, %then115 - %126 = sub i32 %119, 1 - %127 = mul i32 2, %126 - %128 = add i32 %122, %127 - %129 = icmp slt i32 %119, 1 - %130 = icmp sgt i32 %119, 2 - %131 = or i1 %129, %130 - br i1 %131, label %then118, label %else119 + %150 = sub i32 %143, 1 + %151 = mul i32 2, %150 + %152 = add i32 %146, %151 + %153 = icmp slt i32 %143, 1 + %154 = icmp sgt i32 %143, 2 + %155 = or i1 %153, %154 + br i1 %155, label %then118, label %else119 then118: ; preds = %ifcont117 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @85, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @84, i32 0, i32 0), i32 %119, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 %143, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont120 @@ -751,13 +775,13 @@ else119: ; preds = %ifcont117 br label %ifcont120 ifcont120: ; preds = %else119, %then118 - %132 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 %128 - %133 = load i32, i32* %i1, align 4 - %134 = load i32, i32* %j2, align 4 - %135 = add i32 %133, %134 - %136 = add i32 %135, 10 - %137 = sitofp i32 %136 to double - store double %137, double* %132, align 8 + %156 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 %152 + %157 = load i32, i32* %i1, align 4 + %158 = load i32, i32* %j2, align 4 + %159 = add i32 %157, %158 + %160 = add i32 %159, 10 + %161 = sitofp i32 %160 to double + store double %161, double* %156, align 8 br label %loop.head113 loop.end121: ; preds = %loop.head113 @@ -767,7 +791,7 @@ loop.end122: ; preds = %loop.head111 br i1 false, label %then123, label %else124 then123: ; preds = %loop.end122 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @87, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @86, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont125 @@ -778,7 +802,7 @@ ifcont125: ; preds = %else124, %then123 br i1 false, label %then126, label %else127 then126: ; preds = %ifcont125 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @89, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @88, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont128 @@ -786,13 +810,15 @@ else127: ; preds = %ifcont125 br label %ifcont128 ifcont128: ; preds = %else127, %then126 - %138 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 0 - %139 = load double, double* %138, align 8 - %140 = fcmp une double %139, 1.200000e+01 - br i1 %140, label %then129, label %else130 + %162 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 0 + %163 = load double, double* %162, align 8 + %164 = fcmp une double %163, 1.200000e+01 + br i1 %164, label %then129, label %else130 then129: ; preds = %ifcont128 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @92, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @90, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @91, i32 0, i32 0)) + %165 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 + %166 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @66, i32 0, i32 0), i8* %165, i8* %166) call void @exit(i32 1) br label %ifcont131 @@ -803,7 +829,7 @@ ifcont131: ; preds = %else130, %then129 br i1 false, label %then132, label %else133 then132: ; preds = %ifcont131 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @94, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @93, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @68, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @67, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont134 @@ -814,7 +840,7 @@ ifcont134: ; preds = %else133, %then132 br i1 false, label %then135, label %else136 then135: ; preds = %ifcont134 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @96, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @95, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @69, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont137 @@ -822,13 +848,15 @@ else136: ; preds = %ifcont134 br label %ifcont137 ifcont137: ; preds = %else136, %then135 - %141 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 2 - %142 = load double, double* %141, align 8 - %143 = fcmp une double %142, 1.300000e+01 - br i1 %143, label %then138, label %else139 + %167 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 2 + %168 = load double, double* %167, align 8 + %169 = fcmp une double %168, 1.300000e+01 + br i1 %169, label %then138, label %else139 then138: ; preds = %ifcont137 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @99, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @97, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @98, i32 0, i32 0)) + %170 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 + %171 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @71, i32 0, i32 0), i8* %170, i8* %171) call void @exit(i32 1) br label %ifcont140 @@ -839,7 +867,7 @@ ifcont140: ; preds = %else139, %then138 br i1 false, label %then141, label %else142 then141: ; preds = %ifcont140 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @101, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @100, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont143 @@ -850,7 +878,7 @@ ifcont143: ; preds = %else142, %then141 br i1 false, label %then144, label %else145 then144: ; preds = %ifcont143 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @103, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @102, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont146 @@ -858,13 +886,15 @@ else145: ; preds = %ifcont143 br label %ifcont146 ifcont146: ; preds = %else145, %then144 - %144 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 1 - %145 = load double, double* %144, align 8 - %146 = fcmp une double %145, 1.300000e+01 - br i1 %146, label %then147, label %else148 + %172 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 1 + %173 = load double, double* %172, align 8 + %174 = fcmp une double %173, 1.300000e+01 + br i1 %174, label %then147, label %else148 then147: ; preds = %ifcont146 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0)) + %175 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 + %176 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @76, i32 0, i32 0), i8* %175, i8* %176) call void @exit(i32 1) br label %ifcont149 @@ -875,7 +905,7 @@ ifcont149: ; preds = %else148, %then147 br i1 false, label %then150, label %else151 then150: ; preds = %ifcont149 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) br label %ifcont152 @@ -886,7 +916,7 @@ ifcont152: ; preds = %else151, %then150 br i1 false, label %then153, label %else154 then153: ; preds = %ifcont152 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @110, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @109, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) br label %ifcont155 @@ -894,13 +924,15 @@ else154: ; preds = %ifcont152 br label %ifcont155 ifcont155: ; preds = %else154, %then153 - %147 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 3 - %148 = load double, double* %147, align 8 - %149 = fcmp une double %148, 1.400000e+01 - br i1 %149, label %then156, label %else157 + %177 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 3 + %178 = load double, double* %177, align 8 + %179 = fcmp une double %178, 1.400000e+01 + br i1 %179, label %then156, label %else157 then156: ; preds = %ifcont155 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @113, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @111, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @112, i32 0, i32 0)) + %180 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 + %181 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* %180, i8* %181) call void @exit(i32 1) br label %ifcont158 diff --git a/tests/reference/llvm-arrays_01_size-aaed99f.json b/tests/reference/llvm-arrays_01_size-aaed99f.json index 980bd93207f..be441300025 100644 --- a/tests/reference/llvm-arrays_01_size-aaed99f.json +++ b/tests/reference/llvm-arrays_01_size-aaed99f.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01_size-aaed99f.stdout", - "stdout_hash": "bf1826bc1e69a06e911dd1169026d16f041498da6a6f8719d1753619", + "stdout_hash": "9b611b0f4a1dddb3af0855b886eb4a0dea47cf1a087d84a4893e8401", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01_size-aaed99f.stdout b/tests/reference/llvm-arrays_01_size-aaed99f.stdout index 9c7f798268d..421d90909ca 100644 --- a/tests/reference/llvm-arrays_01_size-aaed99f.stdout +++ b/tests/reference/llvm-arrays_01_size-aaed99f.stdout @@ -13,66 +13,112 @@ source_filename = "LFortran" @string_const_data.5 = private constant [2 x i8] c"\0A\00" @string_const.6 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.5, i32 0, i32 0), i64 1 }> @1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@2 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@3 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@5 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.7 = private constant [11 x i8] c"ERROR STOP\00" @string_const.8 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.7, i32 0, i32 0), i64 10 }> @string_const_data.9 = private constant [2 x i8] c"\0A\00" @string_const.10 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.9, i32 0, i32 0), i64 1 }> -@2 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@7 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@8 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.11 = private constant [11 x i8] c"ERROR STOP\00" @string_const.12 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.11, i32 0, i32 0), i64 10 }> @string_const_data.13 = private constant [2 x i8] c"\0A\00" @string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.13, i32 0, i32 0), i64 1 }> -@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@9 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@10 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@11 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.15 = private constant [11 x i8] c"ERROR STOP\00" @string_const.16 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.15, i32 0, i32 0), i64 10 }> @string_const_data.17 = private constant [2 x i8] c"\0A\00" @string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.17, i32 0, i32 0), i64 1 }> -@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@12 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@13 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@14 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@15 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@16 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.19 = private constant [11 x i8] c"ERROR STOP\00" @string_const.20 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.19, i32 0, i32 0), i64 10 }> @string_const_data.21 = private constant [2 x i8] c"\0A\00" @string_const.22 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.21, i32 0, i32 0), i64 1 }> -@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@17 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@18 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@19 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.23 = private constant [11 x i8] c"ERROR STOP\00" @string_const.24 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.23, i32 0, i32 0), i64 10 }> @string_const_data.25 = private constant [2 x i8] c"\0A\00" @string_const.26 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.25, i32 0, i32 0), i64 1 }> -@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@20 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@21 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@22 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.27 = private constant [11 x i8] c"ERROR STOP\00" @string_const.28 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.27, i32 0, i32 0), i64 10 }> @string_const_data.29 = private constant [2 x i8] c"\0A\00" @string_const.30 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.29, i32 0, i32 0), i64 1 }> -@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@23 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@24 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@25 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.31 = private constant [11 x i8] c"ERROR STOP\00" @string_const.32 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.31, i32 0, i32 0), i64 10 }> @string_const_data.33 = private constant [2 x i8] c"\0A\00" @string_const.34 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.33, i32 0, i32 0), i64 1 }> -@8 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@26 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@27 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@28 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@29 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@30 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@31 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@32 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.35 = private constant [11 x i8] c"ERROR STOP\00" @string_const.36 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.35, i32 0, i32 0), i64 10 }> @string_const_data.37 = private constant [2 x i8] c"\0A\00" @string_const.38 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.37, i32 0, i32 0), i64 1 }> -@9 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@33 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@34 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@35 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.39 = private constant [11 x i8] c"ERROR STOP\00" @string_const.40 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.39, i32 0, i32 0), i64 10 }> @string_const_data.41 = private constant [2 x i8] c"\0A\00" @string_const.42 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.41, i32 0, i32 0), i64 1 }> -@10 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@36 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@37 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@38 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.43 = private constant [11 x i8] c"ERROR STOP\00" @string_const.44 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.43, i32 0, i32 0), i64 10 }> @string_const_data.45 = private constant [2 x i8] c"\0A\00" @string_const.46 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.45, i32 0, i32 0), i64 1 }> -@11 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@39 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@40 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@41 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@42 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@43 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@44 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@45 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@46 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@47 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@48 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@49 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@50 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@51 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.47 = private constant [11 x i8] c"ERROR STOP\00" @string_const.48 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.47, i32 0, i32 0), i64 10 }> @string_const_data.49 = private constant [2 x i8] c"\0A\00" @string_const.50 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.49, i32 0, i32 0), i64 1 }> -@12 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@52 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@53 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@54 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@55 = private unnamed_addr constant [2 x i8] c"a\00", align 1 +@56 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@57 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@58 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.51 = private constant [11 x i8] c"ERROR STOP\00" @string_const.52 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.51, i32 0, i32 0), i64 10 }> @string_const_data.53 = private constant [2 x i8] c"\0A\00" @string_const.54 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.53, i32 0, i32 0), i64 1 }> -@13 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@59 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -120,7 +166,7 @@ ifcont6: ; preds = %else5, %then4 store i32 0, i32* %i1, align 4 br label %loop.head -loop.head: ; preds = %loop.body, %ifcont6 +loop.head: ; preds = %ifcont9, %ifcont6 %10 = load i32, i32* %i1, align 4 %11 = add i32 %10, 1 %12 = load i32, i32* %size_a2, align 4 @@ -135,22 +181,13 @@ loop.body: ; preds = %loop.head %17 = sub i32 %16, 1 %18 = mul i32 1, %17 %19 = add i32 0, %18 - %20 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %19 - %21 = load i32, i32* %i1, align 4 - %22 = add i32 %21, 10 - store i32 %22, i32* %20, align 4 - br label %loop.head + %20 = icmp slt i32 %16, 1 + %21 = icmp sgt i32 %16, 3 + %22 = or i1 %20, %21 + br i1 %22, label %then7, label %else8 -loop.end: ; preds = %loop.head - %23 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %24 = load i32, i32* %23, align 4 - %25 = icmp ne i32 %24, 11 - br i1 %25, label %then7, label %else8 - -then7: ; preds = %loop.end - %26 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 - %27 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i8* %26, i8* %27) +then7: ; preds = %loop.body + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 %16, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont9 @@ -158,15 +195,17 @@ else8: ; preds = %loop.body br label %ifcont9 ifcont9: ; preds = %else8, %then7 - %28 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 1 - %29 = load i32, i32* %28, align 4 - %30 = icmp ne i32 %29, 12 - br i1 %30, label %then10, label %else11 + %23 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %19 + %24 = load i32, i32* %i1, align 4 + %25 = add i32 %24, 10 + store i32 %25, i32* %23, align 4 + br label %loop.head + +loop.end: ; preds = %loop.head + br i1 false, label %then10, label %else11 -then10: ; preds = %ifcont9 - %31 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 - %32 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %31, i8* %32) +then10: ; preds = %loop.end + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont12 @@ -174,15 +213,15 @@ else11: ; preds = %loop.end br label %ifcont12 ifcont12: ; preds = %else11, %then10 - %33 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 2 - %34 = load i32, i32* %33, align 4 - %35 = icmp ne i32 %34, 13 - br i1 %35, label %then13, label %else14 + %26 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %27 = load i32, i32* %26, align 4 + %28 = icmp ne i32 %27, 11 + br i1 %28, label %then13, label %else14 then13: ; preds = %ifcont12 - %36 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 - %37 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %36, i8* %37) + %29 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 + %30 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %29, i8* %30) call void @exit(i32 1) br label %ifcont15 @@ -192,38 +231,24 @@ else14: ; preds = %ifcont12 ifcont15: ; preds = %else14, %then13 br i1 false, label %then16, label %else17 -loop.head16: ; preds = %loop.body17, %ifcont15 - %38 = load i32, i32* %i1, align 4 - %39 = add i32 %38, 1 - %40 = load i32, i32* %size_b3, align 4 - %41 = add i32 10, %40 - %42 = icmp sle i32 %39, %41 - br i1 %42, label %loop.body17, label %loop.end18 - -loop.body17: ; preds = %loop.head16 - %43 = load i32, i32* %i1, align 4 - %44 = add i32 %43, 1 - store i32 %44, i32* %i1, align 4 - %45 = load i32, i32* %i1, align 4 - %46 = sub i32 %45, 10 - %47 = sub i32 %46, 1 - %48 = mul i32 1, %47 - %49 = add i32 0, %48 - %50 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %49 - %51 = load i32, i32* %i1, align 4 - store i32 %51, i32* %50, align 4 - br label %loop.head16 - -loop.end18: ; preds = %loop.head16 - %52 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %53 = load i32, i32* %52, align 4 - %54 = icmp ne i32 %53, 11 - br i1 %54, label %then19, label %else20 - -then19: ; preds = %loop.end18 - %55 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 - %56 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %55, i8* %56) +then16: ; preds = %ifcont15 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @8, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @7, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) + call void @exit(i32 1) + br label %ifcont18 + +else17: ; preds = %ifcont15 + br label %ifcont18 + +ifcont18: ; preds = %else17, %then16 + %31 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 1 + %32 = load i32, i32* %31, align 4 + %33 = icmp ne i32 %32, 12 + br i1 %33, label %then19, label %else20 + +then19: ; preds = %ifcont18 + %34 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 + %35 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %34, i8* %35) call void @exit(i32 1) br label %ifcont21 @@ -231,15 +256,10 @@ else20: ; preds = %ifcont18 br label %ifcont21 ifcont21: ; preds = %else20, %then19 - %57 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %58 = load i32, i32* %57, align 4 - %59 = icmp ne i32 %58, 12 - br i1 %59, label %then22, label %else23 + br i1 false, label %then22, label %else23 then22: ; preds = %ifcont21 - %60 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 - %61 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %60, i8* %61) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @11, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @10, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont24 @@ -247,15 +267,15 @@ else23: ; preds = %ifcont21 br label %ifcont24 ifcont24: ; preds = %else23, %then22 - %62 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %63 = load i32, i32* %62, align 4 - %64 = icmp ne i32 %63, 13 - br i1 %64, label %then25, label %else26 + %36 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 2 + %37 = load i32, i32* %36, align 4 + %38 = icmp ne i32 %37, 13 + br i1 %38, label %then25, label %else26 then25: ; preds = %ifcont24 - %65 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 - %66 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %65, i8* %66) + %39 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 + %40 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i8* %39, i8* %40) call void @exit(i32 1) br label %ifcont27 @@ -263,15 +283,33 @@ else26: ; preds = %ifcont24 br label %ifcont27 ifcont27: ; preds = %else26, %then25 - %67 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %68 = load i32, i32* %67, align 4 - %69 = icmp ne i32 %68, 14 - br i1 %69, label %then28, label %else29 + store i32 10, i32* %i1, align 4 + br label %loop.head28 -then28: ; preds = %ifcont27 - %70 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 - %71 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %70, i8* %71) +loop.head28: ; preds = %ifcont32, %ifcont27 + %41 = load i32, i32* %i1, align 4 + %42 = add i32 %41, 1 + %43 = load i32, i32* %size_b3, align 4 + %44 = add i32 10, %43 + %45 = icmp sle i32 %42, %44 + br i1 %45, label %loop.body29, label %loop.end33 + +loop.body29: ; preds = %loop.head28 + %46 = load i32, i32* %i1, align 4 + %47 = add i32 %46, 1 + store i32 %47, i32* %i1, align 4 + %48 = load i32, i32* %i1, align 4 + %49 = sub i32 %48, 10 + %50 = sub i32 %49, 1 + %51 = mul i32 1, %50 + %52 = add i32 0, %51 + %53 = icmp slt i32 %49, 1 + %54 = icmp sgt i32 %49, 4 + %55 = or i1 %53, %54 + br i1 %55, label %then30, label %else31 + +then30: ; preds = %loop.body29 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 %49, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont32 @@ -279,47 +317,16 @@ else31: ; preds = %loop.body29 br label %ifcont32 ifcont32: ; preds = %else31, %then30 - %46 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %42 - %47 = load i32, i32* %i1, align 4 - store i32 %47, i32* %46, align 4 + %56 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %52 + %57 = load i32, i32* %i1, align 4 + store i32 %57, i32* %56, align 4 br label %loop.head28 -loop.head31: ; preds = %loop.body32, %ifcont30 - %72 = load i32, i32* %i1, align 4 - %73 = add i32 %72, 1 - %74 = load i32, i32* %size_a2, align 4 - %75 = icmp sle i32 %73, %74 - br i1 %75, label %loop.body32, label %loop.end33 - -loop.body32: ; preds = %loop.head31 - %76 = load i32, i32* %i1, align 4 - %77 = add i32 %76, 1 - store i32 %77, i32* %i1, align 4 - %78 = load i32, i32* %i1, align 4 - %79 = sub i32 %78, 1 - %80 = mul i32 1, %79 - %81 = add i32 0, %80 - %82 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %81 - %83 = load i32, i32* %i1, align 4 - %84 = sub i32 %83, 1 - %85 = mul i32 1, %84 - %86 = add i32 0, %85 - %87 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %86 - %88 = load i32, i32* %87, align 4 - %89 = sub i32 %88, 10 - store i32 %89, i32* %82, align 4 - br label %loop.head31 - -loop.end33: ; preds = %loop.head31 - %90 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %91 = load i32, i32* %90, align 4 - %92 = icmp ne i32 %91, 1 - br i1 %92, label %then34, label %else35 +loop.end33: ; preds = %loop.head28 + br i1 false, label %then34, label %else35 then34: ; preds = %loop.end33 - %93 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 - %94 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %93, i8* %94) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont36 @@ -327,15 +334,15 @@ else35: ; preds = %loop.end33 br label %ifcont36 ifcont36: ; preds = %else35, %then34 - %95 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %96 = load i32, i32* %95, align 4 - %97 = icmp ne i32 %96, 2 - br i1 %97, label %then37, label %else38 + %58 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %59 = load i32, i32* %58, align 4 + %60 = icmp ne i32 %59, 11 + br i1 %60, label %then37, label %else38 then37: ; preds = %ifcont36 - %98 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 - %99 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %98, i8* %99) + %61 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 + %62 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @17, i32 0, i32 0), i8* %61, i8* %62) call void @exit(i32 1) br label %ifcont39 @@ -343,15 +350,10 @@ else38: ; preds = %ifcont36 br label %ifcont39 ifcont39: ; preds = %else38, %then37 - %100 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %101 = load i32, i32* %100, align 4 - %102 = icmp ne i32 %101, 3 - br i1 %102, label %then40, label %else41 + br i1 false, label %then40, label %else41 then40: ; preds = %ifcont39 - %103 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 - %104 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %103, i8* %104) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @19, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @18, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont42 @@ -359,28 +361,15 @@ else41: ; preds = %ifcont39 br label %ifcont42 ifcont42: ; preds = %else41, %then40 - %105 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %106 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %107 = load i32, i32* %106, align 4 - %108 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %109 = load i32, i32* %108, align 4 - %110 = add i32 %107, %109 - %111 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %112 = load i32, i32* %111, align 4 - %113 = add i32 %110, %112 - %114 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %115 = load i32, i32* %114, align 4 - %116 = add i32 %113, %115 - store i32 %116, i32* %105, align 4 - %117 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %118 = load i32, i32* %117, align 4 - %119 = icmp ne i32 %118, 17 - br i1 %119, label %then43, label %else44 + %63 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %64 = load i32, i32* %63, align 4 + %65 = icmp ne i32 %64, 12 + br i1 %65, label %then43, label %else44 then43: ; preds = %ifcont42 - %120 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 - %121 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i8* %120, i8* %121) + %66 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 + %67 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @20, i32 0, i32 0), i8* %66, i8* %67) call void @exit(i32 1) br label %ifcont45 @@ -388,19 +377,10 @@ else44: ; preds = %ifcont42 br label %ifcont45 ifcont45: ; preds = %else44, %then43 - %122 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %123 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %124 = load i32, i32* %123, align 4 - store i32 %124, i32* %122, align 4 - %125 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %126 = load i32, i32* %125, align 4 - %127 = icmp ne i32 %126, 11 - br i1 %127, label %then46, label %else47 + br i1 false, label %then46, label %else47 then46: ; preds = %ifcont45 - %128 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 - %129 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @13, i32 0, i32 0), i8* %128, i8* %129) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @22, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @21, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont48 @@ -408,13 +388,15 @@ else47: ; preds = %ifcont45 br label %ifcont48 ifcont48: ; preds = %else47, %then46 - %54 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %55 = load i32, i32* %54, align 4 - %56 = icmp ne i32 %55, 13 - br i1 %56, label %then49, label %else50 + %68 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %69 = load i32, i32* %68, align 4 + %70 = icmp ne i32 %69, 13 + br i1 %70, label %then49, label %else50 then49: ; preds = %ifcont48 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @39, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @37, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @38, i32 0, i32 0)) + %71 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 + %72 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @23, i32 0, i32 0), i8* %71, i8* %72) call void @exit(i32 1) br label %ifcont51 @@ -425,7 +407,7 @@ ifcont51: ; preds = %else50, %then49 br i1 false, label %then52, label %else53 then52: ; preds = %ifcont51 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @25, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @24, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont54 @@ -433,13 +415,15 @@ else53: ; preds = %ifcont51 br label %ifcont54 ifcont54: ; preds = %else53, %then52 - %57 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %58 = load i32, i32* %57, align 4 - %59 = icmp ne i32 %58, 14 - br i1 %59, label %then55, label %else56 + %73 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %74 = load i32, i32* %73, align 4 + %75 = icmp ne i32 %74, 14 + br i1 %75, label %then55, label %else56 then55: ; preds = %ifcont54 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @44, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @42, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @43, i32 0, i32 0)) + %76 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 + %77 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @26, i32 0, i32 0), i8* %76, i8* %77) call void @exit(i32 1) br label %ifcont57 @@ -451,27 +435,27 @@ ifcont57: ; preds = %else56, %then55 br label %loop.head58 loop.head58: ; preds = %ifcont65, %ifcont57 - %60 = load i32, i32* %i1, align 4 - %61 = add i32 %60, 1 - %62 = load i32, i32* %size_a2, align 4 - %63 = icmp sle i32 %61, %62 - br i1 %63, label %loop.body59, label %loop.end66 + %78 = load i32, i32* %i1, align 4 + %79 = add i32 %78, 1 + %80 = load i32, i32* %size_a2, align 4 + %81 = icmp sle i32 %79, %80 + br i1 %81, label %loop.body59, label %loop.end66 loop.body59: ; preds = %loop.head58 - %64 = load i32, i32* %i1, align 4 - %65 = add i32 %64, 1 - store i32 %65, i32* %i1, align 4 - %66 = load i32, i32* %i1, align 4 - %67 = sub i32 %66, 1 - %68 = mul i32 1, %67 - %69 = add i32 0, %68 - %70 = icmp slt i32 %66, 1 - %71 = icmp sgt i32 %66, 4 - %72 = or i1 %70, %71 - br i1 %72, label %then60, label %else61 + %82 = load i32, i32* %i1, align 4 + %83 = add i32 %82, 1 + store i32 %83, i32* %i1, align 4 + %84 = load i32, i32* %i1, align 4 + %85 = sub i32 %84, 1 + %86 = mul i32 1, %85 + %87 = add i32 0, %86 + %88 = icmp slt i32 %84, 1 + %89 = icmp sgt i32 %84, 4 + %90 = or i1 %88, %89 + br i1 %90, label %then60, label %else61 then60: ; preds = %loop.body59 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @46, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @45, i32 0, i32 0), i32 %66, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %84, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont62 @@ -479,18 +463,18 @@ else61: ; preds = %loop.body59 br label %ifcont62 ifcont62: ; preds = %else61, %then60 - %73 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %69 - %74 = load i32, i32* %i1, align 4 - %75 = sub i32 %74, 1 - %76 = mul i32 1, %75 - %77 = add i32 0, %76 - %78 = icmp slt i32 %74, 1 - %79 = icmp sgt i32 %74, 3 - %80 = or i1 %78, %79 - br i1 %80, label %then63, label %else64 + %91 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %87 + %92 = load i32, i32* %i1, align 4 + %93 = sub i32 %92, 1 + %94 = mul i32 1, %93 + %95 = add i32 0, %94 + %96 = icmp slt i32 %92, 1 + %97 = icmp sgt i32 %92, 3 + %98 = or i1 %96, %97 + br i1 %98, label %then63, label %else64 then63: ; preds = %ifcont62 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @48, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @47, i32 0, i32 0), i32 %74, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 %92, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont65 @@ -498,17 +482,17 @@ else64: ; preds = %ifcont62 br label %ifcont65 ifcont65: ; preds = %else64, %then63 - %81 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %77 - %82 = load i32, i32* %81, align 4 - %83 = sub i32 %82, 10 - store i32 %83, i32* %73, align 4 + %99 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %95 + %100 = load i32, i32* %99, align 4 + %101 = sub i32 %100, 10 + store i32 %101, i32* %91, align 4 br label %loop.head58 loop.end66: ; preds = %loop.head58 br i1 false, label %then67, label %else68 then67: ; preds = %loop.end66 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @50, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @49, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @32, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @31, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont69 @@ -516,13 +500,15 @@ else68: ; preds = %loop.end66 br label %ifcont69 ifcont69: ; preds = %else68, %then67 - %84 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %85 = load i32, i32* %84, align 4 - %86 = icmp ne i32 %85, 1 - br i1 %86, label %then70, label %else71 + %102 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %103 = load i32, i32* %102, align 4 + %104 = icmp ne i32 %103, 1 + br i1 %104, label %then70, label %else71 then70: ; preds = %ifcont69 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @53, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @51, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @52, i32 0, i32 0)) + %105 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 + %106 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @33, i32 0, i32 0), i8* %105, i8* %106) call void @exit(i32 1) br label %ifcont72 @@ -533,7 +519,7 @@ ifcont72: ; preds = %else71, %then70 br i1 false, label %then73, label %else74 then73: ; preds = %ifcont72 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @54, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @35, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @34, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont75 @@ -541,13 +527,15 @@ else74: ; preds = %ifcont72 br label %ifcont75 ifcont75: ; preds = %else74, %then73 - %87 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %88 = load i32, i32* %87, align 4 - %89 = icmp ne i32 %88, 2 - br i1 %89, label %then76, label %else77 + %107 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %108 = load i32, i32* %107, align 4 + %109 = icmp ne i32 %108, 2 + br i1 %109, label %then76, label %else77 then76: ; preds = %ifcont75 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @58, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @57, i32 0, i32 0)) + %110 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 + %111 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @36, i32 0, i32 0), i8* %110, i8* %111) call void @exit(i32 1) br label %ifcont78 @@ -558,7 +546,7 @@ ifcont78: ; preds = %else77, %then76 br i1 false, label %then79, label %else80 then79: ; preds = %ifcont78 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @60, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @59, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @38, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @37, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont81 @@ -566,13 +554,15 @@ else80: ; preds = %ifcont78 br label %ifcont81 ifcont81: ; preds = %else80, %then79 - %90 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %91 = load i32, i32* %90, align 4 - %92 = icmp ne i32 %91, 3 - br i1 %92, label %then82, label %else83 + %112 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %113 = load i32, i32* %112, align 4 + %114 = icmp ne i32 %113, 3 + br i1 %114, label %then82, label %else83 then82: ; preds = %ifcont81 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0)) + %115 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 + %116 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @39, i32 0, i32 0), i8* %115, i8* %116) call void @exit(i32 1) br label %ifcont84 @@ -583,7 +573,7 @@ ifcont84: ; preds = %else83, %then82 br i1 false, label %then85, label %else86 then85: ; preds = %ifcont84 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont87 @@ -591,11 +581,11 @@ else86: ; preds = %ifcont84 br label %ifcont87 ifcont87: ; preds = %else86, %then85 - %93 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %117 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 br i1 false, label %then88, label %else89 then88: ; preds = %ifcont87 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @43, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @42, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont90 @@ -603,12 +593,12 @@ else89: ; preds = %ifcont87 br label %ifcont90 ifcont90: ; preds = %else89, %then88 - %94 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 - %95 = load i32, i32* %94, align 4 + %118 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 + %119 = load i32, i32* %118, align 4 br i1 false, label %then91, label %else92 then91: ; preds = %ifcont90 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @44, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont93 @@ -616,13 +606,13 @@ else92: ; preds = %ifcont90 br label %ifcont93 ifcont93: ; preds = %else92, %then91 - %96 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 - %97 = load i32, i32* %96, align 4 - %98 = add i32 %95, %97 + %120 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 + %121 = load i32, i32* %120, align 4 + %122 = add i32 %119, %121 br i1 false, label %then94, label %else95 then94: ; preds = %ifcont93 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @71, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @70, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont96 @@ -630,13 +620,13 @@ else95: ; preds = %ifcont93 br label %ifcont96 ifcont96: ; preds = %else95, %then94 - %99 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 - %100 = load i32, i32* %99, align 4 - %101 = add i32 %98, %100 + %123 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 + %124 = load i32, i32* %123, align 4 + %125 = add i32 %122, %124 br i1 false, label %then97, label %else98 then97: ; preds = %ifcont96 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont99 @@ -644,14 +634,14 @@ else98: ; preds = %ifcont96 br label %ifcont99 ifcont99: ; preds = %else98, %then97 - %102 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %103 = load i32, i32* %102, align 4 - %104 = add i32 %101, %103 - store i32 %104, i32* %93, align 4 + %126 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %127 = load i32, i32* %126, align 4 + %128 = add i32 %125, %127 + store i32 %128, i32* %117, align 4 br i1 false, label %then100, label %else101 then100: ; preds = %ifcont99 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @51, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @50, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont102 @@ -659,13 +649,15 @@ else101: ; preds = %ifcont99 br label %ifcont102 ifcont102: ; preds = %else101, %then100 - %105 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %106 = load i32, i32* %105, align 4 - %107 = icmp ne i32 %106, 17 - br i1 %107, label %then103, label %else104 + %129 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %130 = load i32, i32* %129, align 4 + %131 = icmp ne i32 %130, 17 + br i1 %131, label %then103, label %else104 then103: ; preds = %ifcont102 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @76, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0)) + %132 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 + %133 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @52, i32 0, i32 0), i8* %132, i8* %133) call void @exit(i32 1) br label %ifcont105 @@ -676,7 +668,7 @@ ifcont105: ; preds = %else104, %then103 br i1 false, label %then106, label %else107 then106: ; preds = %ifcont105 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont108 @@ -684,11 +676,11 @@ else107: ; preds = %ifcont105 br label %ifcont108 ifcont108: ; preds = %else107, %then106 - %108 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %134 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 br i1 false, label %then109, label %else110 then109: ; preds = %ifcont108 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @82, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @81, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont111 @@ -696,13 +688,13 @@ else110: ; preds = %ifcont108 br label %ifcont111 ifcont111: ; preds = %else110, %then109 - %109 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 - %110 = load i32, i32* %109, align 4 - store i32 %110, i32* %108, align 4 + %135 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 + %136 = load i32, i32* %135, align 4 + store i32 %136, i32* %134, align 4 br i1 false, label %then112, label %else113 then112: ; preds = %ifcont111 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @84, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @83, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @58, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @57, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) br label %ifcont114 @@ -710,13 +702,15 @@ else113: ; preds = %ifcont111 br label %ifcont114 ifcont114: ; preds = %else113, %then112 - %111 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - %112 = load i32, i32* %111, align 4 - %113 = icmp ne i32 %112, 11 - br i1 %113, label %then115, label %else116 + %137 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 + %138 = load i32, i32* %137, align 4 + %139 = icmp ne i32 %138, 11 + br i1 %139, label %then115, label %else116 then115: ; preds = %ifcont114 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @87, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @85, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @86, i32 0, i32 0)) + %140 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 + %141 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @59, i32 0, i32 0), i8* %140, i8* %141) call void @exit(i32 1) br label %ifcont117 diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.json b/tests/reference/llvm-implicit_interface_04-9b6786e.json index 85c1e396621..5d17598fd43 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.json +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-implicit_interface_04-9b6786e.stdout", - "stdout_hash": "b513cba0a14ae1d3800810977f297f76d32b24832aed59539260752d", + "stdout_hash": "40978903c72afdb9aa82bcf257ef31594db8a83c1b3195a4596f1b3f", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout index 63824ac2acd..2db5d054bf2 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout @@ -7,40 +7,48 @@ source_filename = "LFortran" @0 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 @serialization_info = private unnamed_addr constant [3 x i8] c"R4\00", align 1 @1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@2 = private unnamed_addr constant [4 x i8] c"arr\00", align 1 +@3 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data = private constant [11 x i8] c"ERROR STOP\00" @string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data, i32 0, i32 0), i64 10 }> @string_const_data.1 = private constant [2 x i8] c"\0A\00" @string_const.2 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.1, i32 0, i32 0), i64 1 }> -@2 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 @string_const_data.3 = private constant [11 x i8] c"ERROR STOP\00" @string_const.4 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.3, i32 0, i32 0), i64 10 }> @string_const_data.5 = private constant [2 x i8] c"\0A\00" @string_const.6 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.5, i32 0, i32 0), i64 1 }> -@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@6 = private unnamed_addr constant [5 x i8] c"arr1\00", align 1 +@7 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.7 = private constant [11 x i8] c"ERROR STOP\00" @string_const.8 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.7, i32 0, i32 0), i64 10 }> @string_const_data.9 = private constant [2 x i8] c"\0A\00" @string_const.10 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.9, i32 0, i32 0), i64 1 }> -@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@8 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@9 = private unnamed_addr constant [5 x i8] c"arr1\00", align 1 +@10 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.11 = private constant [11 x i8] c"ERROR STOP\00" @string_const.12 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.11, i32 0, i32 0), i64 10 }> @string_const_data.13 = private constant [2 x i8] c"\0A\00" @string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.13, i32 0, i32 0), i64 1 }> -@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@11 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@12 = private unnamed_addr constant [5 x i8] c"arr1\00", align 1 +@13 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 @string_const_data.15 = private constant [11 x i8] c"ERROR STOP\00" @string_const.16 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.15, i32 0, i32 0), i64 10 }> @string_const_data.17 = private constant [2 x i8] c"\0A\00" @string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.17, i32 0, i32 0), i64 1 }> -@6 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@14 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 @main.b = internal global [3 x i32] zeroinitializer -@25 = private unnamed_addr constant [2 x i8] c"b\00", align 1 -@26 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 -@27 = private unnamed_addr constant [2 x i8] c"b\00", align 1 -@28 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 -@29 = private unnamed_addr constant [2 x i8] c"b\00", align 1 -@30 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 -@31 = private unnamed_addr constant [7 x i8] c"driver\00", align 1 -@32 = private unnamed_addr constant [143 x i8] c"Runtime error: Array shape mismatch in subroutine '%s'\0A\0ATried to match size %d of dimension %d of argument number %d, but expected size is %d\0A\00", align 1 +@15 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@16 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@17 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@18 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@19 = private unnamed_addr constant [2 x i8] c"b\00", align 1 +@20 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@21 = private unnamed_addr constant [7 x i8] c"driver\00", align 1 +@22 = private unnamed_addr constant [143 x i8] c"Runtime error: Array shape mismatch in subroutine '%s'\0A\0ATried to match size %d of dimension %d of argument number %d, but expected size is %d\0A\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: @@ -58,7 +66,7 @@ define i32 @main(i32 %0, i8** %1) { br i1 %8, label %then, label %else then: ; preds = %.entry - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @26, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @25, i32 0, i32 0), i32 %2, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 %2, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont @@ -79,7 +87,7 @@ ifcont: ; preds = %else, %then br i1 %16, label %then2, label %else3 then2: ; preds = %ifcont - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %10, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @18, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @17, i32 0, i32 0), i32 %10, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont4 @@ -100,7 +108,7 @@ ifcont4: ; preds = %else3, %then2 br i1 %24, label %then5, label %else6 then5: ; preds = %ifcont4 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 %18, i32 1, i32 1, i32 3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 %18, i32 1, i32 1, i32 3) call void @exit(i32 1) br label %ifcont7 @@ -115,7 +123,7 @@ ifcont7: ; preds = %else6, %then5 br i1 %27, label %then8, label %else9 then8: ; preds = %ifcont7 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @32, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @31, i32 0, i32 0), i32 3, i32 1, i32 2, i32 %26) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @22, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @21, i32 0, i32 0), i32 3, i32 1, i32 2, i32 %26) call void @exit(i32 1) br label %ifcont10 @@ -147,9 +155,24 @@ define void @driver(void (i32*, i32*, i32*)* %fnc, i32* %arr, i32* %m) { %7 = load i8*, i8** %6, align 8 call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0)) %8 = load i32, i32* %m, align 4 - %9 = mul i32 1, %8 - %10 = getelementptr inbounds i32, i32* %arr, i32 2 - call void %fnc(i32* %arr, i32* %m, i32* %10) + %9 = add i32 1, %8 + %10 = sub i32 %9, 1 + %11 = icmp sgt i32 3, %10 + %12 = or i1 false, %11 + br i1 %12, label %then, label %else + +then: ; preds = %.entry + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @2, i32 0, i32 0), i32 3, i32 1, i32 1, i32 %10) + call void @exit(i32 1) + br label %ifcont + +else: ; preds = %.entry + br label %ifcont + +ifcont: ; preds = %else, %then + %13 = mul i32 1, %8 + %14 = getelementptr inbounds i32, i32* %arr, i32 2 + call void %fnc(i32* %arr, i32* %m, i32* %14) br label %return return: ; preds = %ifcont @@ -167,7 +190,7 @@ define void @implicit_interface_check(i32* %arr1, i32* %m, i32* %c) { then: ; preds = %.entry %2 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 %3 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i8* %2, i8* %3) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %2, i8* %3) call void @exit(i32 1) br label %ifcont @@ -182,7 +205,7 @@ ifcont: ; preds = %else, %then then1: ; preds = %ifcont %6 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 %7 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %6, i8* %7) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %6, i8* %7) call void @exit(i32 1) br label %ifcont3 @@ -191,16 +214,14 @@ else2: ; preds = %ifcont ifcont3: ; preds = %else2, %then1 %8 = load i32, i32* %m, align 4 - %9 = mul i32 1, %8 - %10 = getelementptr inbounds i32, i32* %arr1, i32 0 - %11 = load i32, i32* %10, align 4 - %12 = icmp ne i32 %11, 10 + %9 = add i32 1, %8 + %10 = sub i32 %9, 1 + %11 = icmp sgt i32 1, %10 + %12 = or i1 false, %11 br i1 %12, label %then4, label %else5 then4: ; preds = %ifcont3 - %13 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 - %14 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %13, i8* %14) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @7, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i32 1, i32 1, i32 1, i32 %10) call void @exit(i32 1) br label %ifcont6 @@ -208,17 +229,16 @@ else5: ; preds = %ifcont3 br label %ifcont6 ifcont6: ; preds = %else5, %then4 - %15 = load i32, i32* %m, align 4 - %16 = mul i32 1, %15 - %17 = getelementptr inbounds i32, i32* %arr1, i32 1 - %18 = load i32, i32* %17, align 4 - %19 = icmp ne i32 %18, 20 - br i1 %19, label %then7, label %else8 + %13 = mul i32 1, %8 + %14 = getelementptr inbounds i32, i32* %arr1, i32 0 + %15 = load i32, i32* %14, align 4 + %16 = icmp ne i32 %15, 10 + br i1 %16, label %then7, label %else8 then7: ; preds = %ifcont6 - %20 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 - %21 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %20, i8* %21) + %17 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 + %18 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %17, i8* %18) call void @exit(i32 1) br label %ifcont9 @@ -226,17 +246,15 @@ else8: ; preds = %ifcont6 br label %ifcont9 ifcont9: ; preds = %else8, %then7 - %22 = load i32, i32* %m, align 4 - %23 = mul i32 1, %22 - %24 = getelementptr inbounds i32, i32* %arr1, i32 2 - %25 = load i32, i32* %24, align 4 - %26 = icmp ne i32 %25, 30 - br i1 %26, label %then10, label %else11 + %19 = load i32, i32* %m, align 4 + %20 = add i32 1, %19 + %21 = sub i32 %20, 1 + %22 = icmp sgt i32 2, %21 + %23 = or i1 false, %22 + br i1 %23, label %then10, label %else11 then10: ; preds = %ifcont9 - %27 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 - %28 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %27, i8* %28) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i32 2, i32 1, i32 1, i32 %21) call void @exit(i32 1) br label %ifcont12 @@ -244,14 +262,16 @@ else11: ; preds = %ifcont9 br label %ifcont12 ifcont12: ; preds = %else11, %then10 - %18 = mul i32 1, %13 - %19 = getelementptr inbounds i32, i32* %arr1, i32 1 - %20 = load i32, i32* %19, align 4 - %21 = icmp ne i32 %20, 20 - br i1 %21, label %then13, label %else14 + %24 = mul i32 1, %19 + %25 = getelementptr inbounds i32, i32* %arr1, i32 1 + %26 = load i32, i32* %25, align 4 + %27 = icmp ne i32 %26, 20 + br i1 %27, label %then13, label %else14 then13: ; preds = %ifcont12 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @19, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @18, i32 0, i32 0)) + %28 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 + %29 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %28, i8* %29) call void @exit(i32 1) br label %ifcont15 @@ -259,15 +279,15 @@ else14: ; preds = %ifcont12 br label %ifcont15 ifcont15: ; preds = %else14, %then13 - %22 = load i32, i32* %m, align 4 - %23 = add i32 1, %22 - %24 = sub i32 %23, 1 - %25 = icmp sgt i32 3, %24 - %26 = or i1 false, %25 - br i1 %26, label %then16, label %else17 + %30 = load i32, i32* %m, align 4 + %31 = add i32 1, %30 + %32 = sub i32 %31, 1 + %33 = icmp sgt i32 3, %32 + %34 = or i1 false, %33 + br i1 %34, label %then16, label %else17 then16: ; preds = %ifcont15 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @21, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @20, i32 0, i32 0), i32 3, i32 1, i32 1, i32 %24) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @13, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i32 3, i32 1, i32 1, i32 %32) call void @exit(i32 1) br label %ifcont18 @@ -275,14 +295,16 @@ else17: ; preds = %ifcont15 br label %ifcont18 ifcont18: ; preds = %else17, %then16 - %27 = mul i32 1, %22 - %28 = getelementptr inbounds i32, i32* %arr1, i32 2 - %29 = load i32, i32* %28, align 4 - %30 = icmp ne i32 %29, 30 - br i1 %30, label %then19, label %else20 + %35 = mul i32 1, %30 + %36 = getelementptr inbounds i32, i32* %arr1, i32 2 + %37 = load i32, i32* %36, align 4 + %38 = icmp ne i32 %37, 30 + br i1 %38, label %then19, label %else20 then19: ; preds = %ifcont18 - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @24, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @22, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @23, i32 0, i32 0)) + %39 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 + %40 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %39, i8* %40) call void @exit(i32 1) br label %ifcont21 diff --git a/tests/reference/llvm-modules_36-53c9a79.json b/tests/reference/llvm-modules_36-53c9a79.json index 0057642a349..3545d25cbd8 100644 --- a/tests/reference/llvm-modules_36-53c9a79.json +++ b/tests/reference/llvm-modules_36-53c9a79.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-modules_36-53c9a79.stdout", - "stdout_hash": "df56e114ae3351baf755da0b09a1b98d00551e933033fe0312323ed9", + "stdout_hash": "ed7d419157bdc3660d495db9457633eb70ef577ee53d495cf992c014", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-modules_36-53c9a79.stdout b/tests/reference/llvm-modules_36-53c9a79.stdout index d2ab2b8e245..7e30064d23e 100644 --- a/tests/reference/llvm-modules_36-53c9a79.stdout +++ b/tests/reference/llvm-modules_36-53c9a79.stdout @@ -7,8 +7,16 @@ source_filename = "LFortran" %fpm_build_settings = type <{ i1 }> %__vtab_fpm_run_settings = type { i64 } +@0 = private unnamed_addr constant [47 x i8] c"__libasr_created__intrinsic_array_function_Any\00", align 1 +@1 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@2 = private unnamed_addr constant [6 x i8] c"found\00", align 1 +@3 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 +@4 = private unnamed_addr constant [35 x i8] c"_lcompilers_Any_4_1_0_logical____0\00", align 1 +@5 = private unnamed_addr constant [143 x i8] c"Runtime error: Array shape mismatch in subroutine '%s'\0A\0ATried to match size %d of dimension %d of argument number %d, but expected size is %d\0A\00", align 1 @string_const_data = private constant [1 x i8] zeroinitializer @string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([1 x i8], [1 x i8]* @string_const_data, i32 0, i32 0), i64 0 }> +@6 = private unnamed_addr constant [5 x i8] c"mask\00", align 1 +@7 = private unnamed_addr constant [120 x i8] c"Runtime error: Array '%s' index out of bounds.\0A\0ATried to access index %d of dimension %d, but valid range is %d to %d.\0A\00", align 1 define i1 @_lcompilers_Any_4_1_0_logical____0(i1* %mask, i32* %__1mask) { .entry: @@ -45,7 +53,7 @@ loop.body: ; preds = %loop.head br i1 %18, label %then, label %else then: ; preds = %loop.body - call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i32 %9, i32 1, i32 1, i32 %15) + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @7, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i32 %9, i32 1, i32 1, i32 %15) call void @exit(i32 1) br label %ifcont @@ -141,43 +149,9 @@ loop.body: ; preds = %ifcont8 %17 = or i1 %15, %16 br i1 %17, label %then9, label %else10 -loop.end: ; preds = %ifcont8 - %25 = getelementptr [2 x i1], [2 x i1]* %__libasr_created__intrinsic_array_function_Any, i32 0, i32 0 - store i32 2, i32* %call_arg_value, align 4 - %26 = call i1 @_lcompilers_Any_4_1_0_logical____0(i1* %25, i32* %call_arg_value) - store i1 %26, i1* %__libasr_created__intrinsic_array_function_Any1, align 1 - %27 = load i1, i1* %__libasr_created__intrinsic_array_function_Any1, align 1 - %28 = load i1, i1* %toomany, align 1 - %29 = load i1, i1* %test, align 1 - %30 = xor i1 %29, true - %31 = icmp eq i1 %28, false - %32 = select i1 %31, i1 %28, i1 %30 - %33 = load i1, i1* %toomany, align 1 - %34 = getelementptr %fpm_run_settings_polymorphic, %fpm_run_settings_polymorphic* %settings, i32 0, i32 1 - %35 = load %fpm_run_settings*, %fpm_run_settings** %34, align 8 - %36 = getelementptr %fpm_run_settings, %fpm_run_settings* %35, i32 0, i32 3 - %37 = getelementptr %string_descriptor, %string_descriptor* %36, i32 0, i32 0 - %38 = load i8*, i8** %37, align 8 - %39 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 - %40 = call i32 @str_compare(i8* %38, i64 6, i8* %39, i64 0) - %41 = icmp ne i32 %40, 0 - %42 = icmp eq i1 %33, false - %43 = select i1 %42, i1 %33, i1 %41 - %44 = icmp eq i1 %32, false - %45 = select i1 %44, i1 %43, i1 %32 - %46 = getelementptr %fpm_run_settings_polymorphic, %fpm_run_settings_polymorphic* %settings, i32 0, i32 1 - %47 = load %fpm_run_settings*, %fpm_run_settings** %46, align 8 - %48 = getelementptr %fpm_run_settings, %fpm_run_settings* %47, i32 0, i32 0 - %49 = getelementptr %fpm_build_settings, %fpm_build_settings* %48, i32 0, i32 0 - %50 = load i1, i1* %49, align 1 - %51 = xor i1 %50, true - %52 = icmp eq i1 %45, false - %53 = select i1 %52, i1 %45, i1 %51 - %54 = icmp eq i1 %27, false - %55 = select i1 %54, i1 %53, i1 %27 - br i1 %55, label %then9, label %else10 - -then9: ; preds = %loop.end +then9: ; preds = %loop.body + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @0, i32 0, i32 0), i32 %11, i32 1, i32 1, i32 2) + call void @exit(i32 1) br label %ifcont11 else10: ; preds = %loop.body @@ -238,27 +212,26 @@ ifcont17: ; preds = %else16, %then15 %40 = getelementptr %fpm_run_settings_polymorphic, %fpm_run_settings_polymorphic* %settings, i32 0, i32 1 %41 = load %fpm_run_settings*, %fpm_run_settings** %40, align 8 %42 = getelementptr %fpm_run_settings, %fpm_run_settings* %41, i32 0, i32 3 - %43 = load i8*, i8** %42, align 8 - %44 = alloca i8*, align 8 - store i8* %43, i8** %44, align 8 - %45 = alloca i8*, align 8 - store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @6, i32 0, i32 0), i8** %45, align 8 - %46 = call i1 @_lpython_str_compare_noteq(i8** %44, i8** %45) - %47 = icmp eq i1 %39, false - %48 = select i1 %47, i1 %39, i1 %46 - %49 = icmp eq i1 %38, false - %50 = select i1 %49, i1 %48, i1 %38 - %51 = getelementptr %fpm_run_settings_polymorphic, %fpm_run_settings_polymorphic* %settings, i32 0, i32 1 - %52 = load %fpm_run_settings*, %fpm_run_settings** %51, align 8 - %53 = getelementptr %fpm_run_settings, %fpm_run_settings* %52, i32 0, i32 0 - %54 = getelementptr %fpm_build_settings, %fpm_build_settings* %53, i32 0, i32 0 - %55 = load i1, i1* %54, align 1 - %56 = xor i1 %55, true - %57 = icmp eq i1 %50, false - %58 = select i1 %57, i1 %50, i1 %56 - %59 = icmp eq i1 %33, false - %60 = select i1 %59, i1 %58, i1 %33 - br i1 %60, label %then18, label %else19 + %43 = getelementptr %string_descriptor, %string_descriptor* %42, i32 0, i32 0 + %44 = load i8*, i8** %43, align 8 + %45 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 + %46 = call i32 @str_compare(i8* %44, i64 6, i8* %45, i64 0) + %47 = icmp ne i32 %46, 0 + %48 = icmp eq i1 %39, false + %49 = select i1 %48, i1 %39, i1 %47 + %50 = icmp eq i1 %38, false + %51 = select i1 %50, i1 %49, i1 %38 + %52 = getelementptr %fpm_run_settings_polymorphic, %fpm_run_settings_polymorphic* %settings, i32 0, i32 1 + %53 = load %fpm_run_settings*, %fpm_run_settings** %52, align 8 + %54 = getelementptr %fpm_run_settings, %fpm_run_settings* %53, i32 0, i32 0 + %55 = getelementptr %fpm_build_settings, %fpm_build_settings* %54, i32 0, i32 0 + %56 = load i1, i1* %55, align 1 + %57 = xor i1 %56, true + %58 = icmp eq i1 %51, false + %59 = select i1 %58, i1 %51, i1 %57 + %60 = icmp eq i1 %33, false + %61 = select i1 %60, i1 %59, i1 %33 + br i1 %61, label %then18, label %else19 then18: ; preds = %ifcont17 br label %ifcont20 @@ -273,6 +246,10 @@ return: ; preds = %ifcont20 ret void } +declare void @_lcompilers_print_error(i8*, ...) + +declare void @exit(i32) + declare i32 @str_compare(i8*, i64, i8*, i64) define i32 @main(i32 %0, i8** %1) { From 5220d7904c625854bc5f8d1d269a8a3dc0d9296c Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Fri, 25 Jul 2025 16:43:42 +0000 Subject: [PATCH 088/119] fix: add unreachable after exit in bounds checking to fix a segfault --- src/libasr/codegen/llvm_utils.h | 64 ++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/libasr/codegen/llvm_utils.h b/src/libasr/codegen/llvm_utils.h index 6d9139bf266..9e6a4785131 100644 --- a/src/libasr/codegen/llvm_utils.h +++ b/src/libasr/codegen/llvm_utils.h @@ -272,35 +272,41 @@ namespace LCompilers { template void generate_runtime_error(llvm::Value* cond, std::string message, Args... args) { - create_if_else(cond, - [&](){ - llvm::Value* formatted_msg = builder->CreateGlobalStringPtr(message); - llvm::Function* print_error_fn = module->getFunction("_lcompilers_print_error"); - if (!print_error_fn) { - llvm::FunctionType* error_fn_type = llvm::FunctionType::get( - llvm::Type::getVoidTy(context), - {llvm::Type::getInt8Ty(context)->getPointerTo()}, - true); - print_error_fn = llvm::Function::Create(error_fn_type, - llvm::Function::ExternalLinkage, "_lcompilers_print_error", module); - } - - std::vector vec = {formatted_msg, args...}; - builder->CreateCall(print_error_fn, vec); - - llvm::Function* exit_fn = module->getFunction("exit"); - if (!exit_fn) { - llvm::FunctionType* exit_fn_type = llvm::FunctionType::get( - llvm::Type::getVoidTy(context), - {llvm::Type::getInt32Ty(context)}, - false); - exit_fn = llvm::Function::Create(exit_fn_type, - llvm::Function::ExternalLinkage, "exit", module); - } - - builder->CreateCall(exit_fn, {llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), 1)}); - }, - [](){}); + llvm::Function *fn = builder->GetInsertBlock()->getParent(); + + llvm::BasicBlock *thenBB = llvm::BasicBlock::Create(context, "then", fn); + llvm::BasicBlock *mergeBB = llvm::BasicBlock::Create(context, "ifcont"); + + builder->CreateCondBr(cond, thenBB, mergeBB); + builder->SetInsertPoint(thenBB); { + llvm::Value* formatted_msg = builder->CreateGlobalStringPtr(message); + llvm::Function* print_error_fn = module->getFunction("_lcompilers_print_error"); + if (!print_error_fn) { + llvm::FunctionType* error_fn_type = llvm::FunctionType::get( + llvm::Type::getVoidTy(context), + {llvm::Type::getInt8Ty(context)->getPointerTo()}, + true); + print_error_fn = llvm::Function::Create(error_fn_type, + llvm::Function::ExternalLinkage, "_lcompilers_print_error", module); + } + + std::vector vec = {formatted_msg, args...}; + builder->CreateCall(print_error_fn, vec); + + llvm::Function* exit_fn = module->getFunction("exit"); + if (!exit_fn) { + llvm::FunctionType* exit_fn_type = llvm::FunctionType::get( + llvm::Type::getVoidTy(context), + {llvm::Type::getInt32Ty(context)}, + false); + exit_fn = llvm::Function::Create(exit_fn_type, + llvm::Function::ExternalLinkage, "exit", module); + } + + builder->CreateCall(exit_fn, {llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), 1)}); + builder->CreateUnreachable(); + } + start_new_block(mergeBB); } /* From bca6d4ef7d183a2b718874e783f7941b5c5fc8bc Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Fri, 25 Jul 2025 18:10:30 +0000 Subject: [PATCH 089/119] fix(openmp): pass in lower_bounds in CPtrToPointer --- src/libasr/codegen/asr_to_llvm.cpp | 20 +++++++------------- src/libasr/pass/array_op.cpp | 9 +++++++-- src/libasr/pass/openmp.cpp | 7 ++++++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 5aaf3937997..c962f4fe82f 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5549,12 +5549,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm_cptr = builder->CreateBitCast(llvm_cptr, llvm_fptr_data_type->getPointerTo()); builder->CreateStore(llvm_cptr, fptr_data); llvm::Value* prod = llvm::ConstantInt::get(context, llvm::APInt(32, 1)); - ASR::ArrayConstant_t* lower_bounds = nullptr; - if( x.m_lower_bounds ) { - LCOMPILERS_ASSERT(ASR::is_a(*x.m_lower_bounds)); - lower_bounds = ASR::down_cast(x.m_lower_bounds); - LCOMPILERS_ASSERT(fptr_rank == ASRUtils::get_fixed_size_of_array(lower_bounds->m_type)); - } for( int i = 0; i < fptr_rank; i++ ) { llvm::Value* curr_dim = llvm::ConstantInt::get(context, llvm::APInt(32, i)); llvm::Value* desi = arr_descr->get_pointer_to_dimension_descriptor(fptr_des, curr_dim); @@ -5564,25 +5558,25 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor builder->CreateStore(prod, desi_stride); llvm::Value* i32_one = llvm::ConstantInt::get(context, llvm::APInt(32, 1)); llvm::Value* new_lb = i32_one; - if( lower_bounds ) { + if( x.m_lower_bounds ) { int ptr_loads_copy = ptr_loads; ptr_loads = 2; - this->visit_expr_wrapper(ASRUtils::fetch_ArrayConstant_value(al, lower_bounds, i), true); + this->visit_expr_wrapper(x.m_lower_bounds, true); ptr_loads = ptr_loads_copy; - new_lb = tmp; + tmp = llvm_utils->create_ptr_gep2(llvm::Type::getInt32Ty(context), tmp, i); + new_lb = llvm_utils->CreateLoad2(llvm::Type::getInt32Ty(context), tmp); } - llvm::Value* new_ub = nullptr; + llvm::Value* new_size = nullptr; if( ASRUtils::extract_physical_type(asr_shape_type) == ASR::array_physical_typeType::DescriptorArray || ASRUtils::extract_physical_type(asr_shape_type) == ASR::array_physical_typeType::PointerToDataArray ) { - new_ub = shape_data ? llvm_utils->CreateLoad2( + new_size = shape_data ? llvm_utils->CreateLoad2( llvm::Type::getInt32Ty(context), llvm_utils->create_ptr_gep(shape_data, i)) : i32_one; } else if( ASRUtils::extract_physical_type(asr_shape_type) == ASR::array_physical_typeType::FixedSizeArray ) { llvm::Type* shape_llvm_type = llvm_utils->get_type_from_ttype_t_util(shape, asr_shape_type, module.get()); - new_ub = shape_data ? llvm_utils->CreateLoad2( + new_size = shape_data ? llvm_utils->CreateLoad2( llvm::Type::getInt32Ty(context), llvm_utils->create_gep2(shape_llvm_type, shape_data, i)) : i32_one; } builder->CreateStore(new_lb, desi_lb); - llvm::Value* new_size = builder->CreateAdd(builder->CreateSub(new_ub, new_lb), i32_one); builder->CreateStore(new_size, desi_size); prod = builder->CreateMul(prod, new_size); } diff --git a/src/libasr/pass/array_op.cpp b/src/libasr/pass/array_op.cpp index be328b643d7..591e7d63eea 100644 --- a/src/libasr/pass/array_op.cpp +++ b/src/libasr/pass/array_op.cpp @@ -322,6 +322,10 @@ class ReplaceArrayOp: public ASR::BaseExprReplacer { fix_type_visitor.current_scope = current_scope; fix_type_visitor.visit_ttype(*result_element_type); + ASRUtils::ASRBuilder builder(al, loc); + ASR::dimension_t* m_dims = nullptr; + ASRUtils::extract_dimensions_from_ttype(arr_type, m_dims); + for( int64_t i = 0; i < ASRUtils::get_fixed_size_of_array(arr_type); i++ ) { ASR::expr_t* x_i = nullptr; if( x->m_value ) { @@ -335,8 +339,9 @@ class ReplaceArrayOp: public ASR::BaseExprReplacer { ASR::array_index_t array_index_arg; array_index_arg.loc = loc; array_index_arg.m_left = nullptr; - array_index_arg.m_right = make_ConstantWithKind( - make_IntegerConstant_t, make_Integer_t, i + 1, 4, loc); + // TODO: Make this work with any rank + array_index_arg.m_right = builder.Add(m_dims[0].m_start, make_ConstantWithKind( + make_IntegerConstant_t, make_Integer_t, i, 4, loc)); array_index_arg.m_step = nullptr; array_index_args.push_back(al, array_index_arg); ASR::expr_t* y_i = ASRUtils::EXPR(ASRUtils::make_ArrayItem_t_util(al, loc, diff --git a/src/libasr/pass/openmp.cpp b/src/libasr/pass/openmp.cpp index d412a3850b2..48942005fbb 100644 --- a/src/libasr/pass/openmp.cpp +++ b/src/libasr/pass/openmp.cpp @@ -2108,6 +2108,7 @@ class ParallelRegionVisitor : // Handle arrays (existing logic) ASR::Array_t* array_type = ASR::down_cast(ASRUtils::type_get_past_pointer(sym_type)); Vec size_args; size_args.reserve(al, array_type->n_dims); + Vec lbounds; lbounds.reserve(al, array_type->n_dims); for (size_t i = 0; i < array_type->n_dims; i++) { std::string ubound_name = std::string(ASRUtils::symbol_name(thread_data_sym)) + "_ubound_" + it.first + "_" + std::to_string(i); @@ -2126,17 +2127,21 @@ class ParallelRegionVisitor : ASR::expr_t* lbound = ASRUtils::EXPR(ASR::make_StructInstanceMember_t(al, loc, tdata_expr, lbound_sym, ASRUtils::symbol_type(lbound_sym), nullptr)); size_args.push_back(al, b.Add(b.Sub(ubound, lbound), b.i32(1))); + lbounds.push_back(al, lbound); } ASR::expr_t* shape = ASRUtils::EXPR(ASRUtils::make_ArrayConstructor_t_util(al, loc, size_args.p, size_args.n, ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4)), ASR::arraystorageType::ColMajor)); + ASR::expr_t* lbounds_constructor = ASRUtils::EXPR(ASRUtils::make_ArrayConstructor_t_util(al, loc, + lbounds.p, lbounds.n, ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4)), ASR::arraystorageType::ColMajor)); // call c_f_pointer(tdata%, , [ubound-lbound+1]) body.push_back(al, b.CPtrToPointer( ASRUtils::EXPR(ASR::make_StructInstanceMember_t(al, loc, tdata_expr, sym, ASRUtils::symbol_type(sym), nullptr)), b.Var(current_scope->get_symbol(it.first)), - shape + shape, + lbounds_constructor )); } else if (is_shared) { // Handle shared non-array variables using CPtr approach From e0248348648431d95b416bdfbdd653976b1b319a Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Fri, 25 Jul 2025 18:10:35 +0000 Subject: [PATCH 090/119] tests: update references --- tests/reference/llvm-allocate_03-495d621.json | 2 +- .../reference/llvm-allocate_03-495d621.stdout | 618 ++++++---------- tests/reference/llvm-arrays_01-91893af.json | 2 +- tests/reference/llvm-arrays_01-91893af.stdout | 419 +++++------ .../llvm-arrays_01_complex-c90dbdd.json | 2 +- .../llvm-arrays_01_complex-c90dbdd.stdout | 601 +++++++--------- .../llvm-arrays_01_logical-f19a63d.json | 2 +- .../llvm-arrays_01_logical-f19a63d.stdout | 681 ++++++++---------- .../llvm-arrays_01_real-6c5e850.json | 2 +- .../llvm-arrays_01_real-6c5e850.stdout | 601 +++++++--------- .../llvm-arrays_01_size-aaed99f.json | 2 +- .../llvm-arrays_01_size-aaed99f.stdout | 423 +++++------ .../llvm-implicit_interface_04-9b6786e.json | 2 +- .../llvm-implicit_interface_04-9b6786e.stdout | 120 ++- tests/reference/llvm-modules_36-53c9a79.json | 2 +- .../reference/llvm-modules_36-53c9a79.stdout | 56 +- 16 files changed, 1451 insertions(+), 2084 deletions(-) diff --git a/tests/reference/llvm-allocate_03-495d621.json b/tests/reference/llvm-allocate_03-495d621.json index 147101ec475..4ee9bade9c6 100644 --- a/tests/reference/llvm-allocate_03-495d621.json +++ b/tests/reference/llvm-allocate_03-495d621.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-allocate_03-495d621.stdout", - "stdout_hash": "001b1c61316bee5096e87ac97fc71b11d4b5c21bcbf576415a185832", + "stdout_hash": "a312cc8b5b36df8bf02db303a8f73e62fee216dc953c1e3afb458252", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-allocate_03-495d621.stdout b/tests/reference/llvm-allocate_03-495d621.stdout index 2b86745d65d..86c2fd96050 100644 --- a/tests/reference/llvm-allocate_03-495d621.stdout +++ b/tests/reference/llvm-allocate_03-495d621.stdout @@ -252,17 +252,14 @@ ifcont5: ; preds = %else4, %then3 %50 = ptrtoint i32* %49 to i64 %51 = icmp ne i64 %50, 0 %52 = xor i1 %51, true - br i1 %52, label %then6, label %else7 + br i1 %52, label %then6, label %ifcont7 then6: ; preds = %ifcont5 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @84, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @83, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont8 + unreachable -else7: ; preds = %ifcont5 - br label %ifcont8 - -ifcont8: ; preds = %else7, %then6 +ifcont7: ; preds = %ifcont5 %53 = getelementptr %array, %array* %47, i32 0, i32 2 %54 = load %dimension_descriptor*, %dimension_descriptor** %53, align 8 %55 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %54, i32 0 @@ -276,17 +273,14 @@ ifcont8: ; preds = %else7, %then6 %63 = icmp slt i32 1, %57 %64 = icmp sgt i32 1, %62 %65 = or i1 %63, %64 - br i1 %65, label %then9, label %else10 + br i1 %65, label %then8, label %ifcont9 -then9: ; preds = %ifcont8 +then8: ; preds = %ifcont7 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @86, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @85, i32 0, i32 0), i32 1, i32 1, i32 %57, i32 %62) call void @exit(i32 1) - br label %ifcont11 - -else10: ; preds = %ifcont8 - br label %ifcont11 + unreachable -ifcont11: ; preds = %else10, %then9 +ifcont9: ; preds = %ifcont7 %66 = getelementptr %dimension_descriptor, %dimension_descriptor* %55, i32 0, i32 0 %67 = load i32, i32* %66, align 4 %68 = mul i32 %67, %60 @@ -302,17 +296,14 @@ ifcont11: ; preds = %else10, %then9 %78 = icmp slt i32 1, %72 %79 = icmp sgt i32 1, %77 %80 = or i1 %78, %79 - br i1 %80, label %then12, label %else13 + br i1 %80, label %then10, label %ifcont11 -then12: ; preds = %ifcont11 +then10: ; preds = %ifcont9 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @88, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @87, i32 0, i32 0), i32 1, i32 2, i32 %72, i32 %77) call void @exit(i32 1) - br label %ifcont14 - -else13: ; preds = %ifcont11 - br label %ifcont14 + unreachable -ifcont14: ; preds = %else13, %then12 +ifcont11: ; preds = %ifcont9 %81 = getelementptr %dimension_descriptor, %dimension_descriptor* %70, i32 0, i32 0 %82 = load i32, i32* %81, align 4 %83 = mul i32 %82, %75 @@ -328,17 +319,14 @@ ifcont14: ; preds = %else13, %then12 %93 = icmp slt i32 1, %87 %94 = icmp sgt i32 1, %92 %95 = or i1 %93, %94 - br i1 %95, label %then15, label %else16 + br i1 %95, label %then12, label %ifcont13 -then15: ; preds = %ifcont14 +then12: ; preds = %ifcont11 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @90, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @89, i32 0, i32 0), i32 1, i32 3, i32 %87, i32 %92) call void @exit(i32 1) - br label %ifcont17 - -else16: ; preds = %ifcont14 - br label %ifcont17 + unreachable -ifcont17: ; preds = %else16, %then15 +ifcont13: ; preds = %ifcont11 %96 = getelementptr %dimension_descriptor, %dimension_descriptor* %85, i32 0, i32 0 %97 = load i32, i32* %96, align 4 %98 = mul i32 %97, %90 @@ -355,9 +343,9 @@ ifcont17: ; preds = %else16, %then15 %108 = load i32*, i32** %107, align 8 %109 = ptrtoint i32* %108 to i64 %110 = icmp ne i64 %109, 0 - br i1 %110, label %then18, label %else19 + br i1 %110, label %then14, label %else15 -then18: ; preds = %ifcont17 +then14: ; preds = %ifcont13 %111 = getelementptr %array, %array* %106, i32 0, i32 0 %112 = load i32*, i32** %111, align 8 %113 = alloca i8*, align 8 @@ -367,12 +355,12 @@ then18: ; preds = %ifcont17 call void @_lfortran_free(i8* %115) %116 = getelementptr %array, %array* %106, i32 0, i32 0 store i32* null, i32** %116, align 8 - br label %ifcont20 + br label %ifcont16 -else19: ; preds = %ifcont17 - br label %ifcont20 +else15: ; preds = %ifcont13 + br label %ifcont16 -ifcont20: ; preds = %else19, %then18 +ifcont16: ; preds = %else15, %then14 call void @h(%array** %c) %117 = call i32 @g(%array** %c) store i32 %117, i32* %r1, align 4 @@ -382,17 +370,14 @@ ifcont20: ; preds = %else19, %then18 %121 = ptrtoint i32* %120 to i64 %122 = icmp ne i64 %121, 0 %123 = xor i1 %122, true - br i1 %123, label %then21, label %else22 + br i1 %123, label %then17, label %ifcont18 -then21: ; preds = %ifcont20 +then17: ; preds = %ifcont16 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @92, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @91, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont23 + unreachable -else22: ; preds = %ifcont20 - br label %ifcont23 - -ifcont23: ; preds = %else22, %then21 +ifcont18: ; preds = %ifcont16 %124 = getelementptr %array, %array* %118, i32 0, i32 2 %125 = load %dimension_descriptor*, %dimension_descriptor** %124, align 8 %126 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %125, i32 0 @@ -406,17 +391,14 @@ ifcont23: ; preds = %else22, %then21 %134 = icmp slt i32 1, %128 %135 = icmp sgt i32 1, %133 %136 = or i1 %134, %135 - br i1 %136, label %then24, label %else25 + br i1 %136, label %then19, label %ifcont20 -then24: ; preds = %ifcont23 +then19: ; preds = %ifcont18 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @94, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @93, i32 0, i32 0), i32 1, i32 1, i32 %128, i32 %133) call void @exit(i32 1) - br label %ifcont26 + unreachable -else25: ; preds = %ifcont23 - br label %ifcont26 - -ifcont26: ; preds = %else25, %then24 +ifcont20: ; preds = %ifcont18 %137 = getelementptr %dimension_descriptor, %dimension_descriptor* %126, i32 0, i32 0 %138 = load i32, i32* %137, align 4 %139 = mul i32 %138, %131 @@ -432,17 +414,14 @@ ifcont26: ; preds = %else25, %then24 %149 = icmp slt i32 1, %143 %150 = icmp sgt i32 1, %148 %151 = or i1 %149, %150 - br i1 %151, label %then27, label %else28 + br i1 %151, label %then21, label %ifcont22 -then27: ; preds = %ifcont26 +then21: ; preds = %ifcont20 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @96, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @95, i32 0, i32 0), i32 1, i32 2, i32 %143, i32 %148) call void @exit(i32 1) - br label %ifcont29 - -else28: ; preds = %ifcont26 - br label %ifcont29 + unreachable -ifcont29: ; preds = %else28, %then27 +ifcont22: ; preds = %ifcont20 %152 = getelementptr %dimension_descriptor, %dimension_descriptor* %141, i32 0, i32 0 %153 = load i32, i32* %152, align 4 %154 = mul i32 %153, %146 @@ -458,17 +437,14 @@ ifcont29: ; preds = %else28, %then27 %164 = icmp slt i32 1, %158 %165 = icmp sgt i32 1, %163 %166 = or i1 %164, %165 - br i1 %166, label %then30, label %else31 + br i1 %166, label %then23, label %ifcont24 -then30: ; preds = %ifcont29 +then23: ; preds = %ifcont22 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @98, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @97, i32 0, i32 0), i32 1, i32 3, i32 %158, i32 %163) call void @exit(i32 1) - br label %ifcont32 + unreachable -else31: ; preds = %ifcont29 - br label %ifcont32 - -ifcont32: ; preds = %else31, %then30 +ifcont24: ; preds = %ifcont22 %167 = getelementptr %dimension_descriptor, %dimension_descriptor* %156, i32 0, i32 0 %168 = load i32, i32* %167, align 4 %169 = mul i32 %168, %161 @@ -481,36 +457,33 @@ ifcont32: ; preds = %else31, %then30 %176 = getelementptr inbounds i32, i32* %175, i32 %173 %177 = load i32, i32* %176, align 4 %178 = icmp ne i32 %177, 8 - br i1 %178, label %then33, label %else34 + br i1 %178, label %then25, label %else26 -then33: ; preds = %ifcont32 +then25: ; preds = %ifcont24 %179 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 %180 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @99, i32 0, i32 0), i8* %179, i8* %180) call void @exit(i32 1) - br label %ifcont35 + br label %ifcont27 -else34: ; preds = %ifcont32 - br label %ifcont35 +else26: ; preds = %ifcont24 + br label %ifcont27 -ifcont35: ; preds = %else34, %then33 +ifcont27: ; preds = %else26, %then25 %181 = load %array*, %array** %c, align 8 %182 = getelementptr %array, %array* %181, i32 0, i32 0 %183 = load i32*, i32** %182, align 8 %184 = ptrtoint i32* %183 to i64 %185 = icmp ne i64 %184, 0 %186 = xor i1 %185, true - br i1 %186, label %then36, label %else37 + br i1 %186, label %then28, label %ifcont29 -then36: ; preds = %ifcont35 +then28: ; preds = %ifcont27 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @102, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @101, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont38 - -else37: ; preds = %ifcont35 - br label %ifcont38 + unreachable -ifcont38: ; preds = %else37, %then36 +ifcont29: ; preds = %ifcont27 %187 = getelementptr %array, %array* %181, i32 0, i32 2 %188 = load %dimension_descriptor*, %dimension_descriptor** %187, align 8 %189 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %188, i32 0 @@ -524,17 +497,14 @@ ifcont38: ; preds = %else37, %then36 %197 = icmp slt i32 1, %191 %198 = icmp sgt i32 1, %196 %199 = or i1 %197, %198 - br i1 %199, label %then39, label %else40 + br i1 %199, label %then30, label %ifcont31 -then39: ; preds = %ifcont38 +then30: ; preds = %ifcont29 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @104, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @103, i32 0, i32 0), i32 1, i32 1, i32 %191, i32 %196) call void @exit(i32 1) - br label %ifcont41 + unreachable -else40: ; preds = %ifcont38 - br label %ifcont41 - -ifcont41: ; preds = %else40, %then39 +ifcont31: ; preds = %ifcont29 %200 = getelementptr %dimension_descriptor, %dimension_descriptor* %189, i32 0, i32 0 %201 = load i32, i32* %200, align 4 %202 = mul i32 %201, %194 @@ -550,17 +520,14 @@ ifcont41: ; preds = %else40, %then39 %212 = icmp slt i32 1, %206 %213 = icmp sgt i32 1, %211 %214 = or i1 %212, %213 - br i1 %214, label %then42, label %else43 + br i1 %214, label %then32, label %ifcont33 -then42: ; preds = %ifcont41 +then32: ; preds = %ifcont31 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @106, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @105, i32 0, i32 0), i32 1, i32 2, i32 %206, i32 %211) call void @exit(i32 1) - br label %ifcont44 + unreachable -else43: ; preds = %ifcont41 - br label %ifcont44 - -ifcont44: ; preds = %else43, %then42 +ifcont33: ; preds = %ifcont31 %215 = getelementptr %dimension_descriptor, %dimension_descriptor* %204, i32 0, i32 0 %216 = load i32, i32* %215, align 4 %217 = mul i32 %216, %209 @@ -576,17 +543,14 @@ ifcont44: ; preds = %else43, %then42 %227 = icmp slt i32 1, %221 %228 = icmp sgt i32 1, %226 %229 = or i1 %227, %228 - br i1 %229, label %then45, label %else46 + br i1 %229, label %then34, label %ifcont35 -then45: ; preds = %ifcont44 +then34: ; preds = %ifcont33 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @108, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @107, i32 0, i32 0), i32 1, i32 3, i32 %221, i32 %226) call void @exit(i32 1) - br label %ifcont47 - -else46: ; preds = %ifcont44 - br label %ifcont47 + unreachable -ifcont47: ; preds = %else46, %then45 +ifcont35: ; preds = %ifcont33 %230 = getelementptr %dimension_descriptor, %dimension_descriptor* %219, i32 0, i32 0 %231 = load i32, i32* %230, align 4 %232 = mul i32 %231, %224 @@ -616,9 +580,9 @@ ifcont47: ; preds = %else46, %then45 %251 = load i32*, i32** %250, align 8 %252 = ptrtoint i32* %251 to i64 %253 = icmp ne i64 %252, 0 - br i1 %253, label %then48, label %else49 + br i1 %253, label %then36, label %else37 -then48: ; preds = %ifcont47 +then36: ; preds = %ifcont35 %254 = getelementptr %array, %array* %249, i32 0, i32 0 %255 = load i32*, i32** %254, align 8 %256 = alloca i8*, align 8 @@ -628,16 +592,16 @@ then48: ; preds = %ifcont47 call void @_lfortran_free(i8* %258) %259 = getelementptr %array, %array* %249, i32 0, i32 0 store i32* null, i32** %259, align 8 - br label %ifcont50 + br label %ifcont38 -else49: ; preds = %ifcont47 - br label %ifcont50 +else37: ; preds = %ifcont35 + br label %ifcont38 -ifcont50: ; preds = %else49, %then48 +ifcont38: ; preds = %else37, %then36 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont50 +return: ; preds = %ifcont38 ret i32 0 } @@ -709,17 +673,14 @@ ifcont: ; preds = %else, %then %36 = ptrtoint i32* %35 to i64 %37 = icmp ne i64 %36, 0 %38 = xor i1 %37, true - br i1 %38, label %then1, label %else2 + br i1 %38, label %then1, label %ifcont2 then1: ; preds = %ifcont call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont3 - -else2: ; preds = %ifcont - br label %ifcont3 + unreachable -ifcont3: ; preds = %else2, %then1 +ifcont2: ; preds = %ifcont %39 = getelementptr %array, %array* %33, i32 0, i32 2 %40 = load %dimension_descriptor*, %dimension_descriptor** %39, align 8 %41 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %40, i32 0 @@ -733,17 +694,14 @@ ifcont3: ; preds = %else2, %then1 %49 = icmp slt i32 1, %43 %50 = icmp sgt i32 1, %48 %51 = or i1 %49, %50 - br i1 %51, label %then4, label %else5 + br i1 %51, label %then3, label %ifcont4 -then4: ; preds = %ifcont3 +then3: ; preds = %ifcont2 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 1, i32 1, i32 %43, i32 %48) call void @exit(i32 1) - br label %ifcont6 - -else5: ; preds = %ifcont3 - br label %ifcont6 + unreachable -ifcont6: ; preds = %else5, %then4 +ifcont4: ; preds = %ifcont2 %52 = getelementptr %dimension_descriptor, %dimension_descriptor* %41, i32 0, i32 0 %53 = load i32, i32* %52, align 4 %54 = mul i32 %53, %46 @@ -759,17 +717,14 @@ ifcont6: ; preds = %else5, %then4 %64 = icmp slt i32 1, %58 %65 = icmp sgt i32 1, %63 %66 = or i1 %64, %65 - br i1 %66, label %then7, label %else8 + br i1 %66, label %then5, label %ifcont6 -then7: ; preds = %ifcont6 +then5: ; preds = %ifcont4 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0), i32 1, i32 2, i32 %58, i32 %63) call void @exit(i32 1) - br label %ifcont9 - -else8: ; preds = %ifcont6 - br label %ifcont9 + unreachable -ifcont9: ; preds = %else8, %then7 +ifcont6: ; preds = %ifcont4 %67 = getelementptr %dimension_descriptor, %dimension_descriptor* %56, i32 0, i32 0 %68 = load i32, i32* %67, align 4 %69 = mul i32 %68, %61 @@ -785,17 +740,14 @@ ifcont9: ; preds = %else8, %then7 %79 = icmp slt i32 1, %73 %80 = icmp sgt i32 1, %78 %81 = or i1 %79, %80 - br i1 %81, label %then10, label %else11 + br i1 %81, label %then7, label %ifcont8 -then10: ; preds = %ifcont9 +then7: ; preds = %ifcont6 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @6, i32 0, i32 0), i32 1, i32 3, i32 %73, i32 %78) call void @exit(i32 1) - br label %ifcont12 - -else11: ; preds = %ifcont9 - br label %ifcont12 + unreachable -ifcont12: ; preds = %else11, %then10 +ifcont8: ; preds = %ifcont6 %82 = getelementptr %dimension_descriptor, %dimension_descriptor* %71, i32 0, i32 0 %83 = load i32, i32* %82, align 4 %84 = mul i32 %83, %76 @@ -809,7 +761,7 @@ ifcont12: ; preds = %else11, %then10 store i32 99, i32* %91, align 4 br label %return -return: ; preds = %ifcont12 +return: ; preds = %ifcont8 ret void } @@ -822,17 +774,14 @@ define i32 @g(%array** %x) { %3 = ptrtoint i32* %2 to i64 %4 = icmp ne i64 %3, 0 %5 = xor i1 %4, true - br i1 %5, label %then, label %else + br i1 %5, label %then, label %ifcont then: ; preds = %.entry call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @10, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @9, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont - -else: ; preds = %.entry - br label %ifcont + unreachable -ifcont: ; preds = %else, %then +ifcont: ; preds = %.entry %6 = getelementptr %array, %array* %0, i32 0, i32 2 %7 = load %dimension_descriptor*, %dimension_descriptor** %6, align 8 %8 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %7, i32 0 @@ -846,17 +795,14 @@ ifcont: ; preds = %else, %then %16 = icmp slt i32 1, %10 %17 = icmp sgt i32 1, %15 %18 = or i1 %16, %17 - br i1 %18, label %then1, label %else2 + br i1 %18, label %then1, label %ifcont2 then1: ; preds = %ifcont call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i32 1, i32 1, i32 %10, i32 %15) call void @exit(i32 1) - br label %ifcont3 - -else2: ; preds = %ifcont - br label %ifcont3 + unreachable -ifcont3: ; preds = %else2, %then1 +ifcont2: ; preds = %ifcont %19 = getelementptr %dimension_descriptor, %dimension_descriptor* %8, i32 0, i32 0 %20 = load i32, i32* %19, align 4 %21 = mul i32 %20, %13 @@ -872,17 +818,14 @@ ifcont3: ; preds = %else2, %then1 %31 = icmp slt i32 1, %25 %32 = icmp sgt i32 1, %30 %33 = or i1 %31, %32 - br i1 %33, label %then4, label %else5 + br i1 %33, label %then3, label %ifcont4 -then4: ; preds = %ifcont3 +then3: ; preds = %ifcont2 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 1, i32 2, i32 %25, i32 %30) call void @exit(i32 1) - br label %ifcont6 - -else5: ; preds = %ifcont3 - br label %ifcont6 + unreachable -ifcont6: ; preds = %else5, %then4 +ifcont4: ; preds = %ifcont2 %34 = getelementptr %dimension_descriptor, %dimension_descriptor* %23, i32 0, i32 0 %35 = load i32, i32* %34, align 4 %36 = mul i32 %35, %28 @@ -898,17 +841,14 @@ ifcont6: ; preds = %else5, %then4 %46 = icmp slt i32 1, %40 %47 = icmp sgt i32 1, %45 %48 = or i1 %46, %47 - br i1 %48, label %then7, label %else8 + br i1 %48, label %then5, label %ifcont6 -then7: ; preds = %ifcont6 +then5: ; preds = %ifcont4 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 1, i32 3, i32 %40, i32 %45) call void @exit(i32 1) - br label %ifcont9 - -else8: ; preds = %ifcont6 - br label %ifcont9 + unreachable -ifcont9: ; preds = %else8, %then7 +ifcont6: ; preds = %ifcont4 %49 = getelementptr %dimension_descriptor, %dimension_descriptor* %38, i32 0, i32 0 %50 = load i32, i32* %49, align 4 %51 = mul i32 %50, %43 @@ -939,17 +879,14 @@ ifcont9: ; preds = %else8, %then7 %71 = ptrtoint i32* %70 to i64 %72 = icmp ne i64 %71, 0 %73 = xor i1 %72, true - br i1 %73, label %then10, label %else11 + br i1 %73, label %then7, label %ifcont8 -then10: ; preds = %ifcont9 +then7: ; preds = %ifcont6 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @19, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @18, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont12 - -else11: ; preds = %ifcont9 - br label %ifcont12 + unreachable -ifcont12: ; preds = %else11, %then10 +ifcont8: ; preds = %ifcont6 %74 = getelementptr %array, %array* %68, i32 0, i32 2 %75 = load %dimension_descriptor*, %dimension_descriptor** %74, align 8 %76 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %75, i32 0 @@ -963,17 +900,14 @@ ifcont12: ; preds = %else11, %then10 %84 = icmp slt i32 1, %78 %85 = icmp sgt i32 1, %83 %86 = or i1 %84, %85 - br i1 %86, label %then13, label %else14 + br i1 %86, label %then9, label %ifcont10 -then13: ; preds = %ifcont12 +then9: ; preds = %ifcont8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @21, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @20, i32 0, i32 0), i32 1, i32 1, i32 %78, i32 %83) call void @exit(i32 1) - br label %ifcont15 + unreachable -else14: ; preds = %ifcont12 - br label %ifcont15 - -ifcont15: ; preds = %else14, %then13 +ifcont10: ; preds = %ifcont8 %87 = getelementptr %dimension_descriptor, %dimension_descriptor* %76, i32 0, i32 0 %88 = load i32, i32* %87, align 4 %89 = mul i32 %88, %81 @@ -989,17 +923,14 @@ ifcont15: ; preds = %else14, %then13 %99 = icmp slt i32 1, %93 %100 = icmp sgt i32 1, %98 %101 = or i1 %99, %100 - br i1 %101, label %then16, label %else17 + br i1 %101, label %then11, label %ifcont12 -then16: ; preds = %ifcont15 +then11: ; preds = %ifcont10 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @22, i32 0, i32 0), i32 1, i32 2, i32 %93, i32 %98) call void @exit(i32 1) - br label %ifcont18 - -else17: ; preds = %ifcont15 - br label %ifcont18 + unreachable -ifcont18: ; preds = %else17, %then16 +ifcont12: ; preds = %ifcont10 %102 = getelementptr %dimension_descriptor, %dimension_descriptor* %91, i32 0, i32 0 %103 = load i32, i32* %102, align 4 %104 = mul i32 %103, %96 @@ -1015,17 +946,14 @@ ifcont18: ; preds = %else17, %then16 %114 = icmp slt i32 1, %108 %115 = icmp sgt i32 1, %113 %116 = or i1 %114, %115 - br i1 %116, label %then19, label %else20 + br i1 %116, label %then13, label %ifcont14 -then19: ; preds = %ifcont18 +then13: ; preds = %ifcont12 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @25, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @24, i32 0, i32 0), i32 1, i32 3, i32 %108, i32 %113) call void @exit(i32 1) - br label %ifcont21 + unreachable -else20: ; preds = %ifcont18 - br label %ifcont21 - -ifcont21: ; preds = %else20, %then19 +ifcont14: ; preds = %ifcont12 %117 = getelementptr %dimension_descriptor, %dimension_descriptor* %106, i32 0, i32 0 %118 = load i32, i32* %117, align 4 %119 = mul i32 %118, %111 @@ -1038,27 +966,27 @@ ifcont21: ; preds = %else20, %then19 %126 = getelementptr inbounds i32, i32* %125, i32 %123 %127 = load i32, i32* %126, align 4 %128 = icmp ne i32 %127, 8 - br i1 %128, label %then22, label %else23 + br i1 %128, label %then15, label %else -then22: ; preds = %ifcont21 +then15: ; preds = %ifcont14 %129 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 %130 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @26, i32 0, i32 0), i8* %129, i8* %130) call void @exit(i32 1) - br label %ifcont24 + br label %ifcont16 -else23: ; preds = %ifcont21 - br label %ifcont24 +else: ; preds = %ifcont14 + br label %ifcont16 -ifcont24: ; preds = %else23, %then22 +ifcont16: ; preds = %else, %then15 %131 = load %array*, %array** %x, align 8 %132 = getelementptr %array, %array* %131, i32 0, i32 0 %133 = load i32*, i32** %132, align 8 %134 = ptrtoint i32* %133 to i64 %135 = icmp ne i64 %134, 0 - br i1 %135, label %then25, label %else26 + br i1 %135, label %then17, label %else18 -then25: ; preds = %ifcont24 +then17: ; preds = %ifcont16 %136 = getelementptr %array, %array* %131, i32 0, i32 0 %137 = load i32*, i32** %136, align 8 %138 = alloca i8*, align 8 @@ -1068,12 +996,12 @@ then25: ; preds = %ifcont24 call void @_lfortran_free(i8* %140) %141 = getelementptr %array, %array* %131, i32 0, i32 0 store i32* null, i32** %141, align 8 - br label %ifcont27 + br label %ifcont19 -else26: ; preds = %ifcont24 - br label %ifcont27 +else18: ; preds = %ifcont16 + br label %ifcont19 -ifcont27: ; preds = %else26, %then25 +ifcont19: ; preds = %else18, %then17 call void @f(%array** %x) %142 = load %array*, %array** %x, align 8 %143 = getelementptr %array, %array* %142, i32 0, i32 0 @@ -1081,17 +1009,14 @@ ifcont27: ; preds = %else26, %then25 %145 = ptrtoint i32* %144 to i64 %146 = icmp ne i64 %145, 0 %147 = xor i1 %146, true - br i1 %147, label %then28, label %else29 + br i1 %147, label %then20, label %ifcont21 -then28: ; preds = %ifcont27 +then20: ; preds = %ifcont19 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @29, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @28, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont30 - -else29: ; preds = %ifcont27 - br label %ifcont30 + unreachable -ifcont30: ; preds = %else29, %then28 +ifcont21: ; preds = %ifcont19 %148 = getelementptr %array, %array* %142, i32 0, i32 2 %149 = load %dimension_descriptor*, %dimension_descriptor** %148, align 8 %150 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %149, i32 0 @@ -1105,17 +1030,14 @@ ifcont30: ; preds = %else29, %then28 %158 = icmp slt i32 1, %152 %159 = icmp sgt i32 1, %157 %160 = or i1 %158, %159 - br i1 %160, label %then31, label %else32 + br i1 %160, label %then22, label %ifcont23 -then31: ; preds = %ifcont30 +then22: ; preds = %ifcont21 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @31, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @30, i32 0, i32 0), i32 1, i32 1, i32 %152, i32 %157) call void @exit(i32 1) - br label %ifcont33 - -else32: ; preds = %ifcont30 - br label %ifcont33 + unreachable -ifcont33: ; preds = %else32, %then31 +ifcont23: ; preds = %ifcont21 %161 = getelementptr %dimension_descriptor, %dimension_descriptor* %150, i32 0, i32 0 %162 = load i32, i32* %161, align 4 %163 = mul i32 %162, %155 @@ -1131,17 +1053,14 @@ ifcont33: ; preds = %else32, %then31 %173 = icmp slt i32 1, %167 %174 = icmp sgt i32 1, %172 %175 = or i1 %173, %174 - br i1 %175, label %then34, label %else35 + br i1 %175, label %then24, label %ifcont25 -then34: ; preds = %ifcont33 +then24: ; preds = %ifcont23 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0), i32 1, i32 2, i32 %167, i32 %172) call void @exit(i32 1) - br label %ifcont36 + unreachable -else35: ; preds = %ifcont33 - br label %ifcont36 - -ifcont36: ; preds = %else35, %then34 +ifcont25: ; preds = %ifcont23 %176 = getelementptr %dimension_descriptor, %dimension_descriptor* %165, i32 0, i32 0 %177 = load i32, i32* %176, align 4 %178 = mul i32 %177, %170 @@ -1157,17 +1076,14 @@ ifcont36: ; preds = %else35, %then34 %188 = icmp slt i32 1, %182 %189 = icmp sgt i32 1, %187 %190 = or i1 %188, %189 - br i1 %190, label %then37, label %else38 + br i1 %190, label %then26, label %ifcont27 -then37: ; preds = %ifcont36 +then26: ; preds = %ifcont25 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @35, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @34, i32 0, i32 0), i32 1, i32 3, i32 %182, i32 %187) call void @exit(i32 1) - br label %ifcont39 - -else38: ; preds = %ifcont36 - br label %ifcont39 + unreachable -ifcont39: ; preds = %else38, %then37 +ifcont27: ; preds = %ifcont25 %191 = getelementptr %dimension_descriptor, %dimension_descriptor* %180, i32 0, i32 0 %192 = load i32, i32* %191, align 4 %193 = mul i32 %192, %185 @@ -1184,12 +1100,12 @@ ifcont39: ; preds = %else38, %then37 %203 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @serialization_info.3, i32 0, i32 0), i32 0, i32 0, i32* %202) %204 = call i64 @_lfortran_str_len(i8* %203) %205 = call i8* @_lfortran_malloc(i64 16) - %stringFormat_desc40 = bitcast i8* %205 to %string_descriptor* - %206 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc40, i32 0, i32 0 + %stringFormat_desc28 = bitcast i8* %205 to %string_descriptor* + %206 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc28, i32 0, i32 0 store i8* %203, i8** %206, align 8 - %207 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc40, i32 0, i32 1 + %207 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc28, i32 0, i32 1 store i64 %204, i64* %207, align 4 - %208 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc40, i32 0, i32 0 + %208 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc28, i32 0, i32 0 %209 = load i8*, i8** %208, align 8 call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @36, i32 0, i32 0), i8* %209, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0)) %210 = load %array*, %array** %x, align 8 @@ -1198,17 +1114,14 @@ ifcont39: ; preds = %else38, %then37 %213 = ptrtoint i32* %212 to i64 %214 = icmp ne i64 %213, 0 %215 = xor i1 %214, true - br i1 %215, label %then41, label %else42 + br i1 %215, label %then29, label %ifcont30 -then41: ; preds = %ifcont39 +then29: ; preds = %ifcont27 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @38, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @37, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont43 - -else42: ; preds = %ifcont39 - br label %ifcont43 + unreachable -ifcont43: ; preds = %else42, %then41 +ifcont30: ; preds = %ifcont27 %216 = getelementptr %array, %array* %210, i32 0, i32 2 %217 = load %dimension_descriptor*, %dimension_descriptor** %216, align 8 %218 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %217, i32 0 @@ -1222,17 +1135,14 @@ ifcont43: ; preds = %else42, %then41 %226 = icmp slt i32 1, %220 %227 = icmp sgt i32 1, %225 %228 = or i1 %226, %227 - br i1 %228, label %then44, label %else45 + br i1 %228, label %then31, label %ifcont32 -then44: ; preds = %ifcont43 +then31: ; preds = %ifcont30 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @40, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @39, i32 0, i32 0), i32 1, i32 1, i32 %220, i32 %225) call void @exit(i32 1) - br label %ifcont46 + unreachable -else45: ; preds = %ifcont43 - br label %ifcont46 - -ifcont46: ; preds = %else45, %then44 +ifcont32: ; preds = %ifcont30 %229 = getelementptr %dimension_descriptor, %dimension_descriptor* %218, i32 0, i32 0 %230 = load i32, i32* %229, align 4 %231 = mul i32 %230, %223 @@ -1248,17 +1158,14 @@ ifcont46: ; preds = %else45, %then44 %241 = icmp slt i32 1, %235 %242 = icmp sgt i32 1, %240 %243 = or i1 %241, %242 - br i1 %243, label %then47, label %else48 + br i1 %243, label %then33, label %ifcont34 -then47: ; preds = %ifcont46 +then33: ; preds = %ifcont32 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @42, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @41, i32 0, i32 0), i32 1, i32 2, i32 %235, i32 %240) call void @exit(i32 1) - br label %ifcont49 - -else48: ; preds = %ifcont46 - br label %ifcont49 + unreachable -ifcont49: ; preds = %else48, %then47 +ifcont34: ; preds = %ifcont32 %244 = getelementptr %dimension_descriptor, %dimension_descriptor* %233, i32 0, i32 0 %245 = load i32, i32* %244, align 4 %246 = mul i32 %245, %238 @@ -1274,17 +1181,14 @@ ifcont49: ; preds = %else48, %then47 %256 = icmp slt i32 1, %250 %257 = icmp sgt i32 1, %255 %258 = or i1 %256, %257 - br i1 %258, label %then50, label %else51 + br i1 %258, label %then35, label %ifcont36 -then50: ; preds = %ifcont49 +then35: ; preds = %ifcont34 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @44, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @43, i32 0, i32 0), i32 1, i32 3, i32 %250, i32 %255) call void @exit(i32 1) - br label %ifcont52 + unreachable -else51: ; preds = %ifcont49 - br label %ifcont52 - -ifcont52: ; preds = %else51, %then50 +ifcont36: ; preds = %ifcont34 %259 = getelementptr %dimension_descriptor, %dimension_descriptor* %248, i32 0, i32 0 %260 = load i32, i32* %259, align 4 %261 = mul i32 %260, %253 @@ -1297,36 +1201,33 @@ ifcont52: ; preds = %else51, %then50 %268 = getelementptr inbounds i32, i32* %267, i32 %265 %269 = load i32, i32* %268, align 4 %270 = icmp ne i32 %269, 99 - br i1 %270, label %then53, label %else54 + br i1 %270, label %then37, label %else38 -then53: ; preds = %ifcont52 +then37: ; preds = %ifcont36 %271 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.5, i32 0, i32 0), align 8 %272 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.7, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @45, i32 0, i32 0), i8* %271, i8* %272) call void @exit(i32 1) - br label %ifcont55 + br label %ifcont39 -else54: ; preds = %ifcont52 - br label %ifcont55 +else38: ; preds = %ifcont36 + br label %ifcont39 -ifcont55: ; preds = %else54, %then53 +ifcont39: ; preds = %else38, %then37 %273 = load %array*, %array** %x, align 8 %274 = getelementptr %array, %array* %273, i32 0, i32 0 %275 = load i32*, i32** %274, align 8 %276 = ptrtoint i32* %275 to i64 %277 = icmp ne i64 %276, 0 %278 = xor i1 %277, true - br i1 %278, label %then56, label %else57 + br i1 %278, label %then40, label %ifcont41 -then56: ; preds = %ifcont55 +then40: ; preds = %ifcont39 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont58 + unreachable -else57: ; preds = %ifcont55 - br label %ifcont58 - -ifcont58: ; preds = %else57, %then56 +ifcont41: ; preds = %ifcont39 %279 = getelementptr %array, %array* %273, i32 0, i32 2 %280 = load %dimension_descriptor*, %dimension_descriptor** %279, align 8 %281 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %280, i32 0 @@ -1340,17 +1241,14 @@ ifcont58: ; preds = %else57, %then56 %289 = icmp slt i32 1, %283 %290 = icmp sgt i32 1, %288 %291 = or i1 %289, %290 - br i1 %291, label %then59, label %else60 + br i1 %291, label %then42, label %ifcont43 -then59: ; preds = %ifcont58 +then42: ; preds = %ifcont41 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 1, i32 1, i32 %283, i32 %288) call void @exit(i32 1) - br label %ifcont61 - -else60: ; preds = %ifcont58 - br label %ifcont61 + unreachable -ifcont61: ; preds = %else60, %then59 +ifcont43: ; preds = %ifcont41 %292 = getelementptr %dimension_descriptor, %dimension_descriptor* %281, i32 0, i32 0 %293 = load i32, i32* %292, align 4 %294 = mul i32 %293, %286 @@ -1366,17 +1264,14 @@ ifcont61: ; preds = %else60, %then59 %304 = icmp slt i32 1, %298 %305 = icmp sgt i32 1, %303 %306 = or i1 %304, %305 - br i1 %306, label %then62, label %else63 + br i1 %306, label %then44, label %ifcont45 -then62: ; preds = %ifcont61 +then44: ; preds = %ifcont43 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @51, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @50, i32 0, i32 0), i32 1, i32 2, i32 %298, i32 %303) call void @exit(i32 1) - br label %ifcont64 - -else63: ; preds = %ifcont61 - br label %ifcont64 + unreachable -ifcont64: ; preds = %else63, %then62 +ifcont45: ; preds = %ifcont43 %307 = getelementptr %dimension_descriptor, %dimension_descriptor* %296, i32 0, i32 0 %308 = load i32, i32* %307, align 4 %309 = mul i32 %308, %301 @@ -1392,17 +1287,14 @@ ifcont64: ; preds = %else63, %then62 %319 = icmp slt i32 1, %313 %320 = icmp sgt i32 1, %318 %321 = or i1 %319, %320 - br i1 %321, label %then65, label %else66 + br i1 %321, label %then46, label %ifcont47 -then65: ; preds = %ifcont64 +then46: ; preds = %ifcont45 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @53, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @52, i32 0, i32 0), i32 1, i32 3, i32 %313, i32 %318) call void @exit(i32 1) - br label %ifcont67 + unreachable -else66: ; preds = %ifcont64 - br label %ifcont67 - -ifcont67: ; preds = %else66, %then65 +ifcont47: ; preds = %ifcont45 %322 = getelementptr %dimension_descriptor, %dimension_descriptor* %311, i32 0, i32 0 %323 = load i32, i32* %322, align 4 %324 = mul i32 %323, %316 @@ -1417,7 +1309,7 @@ ifcont67: ; preds = %else66, %then65 store i32 0, i32* %r, align 4 br label %return -return: ; preds = %ifcont67 +return: ; preds = %ifcont47 %332 = load i32, i32* %r, align 4 ret i32 %332 } @@ -1473,17 +1365,14 @@ ifcont3: ; preds = %else2, %then1 %22 = ptrtoint i32* %21 to i64 %23 = icmp ne i64 %22, 0 %24 = xor i1 %23, true - br i1 %24, label %then4, label %else5 + br i1 %24, label %then4, label %ifcont5 then4: ; preds = %ifcont3 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont6 - -else5: ; preds = %ifcont3 - br label %ifcont6 + unreachable -ifcont6: ; preds = %else5, %then4 +ifcont5: ; preds = %ifcont3 %25 = getelementptr %array, %array* %19, i32 0, i32 2 %26 = load %dimension_descriptor*, %dimension_descriptor** %25, align 8 %27 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %26, i32 0 @@ -1497,17 +1386,14 @@ ifcont6: ; preds = %else5, %then4 %35 = icmp slt i32 1, %29 %36 = icmp sgt i32 1, %34 %37 = or i1 %35, %36 - br i1 %37, label %then7, label %else8 + br i1 %37, label %then6, label %ifcont7 -then7: ; preds = %ifcont6 +then6: ; preds = %ifcont5 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 1, i32 1, i32 %29, i32 %34) call void @exit(i32 1) - br label %ifcont9 - -else8: ; preds = %ifcont6 - br label %ifcont9 + unreachable -ifcont9: ; preds = %else8, %then7 +ifcont7: ; preds = %ifcont5 %38 = getelementptr %dimension_descriptor, %dimension_descriptor* %27, i32 0, i32 0 %39 = load i32, i32* %38, align 4 %40 = mul i32 %39, %32 @@ -1523,17 +1409,14 @@ ifcont9: ; preds = %else8, %then7 %50 = icmp slt i32 1, %44 %51 = icmp sgt i32 1, %49 %52 = or i1 %50, %51 - br i1 %52, label %then10, label %else11 + br i1 %52, label %then8, label %ifcont9 -then10: ; preds = %ifcont9 +then8: ; preds = %ifcont7 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 1, i32 2, i32 %44, i32 %49) call void @exit(i32 1) - br label %ifcont12 - -else11: ; preds = %ifcont9 - br label %ifcont12 + unreachable -ifcont12: ; preds = %else11, %then10 +ifcont9: ; preds = %ifcont7 %53 = getelementptr %dimension_descriptor, %dimension_descriptor* %42, i32 0, i32 0 %54 = load i32, i32* %53, align 4 %55 = mul i32 %54, %47 @@ -1549,17 +1432,14 @@ ifcont12: ; preds = %else11, %then10 %65 = icmp slt i32 1, %59 %66 = icmp sgt i32 1, %64 %67 = or i1 %65, %66 - br i1 %67, label %then13, label %else14 + br i1 %67, label %then10, label %ifcont11 -then13: ; preds = %ifcont12 +then10: ; preds = %ifcont9 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 1, i32 3, i32 %59, i32 %64) call void @exit(i32 1) - br label %ifcont15 - -else14: ; preds = %ifcont12 - br label %ifcont15 + unreachable -ifcont15: ; preds = %else14, %then13 +ifcont11: ; preds = %ifcont9 %68 = getelementptr %dimension_descriptor, %dimension_descriptor* %57, i32 0, i32 0 %69 = load i32, i32* %68, align 4 %70 = mul i32 %69, %62 @@ -1590,17 +1470,14 @@ ifcont15: ; preds = %else14, %then13 %90 = ptrtoint i32* %89 to i64 %91 = icmp ne i64 %90, 0 %92 = xor i1 %91, true - br i1 %92, label %then16, label %else17 + br i1 %92, label %then12, label %ifcont13 -then16: ; preds = %ifcont15 +then12: ; preds = %ifcont11 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @66, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @65, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont18 - -else17: ; preds = %ifcont15 - br label %ifcont18 + unreachable -ifcont18: ; preds = %else17, %then16 +ifcont13: ; preds = %ifcont11 %93 = getelementptr %array, %array* %87, i32 0, i32 2 %94 = load %dimension_descriptor*, %dimension_descriptor** %93, align 8 %95 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %94, i32 0 @@ -1614,17 +1491,14 @@ ifcont18: ; preds = %else17, %then16 %103 = icmp slt i32 1, %97 %104 = icmp sgt i32 1, %102 %105 = or i1 %103, %104 - br i1 %105, label %then19, label %else20 + br i1 %105, label %then14, label %ifcont15 -then19: ; preds = %ifcont18 +then14: ; preds = %ifcont13 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @68, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @67, i32 0, i32 0), i32 1, i32 1, i32 %97, i32 %102) call void @exit(i32 1) - br label %ifcont21 - -else20: ; preds = %ifcont18 - br label %ifcont21 + unreachable -ifcont21: ; preds = %else20, %then19 +ifcont15: ; preds = %ifcont13 %106 = getelementptr %dimension_descriptor, %dimension_descriptor* %95, i32 0, i32 0 %107 = load i32, i32* %106, align 4 %108 = mul i32 %107, %100 @@ -1640,17 +1514,14 @@ ifcont21: ; preds = %else20, %then19 %118 = icmp slt i32 1, %112 %119 = icmp sgt i32 1, %117 %120 = or i1 %118, %119 - br i1 %120, label %then22, label %else23 + br i1 %120, label %then16, label %ifcont17 -then22: ; preds = %ifcont21 +then16: ; preds = %ifcont15 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @69, i32 0, i32 0), i32 1, i32 2, i32 %112, i32 %117) call void @exit(i32 1) - br label %ifcont24 - -else23: ; preds = %ifcont21 - br label %ifcont24 + unreachable -ifcont24: ; preds = %else23, %then22 +ifcont17: ; preds = %ifcont15 %121 = getelementptr %dimension_descriptor, %dimension_descriptor* %110, i32 0, i32 0 %122 = load i32, i32* %121, align 4 %123 = mul i32 %122, %115 @@ -1666,17 +1537,14 @@ ifcont24: ; preds = %else23, %then22 %133 = icmp slt i32 1, %127 %134 = icmp sgt i32 1, %132 %135 = or i1 %133, %134 - br i1 %135, label %then25, label %else26 + br i1 %135, label %then18, label %ifcont19 -then25: ; preds = %ifcont24 +then18: ; preds = %ifcont17 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @72, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @71, i32 0, i32 0), i32 1, i32 3, i32 %127, i32 %132) call void @exit(i32 1) - br label %ifcont27 + unreachable -else26: ; preds = %ifcont24 - br label %ifcont27 - -ifcont27: ; preds = %else26, %then25 +ifcont19: ; preds = %ifcont17 %136 = getelementptr %dimension_descriptor, %dimension_descriptor* %125, i32 0, i32 0 %137 = load i32, i32* %136, align 4 %138 = mul i32 %137, %130 @@ -1689,36 +1557,33 @@ ifcont27: ; preds = %else26, %then25 %145 = getelementptr inbounds i32, i32* %144, i32 %142 %146 = load i32, i32* %145, align 4 %147 = icmp ne i32 %146, 99 - br i1 %147, label %then28, label %else29 + br i1 %147, label %then20, label %else21 -then28: ; preds = %ifcont27 +then20: ; preds = %ifcont19 %148 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 %149 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @73, i32 0, i32 0), i8* %148, i8* %149) call void @exit(i32 1) - br label %ifcont30 + br label %ifcont22 -else29: ; preds = %ifcont27 - br label %ifcont30 +else21: ; preds = %ifcont19 + br label %ifcont22 -ifcont30: ; preds = %else29, %then28 +ifcont22: ; preds = %else21, %then20 %150 = load %array*, %array** %c, align 8 %151 = getelementptr %array, %array* %150, i32 0, i32 0 %152 = load i32*, i32** %151, align 8 %153 = ptrtoint i32* %152 to i64 %154 = icmp ne i64 %153, 0 %155 = xor i1 %154, true - br i1 %155, label %then31, label %else32 + br i1 %155, label %then23, label %ifcont24 -then31: ; preds = %ifcont30 +then23: ; preds = %ifcont22 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0)) call void @exit(i32 1) - br label %ifcont33 - -else32: ; preds = %ifcont30 - br label %ifcont33 + unreachable -ifcont33: ; preds = %else32, %then31 +ifcont24: ; preds = %ifcont22 %156 = getelementptr %array, %array* %150, i32 0, i32 2 %157 = load %dimension_descriptor*, %dimension_descriptor** %156, align 8 %158 = getelementptr inbounds %dimension_descriptor, %dimension_descriptor* %157, i32 0 @@ -1732,17 +1597,14 @@ ifcont33: ; preds = %else32, %then31 %166 = icmp slt i32 1, %160 %167 = icmp sgt i32 1, %165 %168 = or i1 %166, %167 - br i1 %168, label %then34, label %else35 + br i1 %168, label %then25, label %ifcont26 -then34: ; preds = %ifcont33 +then25: ; preds = %ifcont24 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @77, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @76, i32 0, i32 0), i32 1, i32 1, i32 %160, i32 %165) call void @exit(i32 1) - br label %ifcont36 + unreachable -else35: ; preds = %ifcont33 - br label %ifcont36 - -ifcont36: ; preds = %else35, %then34 +ifcont26: ; preds = %ifcont24 %169 = getelementptr %dimension_descriptor, %dimension_descriptor* %158, i32 0, i32 0 %170 = load i32, i32* %169, align 4 %171 = mul i32 %170, %163 @@ -1758,17 +1620,14 @@ ifcont36: ; preds = %else35, %then34 %181 = icmp slt i32 1, %175 %182 = icmp sgt i32 1, %180 %183 = or i1 %181, %182 - br i1 %183, label %then37, label %else38 + br i1 %183, label %then27, label %ifcont28 -then37: ; preds = %ifcont36 +then27: ; preds = %ifcont26 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @79, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @78, i32 0, i32 0), i32 1, i32 2, i32 %175, i32 %180) call void @exit(i32 1) - br label %ifcont39 - -else38: ; preds = %ifcont36 - br label %ifcont39 + unreachable -ifcont39: ; preds = %else38, %then37 +ifcont28: ; preds = %ifcont26 %184 = getelementptr %dimension_descriptor, %dimension_descriptor* %173, i32 0, i32 0 %185 = load i32, i32* %184, align 4 %186 = mul i32 %185, %178 @@ -1784,17 +1643,14 @@ ifcont39: ; preds = %else38, %then37 %196 = icmp slt i32 1, %190 %197 = icmp sgt i32 1, %195 %198 = or i1 %196, %197 - br i1 %198, label %then40, label %else41 + br i1 %198, label %then29, label %ifcont30 -then40: ; preds = %ifcont39 +then29: ; preds = %ifcont28 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @81, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @80, i32 0, i32 0), i32 1, i32 3, i32 %190, i32 %195) call void @exit(i32 1) - br label %ifcont42 - -else41: ; preds = %ifcont39 - br label %ifcont42 + unreachable -ifcont42: ; preds = %else41, %then40 +ifcont30: ; preds = %ifcont28 %199 = getelementptr %dimension_descriptor, %dimension_descriptor* %188, i32 0, i32 0 %200 = load i32, i32* %199, align 4 %201 = mul i32 %200, %193 @@ -1808,7 +1664,7 @@ ifcont42: ; preds = %else41, %then40 store i32 8, i32* %208, align 4 br label %return -return: ; preds = %ifcont42 +return: ; preds = %ifcont30 ret void } diff --git a/tests/reference/llvm-arrays_01-91893af.json b/tests/reference/llvm-arrays_01-91893af.json index 3031d65c27d..c62974f1ed3 100644 --- a/tests/reference/llvm-arrays_01-91893af.json +++ b/tests/reference/llvm-arrays_01-91893af.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01-91893af.stdout", - "stdout_hash": "7e6eaf20854bb55c7e2206f4019bd183338fb937cc68c2dc25149b86", + "stdout_hash": "5f05220edae4b1bece7a84f323f59b95a4efd7819f9b3020b6dc375f", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01-91893af.stdout b/tests/reference/llvm-arrays_01-91893af.stdout index fcf3db18f55..fb5ddce46bd 100644 --- a/tests/reference/llvm-arrays_01-91893af.stdout +++ b/tests/reference/llvm-arrays_01-91893af.stdout @@ -137,17 +137,14 @@ loop.body: ; preds = %loop.head %11 = icmp slt i32 %7, 1 %12 = icmp sgt i32 %7, 3 %13 = or i1 %11, %12 - br i1 %13, label %then, label %else + br i1 %13, label %then, label %ifcont then: ; preds = %loop.body call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 %7, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont + unreachable -else: ; preds = %loop.body - br label %ifcont - -ifcont: ; preds = %else, %then +ifcont: ; preds = %loop.body %14 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %10 %15 = load i32, i32* %i1, align 4 %16 = add i32 %15, 10 @@ -155,97 +152,88 @@ ifcont: ; preds = %else, %then br label %loop.head loop.end: ; preds = %loop.head - br i1 false, label %then2, label %else3 + br i1 false, label %then2, label %ifcont3 then2: ; preds = %loop.end call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont4 - -else3: ; preds = %loop.end - br label %ifcont4 + unreachable -ifcont4: ; preds = %else3, %then2 +ifcont3: ; preds = %loop.end %17 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 %18 = load i32, i32* %17, align 4 %19 = icmp ne i32 %18, 11 - br i1 %19, label %then5, label %else6 + br i1 %19, label %then4, label %else -then5: ; preds = %ifcont4 +then4: ; preds = %ifcont3 %20 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 %21 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %20, i8* %21) call void @exit(i32 1) - br label %ifcont7 + br label %ifcont5 -else6: ; preds = %ifcont4 - br label %ifcont7 +else: ; preds = %ifcont3 + br label %ifcont5 -ifcont7: ; preds = %else6, %then5 - br i1 false, label %then8, label %else9 +ifcont5: ; preds = %else, %then4 + br i1 false, label %then6, label %ifcont7 -then8: ; preds = %ifcont7 +then6: ; preds = %ifcont5 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @5, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont10 + unreachable -else9: ; preds = %ifcont7 - br label %ifcont10 - -ifcont10: ; preds = %else9, %then8 +ifcont7: ; preds = %ifcont5 %22 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 1 %23 = load i32, i32* %22, align 4 %24 = icmp ne i32 %23, 12 - br i1 %24, label %then11, label %else12 + br i1 %24, label %then8, label %else9 -then11: ; preds = %ifcont10 +then8: ; preds = %ifcont7 %25 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 %26 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %25, i8* %26) call void @exit(i32 1) - br label %ifcont13 + br label %ifcont10 -else12: ; preds = %ifcont10 - br label %ifcont13 +else9: ; preds = %ifcont7 + br label %ifcont10 -ifcont13: ; preds = %else12, %then11 - br i1 false, label %then14, label %else15 +ifcont10: ; preds = %else9, %then8 + br i1 false, label %then11, label %ifcont12 -then14: ; preds = %ifcont13 +then11: ; preds = %ifcont10 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @9, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @8, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont16 - -else15: ; preds = %ifcont13 - br label %ifcont16 + unreachable -ifcont16: ; preds = %else15, %then14 +ifcont12: ; preds = %ifcont10 %27 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 2 %28 = load i32, i32* %27, align 4 %29 = icmp ne i32 %28, 13 - br i1 %29, label %then17, label %else18 + br i1 %29, label %then13, label %else14 -then17: ; preds = %ifcont16 +then13: ; preds = %ifcont12 %30 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 %31 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %30, i8* %31) call void @exit(i32 1) - br label %ifcont19 + br label %ifcont15 -else18: ; preds = %ifcont16 - br label %ifcont19 +else14: ; preds = %ifcont12 + br label %ifcont15 -ifcont19: ; preds = %else18, %then17 +ifcont15: ; preds = %else14, %then13 store i32 10, i32* %i1, align 4 - br label %loop.head20 + br label %loop.head16 -loop.head20: ; preds = %ifcont24, %ifcont19 +loop.head16: ; preds = %ifcont19, %ifcont15 %32 = load i32, i32* %i1, align 4 %33 = add i32 %32, 1 %34 = icmp sle i32 %33, 14 - br i1 %34, label %loop.body21, label %loop.end25 + br i1 %34, label %loop.body17, label %loop.end20 -loop.body21: ; preds = %loop.head20 +loop.body17: ; preds = %loop.head16 %35 = load i32, i32* %i1, align 4 %36 = add i32 %35, 1 store i32 %36, i32* %i1, align 4 @@ -257,141 +245,126 @@ loop.body21: ; preds = %loop.head20 %42 = icmp slt i32 %38, 1 %43 = icmp sgt i32 %38, 4 %44 = or i1 %42, %43 - br i1 %44, label %then22, label %else23 + br i1 %44, label %then18, label %ifcont19 -then22: ; preds = %loop.body21 +then18: ; preds = %loop.body17 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i32 %38, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont24 + unreachable -else23: ; preds = %loop.body21 - br label %ifcont24 - -ifcont24: ; preds = %else23, %then22 +ifcont19: ; preds = %loop.body17 %45 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %41 %46 = load i32, i32* %i1, align 4 store i32 %46, i32* %45, align 4 - br label %loop.head20 + br label %loop.head16 -loop.end25: ; preds = %loop.head20 - br i1 false, label %then26, label %else27 +loop.end20: ; preds = %loop.head16 + br i1 false, label %then21, label %ifcont22 -then26: ; preds = %loop.end25 +then21: ; preds = %loop.end20 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont28 - -else27: ; preds = %loop.end25 - br label %ifcont28 + unreachable -ifcont28: ; preds = %else27, %then26 +ifcont22: ; preds = %loop.end20 %47 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 %48 = load i32, i32* %47, align 4 %49 = icmp ne i32 %48, 11 - br i1 %49, label %then29, label %else30 + br i1 %49, label %then23, label %else24 -then29: ; preds = %ifcont28 +then23: ; preds = %ifcont22 %50 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 %51 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %50, i8* %51) call void @exit(i32 1) - br label %ifcont31 + br label %ifcont25 -else30: ; preds = %ifcont28 - br label %ifcont31 +else24: ; preds = %ifcont22 + br label %ifcont25 -ifcont31: ; preds = %else30, %then29 - br i1 false, label %then32, label %else33 +ifcont25: ; preds = %else24, %then23 + br i1 false, label %then26, label %ifcont27 -then32: ; preds = %ifcont31 +then26: ; preds = %ifcont25 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @16, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont34 + unreachable -else33: ; preds = %ifcont31 - br label %ifcont34 - -ifcont34: ; preds = %else33, %then32 +ifcont27: ; preds = %ifcont25 %52 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 %53 = load i32, i32* %52, align 4 %54 = icmp ne i32 %53, 12 - br i1 %54, label %then35, label %else36 + br i1 %54, label %then28, label %else29 -then35: ; preds = %ifcont34 +then28: ; preds = %ifcont27 %55 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 %56 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @18, i32 0, i32 0), i8* %55, i8* %56) call void @exit(i32 1) - br label %ifcont37 + br label %ifcont30 -else36: ; preds = %ifcont34 - br label %ifcont37 +else29: ; preds = %ifcont27 + br label %ifcont30 -ifcont37: ; preds = %else36, %then35 - br i1 false, label %then38, label %else39 +ifcont30: ; preds = %else29, %then28 + br i1 false, label %then31, label %ifcont32 -then38: ; preds = %ifcont37 +then31: ; preds = %ifcont30 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont40 - -else39: ; preds = %ifcont37 - br label %ifcont40 + unreachable -ifcont40: ; preds = %else39, %then38 +ifcont32: ; preds = %ifcont30 %57 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 %58 = load i32, i32* %57, align 4 %59 = icmp ne i32 %58, 13 - br i1 %59, label %then41, label %else42 + br i1 %59, label %then33, label %else34 -then41: ; preds = %ifcont40 +then33: ; preds = %ifcont32 %60 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 %61 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @21, i32 0, i32 0), i8* %60, i8* %61) call void @exit(i32 1) - br label %ifcont43 + br label %ifcont35 -else42: ; preds = %ifcont40 - br label %ifcont43 +else34: ; preds = %ifcont32 + br label %ifcont35 -ifcont43: ; preds = %else42, %then41 - br i1 false, label %then44, label %else45 +ifcont35: ; preds = %else34, %then33 + br i1 false, label %then36, label %ifcont37 -then44: ; preds = %ifcont43 +then36: ; preds = %ifcont35 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @22, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont46 - -else45: ; preds = %ifcont43 - br label %ifcont46 + unreachable -ifcont46: ; preds = %else45, %then44 +ifcont37: ; preds = %ifcont35 %62 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 %63 = load i32, i32* %62, align 4 %64 = icmp ne i32 %63, 14 - br i1 %64, label %then47, label %else48 + br i1 %64, label %then38, label %else39 -then47: ; preds = %ifcont46 +then38: ; preds = %ifcont37 %65 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 %66 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @24, i32 0, i32 0), i8* %65, i8* %66) call void @exit(i32 1) - br label %ifcont49 + br label %ifcont40 -else48: ; preds = %ifcont46 - br label %ifcont49 +else39: ; preds = %ifcont37 + br label %ifcont40 -ifcont49: ; preds = %else48, %then47 +ifcont40: ; preds = %else39, %then38 store i32 0, i32* %i1, align 4 - br label %loop.head50 + br label %loop.head41 -loop.head50: ; preds = %ifcont57, %ifcont49 +loop.head41: ; preds = %ifcont46, %ifcont40 %67 = load i32, i32* %i1, align 4 %68 = add i32 %67, 1 %69 = icmp sle i32 %68, 3 - br i1 %69, label %loop.body51, label %loop.end58 + br i1 %69, label %loop.body42, label %loop.end47 -loop.body51: ; preds = %loop.head50 +loop.body42: ; preds = %loop.head41 %70 = load i32, i32* %i1, align 4 %71 = add i32 %70, 1 store i32 %71, i32* %i1, align 4 @@ -402,17 +375,14 @@ loop.body51: ; preds = %loop.head50 %76 = icmp slt i32 %72, 1 %77 = icmp sgt i32 %72, 4 %78 = or i1 %76, %77 - br i1 %78, label %then52, label %else53 + br i1 %78, label %then43, label %ifcont44 -then52: ; preds = %loop.body51 +then43: ; preds = %loop.body42 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @26, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @25, i32 0, i32 0), i32 %72, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont54 + unreachable -else53: ; preds = %loop.body51 - br label %ifcont54 - -ifcont54: ; preds = %else53, %then52 +ifcont44: ; preds = %loop.body42 %79 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %75 %80 = load i32, i32* %i1, align 4 %81 = sub i32 %80, 1 @@ -421,257 +391,218 @@ ifcont54: ; preds = %else53, %then52 %84 = icmp slt i32 %80, 1 %85 = icmp sgt i32 %80, 3 %86 = or i1 %84, %85 - br i1 %86, label %then55, label %else56 + br i1 %86, label %then45, label %ifcont46 -then55: ; preds = %ifcont54 +then45: ; preds = %ifcont44 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %80, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont57 - -else56: ; preds = %ifcont54 - br label %ifcont57 + unreachable -ifcont57: ; preds = %else56, %then55 +ifcont46: ; preds = %ifcont44 %87 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %83 %88 = load i32, i32* %87, align 4 %89 = sub i32 %88, 10 store i32 %89, i32* %79, align 4 - br label %loop.head50 + br label %loop.head41 -loop.end58: ; preds = %loop.head50 - br i1 false, label %then59, label %else60 +loop.end47: ; preds = %loop.head41 + br i1 false, label %then48, label %ifcont49 -then59: ; preds = %loop.end58 +then48: ; preds = %loop.end47 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont61 - -else60: ; preds = %loop.end58 - br label %ifcont61 + unreachable -ifcont61: ; preds = %else60, %then59 +ifcont49: ; preds = %loop.end47 %90 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 %91 = load i32, i32* %90, align 4 %92 = icmp ne i32 %91, 1 - br i1 %92, label %then62, label %else63 + br i1 %92, label %then50, label %else51 -then62: ; preds = %ifcont61 +then50: ; preds = %ifcont49 %93 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 %94 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @31, i32 0, i32 0), i8* %93, i8* %94) call void @exit(i32 1) - br label %ifcont64 + br label %ifcont52 -else63: ; preds = %ifcont61 - br label %ifcont64 +else51: ; preds = %ifcont49 + br label %ifcont52 -ifcont64: ; preds = %else63, %then62 - br i1 false, label %then65, label %else66 +ifcont52: ; preds = %else51, %then50 + br i1 false, label %then53, label %ifcont54 -then65: ; preds = %ifcont64 +then53: ; preds = %ifcont52 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont67 - -else66: ; preds = %ifcont64 - br label %ifcont67 + unreachable -ifcont67: ; preds = %else66, %then65 +ifcont54: ; preds = %ifcont52 %95 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 %96 = load i32, i32* %95, align 4 %97 = icmp ne i32 %96, 2 - br i1 %97, label %then68, label %else69 + br i1 %97, label %then55, label %else56 -then68: ; preds = %ifcont67 +then55: ; preds = %ifcont54 %98 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 %99 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @34, i32 0, i32 0), i8* %98, i8* %99) call void @exit(i32 1) - br label %ifcont70 + br label %ifcont57 -else69: ; preds = %ifcont67 - br label %ifcont70 +else56: ; preds = %ifcont54 + br label %ifcont57 -ifcont70: ; preds = %else69, %then68 - br i1 false, label %then71, label %else72 +ifcont57: ; preds = %else56, %then55 + br i1 false, label %then58, label %ifcont59 -then71: ; preds = %ifcont70 +then58: ; preds = %ifcont57 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont73 - -else72: ; preds = %ifcont70 - br label %ifcont73 + unreachable -ifcont73: ; preds = %else72, %then71 +ifcont59: ; preds = %ifcont57 %100 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 %101 = load i32, i32* %100, align 4 %102 = icmp ne i32 %101, 3 - br i1 %102, label %then74, label %else75 + br i1 %102, label %then60, label %else61 -then74: ; preds = %ifcont73 +then60: ; preds = %ifcont59 %103 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 %104 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @37, i32 0, i32 0), i8* %103, i8* %104) call void @exit(i32 1) - br label %ifcont76 + br label %ifcont62 -else75: ; preds = %ifcont73 - br label %ifcont76 +else61: ; preds = %ifcont59 + br label %ifcont62 -ifcont76: ; preds = %else75, %then74 - br i1 false, label %then77, label %else78 +ifcont62: ; preds = %else61, %then60 + br i1 false, label %then63, label %ifcont64 -then77: ; preds = %ifcont76 +then63: ; preds = %ifcont62 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @39, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @38, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont79 + unreachable -else78: ; preds = %ifcont76 - br label %ifcont79 - -ifcont79: ; preds = %else78, %then77 +ifcont64: ; preds = %ifcont62 %105 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - br i1 false, label %then80, label %else81 + br i1 false, label %then65, label %ifcont66 -then80: ; preds = %ifcont79 +then65: ; preds = %ifcont64 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont82 - -else81: ; preds = %ifcont79 - br label %ifcont82 + unreachable -ifcont82: ; preds = %else81, %then80 +ifcont66: ; preds = %ifcont64 %106 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 %107 = load i32, i32* %106, align 4 - br i1 false, label %then83, label %else84 + br i1 false, label %then67, label %ifcont68 -then83: ; preds = %ifcont82 +then67: ; preds = %ifcont66 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @43, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @42, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont85 + unreachable -else84: ; preds = %ifcont82 - br label %ifcont85 - -ifcont85: ; preds = %else84, %then83 +ifcont68: ; preds = %ifcont66 %108 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 %109 = load i32, i32* %108, align 4 %110 = add i32 %107, %109 - br i1 false, label %then86, label %else87 + br i1 false, label %then69, label %ifcont70 -then86: ; preds = %ifcont85 +then69: ; preds = %ifcont68 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @44, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont88 - -else87: ; preds = %ifcont85 - br label %ifcont88 + unreachable -ifcont88: ; preds = %else87, %then86 +ifcont70: ; preds = %ifcont68 %111 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 %112 = load i32, i32* %111, align 4 %113 = add i32 %110, %112 - br i1 false, label %then89, label %else90 + br i1 false, label %then71, label %ifcont72 -then89: ; preds = %ifcont88 +then71: ; preds = %ifcont70 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont91 - -else90: ; preds = %ifcont88 - br label %ifcont91 + unreachable -ifcont91: ; preds = %else90, %then89 +ifcont72: ; preds = %ifcont70 %114 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 %115 = load i32, i32* %114, align 4 %116 = add i32 %113, %115 store i32 %116, i32* %105, align 4 - br i1 false, label %then92, label %else93 + br i1 false, label %then73, label %ifcont74 -then92: ; preds = %ifcont91 +then73: ; preds = %ifcont72 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont94 + unreachable -else93: ; preds = %ifcont91 - br label %ifcont94 - -ifcont94: ; preds = %else93, %then92 +ifcont74: ; preds = %ifcont72 %117 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 %118 = load i32, i32* %117, align 4 %119 = icmp ne i32 %118, 17 - br i1 %119, label %then95, label %else96 + br i1 %119, label %then75, label %else76 -then95: ; preds = %ifcont94 +then75: ; preds = %ifcont74 %120 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 %121 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @50, i32 0, i32 0), i8* %120, i8* %121) call void @exit(i32 1) - br label %ifcont97 + br label %ifcont77 -else96: ; preds = %ifcont94 - br label %ifcont97 +else76: ; preds = %ifcont74 + br label %ifcont77 -ifcont97: ; preds = %else96, %then95 - br i1 false, label %then98, label %else99 +ifcont77: ; preds = %else76, %then75 + br i1 false, label %then78, label %ifcont79 -then98: ; preds = %ifcont97 +then78: ; preds = %ifcont77 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont100 - -else99: ; preds = %ifcont97 - br label %ifcont100 + unreachable -ifcont100: ; preds = %else99, %then98 +ifcont79: ; preds = %ifcont77 %122 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - br i1 false, label %then101, label %else102 + br i1 false, label %then80, label %ifcont81 -then101: ; preds = %ifcont100 +then80: ; preds = %ifcont79 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont103 - -else102: ; preds = %ifcont100 - br label %ifcont103 + unreachable -ifcont103: ; preds = %else102, %then101 +ifcont81: ; preds = %ifcont79 %123 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 %124 = load i32, i32* %123, align 4 store i32 %124, i32* %122, align 4 - br i1 false, label %then104, label %else105 + br i1 false, label %then82, label %ifcont83 -then104: ; preds = %ifcont103 +then82: ; preds = %ifcont81 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont106 - -else105: ; preds = %ifcont103 - br label %ifcont106 + unreachable -ifcont106: ; preds = %else105, %then104 +ifcont83: ; preds = %ifcont81 %125 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 %126 = load i32, i32* %125, align 4 %127 = icmp ne i32 %126, 11 - br i1 %127, label %then107, label %else108 + br i1 %127, label %then84, label %else85 -then107: ; preds = %ifcont106 +then84: ; preds = %ifcont83 %128 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 %129 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* %128, i8* %129) call void @exit(i32 1) - br label %ifcont109 + br label %ifcont86 -else108: ; preds = %ifcont106 - br label %ifcont109 +else85: ; preds = %ifcont83 + br label %ifcont86 -ifcont109: ; preds = %else108, %then107 +ifcont86: ; preds = %else85, %then84 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont109 +return: ; preds = %ifcont86 ret i32 0 } diff --git a/tests/reference/llvm-arrays_01_complex-c90dbdd.json b/tests/reference/llvm-arrays_01_complex-c90dbdd.json index a2c7844096a..7a16a696377 100644 --- a/tests/reference/llvm-arrays_01_complex-c90dbdd.json +++ b/tests/reference/llvm-arrays_01_complex-c90dbdd.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01_complex-c90dbdd.stdout", - "stdout_hash": "add8a39604ffcbebcd738b81c6eedaff27b95028aaf1aeef14ba72b0", + "stdout_hash": "a04db50617d3ed917c90cd384ea01678bc70e4114dc59204df105c29", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout b/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout index ad81718e0ee..738b0da0cb3 100644 --- a/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout +++ b/tests/reference/llvm-arrays_01_complex-c90dbdd.stdout @@ -181,17 +181,14 @@ loop.body: ; preds = %loop.head %11 = icmp slt i32 %7, 1 %12 = icmp sgt i32 %7, 3 %13 = or i1 %11, %12 - br i1 %13, label %then, label %else + br i1 %13, label %then, label %ifcont then: ; preds = %loop.body call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 %7, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont + unreachable -else: ; preds = %loop.body - br label %ifcont - -ifcont: ; preds = %else, %then +ifcont: ; preds = %loop.body %14 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 %10 %15 = load i32, i32* %i1, align 4 %16 = add i32 %15, 10 @@ -206,17 +203,14 @@ ifcont: ; preds = %else, %then br label %loop.head loop.end: ; preds = %loop.head - br i1 false, label %then3, label %else4 + br i1 false, label %then3, label %ifcont4 then3: ; preds = %loop.end call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont5 - -else4: ; preds = %loop.end - br label %ifcont5 + unreachable -ifcont5: ; preds = %else4, %then3 +ifcont4: ; preds = %loop.end %22 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 %23 = load %complex_4, %complex_4* %22, align 1 %24 = alloca %complex_4, align 8 @@ -244,30 +238,27 @@ ifcont5: ; preds = %else4, %then3 %40 = fcmp one float %30, %33 %41 = fcmp one float %36, %39 %42 = or i1 %40, %41 - br i1 %42, label %then6, label %else7 + br i1 %42, label %then5, label %else -then6: ; preds = %ifcont5 +then5: ; preds = %ifcont4 %43 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 %44 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %43, i8* %44) call void @exit(i32 1) - br label %ifcont8 + br label %ifcont6 -else7: ; preds = %ifcont5 - br label %ifcont8 +else: ; preds = %ifcont4 + br label %ifcont6 -ifcont8: ; preds = %else7, %then6 - br i1 false, label %then9, label %else10 +ifcont6: ; preds = %else, %then5 + br i1 false, label %then7, label %ifcont8 -then9: ; preds = %ifcont8 +then7: ; preds = %ifcont6 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @5, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont11 - -else10: ; preds = %ifcont8 - br label %ifcont11 + unreachable -ifcont11: ; preds = %else10, %then9 +ifcont8: ; preds = %ifcont6 %45 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 1 %46 = load %complex_4, %complex_4* %45, align 1 %47 = alloca %complex_4, align 8 @@ -295,30 +286,27 @@ ifcont11: ; preds = %else10, %then9 %63 = fcmp one float %53, %56 %64 = fcmp one float %59, %62 %65 = or i1 %63, %64 - br i1 %65, label %then12, label %else13 + br i1 %65, label %then9, label %else10 -then12: ; preds = %ifcont11 +then9: ; preds = %ifcont8 %66 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 %67 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %66, i8* %67) call void @exit(i32 1) - br label %ifcont14 + br label %ifcont11 -else13: ; preds = %ifcont11 - br label %ifcont14 +else10: ; preds = %ifcont8 + br label %ifcont11 -ifcont14: ; preds = %else13, %then12 - br i1 false, label %then15, label %else16 +ifcont11: ; preds = %else10, %then9 + br i1 false, label %then12, label %ifcont13 -then15: ; preds = %ifcont14 +then12: ; preds = %ifcont11 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @9, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @8, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont17 + unreachable -else16: ; preds = %ifcont14 - br label %ifcont17 - -ifcont17: ; preds = %else16, %then15 +ifcont13: ; preds = %ifcont11 %68 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 2 %69 = load %complex_4, %complex_4* %68, align 1 %70 = alloca %complex_4, align 8 @@ -346,29 +334,29 @@ ifcont17: ; preds = %else16, %then15 %86 = fcmp one float %76, %79 %87 = fcmp one float %82, %85 %88 = or i1 %86, %87 - br i1 %88, label %then18, label %else19 + br i1 %88, label %then14, label %else15 -then18: ; preds = %ifcont17 +then14: ; preds = %ifcont13 %89 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 %90 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %89, i8* %90) call void @exit(i32 1) - br label %ifcont20 + br label %ifcont16 -else19: ; preds = %ifcont17 - br label %ifcont20 +else15: ; preds = %ifcont13 + br label %ifcont16 -ifcont20: ; preds = %else19, %then18 +ifcont16: ; preds = %else15, %then14 store i32 10, i32* %i1, align 4 - br label %loop.head21 + br label %loop.head17 -loop.head21: ; preds = %ifcont25, %ifcont20 +loop.head17: ; preds = %ifcont20, %ifcont16 %91 = load i32, i32* %i1, align 4 %92 = add i32 %91, 1 %93 = icmp sle i32 %92, 14 - br i1 %93, label %loop.body22, label %loop.end26 + br i1 %93, label %loop.body18, label %loop.end21 -loop.body22: ; preds = %loop.head21 +loop.body18: ; preds = %loop.head17 %94 = load i32, i32* %i1, align 4 %95 = add i32 %94, 1 store i32 %95, i32* %i1, align 4 @@ -380,17 +368,14 @@ loop.body22: ; preds = %loop.head21 %101 = icmp slt i32 %97, 1 %102 = icmp sgt i32 %97, 4 %103 = or i1 %101, %102 - br i1 %103, label %then23, label %else24 + br i1 %103, label %then19, label %ifcont20 -then23: ; preds = %loop.body22 +then19: ; preds = %loop.body18 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i32 %97, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont25 - -else24: ; preds = %loop.body22 - br label %ifcont25 + unreachable -ifcont25: ; preds = %else24, %then23 +ifcont20: ; preds = %loop.body18 %104 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 %100 %105 = load i32, i32* %i1, align 4 %106 = sitofp i32 %105 to float @@ -401,20 +386,17 @@ ifcont25: ; preds = %else24, %then23 store float 0.000000e+00, float* %109, align 4 %110 = load %complex_4, %complex_4* %107, align 1 store %complex_4 %110, %complex_4* %104, align 1 - br label %loop.head21 + br label %loop.head17 -loop.end26: ; preds = %loop.head21 - br i1 false, label %then27, label %else28 +loop.end21: ; preds = %loop.head17 + br i1 false, label %then22, label %ifcont23 -then27: ; preds = %loop.end26 +then22: ; preds = %loop.end21 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont29 - -else28: ; preds = %loop.end26 - br label %ifcont29 + unreachable -ifcont29: ; preds = %else28, %then27 +ifcont23: ; preds = %loop.end21 %111 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 %112 = load %complex_4, %complex_4* %111, align 1 %113 = alloca %complex_4, align 8 @@ -442,30 +424,27 @@ ifcont29: ; preds = %else28, %then27 %129 = fcmp one float %119, %122 %130 = fcmp one float %125, %128 %131 = or i1 %129, %130 - br i1 %131, label %then30, label %else31 + br i1 %131, label %then24, label %else25 -then30: ; preds = %ifcont29 +then24: ; preds = %ifcont23 %132 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 %133 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %132, i8* %133) call void @exit(i32 1) - br label %ifcont32 + br label %ifcont26 -else31: ; preds = %ifcont29 - br label %ifcont32 +else25: ; preds = %ifcont23 + br label %ifcont26 -ifcont32: ; preds = %else31, %then30 - br i1 false, label %then33, label %else34 +ifcont26: ; preds = %else25, %then24 + br i1 false, label %then27, label %ifcont28 -then33: ; preds = %ifcont32 +then27: ; preds = %ifcont26 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @16, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont35 + unreachable -else34: ; preds = %ifcont32 - br label %ifcont35 - -ifcont35: ; preds = %else34, %then33 +ifcont28: ; preds = %ifcont26 %134 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 %135 = load %complex_4, %complex_4* %134, align 1 %136 = alloca %complex_4, align 8 @@ -493,30 +472,27 @@ ifcont35: ; preds = %else34, %then33 %152 = fcmp one float %142, %145 %153 = fcmp one float %148, %151 %154 = or i1 %152, %153 - br i1 %154, label %then36, label %else37 + br i1 %154, label %then29, label %else30 -then36: ; preds = %ifcont35 +then29: ; preds = %ifcont28 %155 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 %156 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @18, i32 0, i32 0), i8* %155, i8* %156) call void @exit(i32 1) - br label %ifcont38 + br label %ifcont31 -else37: ; preds = %ifcont35 - br label %ifcont38 +else30: ; preds = %ifcont28 + br label %ifcont31 -ifcont38: ; preds = %else37, %then36 - br i1 false, label %then39, label %else40 +ifcont31: ; preds = %else30, %then29 + br i1 false, label %then32, label %ifcont33 -then39: ; preds = %ifcont38 +then32: ; preds = %ifcont31 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont41 + unreachable -else40: ; preds = %ifcont38 - br label %ifcont41 - -ifcont41: ; preds = %else40, %then39 +ifcont33: ; preds = %ifcont31 %157 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 %158 = load %complex_4, %complex_4* %157, align 1 %159 = alloca %complex_4, align 8 @@ -544,30 +520,27 @@ ifcont41: ; preds = %else40, %then39 %175 = fcmp one float %165, %168 %176 = fcmp one float %171, %174 %177 = or i1 %175, %176 - br i1 %177, label %then42, label %else43 + br i1 %177, label %then34, label %else35 -then42: ; preds = %ifcont41 +then34: ; preds = %ifcont33 %178 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 %179 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @21, i32 0, i32 0), i8* %178, i8* %179) call void @exit(i32 1) - br label %ifcont44 + br label %ifcont36 -else43: ; preds = %ifcont41 - br label %ifcont44 +else35: ; preds = %ifcont33 + br label %ifcont36 -ifcont44: ; preds = %else43, %then42 - br i1 false, label %then45, label %else46 +ifcont36: ; preds = %else35, %then34 + br i1 false, label %then37, label %ifcont38 -then45: ; preds = %ifcont44 +then37: ; preds = %ifcont36 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @22, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont47 - -else46: ; preds = %ifcont44 - br label %ifcont47 + unreachable -ifcont47: ; preds = %else46, %then45 +ifcont38: ; preds = %ifcont36 %180 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 %181 = load %complex_4, %complex_4* %180, align 1 %182 = alloca %complex_4, align 8 @@ -595,29 +568,29 @@ ifcont47: ; preds = %else46, %then45 %198 = fcmp one float %188, %191 %199 = fcmp one float %194, %197 %200 = or i1 %198, %199 - br i1 %200, label %then48, label %else49 + br i1 %200, label %then39, label %else40 -then48: ; preds = %ifcont47 +then39: ; preds = %ifcont38 %201 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 %202 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @24, i32 0, i32 0), i8* %201, i8* %202) call void @exit(i32 1) - br label %ifcont50 + br label %ifcont41 -else49: ; preds = %ifcont47 - br label %ifcont50 +else40: ; preds = %ifcont38 + br label %ifcont41 -ifcont50: ; preds = %else49, %then48 +ifcont41: ; preds = %else40, %then39 store i32 0, i32* %i1, align 4 - br label %loop.head51 + br label %loop.head42 -loop.head51: ; preds = %ifcont58, %ifcont50 +loop.head42: ; preds = %ifcont47, %ifcont41 %203 = load i32, i32* %i1, align 4 %204 = add i32 %203, 1 %205 = icmp sle i32 %204, 3 - br i1 %205, label %loop.body52, label %loop.end59 + br i1 %205, label %loop.body43, label %loop.end48 -loop.body52: ; preds = %loop.head51 +loop.body43: ; preds = %loop.head42 %206 = load i32, i32* %i1, align 4 %207 = add i32 %206, 1 store i32 %207, i32* %i1, align 4 @@ -628,17 +601,14 @@ loop.body52: ; preds = %loop.head51 %212 = icmp slt i32 %208, 1 %213 = icmp sgt i32 %208, 4 %214 = or i1 %212, %213 - br i1 %214, label %then53, label %else54 + br i1 %214, label %then44, label %ifcont45 -then53: ; preds = %loop.body52 +then44: ; preds = %loop.body43 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @26, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @25, i32 0, i32 0), i32 %208, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont55 - -else54: ; preds = %loop.body52 - br label %ifcont55 + unreachable -ifcont55: ; preds = %else54, %then53 +ifcont45: ; preds = %loop.body43 %215 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 %211 %216 = load i32, i32* %i1, align 4 %217 = sub i32 %216, 1 @@ -647,17 +617,14 @@ ifcont55: ; preds = %else54, %then53 %220 = icmp slt i32 %216, 1 %221 = icmp sgt i32 %216, 3 %222 = or i1 %220, %221 - br i1 %222, label %then56, label %else57 + br i1 %222, label %then46, label %ifcont47 -then56: ; preds = %ifcont55 +then46: ; preds = %ifcont45 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %216, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont58 + unreachable -else57: ; preds = %ifcont55 - br label %ifcont58 - -ifcont58: ; preds = %else57, %then56 +ifcont47: ; preds = %ifcont45 %223 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 %219 %224 = load %complex_4, %complex_4* %223, align 1 %225 = alloca %complex_4, align 8 @@ -674,20 +641,17 @@ ifcont58: ; preds = %else57, %then56 call void @_lfortran_complex_sub_32(%complex_4* %229, %complex_4* %230, %complex_4* %231) %232 = load %complex_4, %complex_4* %231, align 1 store %complex_4 %232, %complex_4* %215, align 1 - br label %loop.head51 + br label %loop.head42 -loop.end59: ; preds = %loop.head51 - br i1 false, label %then60, label %else61 +loop.end48: ; preds = %loop.head42 + br i1 false, label %then49, label %ifcont50 -then60: ; preds = %loop.end59 +then49: ; preds = %loop.end48 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont62 - -else61: ; preds = %loop.end59 - br label %ifcont62 + unreachable -ifcont62: ; preds = %else61, %then60 +ifcont50: ; preds = %loop.end48 %233 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 %234 = load %complex_4, %complex_4* %233, align 1 %235 = alloca %complex_4, align 8 @@ -715,30 +679,27 @@ ifcont62: ; preds = %else61, %then60 %251 = fcmp one float %241, %244 %252 = fcmp one float %247, %250 %253 = or i1 %251, %252 - br i1 %253, label %then63, label %else64 + br i1 %253, label %then51, label %else52 -then63: ; preds = %ifcont62 +then51: ; preds = %ifcont50 %254 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 %255 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @31, i32 0, i32 0), i8* %254, i8* %255) call void @exit(i32 1) - br label %ifcont65 + br label %ifcont53 -else64: ; preds = %ifcont62 - br label %ifcont65 +else52: ; preds = %ifcont50 + br label %ifcont53 -ifcont65: ; preds = %else64, %then63 - br i1 false, label %then66, label %else67 +ifcont53: ; preds = %else52, %then51 + br i1 false, label %then54, label %ifcont55 -then66: ; preds = %ifcont65 +then54: ; preds = %ifcont53 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont68 + unreachable -else67: ; preds = %ifcont65 - br label %ifcont68 - -ifcont68: ; preds = %else67, %then66 +ifcont55: ; preds = %ifcont53 %256 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 %257 = load %complex_4, %complex_4* %256, align 1 %258 = alloca %complex_4, align 8 @@ -766,30 +727,27 @@ ifcont68: ; preds = %else67, %then66 %274 = fcmp one float %264, %267 %275 = fcmp one float %270, %273 %276 = or i1 %274, %275 - br i1 %276, label %then69, label %else70 + br i1 %276, label %then56, label %else57 -then69: ; preds = %ifcont68 +then56: ; preds = %ifcont55 %277 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 %278 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @34, i32 0, i32 0), i8* %277, i8* %278) call void @exit(i32 1) - br label %ifcont71 + br label %ifcont58 -else70: ; preds = %ifcont68 - br label %ifcont71 +else57: ; preds = %ifcont55 + br label %ifcont58 -ifcont71: ; preds = %else70, %then69 - br i1 false, label %then72, label %else73 +ifcont58: ; preds = %else57, %then56 + br i1 false, label %then59, label %ifcont60 -then72: ; preds = %ifcont71 +then59: ; preds = %ifcont58 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont74 - -else73: ; preds = %ifcont71 - br label %ifcont74 + unreachable -ifcont74: ; preds = %else73, %then72 +ifcont60: ; preds = %ifcont58 %279 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 %280 = load %complex_4, %complex_4* %279, align 1 %281 = alloca %complex_4, align 8 @@ -817,55 +775,46 @@ ifcont74: ; preds = %else73, %then72 %297 = fcmp one float %287, %290 %298 = fcmp one float %293, %296 %299 = or i1 %297, %298 - br i1 %299, label %then75, label %else76 + br i1 %299, label %then61, label %else62 -then75: ; preds = %ifcont74 +then61: ; preds = %ifcont60 %300 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 %301 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @37, i32 0, i32 0), i8* %300, i8* %301) call void @exit(i32 1) - br label %ifcont77 + br label %ifcont63 -else76: ; preds = %ifcont74 - br label %ifcont77 +else62: ; preds = %ifcont60 + br label %ifcont63 -ifcont77: ; preds = %else76, %then75 - br i1 false, label %then78, label %else79 +ifcont63: ; preds = %else62, %then61 + br i1 false, label %then64, label %ifcont65 -then78: ; preds = %ifcont77 +then64: ; preds = %ifcont63 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @39, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @38, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont80 + unreachable -else79: ; preds = %ifcont77 - br label %ifcont80 - -ifcont80: ; preds = %else79, %then78 +ifcont65: ; preds = %ifcont63 %302 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 - br i1 false, label %then81, label %else82 + br i1 false, label %then66, label %ifcont67 -then81: ; preds = %ifcont80 +then66: ; preds = %ifcont65 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont83 + unreachable -else82: ; preds = %ifcont80 - br label %ifcont83 - -ifcont83: ; preds = %else82, %then81 +ifcont67: ; preds = %ifcont65 %303 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 0 %304 = load %complex_4, %complex_4* %303, align 1 - br i1 false, label %then84, label %else85 + br i1 false, label %then68, label %ifcont69 -then84: ; preds = %ifcont83 +then68: ; preds = %ifcont67 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @43, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @42, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont86 - -else85: ; preds = %ifcont83 - br label %ifcont86 + unreachable -ifcont86: ; preds = %else85, %then84 +ifcont69: ; preds = %ifcont67 %305 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 1 %306 = load %complex_4, %complex_4* %305, align 1 %307 = alloca %complex_4, align 8 @@ -875,17 +824,14 @@ ifcont86: ; preds = %else85, %then84 %309 = alloca %complex_4, align 8 call void @_lfortran_complex_add_32(%complex_4* %307, %complex_4* %308, %complex_4* %309) %310 = load %complex_4, %complex_4* %309, align 1 - br i1 false, label %then87, label %else88 + br i1 false, label %then70, label %ifcont71 -then87: ; preds = %ifcont86 +then70: ; preds = %ifcont69 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @44, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont89 - -else88: ; preds = %ifcont86 - br label %ifcont89 + unreachable -ifcont89: ; preds = %else88, %then87 +ifcont71: ; preds = %ifcont69 %311 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 2 %312 = load %complex_4, %complex_4* %311, align 1 %313 = alloca %complex_4, align 8 @@ -895,17 +841,14 @@ ifcont89: ; preds = %else88, %then87 %315 = alloca %complex_4, align 8 call void @_lfortran_complex_add_32(%complex_4* %313, %complex_4* %314, %complex_4* %315) %316 = load %complex_4, %complex_4* %315, align 1 - br i1 false, label %then90, label %else91 + br i1 false, label %then72, label %ifcont73 -then90: ; preds = %ifcont89 +then72: ; preds = %ifcont71 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont92 - -else91: ; preds = %ifcont89 - br label %ifcont92 + unreachable -ifcont92: ; preds = %else91, %then90 +ifcont73: ; preds = %ifcont71 %317 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 %318 = load %complex_4, %complex_4* %317, align 1 %319 = alloca %complex_4, align 8 @@ -916,17 +859,14 @@ ifcont92: ; preds = %else91, %then90 call void @_lfortran_complex_add_32(%complex_4* %319, %complex_4* %320, %complex_4* %321) %322 = load %complex_4, %complex_4* %321, align 1 store %complex_4 %322, %complex_4* %302, align 1 - br i1 false, label %then93, label %else94 + br i1 false, label %then74, label %ifcont75 -then93: ; preds = %ifcont92 +then74: ; preds = %ifcont73 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont95 + unreachable -else94: ; preds = %ifcont92 - br label %ifcont95 - -ifcont95: ; preds = %else94, %then93 +ifcont75: ; preds = %ifcont73 %323 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 %324 = load %complex_4, %complex_4* %323, align 1 %325 = alloca %complex_4, align 8 @@ -954,56 +894,47 @@ ifcont95: ; preds = %else94, %then93 %341 = fcmp one float %331, %334 %342 = fcmp one float %337, %340 %343 = or i1 %341, %342 - br i1 %343, label %then96, label %else97 + br i1 %343, label %then76, label %else77 -then96: ; preds = %ifcont95 +then76: ; preds = %ifcont75 %344 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 %345 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @50, i32 0, i32 0), i8* %344, i8* %345) call void @exit(i32 1) - br label %ifcont98 + br label %ifcont78 -else97: ; preds = %ifcont95 - br label %ifcont98 +else77: ; preds = %ifcont75 + br label %ifcont78 -ifcont98: ; preds = %else97, %then96 - br i1 false, label %then99, label %else100 +ifcont78: ; preds = %else77, %then76 + br i1 false, label %then79, label %ifcont80 -then99: ; preds = %ifcont98 +then79: ; preds = %ifcont78 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont101 - -else100: ; preds = %ifcont98 - br label %ifcont101 + unreachable -ifcont101: ; preds = %else100, %then99 +ifcont80: ; preds = %ifcont78 %346 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 - br i1 false, label %then102, label %else103 + br i1 false, label %then81, label %ifcont82 -then102: ; preds = %ifcont101 +then81: ; preds = %ifcont80 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont104 + unreachable -else103: ; preds = %ifcont101 - br label %ifcont104 - -ifcont104: ; preds = %else103, %then102 +ifcont82: ; preds = %ifcont80 %347 = getelementptr [3 x %complex_4], [3 x %complex_4]* %a, i32 0, i32 0 %348 = load %complex_4, %complex_4* %347, align 1 store %complex_4 %348, %complex_4* %346, align 1 - br i1 false, label %then105, label %else106 + br i1 false, label %then83, label %ifcont84 -then105: ; preds = %ifcont104 +then83: ; preds = %ifcont82 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont107 - -else106: ; preds = %ifcont104 - br label %ifcont107 + unreachable -ifcont107: ; preds = %else106, %then105 +ifcont84: ; preds = %ifcont82 %349 = getelementptr [4 x %complex_4], [4 x %complex_4]* %b, i32 0, i32 3 %350 = load %complex_4, %complex_4* %349, align 1 %351 = alloca %complex_4, align 8 @@ -1031,42 +962,42 @@ ifcont107: ; preds = %else106, %then105 %367 = fcmp one float %357, %360 %368 = fcmp one float %363, %366 %369 = or i1 %367, %368 - br i1 %369, label %then108, label %else109 + br i1 %369, label %then85, label %else86 -then108: ; preds = %ifcont107 +then85: ; preds = %ifcont84 %370 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 %371 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* %370, i8* %371) call void @exit(i32 1) - br label %ifcont110 + br label %ifcont87 -else109: ; preds = %ifcont107 - br label %ifcont110 +else86: ; preds = %ifcont84 + br label %ifcont87 -ifcont110: ; preds = %else109, %then108 +ifcont87: ; preds = %else86, %then85 store i32 0, i32* %i1, align 4 - br label %loop.head111 + br label %loop.head88 -loop.head111: ; preds = %loop.end121, %ifcont110 +loop.head88: ; preds = %loop.end96, %ifcont87 %372 = load i32, i32* %i1, align 4 %373 = add i32 %372, 1 %374 = icmp sle i32 %373, 2 - br i1 %374, label %loop.body112, label %loop.end122 + br i1 %374, label %loop.body89, label %loop.end97 -loop.body112: ; preds = %loop.head111 +loop.body89: ; preds = %loop.head88 %375 = load i32, i32* %i1, align 4 %376 = add i32 %375, 1 store i32 %376, i32* %i1, align 4 store i32 0, i32* %j2, align 4 - br label %loop.head113 + br label %loop.head90 -loop.head113: ; preds = %ifcont120, %loop.body112 +loop.head90: ; preds = %ifcont95, %loop.body89 %377 = load i32, i32* %j2, align 4 %378 = add i32 %377, 1 %379 = icmp sle i32 %378, 2 - br i1 %379, label %loop.body114, label %loop.end121 + br i1 %379, label %loop.body91, label %loop.end96 -loop.body114: ; preds = %loop.head113 +loop.body91: ; preds = %loop.head90 %380 = load i32, i32* %j2, align 4 %381 = add i32 %380, 1 store i32 %381, i32* %j2, align 4 @@ -1078,34 +1009,28 @@ loop.body114: ; preds = %loop.head113 %387 = icmp slt i32 %382, 1 %388 = icmp sgt i32 %382, 2 %389 = or i1 %387, %388 - br i1 %389, label %then115, label %else116 + br i1 %389, label %then92, label %ifcont93 -then115: ; preds = %loop.body114 +then92: ; preds = %loop.body91 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 %382, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont117 + unreachable -else116: ; preds = %loop.body114 - br label %ifcont117 - -ifcont117: ; preds = %else116, %then115 +ifcont93: ; preds = %loop.body91 %390 = sub i32 %383, 1 %391 = mul i32 2, %390 %392 = add i32 %386, %391 %393 = icmp slt i32 %383, 1 %394 = icmp sgt i32 %383, 2 %395 = or i1 %393, %394 - br i1 %395, label %then118, label %else119 + br i1 %395, label %then94, label %ifcont95 -then118: ; preds = %ifcont117 +then94: ; preds = %ifcont93 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 %383, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont120 - -else119: ; preds = %ifcont117 - br label %ifcont120 + unreachable -ifcont120: ; preds = %else119, %then118 +ifcont95: ; preds = %ifcont93 %396 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 %392 %397 = load i32, i32* %i1, align 4 %398 = load i32, i32* %j2, align 4 @@ -1119,34 +1044,28 @@ ifcont120: ; preds = %else119, %then118 store float 0.000000e+00, float* %404, align 4 %405 = load %complex_4, %complex_4* %402, align 1 store %complex_4 %405, %complex_4* %396, align 1 - br label %loop.head113 + br label %loop.head90 -loop.end121: ; preds = %loop.head113 - br label %loop.head111 +loop.end96: ; preds = %loop.head90 + br label %loop.head88 -loop.end122: ; preds = %loop.head111 - br i1 false, label %then123, label %else124 +loop.end97: ; preds = %loop.head88 + br i1 false, label %then98, label %ifcont99 -then123: ; preds = %loop.end122 +then98: ; preds = %loop.end97 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont125 + unreachable -else124: ; preds = %loop.end122 - br label %ifcont125 - -ifcont125: ; preds = %else124, %then123 - br i1 false, label %then126, label %else127 +ifcont99: ; preds = %loop.end97 + br i1 false, label %then100, label %ifcont101 -then126: ; preds = %ifcont125 +then100: ; preds = %ifcont99 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont128 + unreachable -else127: ; preds = %ifcont125 - br label %ifcont128 - -ifcont128: ; preds = %else127, %then126 +ifcont101: ; preds = %ifcont99 %406 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 0 %407 = load %complex_4, %complex_4* %406, align 1 %408 = alloca %complex_4, align 8 @@ -1174,41 +1093,35 @@ ifcont128: ; preds = %else127, %then126 %424 = fcmp one float %414, %417 %425 = fcmp one float %420, %423 %426 = or i1 %424, %425 - br i1 %426, label %then129, label %else130 + br i1 %426, label %then102, label %else103 -then129: ; preds = %ifcont128 +then102: ; preds = %ifcont101 %427 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 %428 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @66, i32 0, i32 0), i8* %427, i8* %428) call void @exit(i32 1) - br label %ifcont131 + br label %ifcont104 -else130: ; preds = %ifcont128 - br label %ifcont131 +else103: ; preds = %ifcont101 + br label %ifcont104 -ifcont131: ; preds = %else130, %then129 - br i1 false, label %then132, label %else133 +ifcont104: ; preds = %else103, %then102 + br i1 false, label %then105, label %ifcont106 -then132: ; preds = %ifcont131 +then105: ; preds = %ifcont104 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @68, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @67, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont134 - -else133: ; preds = %ifcont131 - br label %ifcont134 + unreachable -ifcont134: ; preds = %else133, %then132 - br i1 false, label %then135, label %else136 +ifcont106: ; preds = %ifcont104 + br i1 false, label %then107, label %ifcont108 -then135: ; preds = %ifcont134 +then107: ; preds = %ifcont106 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @69, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont137 + unreachable -else136: ; preds = %ifcont134 - br label %ifcont137 - -ifcont137: ; preds = %else136, %then135 +ifcont108: ; preds = %ifcont106 %429 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 2 %430 = load %complex_4, %complex_4* %429, align 1 %431 = alloca %complex_4, align 8 @@ -1236,41 +1149,35 @@ ifcont137: ; preds = %else136, %then135 %447 = fcmp one float %437, %440 %448 = fcmp one float %443, %446 %449 = or i1 %447, %448 - br i1 %449, label %then138, label %else139 + br i1 %449, label %then109, label %else110 -then138: ; preds = %ifcont137 +then109: ; preds = %ifcont108 %450 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 %451 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @71, i32 0, i32 0), i8* %450, i8* %451) call void @exit(i32 1) - br label %ifcont140 + br label %ifcont111 -else139: ; preds = %ifcont137 - br label %ifcont140 +else110: ; preds = %ifcont108 + br label %ifcont111 -ifcont140: ; preds = %else139, %then138 - br i1 false, label %then141, label %else142 +ifcont111: ; preds = %else110, %then109 + br i1 false, label %then112, label %ifcont113 -then141: ; preds = %ifcont140 +then112: ; preds = %ifcont111 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont143 - -else142: ; preds = %ifcont140 - br label %ifcont143 + unreachable -ifcont143: ; preds = %else142, %then141 - br i1 false, label %then144, label %else145 +ifcont113: ; preds = %ifcont111 + br i1 false, label %then114, label %ifcont115 -then144: ; preds = %ifcont143 +then114: ; preds = %ifcont113 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont146 - -else145: ; preds = %ifcont143 - br label %ifcont146 + unreachable -ifcont146: ; preds = %else145, %then144 +ifcont115: ; preds = %ifcont113 %452 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 1 %453 = load %complex_4, %complex_4* %452, align 1 %454 = alloca %complex_4, align 8 @@ -1298,41 +1205,35 @@ ifcont146: ; preds = %else145, %then144 %470 = fcmp one float %460, %463 %471 = fcmp one float %466, %469 %472 = or i1 %470, %471 - br i1 %472, label %then147, label %else148 + br i1 %472, label %then116, label %else117 -then147: ; preds = %ifcont146 +then116: ; preds = %ifcont115 %473 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 %474 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @76, i32 0, i32 0), i8* %473, i8* %474) call void @exit(i32 1) - br label %ifcont149 + br label %ifcont118 -else148: ; preds = %ifcont146 - br label %ifcont149 +else117: ; preds = %ifcont115 + br label %ifcont118 -ifcont149: ; preds = %else148, %then147 - br i1 false, label %then150, label %else151 +ifcont118: ; preds = %else117, %then116 + br i1 false, label %then119, label %ifcont120 -then150: ; preds = %ifcont149 +then119: ; preds = %ifcont118 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont152 + unreachable -else151: ; preds = %ifcont149 - br label %ifcont152 +ifcont120: ; preds = %ifcont118 + br i1 false, label %then121, label %ifcont122 -ifcont152: ; preds = %else151, %then150 - br i1 false, label %then153, label %else154 - -then153: ; preds = %ifcont152 +then121: ; preds = %ifcont120 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont155 - -else154: ; preds = %ifcont152 - br label %ifcont155 + unreachable -ifcont155: ; preds = %else154, %then153 +ifcont122: ; preds = %ifcont120 %475 = getelementptr [4 x %complex_4], [4 x %complex_4]* %c, i32 0, i32 3 %476 = load %complex_4, %complex_4* %475, align 1 %477 = alloca %complex_4, align 8 @@ -1360,23 +1261,23 @@ ifcont155: ; preds = %else154, %then153 %493 = fcmp one float %483, %486 %494 = fcmp one float %489, %492 %495 = or i1 %493, %494 - br i1 %495, label %then156, label %else157 + br i1 %495, label %then123, label %else124 -then156: ; preds = %ifcont155 +then123: ; preds = %ifcont122 %496 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 %497 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* %496, i8* %497) call void @exit(i32 1) - br label %ifcont158 + br label %ifcont125 -else157: ; preds = %ifcont155 - br label %ifcont158 +else124: ; preds = %ifcont122 + br label %ifcont125 -ifcont158: ; preds = %else157, %then156 +ifcont125: ; preds = %else124, %then123 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont158 +return: ; preds = %ifcont125 ret i32 0 } diff --git a/tests/reference/llvm-arrays_01_logical-f19a63d.json b/tests/reference/llvm-arrays_01_logical-f19a63d.json index 9250651f3e6..be25f7a7001 100644 --- a/tests/reference/llvm-arrays_01_logical-f19a63d.json +++ b/tests/reference/llvm-arrays_01_logical-f19a63d.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01_logical-f19a63d.stdout", - "stdout_hash": "1ef5064c26b1b2d0b850070ba4f041d98a9dfb18f945d84eee3efb0f", + "stdout_hash": "28706b8a30f373b81b5b155f66acce14913395104b98bdaf9a1ab202", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01_logical-f19a63d.stdout b/tests/reference/llvm-arrays_01_logical-f19a63d.stdout index d8bace63a9b..f9d512e70fd 100644 --- a/tests/reference/llvm-arrays_01_logical-f19a63d.stdout +++ b/tests/reference/llvm-arrays_01_logical-f19a63d.stdout @@ -172,23 +172,20 @@ define i32 @main(i32 %0, i8** %1) { %c = alloca [4 x i1], align 1 %i1 = alloca i32, align 4 %j2 = alloca i32, align 4 - br i1 false, label %then, label %else + br i1 false, label %then, label %ifcont then: ; preds = %.entry call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont + unreachable -else: ; preds = %.entry - br label %ifcont - -ifcont: ; preds = %else, %then +ifcont: ; preds = %.entry %2 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 store i1 true, i1* %2, align 1 store i32 1, i32* %i1, align 4 br label %loop.head -loop.head: ; preds = %ifcont8, %ifcont +loop.head: ; preds = %ifcont6, %ifcont %3 = load i32, i32* %i1, align 4 %4 = add i32 %3, 1 %5 = icmp sle i32 %4, 3 @@ -205,17 +202,14 @@ loop.body: ; preds = %loop.head %12 = icmp slt i32 %8, 1 %13 = icmp sgt i32 %8, 3 %14 = or i1 %12, %13 - br i1 %14, label %then3, label %else4 + br i1 %14, label %then3, label %ifcont4 then3: ; preds = %loop.body call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 %8, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont5 - -else4: ; preds = %loop.body - br label %ifcont5 + unreachable -ifcont5: ; preds = %else4, %then3 +ifcont4: ; preds = %loop.body %15 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %11 %16 = load i32, i32* %i1, align 4 %17 = sub i32 %16, 1 @@ -225,17 +219,14 @@ ifcont5: ; preds = %else4, %then3 %21 = icmp slt i32 %17, 1 %22 = icmp sgt i32 %17, 3 %23 = or i1 %21, %22 - br i1 %23, label %then6, label %else7 + br i1 %23, label %then5, label %ifcont6 -then6: ; preds = %ifcont5 +then5: ; preds = %ifcont4 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0), i32 %17, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont8 - -else7: ; preds = %ifcont5 - br label %ifcont8 + unreachable -ifcont8: ; preds = %else7, %then6 +ifcont6: ; preds = %ifcont4 %24 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %20 %25 = load i1, i1* %24, align 1 %26 = xor i1 %25, true @@ -243,109 +234,97 @@ ifcont8: ; preds = %else7, %then6 br label %loop.head loop.end: ; preds = %loop.head - br i1 false, label %then9, label %else10 + br i1 false, label %then7, label %ifcont8 -then9: ; preds = %loop.end +then7: ; preds = %loop.end call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @7, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @6, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont11 + unreachable -else10: ; preds = %loop.end - br label %ifcont11 - -ifcont11: ; preds = %else10, %then9 +ifcont8: ; preds = %loop.end %27 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 %28 = load i1, i1* %27, align 1 %29 = xor i1 %28, true - br i1 %29, label %then12, label %else13 + br i1 %29, label %then9, label %else -then12: ; preds = %ifcont11 +then9: ; preds = %ifcont8 %30 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 %31 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %30, i8* %31) call void @exit(i32 1) - br label %ifcont14 + br label %ifcont10 -else13: ; preds = %ifcont11 - br label %ifcont14 +else: ; preds = %ifcont8 + br label %ifcont10 -ifcont14: ; preds = %else13, %then12 - br i1 false, label %then15, label %else16 +ifcont10: ; preds = %else, %then9 + br i1 false, label %then11, label %ifcont12 -then15: ; preds = %ifcont14 +then11: ; preds = %ifcont10 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @10, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @9, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont17 - -else16: ; preds = %ifcont14 - br label %ifcont17 + unreachable -ifcont17: ; preds = %else16, %then15 +ifcont12: ; preds = %ifcont10 %32 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 1 %33 = load i1, i1* %32, align 1 - br i1 %33, label %then18, label %else19 + br i1 %33, label %then13, label %else14 -then18: ; preds = %ifcont17 +then13: ; preds = %ifcont12 %34 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 %35 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %34, i8* %35) call void @exit(i32 1) - br label %ifcont20 + br label %ifcont15 -else19: ; preds = %ifcont17 - br label %ifcont20 +else14: ; preds = %ifcont12 + br label %ifcont15 -ifcont20: ; preds = %else19, %then18 - br i1 false, label %then21, label %else22 +ifcont15: ; preds = %else14, %then13 + br i1 false, label %then16, label %ifcont17 -then21: ; preds = %ifcont20 +then16: ; preds = %ifcont15 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @13, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @12, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont23 - -else22: ; preds = %ifcont20 - br label %ifcont23 + unreachable -ifcont23: ; preds = %else22, %then21 +ifcont17: ; preds = %ifcont15 %36 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 2 %37 = load i1, i1* %36, align 1 %38 = xor i1 %37, true - br i1 %38, label %then24, label %else25 + br i1 %38, label %then18, label %else19 -then24: ; preds = %ifcont23 +then18: ; preds = %ifcont17 %39 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 %40 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %39, i8* %40) call void @exit(i32 1) - br label %ifcont26 + br label %ifcont20 -else25: ; preds = %ifcont23 - br label %ifcont26 +else19: ; preds = %ifcont17 + br label %ifcont20 -ifcont26: ; preds = %else25, %then24 - br i1 false, label %then27, label %else28 +ifcont20: ; preds = %else19, %then18 + br i1 false, label %then21, label %ifcont22 -then27: ; preds = %ifcont26 +then21: ; preds = %ifcont20 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont29 - -else28: ; preds = %ifcont26 - br label %ifcont29 + unreachable -ifcont29: ; preds = %else28, %then27 +ifcont22: ; preds = %ifcont20 %41 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 store i1 false, i1* %41, align 1 store i32 11, i32* %i1, align 4 - br label %loop.head30 + br label %loop.head23 -loop.head30: ; preds = %ifcont37, %ifcont29 +loop.head23: ; preds = %ifcont28, %ifcont22 %42 = load i32, i32* %i1, align 4 %43 = add i32 %42, 1 %44 = icmp sle i32 %43, 14 - br i1 %44, label %loop.body31, label %loop.end38 + br i1 %44, label %loop.body24, label %loop.end29 -loop.body31: ; preds = %loop.head30 +loop.body24: ; preds = %loop.head23 %45 = load i32, i32* %i1, align 4 %46 = add i32 %45, 1 store i32 %46, i32* %i1, align 4 @@ -357,17 +336,14 @@ loop.body31: ; preds = %loop.head30 %52 = icmp slt i32 %48, 1 %53 = icmp sgt i32 %48, 4 %54 = or i1 %52, %53 - br i1 %54, label %then32, label %else33 + br i1 %54, label %then25, label %ifcont26 -then32: ; preds = %loop.body31 +then25: ; preds = %loop.body24 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @18, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @17, i32 0, i32 0), i32 %48, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont34 - -else33: ; preds = %loop.body31 - br label %ifcont34 + unreachable -ifcont34: ; preds = %else33, %then32 +ifcont26: ; preds = %loop.body24 %55 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %51 %56 = load i32, i32* %i1, align 4 %57 = sub i32 %56, 10 @@ -378,140 +354,125 @@ ifcont34: ; preds = %else33, %then32 %62 = icmp slt i32 %58, 1 %63 = icmp sgt i32 %58, 4 %64 = or i1 %62, %63 - br i1 %64, label %then35, label %else36 + br i1 %64, label %then27, label %ifcont28 -then35: ; preds = %ifcont34 +then27: ; preds = %ifcont26 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 %58, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont37 - -else36: ; preds = %ifcont34 - br label %ifcont37 + unreachable -ifcont37: ; preds = %else36, %then35 +ifcont28: ; preds = %ifcont26 %65 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %61 %66 = load i1, i1* %65, align 1 %67 = xor i1 %66, true store i1 %67, i1* %55, align 1 - br label %loop.head30 + br label %loop.head23 -loop.end38: ; preds = %loop.head30 - br i1 false, label %then39, label %else40 +loop.end29: ; preds = %loop.head23 + br i1 false, label %then30, label %ifcont31 -then39: ; preds = %loop.end38 +then30: ; preds = %loop.end29 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @22, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @21, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont41 + unreachable -else40: ; preds = %loop.end38 - br label %ifcont41 - -ifcont41: ; preds = %else40, %then39 +ifcont31: ; preds = %loop.end29 %68 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 %69 = load i1, i1* %68, align 1 - br i1 %69, label %then42, label %else43 + br i1 %69, label %then32, label %else33 -then42: ; preds = %ifcont41 +then32: ; preds = %ifcont31 %70 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 %71 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @23, i32 0, i32 0), i8* %70, i8* %71) call void @exit(i32 1) - br label %ifcont44 + br label %ifcont34 -else43: ; preds = %ifcont41 - br label %ifcont44 +else33: ; preds = %ifcont31 + br label %ifcont34 -ifcont44: ; preds = %else43, %then42 - br i1 false, label %then45, label %else46 +ifcont34: ; preds = %else33, %then32 + br i1 false, label %then35, label %ifcont36 -then45: ; preds = %ifcont44 +then35: ; preds = %ifcont34 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @25, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @24, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont47 + unreachable -else46: ; preds = %ifcont44 - br label %ifcont47 - -ifcont47: ; preds = %else46, %then45 +ifcont36: ; preds = %ifcont34 %72 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 %73 = load i1, i1* %72, align 1 %74 = xor i1 %73, true - br i1 %74, label %then48, label %else49 + br i1 %74, label %then37, label %else38 -then48: ; preds = %ifcont47 +then37: ; preds = %ifcont36 %75 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 %76 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @26, i32 0, i32 0), i8* %75, i8* %76) call void @exit(i32 1) - br label %ifcont50 + br label %ifcont39 -else49: ; preds = %ifcont47 - br label %ifcont50 +else38: ; preds = %ifcont36 + br label %ifcont39 -ifcont50: ; preds = %else49, %then48 - br i1 false, label %then51, label %else52 +ifcont39: ; preds = %else38, %then37 + br i1 false, label %then40, label %ifcont41 -then51: ; preds = %ifcont50 +then40: ; preds = %ifcont39 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont53 - -else52: ; preds = %ifcont50 - br label %ifcont53 + unreachable -ifcont53: ; preds = %else52, %then51 +ifcont41: ; preds = %ifcont39 %77 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 %78 = load i1, i1* %77, align 1 - br i1 %78, label %then54, label %else55 + br i1 %78, label %then42, label %else43 -then54: ; preds = %ifcont53 +then42: ; preds = %ifcont41 %79 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 %80 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @29, i32 0, i32 0), i8* %79, i8* %80) call void @exit(i32 1) - br label %ifcont56 + br label %ifcont44 -else55: ; preds = %ifcont53 - br label %ifcont56 +else43: ; preds = %ifcont41 + br label %ifcont44 -ifcont56: ; preds = %else55, %then54 - br i1 false, label %then57, label %else58 +ifcont44: ; preds = %else43, %then42 + br i1 false, label %then45, label %ifcont46 -then57: ; preds = %ifcont56 +then45: ; preds = %ifcont44 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @31, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @30, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont59 - -else58: ; preds = %ifcont56 - br label %ifcont59 + unreachable -ifcont59: ; preds = %else58, %then57 +ifcont46: ; preds = %ifcont44 %81 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 %82 = load i1, i1* %81, align 1 %83 = xor i1 %82, true - br i1 %83, label %then60, label %else61 + br i1 %83, label %then47, label %else48 -then60: ; preds = %ifcont59 +then47: ; preds = %ifcont46 %84 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 %85 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @32, i32 0, i32 0), i8* %84, i8* %85) call void @exit(i32 1) - br label %ifcont62 + br label %ifcont49 -else61: ; preds = %ifcont59 - br label %ifcont62 +else48: ; preds = %ifcont46 + br label %ifcont49 -ifcont62: ; preds = %else61, %then60 +ifcont49: ; preds = %else48, %then47 store i32 0, i32* %i1, align 4 - br label %loop.head63 + br label %loop.head50 -loop.head63: ; preds = %ifcont70, %ifcont62 +loop.head50: ; preds = %ifcont55, %ifcont49 %86 = load i32, i32* %i1, align 4 %87 = add i32 %86, 1 %88 = icmp sle i32 %87, 3 - br i1 %88, label %loop.body64, label %loop.end71 + br i1 %88, label %loop.body51, label %loop.end56 -loop.body64: ; preds = %loop.head63 +loop.body51: ; preds = %loop.head50 %89 = load i32, i32* %i1, align 4 %90 = add i32 %89, 1 store i32 %90, i32* %i1, align 4 @@ -522,17 +483,14 @@ loop.body64: ; preds = %loop.head63 %95 = icmp slt i32 %91, 1 %96 = icmp sgt i32 %91, 4 %97 = or i1 %95, %96 - br i1 %97, label %then65, label %else66 + br i1 %97, label %then52, label %ifcont53 -then65: ; preds = %loop.body64 +then52: ; preds = %loop.body51 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @34, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @33, i32 0, i32 0), i32 %91, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont67 + unreachable -else66: ; preds = %loop.body64 - br label %ifcont67 - -ifcont67: ; preds = %else66, %then65 +ifcont53: ; preds = %loop.body51 %98 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 %94 %99 = load i32, i32* %i1, align 4 %100 = sub i32 %99, 1 @@ -541,277 +499,238 @@ ifcont67: ; preds = %else66, %then65 %103 = icmp slt i32 %99, 1 %104 = icmp sgt i32 %99, 3 %105 = or i1 %103, %104 - br i1 %105, label %then68, label %else69 + br i1 %105, label %then54, label %ifcont55 -then68: ; preds = %ifcont67 +then54: ; preds = %ifcont53 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0), i32 %99, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont70 + unreachable -else69: ; preds = %ifcont67 - br label %ifcont70 - -ifcont70: ; preds = %else69, %then68 +ifcont55: ; preds = %ifcont53 %106 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 %102 %107 = load i1, i1* %106, align 1 %108 = icmp eq i1 %107, false %109 = select i1 %108, i1 %107, i1 false store i1 %109, i1* %98, align 1 - br label %loop.head63 + br label %loop.head50 -loop.end71: ; preds = %loop.head63 - br i1 false, label %then72, label %else73 +loop.end56: ; preds = %loop.head50 + br i1 false, label %then57, label %ifcont58 -then72: ; preds = %loop.end71 +then57: ; preds = %loop.end56 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @38, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @37, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont74 - -else73: ; preds = %loop.end71 - br label %ifcont74 + unreachable -ifcont74: ; preds = %else73, %then72 +ifcont58: ; preds = %loop.end56 %110 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 %111 = load i1, i1* %110, align 1 - br i1 %111, label %then75, label %else76 + br i1 %111, label %then59, label %else60 -then75: ; preds = %ifcont74 +then59: ; preds = %ifcont58 %112 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 %113 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @39, i32 0, i32 0), i8* %112, i8* %113) call void @exit(i32 1) - br label %ifcont77 + br label %ifcont61 -else76: ; preds = %ifcont74 - br label %ifcont77 +else60: ; preds = %ifcont58 + br label %ifcont61 -ifcont77: ; preds = %else76, %then75 - br i1 false, label %then78, label %else79 +ifcont61: ; preds = %else60, %then59 + br i1 false, label %then62, label %ifcont63 -then78: ; preds = %ifcont77 +then62: ; preds = %ifcont61 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont80 - -else79: ; preds = %ifcont77 - br label %ifcont80 + unreachable -ifcont80: ; preds = %else79, %then78 +ifcont63: ; preds = %ifcont61 %114 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 %115 = load i1, i1* %114, align 1 - br i1 %115, label %then81, label %else82 + br i1 %115, label %then64, label %else65 -then81: ; preds = %ifcont80 +then64: ; preds = %ifcont63 %116 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 %117 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @42, i32 0, i32 0), i8* %116, i8* %117) call void @exit(i32 1) - br label %ifcont83 + br label %ifcont66 -else82: ; preds = %ifcont80 - br label %ifcont83 +else65: ; preds = %ifcont63 + br label %ifcont66 -ifcont83: ; preds = %else82, %then81 - br i1 false, label %then84, label %else85 +ifcont66: ; preds = %else65, %then64 + br i1 false, label %then67, label %ifcont68 -then84: ; preds = %ifcont83 +then67: ; preds = %ifcont66 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @44, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @43, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont86 + unreachable -else85: ; preds = %ifcont83 - br label %ifcont86 - -ifcont86: ; preds = %else85, %then84 +ifcont68: ; preds = %ifcont66 %118 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 %119 = load i1, i1* %118, align 1 - br i1 %119, label %then87, label %else88 + br i1 %119, label %then69, label %else70 -then87: ; preds = %ifcont86 +then69: ; preds = %ifcont68 %120 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 %121 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @45, i32 0, i32 0), i8* %120, i8* %121) call void @exit(i32 1) - br label %ifcont89 + br label %ifcont71 -else88: ; preds = %ifcont86 - br label %ifcont89 +else70: ; preds = %ifcont68 + br label %ifcont71 -ifcont89: ; preds = %else88, %then87 - br i1 false, label %then90, label %else91 +ifcont71: ; preds = %else70, %then69 + br i1 false, label %then72, label %ifcont73 -then90: ; preds = %ifcont89 +then72: ; preds = %ifcont71 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont92 + unreachable -else91: ; preds = %ifcont89 - br label %ifcont92 - -ifcont92: ; preds = %else91, %then90 +ifcont73: ; preds = %ifcont71 %122 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - br i1 false, label %then93, label %else94 + br i1 false, label %then74, label %ifcont75 -then93: ; preds = %ifcont92 +then74: ; preds = %ifcont73 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont95 - -else94: ; preds = %ifcont92 - br label %ifcont95 + unreachable -ifcont95: ; preds = %else94, %then93 +ifcont75: ; preds = %ifcont73 %123 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 0 %124 = load i1, i1* %123, align 1 - br i1 false, label %then96, label %else97 + br i1 false, label %then76, label %ifcont77 -then96: ; preds = %ifcont95 +then76: ; preds = %ifcont75 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @51, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @50, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont98 - -else97: ; preds = %ifcont95 - br label %ifcont98 + unreachable -ifcont98: ; preds = %else97, %then96 +ifcont77: ; preds = %ifcont75 %125 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 1 %126 = load i1, i1* %125, align 1 %127 = icmp eq i1 %124, false %128 = select i1 %127, i1 %126, i1 %124 - br i1 false, label %then99, label %else100 + br i1 false, label %then78, label %ifcont79 -then99: ; preds = %ifcont98 +then78: ; preds = %ifcont77 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @53, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @52, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont101 - -else100: ; preds = %ifcont98 - br label %ifcont101 + unreachable -ifcont101: ; preds = %else100, %then99 +ifcont79: ; preds = %ifcont77 %129 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 2 %130 = load i1, i1* %129, align 1 %131 = icmp eq i1 %128, false %132 = select i1 %131, i1 %130, i1 %128 - br i1 false, label %then102, label %else103 + br i1 false, label %then80, label %ifcont81 -then102: ; preds = %ifcont101 +then80: ; preds = %ifcont79 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @55, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @54, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont104 - -else103: ; preds = %ifcont101 - br label %ifcont104 + unreachable -ifcont104: ; preds = %else103, %then102 +ifcont81: ; preds = %ifcont79 %133 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 %134 = load i1, i1* %133, align 1 %135 = icmp eq i1 %132, false %136 = select i1 %135, i1 %134, i1 %132 store i1 %136, i1* %122, align 1 - br i1 false, label %then105, label %else106 + br i1 false, label %then82, label %ifcont83 -then105: ; preds = %ifcont104 +then82: ; preds = %ifcont81 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @57, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @56, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont107 + unreachable -else106: ; preds = %ifcont104 - br label %ifcont107 - -ifcont107: ; preds = %else106, %then105 +ifcont83: ; preds = %ifcont81 %137 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 %138 = load i1, i1* %137, align 1 %139 = xor i1 %138, true - br i1 %139, label %then108, label %else109 + br i1 %139, label %then84, label %else85 -then108: ; preds = %ifcont107 +then84: ; preds = %ifcont83 %140 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 %141 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @58, i32 0, i32 0), i8* %140, i8* %141) call void @exit(i32 1) - br label %ifcont110 + br label %ifcont86 -else109: ; preds = %ifcont107 - br label %ifcont110 +else85: ; preds = %ifcont83 + br label %ifcont86 -ifcont110: ; preds = %else109, %then108 - br i1 false, label %then111, label %else112 +ifcont86: ; preds = %else85, %then84 + br i1 false, label %then87, label %ifcont88 -then111: ; preds = %ifcont110 +then87: ; preds = %ifcont86 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @60, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @59, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont113 + unreachable -else112: ; preds = %ifcont110 - br label %ifcont113 - -ifcont113: ; preds = %else112, %then111 +ifcont88: ; preds = %ifcont86 %142 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 - br i1 false, label %then114, label %else115 + br i1 false, label %then89, label %ifcont90 -then114: ; preds = %ifcont113 +then89: ; preds = %ifcont88 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @62, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @61, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont116 - -else115: ; preds = %ifcont113 - br label %ifcont116 + unreachable -ifcont116: ; preds = %else115, %then114 +ifcont90: ; preds = %ifcont88 %143 = getelementptr [3 x i1], [3 x i1]* %a, i32 0, i32 0 %144 = load i1, i1* %143, align 1 store i1 %144, i1* %142, align 1 - br i1 false, label %then117, label %else118 + br i1 false, label %then91, label %ifcont92 -then117: ; preds = %ifcont116 +then91: ; preds = %ifcont90 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @64, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @63, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont119 + unreachable -else118: ; preds = %ifcont116 - br label %ifcont119 - -ifcont119: ; preds = %else118, %then117 +ifcont92: ; preds = %ifcont90 %145 = getelementptr [4 x i1], [4 x i1]* %b, i32 0, i32 3 %146 = load i1, i1* %145, align 1 %147 = xor i1 %146, true - br i1 %147, label %then120, label %else121 + br i1 %147, label %then93, label %else94 -then120: ; preds = %ifcont119 +then93: ; preds = %ifcont92 %148 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 %149 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @65, i32 0, i32 0), i8* %148, i8* %149) call void @exit(i32 1) - br label %ifcont122 + br label %ifcont95 -else121: ; preds = %ifcont119 - br label %ifcont122 +else94: ; preds = %ifcont92 + br label %ifcont95 -ifcont122: ; preds = %else121, %then120 +ifcont95: ; preds = %else94, %then93 store i32 0, i32* %i1, align 4 - br label %loop.head123 + br label %loop.head96 -loop.head123: ; preds = %loop.end142, %ifcont122 +loop.head96: ; preds = %loop.end111, %ifcont95 %150 = load i32, i32* %i1, align 4 %151 = add i32 %150, 1 %152 = icmp sle i32 %151, 2 - br i1 %152, label %loop.body124, label %loop.end143 + br i1 %152, label %loop.body97, label %loop.end112 -loop.body124: ; preds = %loop.head123 +loop.body97: ; preds = %loop.head96 %153 = load i32, i32* %i1, align 4 %154 = add i32 %153, 1 store i32 %154, i32* %i1, align 4 store i32 0, i32* %j2, align 4 - br label %loop.head125 + br label %loop.head98 -loop.head125: ; preds = %ifcont141, %loop.body124 +loop.head98: ; preds = %ifcont110, %loop.body97 %155 = load i32, i32* %j2, align 4 %156 = add i32 %155, 1 %157 = icmp sle i32 %156, 2 - br i1 %157, label %loop.body126, label %loop.end142 + br i1 %157, label %loop.body99, label %loop.end111 -loop.body126: ; preds = %loop.head125 +loop.body99: ; preds = %loop.head98 %158 = load i32, i32* %j2, align 4 %159 = add i32 %158, 1 store i32 %159, i32* %j2, align 4 @@ -825,9 +744,9 @@ loop.body126: ; preds = %loop.head125 %167 = mul i32 2, %166 %168 = sub i32 %162, %167 %169 = icmp eq i32 %168, 1 - br i1 %169, label %then127, label %else134 + br i1 %169, label %then100, label %else105 -then127: ; preds = %loop.body126 +then100: ; preds = %loop.body99 %170 = load i32, i32* %i1, align 4 %171 = load i32, i32* %j2, align 4 %172 = sub i32 %170, 1 @@ -836,39 +755,33 @@ then127: ; preds = %loop.body126 %175 = icmp slt i32 %170, 1 %176 = icmp sgt i32 %170, 2 %177 = or i1 %175, %176 - br i1 %177, label %then128, label %else129 + br i1 %177, label %then101, label %ifcont102 -then128: ; preds = %then127 +then101: ; preds = %then100 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @67, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @66, i32 0, i32 0), i32 %170, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont130 - -else129: ; preds = %then127 - br label %ifcont130 + unreachable -ifcont130: ; preds = %else129, %then128 +ifcont102: ; preds = %then100 %178 = sub i32 %171, 1 %179 = mul i32 2, %178 %180 = add i32 %174, %179 %181 = icmp slt i32 %171, 1 %182 = icmp sgt i32 %171, 2 %183 = or i1 %181, %182 - br i1 %183, label %then131, label %else132 + br i1 %183, label %then103, label %ifcont104 -then131: ; preds = %ifcont130 +then103: ; preds = %ifcont102 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @69, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @68, i32 0, i32 0), i32 %171, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont133 + unreachable -else132: ; preds = %ifcont130 - br label %ifcont133 - -ifcont133: ; preds = %else132, %then131 +ifcont104: ; preds = %ifcont102 %184 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %180 store i1 true, i1* %184, align 1 - br label %ifcont141 + br label %ifcont110 -else134: ; preds = %loop.body126 +else105: ; preds = %loop.body99 %185 = load i32, i32* %i1, align 4 %186 = load i32, i32* %j2, align 4 %187 = sub i32 %185, 1 @@ -877,199 +790,169 @@ else134: ; preds = %loop.body126 %190 = icmp slt i32 %185, 1 %191 = icmp sgt i32 %185, 2 %192 = or i1 %190, %191 - br i1 %192, label %then135, label %else136 + br i1 %192, label %then106, label %ifcont107 -then135: ; preds = %else134 +then106: ; preds = %else105 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @71, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @70, i32 0, i32 0), i32 %185, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont137 - -else136: ; preds = %else134 - br label %ifcont137 + unreachable -ifcont137: ; preds = %else136, %then135 +ifcont107: ; preds = %else105 %193 = sub i32 %186, 1 %194 = mul i32 2, %193 %195 = add i32 %189, %194 %196 = icmp slt i32 %186, 1 %197 = icmp sgt i32 %186, 2 %198 = or i1 %196, %197 - br i1 %198, label %then138, label %else139 + br i1 %198, label %then108, label %ifcont109 -then138: ; preds = %ifcont137 +then108: ; preds = %ifcont107 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 %186, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont140 + unreachable -else139: ; preds = %ifcont137 - br label %ifcont140 - -ifcont140: ; preds = %else139, %then138 +ifcont109: ; preds = %ifcont107 %199 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 %195 store i1 false, i1* %199, align 1 - br label %ifcont141 + br label %ifcont110 -ifcont141: ; preds = %ifcont140, %ifcont133 - br label %loop.head125 +ifcont110: ; preds = %ifcont109, %ifcont104 + br label %loop.head98 -loop.end142: ; preds = %loop.head125 - br label %loop.head123 +loop.end111: ; preds = %loop.head98 + br label %loop.head96 -loop.end143: ; preds = %loop.head123 - br i1 false, label %then144, label %else145 +loop.end112: ; preds = %loop.head96 + br i1 false, label %then113, label %ifcont114 -then144: ; preds = %loop.end143 +then113: ; preds = %loop.end112 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont146 - -else145: ; preds = %loop.end143 - br label %ifcont146 + unreachable -ifcont146: ; preds = %else145, %then144 - br i1 false, label %then147, label %else148 +ifcont114: ; preds = %loop.end112 + br i1 false, label %then115, label %ifcont116 -then147: ; preds = %ifcont146 +then115: ; preds = %ifcont114 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @77, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @76, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont149 + unreachable -else148: ; preds = %ifcont146 - br label %ifcont149 - -ifcont149: ; preds = %else148, %then147 +ifcont116: ; preds = %ifcont114 %200 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 0 %201 = load i1, i1* %200, align 1 - br i1 %201, label %then150, label %else151 + br i1 %201, label %then117, label %else118 -then150: ; preds = %ifcont149 +then117: ; preds = %ifcont116 %202 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 %203 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @78, i32 0, i32 0), i8* %202, i8* %203) call void @exit(i32 1) - br label %ifcont152 + br label %ifcont119 -else151: ; preds = %ifcont149 - br label %ifcont152 +else118: ; preds = %ifcont116 + br label %ifcont119 -ifcont152: ; preds = %else151, %then150 - br i1 false, label %then153, label %else154 +ifcont119: ; preds = %else118, %then117 + br i1 false, label %then120, label %ifcont121 -then153: ; preds = %ifcont152 +then120: ; preds = %ifcont119 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont155 - -else154: ; preds = %ifcont152 - br label %ifcont155 + unreachable -ifcont155: ; preds = %else154, %then153 - br i1 false, label %then156, label %else157 +ifcont121: ; preds = %ifcont119 + br i1 false, label %then122, label %ifcont123 -then156: ; preds = %ifcont155 +then122: ; preds = %ifcont121 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @82, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @81, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont158 - -else157: ; preds = %ifcont155 - br label %ifcont158 + unreachable -ifcont158: ; preds = %else157, %then156 +ifcont123: ; preds = %ifcont121 %204 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 2 %205 = load i1, i1* %204, align 1 %206 = xor i1 %205, true - br i1 %206, label %then159, label %else160 + br i1 %206, label %then124, label %else125 -then159: ; preds = %ifcont158 +then124: ; preds = %ifcont123 %207 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 %208 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @83, i32 0, i32 0), i8* %207, i8* %208) call void @exit(i32 1) - br label %ifcont161 + br label %ifcont126 -else160: ; preds = %ifcont158 - br label %ifcont161 +else125: ; preds = %ifcont123 + br label %ifcont126 -ifcont161: ; preds = %else160, %then159 - br i1 false, label %then162, label %else163 +ifcont126: ; preds = %else125, %then124 + br i1 false, label %then127, label %ifcont128 -then162: ; preds = %ifcont161 +then127: ; preds = %ifcont126 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @85, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @84, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont164 + unreachable -else163: ; preds = %ifcont161 - br label %ifcont164 +ifcont128: ; preds = %ifcont126 + br i1 false, label %then129, label %ifcont130 -ifcont164: ; preds = %else163, %then162 - br i1 false, label %then165, label %else166 - -then165: ; preds = %ifcont164 +then129: ; preds = %ifcont128 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @87, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @86, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont167 - -else166: ; preds = %ifcont164 - br label %ifcont167 + unreachable -ifcont167: ; preds = %else166, %then165 +ifcont130: ; preds = %ifcont128 %209 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 1 %210 = load i1, i1* %209, align 1 %211 = xor i1 %210, true - br i1 %211, label %then168, label %else169 + br i1 %211, label %then131, label %else132 -then168: ; preds = %ifcont167 +then131: ; preds = %ifcont130 %212 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 %213 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @88, i32 0, i32 0), i8* %212, i8* %213) call void @exit(i32 1) - br label %ifcont170 + br label %ifcont133 -else169: ; preds = %ifcont167 - br label %ifcont170 +else132: ; preds = %ifcont130 + br label %ifcont133 -ifcont170: ; preds = %else169, %then168 - br i1 false, label %then171, label %else172 +ifcont133: ; preds = %else132, %then131 + br i1 false, label %then134, label %ifcont135 -then171: ; preds = %ifcont170 +then134: ; preds = %ifcont133 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @90, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @89, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont173 - -else172: ; preds = %ifcont170 - br label %ifcont173 + unreachable -ifcont173: ; preds = %else172, %then171 - br i1 false, label %then174, label %else175 +ifcont135: ; preds = %ifcont133 + br i1 false, label %then136, label %ifcont137 -then174: ; preds = %ifcont173 +then136: ; preds = %ifcont135 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @92, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @91, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont176 + unreachable -else175: ; preds = %ifcont173 - br label %ifcont176 - -ifcont176: ; preds = %else175, %then174 +ifcont137: ; preds = %ifcont135 %214 = getelementptr [4 x i1], [4 x i1]* %c, i32 0, i32 3 %215 = load i1, i1* %214, align 1 - br i1 %215, label %then177, label %else178 + br i1 %215, label %then138, label %else139 -then177: ; preds = %ifcont176 +then138: ; preds = %ifcont137 %216 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 %217 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @93, i32 0, i32 0), i8* %216, i8* %217) call void @exit(i32 1) - br label %ifcont179 + br label %ifcont140 -else178: ; preds = %ifcont176 - br label %ifcont179 +else139: ; preds = %ifcont137 + br label %ifcont140 -ifcont179: ; preds = %else178, %then177 +ifcont140: ; preds = %else139, %then138 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont179 +return: ; preds = %ifcont140 ret i32 0 } diff --git a/tests/reference/llvm-arrays_01_real-6c5e850.json b/tests/reference/llvm-arrays_01_real-6c5e850.json index 717239515b5..f333797a914 100644 --- a/tests/reference/llvm-arrays_01_real-6c5e850.json +++ b/tests/reference/llvm-arrays_01_real-6c5e850.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01_real-6c5e850.stdout", - "stdout_hash": "347a9f038653343d85246444f9aa200ed00f5415749c1583505d9721", + "stdout_hash": "7ece294b1b20888d4f5f74bf6fbdef255e0b1a28ce53449f6b975a20", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01_real-6c5e850.stdout b/tests/reference/llvm-arrays_01_real-6c5e850.stdout index 8277192e969..dcfc9792e06 100644 --- a/tests/reference/llvm-arrays_01_real-6c5e850.stdout +++ b/tests/reference/llvm-arrays_01_real-6c5e850.stdout @@ -180,17 +180,14 @@ loop.body: ; preds = %loop.head %11 = icmp slt i32 %7, 1 %12 = icmp sgt i32 %7, 3 %13 = or i1 %11, %12 - br i1 %13, label %then, label %else + br i1 %13, label %then, label %ifcont then: ; preds = %loop.body call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0), i32 %7, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont + unreachable -else: ; preds = %loop.body - br label %ifcont - -ifcont: ; preds = %else, %then +ifcont: ; preds = %loop.body %14 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 %10 %15 = load i32, i32* %i1, align 4 %16 = add i32 %15, 10 @@ -199,97 +196,88 @@ ifcont: ; preds = %else, %then br label %loop.head loop.end: ; preds = %loop.head - br i1 false, label %then3, label %else4 + br i1 false, label %then3, label %ifcont4 then3: ; preds = %loop.end call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont5 - -else4: ; preds = %loop.end - br label %ifcont5 + unreachable -ifcont5: ; preds = %else4, %then3 +ifcont4: ; preds = %loop.end %18 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 %19 = load double, double* %18, align 8 %20 = fcmp une double %19, 1.100000e+01 - br i1 %20, label %then6, label %else7 + br i1 %20, label %then5, label %else -then6: ; preds = %ifcont5 +then5: ; preds = %ifcont4 %21 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 %22 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %21, i8* %22) call void @exit(i32 1) - br label %ifcont8 + br label %ifcont6 -else7: ; preds = %ifcont5 - br label %ifcont8 +else: ; preds = %ifcont4 + br label %ifcont6 -ifcont8: ; preds = %else7, %then6 - br i1 false, label %then9, label %else10 +ifcont6: ; preds = %else, %then5 + br i1 false, label %then7, label %ifcont8 -then9: ; preds = %ifcont8 +then7: ; preds = %ifcont6 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @6, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @5, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont11 - -else10: ; preds = %ifcont8 - br label %ifcont11 + unreachable -ifcont11: ; preds = %else10, %then9 +ifcont8: ; preds = %ifcont6 %23 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 1 %24 = load double, double* %23, align 8 %25 = fcmp une double %24, 1.200000e+01 - br i1 %25, label %then12, label %else13 + br i1 %25, label %then9, label %else10 -then12: ; preds = %ifcont11 +then9: ; preds = %ifcont8 %26 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 %27 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %26, i8* %27) call void @exit(i32 1) - br label %ifcont14 + br label %ifcont11 -else13: ; preds = %ifcont11 - br label %ifcont14 +else10: ; preds = %ifcont8 + br label %ifcont11 -ifcont14: ; preds = %else13, %then12 - br i1 false, label %then15, label %else16 +ifcont11: ; preds = %else10, %then9 + br i1 false, label %then12, label %ifcont13 -then15: ; preds = %ifcont14 +then12: ; preds = %ifcont11 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @9, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @8, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont17 + unreachable -else16: ; preds = %ifcont14 - br label %ifcont17 - -ifcont17: ; preds = %else16, %then15 +ifcont13: ; preds = %ifcont11 %28 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 2 %29 = load double, double* %28, align 8 %30 = fcmp une double %29, 1.300000e+01 - br i1 %30, label %then18, label %else19 + br i1 %30, label %then14, label %else15 -then18: ; preds = %ifcont17 +then14: ; preds = %ifcont13 %31 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 %32 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @10, i32 0, i32 0), i8* %31, i8* %32) call void @exit(i32 1) - br label %ifcont20 + br label %ifcont16 -else19: ; preds = %ifcont17 - br label %ifcont20 +else15: ; preds = %ifcont13 + br label %ifcont16 -ifcont20: ; preds = %else19, %then18 +ifcont16: ; preds = %else15, %then14 store i32 10, i32* %i1, align 4 - br label %loop.head21 + br label %loop.head17 -loop.head21: ; preds = %ifcont25, %ifcont20 +loop.head17: ; preds = %ifcont20, %ifcont16 %33 = load i32, i32* %i1, align 4 %34 = add i32 %33, 1 %35 = icmp sle i32 %34, 14 - br i1 %35, label %loop.body22, label %loop.end26 + br i1 %35, label %loop.body18, label %loop.end21 -loop.body22: ; preds = %loop.head21 +loop.body18: ; preds = %loop.head17 %36 = load i32, i32* %i1, align 4 %37 = add i32 %36, 1 store i32 %37, i32* %i1, align 4 @@ -301,142 +289,127 @@ loop.body22: ; preds = %loop.head21 %43 = icmp slt i32 %39, 1 %44 = icmp sgt i32 %39, 4 %45 = or i1 %43, %44 - br i1 %45, label %then23, label %else24 + br i1 %45, label %then19, label %ifcont20 -then23: ; preds = %loop.body22 +then19: ; preds = %loop.body18 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @12, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @11, i32 0, i32 0), i32 %39, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont25 - -else24: ; preds = %loop.body22 - br label %ifcont25 + unreachable -ifcont25: ; preds = %else24, %then23 +ifcont20: ; preds = %loop.body18 %46 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 %42 %47 = load i32, i32* %i1, align 4 %48 = sitofp i32 %47 to double store double %48, double* %46, align 8 - br label %loop.head21 + br label %loop.head17 -loop.end26: ; preds = %loop.head21 - br i1 false, label %then27, label %else28 +loop.end21: ; preds = %loop.head17 + br i1 false, label %then22, label %ifcont23 -then27: ; preds = %loop.end26 +then22: ; preds = %loop.end21 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont29 - -else28: ; preds = %loop.end26 - br label %ifcont29 + unreachable -ifcont29: ; preds = %else28, %then27 +ifcont23: ; preds = %loop.end21 %49 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 %50 = load double, double* %49, align 8 %51 = fcmp une double %50, 1.100000e+01 - br i1 %51, label %then30, label %else31 + br i1 %51, label %then24, label %else25 -then30: ; preds = %ifcont29 +then24: ; preds = %ifcont23 %52 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 %53 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @15, i32 0, i32 0), i8* %52, i8* %53) call void @exit(i32 1) - br label %ifcont32 + br label %ifcont26 -else31: ; preds = %ifcont29 - br label %ifcont32 +else25: ; preds = %ifcont23 + br label %ifcont26 -ifcont32: ; preds = %else31, %then30 - br i1 false, label %then33, label %else34 +ifcont26: ; preds = %else25, %then24 + br i1 false, label %then27, label %ifcont28 -then33: ; preds = %ifcont32 +then27: ; preds = %ifcont26 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @17, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @16, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont35 + unreachable -else34: ; preds = %ifcont32 - br label %ifcont35 - -ifcont35: ; preds = %else34, %then33 +ifcont28: ; preds = %ifcont26 %54 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 %55 = load double, double* %54, align 8 %56 = fcmp une double %55, 1.200000e+01 - br i1 %56, label %then36, label %else37 + br i1 %56, label %then29, label %else30 -then36: ; preds = %ifcont35 +then29: ; preds = %ifcont28 %57 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 %58 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @18, i32 0, i32 0), i8* %57, i8* %58) call void @exit(i32 1) - br label %ifcont38 + br label %ifcont31 -else37: ; preds = %ifcont35 - br label %ifcont38 +else30: ; preds = %ifcont28 + br label %ifcont31 -ifcont38: ; preds = %else37, %then36 - br i1 false, label %then39, label %else40 +ifcont31: ; preds = %else30, %then29 + br i1 false, label %then32, label %ifcont33 -then39: ; preds = %ifcont38 +then32: ; preds = %ifcont31 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont41 + unreachable -else40: ; preds = %ifcont38 - br label %ifcont41 - -ifcont41: ; preds = %else40, %then39 +ifcont33: ; preds = %ifcont31 %59 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 %60 = load double, double* %59, align 8 %61 = fcmp une double %60, 1.300000e+01 - br i1 %61, label %then42, label %else43 + br i1 %61, label %then34, label %else35 -then42: ; preds = %ifcont41 +then34: ; preds = %ifcont33 %62 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 %63 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @21, i32 0, i32 0), i8* %62, i8* %63) call void @exit(i32 1) - br label %ifcont44 + br label %ifcont36 -else43: ; preds = %ifcont41 - br label %ifcont44 +else35: ; preds = %ifcont33 + br label %ifcont36 -ifcont44: ; preds = %else43, %then42 - br i1 false, label %then45, label %else46 +ifcont36: ; preds = %else35, %then34 + br i1 false, label %then37, label %ifcont38 -then45: ; preds = %ifcont44 +then37: ; preds = %ifcont36 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @23, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @22, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont47 - -else46: ; preds = %ifcont44 - br label %ifcont47 + unreachable -ifcont47: ; preds = %else46, %then45 +ifcont38: ; preds = %ifcont36 %64 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 %65 = load double, double* %64, align 8 %66 = fcmp une double %65, 1.400000e+01 - br i1 %66, label %then48, label %else49 + br i1 %66, label %then39, label %else40 -then48: ; preds = %ifcont47 +then39: ; preds = %ifcont38 %67 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 %68 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @24, i32 0, i32 0), i8* %67, i8* %68) call void @exit(i32 1) - br label %ifcont50 + br label %ifcont41 -else49: ; preds = %ifcont47 - br label %ifcont50 +else40: ; preds = %ifcont38 + br label %ifcont41 -ifcont50: ; preds = %else49, %then48 +ifcont41: ; preds = %else40, %then39 store i32 0, i32* %i1, align 4 - br label %loop.head51 + br label %loop.head42 -loop.head51: ; preds = %ifcont58, %ifcont50 +loop.head42: ; preds = %ifcont47, %ifcont41 %69 = load i32, i32* %i1, align 4 %70 = add i32 %69, 1 %71 = icmp sle i32 %70, 3 - br i1 %71, label %loop.body52, label %loop.end59 + br i1 %71, label %loop.body43, label %loop.end48 -loop.body52: ; preds = %loop.head51 +loop.body43: ; preds = %loop.head42 %72 = load i32, i32* %i1, align 4 %73 = add i32 %72, 1 store i32 %73, i32* %i1, align 4 @@ -447,17 +420,14 @@ loop.body52: ; preds = %loop.head51 %78 = icmp slt i32 %74, 1 %79 = icmp sgt i32 %74, 4 %80 = or i1 %78, %79 - br i1 %80, label %then53, label %else54 + br i1 %80, label %then44, label %ifcont45 -then53: ; preds = %loop.body52 +then44: ; preds = %loop.body43 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @26, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @25, i32 0, i32 0), i32 %74, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont55 - -else54: ; preds = %loop.body52 - br label %ifcont55 + unreachable -ifcont55: ; preds = %else54, %then53 +ifcont45: ; preds = %loop.body43 %81 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 %77 %82 = load i32, i32* %i1, align 4 %83 = sub i32 %82, 1 @@ -466,276 +436,237 @@ ifcont55: ; preds = %else54, %then53 %86 = icmp slt i32 %82, 1 %87 = icmp sgt i32 %82, 3 %88 = or i1 %86, %87 - br i1 %88, label %then56, label %else57 + br i1 %88, label %then46, label %ifcont47 -then56: ; preds = %ifcont55 +then46: ; preds = %ifcont45 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %82, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont58 + unreachable -else57: ; preds = %ifcont55 - br label %ifcont58 - -ifcont58: ; preds = %else57, %then56 +ifcont47: ; preds = %ifcont45 %89 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 %85 %90 = load double, double* %89, align 8 %91 = fsub double %90, 1.000000e+01 store double %91, double* %81, align 8 - br label %loop.head51 + br label %loop.head42 -loop.end59: ; preds = %loop.head51 - br i1 false, label %then60, label %else61 +loop.end48: ; preds = %loop.head42 + br i1 false, label %then49, label %ifcont50 -then60: ; preds = %loop.end59 +then49: ; preds = %loop.end48 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont62 - -else61: ; preds = %loop.end59 - br label %ifcont62 + unreachable -ifcont62: ; preds = %else61, %then60 +ifcont50: ; preds = %loop.end48 %92 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 %93 = load double, double* %92, align 8 %94 = fcmp une double %93, 1.000000e+00 - br i1 %94, label %then63, label %else64 + br i1 %94, label %then51, label %else52 -then63: ; preds = %ifcont62 +then51: ; preds = %ifcont50 %95 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 %96 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @31, i32 0, i32 0), i8* %95, i8* %96) call void @exit(i32 1) - br label %ifcont65 + br label %ifcont53 -else64: ; preds = %ifcont62 - br label %ifcont65 +else52: ; preds = %ifcont50 + br label %ifcont53 -ifcont65: ; preds = %else64, %then63 - br i1 false, label %then66, label %else67 +ifcont53: ; preds = %else52, %then51 + br i1 false, label %then54, label %ifcont55 -then66: ; preds = %ifcont65 +then54: ; preds = %ifcont53 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @33, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @32, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont68 + unreachable -else67: ; preds = %ifcont65 - br label %ifcont68 - -ifcont68: ; preds = %else67, %then66 +ifcont55: ; preds = %ifcont53 %97 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 %98 = load double, double* %97, align 8 %99 = fcmp une double %98, 2.000000e+00 - br i1 %99, label %then69, label %else70 + br i1 %99, label %then56, label %else57 -then69: ; preds = %ifcont68 +then56: ; preds = %ifcont55 %100 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 %101 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @34, i32 0, i32 0), i8* %100, i8* %101) call void @exit(i32 1) - br label %ifcont71 + br label %ifcont58 -else70: ; preds = %ifcont68 - br label %ifcont71 +else57: ; preds = %ifcont55 + br label %ifcont58 -ifcont71: ; preds = %else70, %then69 - br i1 false, label %then72, label %else73 +ifcont58: ; preds = %else57, %then56 + br i1 false, label %then59, label %ifcont60 -then72: ; preds = %ifcont71 +then59: ; preds = %ifcont58 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @36, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @35, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont74 - -else73: ; preds = %ifcont71 - br label %ifcont74 + unreachable -ifcont74: ; preds = %else73, %then72 +ifcont60: ; preds = %ifcont58 %102 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 %103 = load double, double* %102, align 8 %104 = fcmp une double %103, 3.000000e+00 - br i1 %104, label %then75, label %else76 + br i1 %104, label %then61, label %else62 -then75: ; preds = %ifcont74 +then61: ; preds = %ifcont60 %105 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 %106 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @37, i32 0, i32 0), i8* %105, i8* %106) call void @exit(i32 1) - br label %ifcont77 + br label %ifcont63 -else76: ; preds = %ifcont74 - br label %ifcont77 +else62: ; preds = %ifcont60 + br label %ifcont63 -ifcont77: ; preds = %else76, %then75 - br i1 false, label %then78, label %else79 +ifcont63: ; preds = %else62, %then61 + br i1 false, label %then64, label %ifcont65 -then78: ; preds = %ifcont77 +then64: ; preds = %ifcont63 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @39, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @38, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont80 + unreachable -else79: ; preds = %ifcont77 - br label %ifcont80 - -ifcont80: ; preds = %else79, %then78 +ifcont65: ; preds = %ifcont63 %107 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - br i1 false, label %then81, label %else82 + br i1 false, label %then66, label %ifcont67 -then81: ; preds = %ifcont80 +then66: ; preds = %ifcont65 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont83 + unreachable -else82: ; preds = %ifcont80 - br label %ifcont83 - -ifcont83: ; preds = %else82, %then81 +ifcont67: ; preds = %ifcont65 %108 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 0 %109 = load double, double* %108, align 8 - br i1 false, label %then84, label %else85 + br i1 false, label %then68, label %ifcont69 -then84: ; preds = %ifcont83 +then68: ; preds = %ifcont67 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @43, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @42, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont86 - -else85: ; preds = %ifcont83 - br label %ifcont86 + unreachable -ifcont86: ; preds = %else85, %then84 +ifcont69: ; preds = %ifcont67 %110 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 1 %111 = load double, double* %110, align 8 %112 = fadd double %109, %111 - br i1 false, label %then87, label %else88 + br i1 false, label %then70, label %ifcont71 -then87: ; preds = %ifcont86 +then70: ; preds = %ifcont69 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @44, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont89 - -else88: ; preds = %ifcont86 - br label %ifcont89 + unreachable -ifcont89: ; preds = %else88, %then87 +ifcont71: ; preds = %ifcont69 %113 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 2 %114 = load double, double* %113, align 8 %115 = fadd double %112, %114 - br i1 false, label %then90, label %else91 + br i1 false, label %then72, label %ifcont73 -then90: ; preds = %ifcont89 +then72: ; preds = %ifcont71 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont92 - -else91: ; preds = %ifcont89 - br label %ifcont92 + unreachable -ifcont92: ; preds = %else91, %then90 +ifcont73: ; preds = %ifcont71 %116 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 %117 = load double, double* %116, align 8 %118 = fadd double %115, %117 store double %118, double* %107, align 8 - br i1 false, label %then93, label %else94 + br i1 false, label %then74, label %ifcont75 -then93: ; preds = %ifcont92 +then74: ; preds = %ifcont73 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont95 + unreachable -else94: ; preds = %ifcont92 - br label %ifcont95 - -ifcont95: ; preds = %else94, %then93 +ifcont75: ; preds = %ifcont73 %119 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 %120 = load double, double* %119, align 8 %121 = fcmp une double %120, 1.700000e+01 - br i1 %121, label %then96, label %else97 + br i1 %121, label %then76, label %else77 -then96: ; preds = %ifcont95 +then76: ; preds = %ifcont75 %122 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 %123 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @50, i32 0, i32 0), i8* %122, i8* %123) call void @exit(i32 1) - br label %ifcont98 + br label %ifcont78 -else97: ; preds = %ifcont95 - br label %ifcont98 +else77: ; preds = %ifcont75 + br label %ifcont78 -ifcont98: ; preds = %else97, %then96 - br i1 false, label %then99, label %else100 +ifcont78: ; preds = %else77, %then76 + br i1 false, label %then79, label %ifcont80 -then99: ; preds = %ifcont98 +then79: ; preds = %ifcont78 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @52, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @51, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont101 - -else100: ; preds = %ifcont98 - br label %ifcont101 + unreachable -ifcont101: ; preds = %else100, %then99 +ifcont80: ; preds = %ifcont78 %124 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 - br i1 false, label %then102, label %else103 + br i1 false, label %then81, label %ifcont82 -then102: ; preds = %ifcont101 +then81: ; preds = %ifcont80 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont104 + unreachable -else103: ; preds = %ifcont101 - br label %ifcont104 - -ifcont104: ; preds = %else103, %then102 +ifcont82: ; preds = %ifcont80 %125 = getelementptr [3 x double], [3 x double]* %a, i32 0, i32 0 %126 = load double, double* %125, align 8 store double %126, double* %124, align 8 - br i1 false, label %then105, label %else106 + br i1 false, label %then83, label %ifcont84 -then105: ; preds = %ifcont104 +then83: ; preds = %ifcont82 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont107 - -else106: ; preds = %ifcont104 - br label %ifcont107 + unreachable -ifcont107: ; preds = %else106, %then105 +ifcont84: ; preds = %ifcont82 %127 = getelementptr [4 x double], [4 x double]* %b, i32 0, i32 3 %128 = load double, double* %127, align 8 %129 = fcmp une double %128, 1.100000e+01 - br i1 %129, label %then108, label %else109 + br i1 %129, label %then85, label %else86 -then108: ; preds = %ifcont107 +then85: ; preds = %ifcont84 %130 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 %131 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @57, i32 0, i32 0), i8* %130, i8* %131) call void @exit(i32 1) - br label %ifcont110 + br label %ifcont87 -else109: ; preds = %ifcont107 - br label %ifcont110 +else86: ; preds = %ifcont84 + br label %ifcont87 -ifcont110: ; preds = %else109, %then108 +ifcont87: ; preds = %else86, %then85 store i32 0, i32* %i1, align 4 - br label %loop.head111 + br label %loop.head88 -loop.head111: ; preds = %loop.end121, %ifcont110 +loop.head88: ; preds = %loop.end96, %ifcont87 %132 = load i32, i32* %i1, align 4 %133 = add i32 %132, 1 %134 = icmp sle i32 %133, 2 - br i1 %134, label %loop.body112, label %loop.end122 + br i1 %134, label %loop.body89, label %loop.end97 -loop.body112: ; preds = %loop.head111 +loop.body89: ; preds = %loop.head88 %135 = load i32, i32* %i1, align 4 %136 = add i32 %135, 1 store i32 %136, i32* %i1, align 4 store i32 0, i32* %j2, align 4 - br label %loop.head113 + br label %loop.head90 -loop.head113: ; preds = %ifcont120, %loop.body112 +loop.head90: ; preds = %ifcont95, %loop.body89 %137 = load i32, i32* %j2, align 4 %138 = add i32 %137, 1 %139 = icmp sle i32 %138, 2 - br i1 %139, label %loop.body114, label %loop.end121 + br i1 %139, label %loop.body91, label %loop.end96 -loop.body114: ; preds = %loop.head113 +loop.body91: ; preds = %loop.head90 %140 = load i32, i32* %j2, align 4 %141 = add i32 %140, 1 store i32 %141, i32* %j2, align 4 @@ -747,34 +678,28 @@ loop.body114: ; preds = %loop.head113 %147 = icmp slt i32 %142, 1 %148 = icmp sgt i32 %142, 2 %149 = or i1 %147, %148 - br i1 %149, label %then115, label %else116 + br i1 %149, label %then92, label %ifcont93 -then115: ; preds = %loop.body114 +then92: ; preds = %loop.body91 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @59, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @58, i32 0, i32 0), i32 %142, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont117 + unreachable -else116: ; preds = %loop.body114 - br label %ifcont117 - -ifcont117: ; preds = %else116, %then115 +ifcont93: ; preds = %loop.body91 %150 = sub i32 %143, 1 %151 = mul i32 2, %150 %152 = add i32 %146, %151 %153 = icmp slt i32 %143, 1 %154 = icmp sgt i32 %143, 2 %155 = or i1 %153, %154 - br i1 %155, label %then118, label %else119 + br i1 %155, label %then94, label %ifcont95 -then118: ; preds = %ifcont117 +then94: ; preds = %ifcont93 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @61, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @60, i32 0, i32 0), i32 %143, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont120 - -else119: ; preds = %ifcont117 - br label %ifcont120 + unreachable -ifcont120: ; preds = %else119, %then118 +ifcont95: ; preds = %ifcont93 %156 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 %152 %157 = load i32, i32* %i1, align 4 %158 = load i32, i32* %j2, align 4 @@ -782,168 +707,144 @@ ifcont120: ; preds = %else119, %then118 %160 = add i32 %159, 10 %161 = sitofp i32 %160 to double store double %161, double* %156, align 8 - br label %loop.head113 + br label %loop.head90 -loop.end121: ; preds = %loop.head113 - br label %loop.head111 +loop.end96: ; preds = %loop.head90 + br label %loop.head88 -loop.end122: ; preds = %loop.head111 - br i1 false, label %then123, label %else124 +loop.end97: ; preds = %loop.head88 + br i1 false, label %then98, label %ifcont99 -then123: ; preds = %loop.end122 +then98: ; preds = %loop.end97 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @63, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @62, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont125 + unreachable -else124: ; preds = %loop.end122 - br label %ifcont125 - -ifcont125: ; preds = %else124, %then123 - br i1 false, label %then126, label %else127 +ifcont99: ; preds = %loop.end97 + br i1 false, label %then100, label %ifcont101 -then126: ; preds = %ifcont125 +then100: ; preds = %ifcont99 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @65, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @64, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont128 + unreachable -else127: ; preds = %ifcont125 - br label %ifcont128 - -ifcont128: ; preds = %else127, %then126 +ifcont101: ; preds = %ifcont99 %162 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 0 %163 = load double, double* %162, align 8 %164 = fcmp une double %163, 1.200000e+01 - br i1 %164, label %then129, label %else130 + br i1 %164, label %then102, label %else103 -then129: ; preds = %ifcont128 +then102: ; preds = %ifcont101 %165 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 %166 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @66, i32 0, i32 0), i8* %165, i8* %166) call void @exit(i32 1) - br label %ifcont131 + br label %ifcont104 -else130: ; preds = %ifcont128 - br label %ifcont131 +else103: ; preds = %ifcont101 + br label %ifcont104 -ifcont131: ; preds = %else130, %then129 - br i1 false, label %then132, label %else133 +ifcont104: ; preds = %else103, %then102 + br i1 false, label %then105, label %ifcont106 -then132: ; preds = %ifcont131 +then105: ; preds = %ifcont104 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @68, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @67, i32 0, i32 0), i32 1, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont134 - -else133: ; preds = %ifcont131 - br label %ifcont134 + unreachable -ifcont134: ; preds = %else133, %then132 - br i1 false, label %then135, label %else136 +ifcont106: ; preds = %ifcont104 + br i1 false, label %then107, label %ifcont108 -then135: ; preds = %ifcont134 +then107: ; preds = %ifcont106 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @70, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @69, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont137 + unreachable -else136: ; preds = %ifcont134 - br label %ifcont137 - -ifcont137: ; preds = %else136, %then135 +ifcont108: ; preds = %ifcont106 %167 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 2 %168 = load double, double* %167, align 8 %169 = fcmp une double %168, 1.300000e+01 - br i1 %169, label %then138, label %else139 + br i1 %169, label %then109, label %else110 -then138: ; preds = %ifcont137 +then109: ; preds = %ifcont108 %170 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 %171 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @71, i32 0, i32 0), i8* %170, i8* %171) call void @exit(i32 1) - br label %ifcont140 + br label %ifcont111 -else139: ; preds = %ifcont137 - br label %ifcont140 +else110: ; preds = %ifcont108 + br label %ifcont111 -ifcont140: ; preds = %else139, %then138 - br i1 false, label %then141, label %else142 +ifcont111: ; preds = %else110, %then109 + br i1 false, label %then112, label %ifcont113 -then141: ; preds = %ifcont140 +then112: ; preds = %ifcont111 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @73, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @72, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont143 - -else142: ; preds = %ifcont140 - br label %ifcont143 + unreachable -ifcont143: ; preds = %else142, %then141 - br i1 false, label %then144, label %else145 +ifcont113: ; preds = %ifcont111 + br i1 false, label %then114, label %ifcont115 -then144: ; preds = %ifcont143 +then114: ; preds = %ifcont113 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @75, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @74, i32 0, i32 0), i32 1, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont146 - -else145: ; preds = %ifcont143 - br label %ifcont146 + unreachable -ifcont146: ; preds = %else145, %then144 +ifcont115: ; preds = %ifcont113 %172 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 1 %173 = load double, double* %172, align 8 %174 = fcmp une double %173, 1.300000e+01 - br i1 %174, label %then147, label %else148 + br i1 %174, label %then116, label %else117 -then147: ; preds = %ifcont146 +then116: ; preds = %ifcont115 %175 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.56, i32 0, i32 0), align 8 %176 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.58, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @76, i32 0, i32 0), i8* %175, i8* %176) call void @exit(i32 1) - br label %ifcont149 + br label %ifcont118 -else148: ; preds = %ifcont146 - br label %ifcont149 +else117: ; preds = %ifcont115 + br label %ifcont118 -ifcont149: ; preds = %else148, %then147 - br i1 false, label %then150, label %else151 +ifcont118: ; preds = %else117, %then116 + br i1 false, label %then119, label %ifcont120 -then150: ; preds = %ifcont149 +then119: ; preds = %ifcont118 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @78, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @77, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont152 + unreachable -else151: ; preds = %ifcont149 - br label %ifcont152 +ifcont120: ; preds = %ifcont118 + br i1 false, label %then121, label %ifcont122 -ifcont152: ; preds = %else151, %then150 - br i1 false, label %then153, label %else154 - -then153: ; preds = %ifcont152 +then121: ; preds = %ifcont120 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @80, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @79, i32 0, i32 0), i32 2, i32 2, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont155 - -else154: ; preds = %ifcont152 - br label %ifcont155 + unreachable -ifcont155: ; preds = %else154, %then153 +ifcont122: ; preds = %ifcont120 %177 = getelementptr [4 x double], [4 x double]* %c, i32 0, i32 3 %178 = load double, double* %177, align 8 %179 = fcmp une double %178, 1.400000e+01 - br i1 %179, label %then156, label %else157 + br i1 %179, label %then123, label %else124 -then156: ; preds = %ifcont155 +then123: ; preds = %ifcont122 %180 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.60, i32 0, i32 0), align 8 %181 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.62, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @81, i32 0, i32 0), i8* %180, i8* %181) call void @exit(i32 1) - br label %ifcont158 + br label %ifcont125 -else157: ; preds = %ifcont155 - br label %ifcont158 +else124: ; preds = %ifcont122 + br label %ifcont125 -ifcont158: ; preds = %else157, %then156 +ifcont125: ; preds = %else124, %then123 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont158 +return: ; preds = %ifcont125 ret i32 0 } diff --git a/tests/reference/llvm-arrays_01_size-aaed99f.json b/tests/reference/llvm-arrays_01_size-aaed99f.json index be441300025..14cae5b64c8 100644 --- a/tests/reference/llvm-arrays_01_size-aaed99f.json +++ b/tests/reference/llvm-arrays_01_size-aaed99f.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-arrays_01_size-aaed99f.stdout", - "stdout_hash": "9b611b0f4a1dddb3af0855b886eb4a0dea47cf1a087d84a4893e8401", + "stdout_hash": "b7a48d79992e83990b759d3540a57159f769af1b86f2fbb0f532167b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-arrays_01_size-aaed99f.stdout b/tests/reference/llvm-arrays_01_size-aaed99f.stdout index 421d90909ca..79649222c54 100644 --- a/tests/reference/llvm-arrays_01_size-aaed99f.stdout +++ b/tests/reference/llvm-arrays_01_size-aaed99f.stdout @@ -166,7 +166,7 @@ ifcont6: ; preds = %else5, %then4 store i32 0, i32* %i1, align 4 br label %loop.head -loop.head: ; preds = %ifcont9, %ifcont6 +loop.head: ; preds = %ifcont8, %ifcont6 %10 = load i32, i32* %i1, align 4 %11 = add i32 %10, 1 %12 = load i32, i32* %size_a2, align 4 @@ -184,17 +184,14 @@ loop.body: ; preds = %loop.head %20 = icmp slt i32 %16, 1 %21 = icmp sgt i32 %16, 3 %22 = or i1 %20, %21 - br i1 %22, label %then7, label %else8 + br i1 %22, label %then7, label %ifcont8 then7: ; preds = %loop.body call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @2, i32 0, i32 0), i32 %16, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont9 + unreachable -else8: ; preds = %loop.body - br label %ifcont9 - -ifcont9: ; preds = %else8, %then7 +ifcont8: ; preds = %loop.body %23 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %19 %24 = load i32, i32* %i1, align 4 %25 = add i32 %24, 10 @@ -202,99 +199,90 @@ ifcont9: ; preds = %else8, %then7 br label %loop.head loop.end: ; preds = %loop.head - br i1 false, label %then10, label %else11 + br i1 false, label %then9, label %ifcont10 -then10: ; preds = %loop.end +then9: ; preds = %loop.end call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont12 - -else11: ; preds = %loop.end - br label %ifcont12 + unreachable -ifcont12: ; preds = %else11, %then10 +ifcont10: ; preds = %loop.end %26 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 %27 = load i32, i32* %26, align 4 %28 = icmp ne i32 %27, 11 - br i1 %28, label %then13, label %else14 + br i1 %28, label %then11, label %else12 -then13: ; preds = %ifcont12 +then11: ; preds = %ifcont10 %29 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 %30 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i8* %29, i8* %30) call void @exit(i32 1) - br label %ifcont15 + br label %ifcont13 -else14: ; preds = %ifcont12 - br label %ifcont15 +else12: ; preds = %ifcont10 + br label %ifcont13 -ifcont15: ; preds = %else14, %then13 - br i1 false, label %then16, label %else17 +ifcont13: ; preds = %else12, %then11 + br i1 false, label %then14, label %ifcont15 -then16: ; preds = %ifcont15 +then14: ; preds = %ifcont13 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @8, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @7, i32 0, i32 0), i32 2, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont18 + unreachable -else17: ; preds = %ifcont15 - br label %ifcont18 - -ifcont18: ; preds = %else17, %then16 +ifcont15: ; preds = %ifcont13 %31 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 1 %32 = load i32, i32* %31, align 4 %33 = icmp ne i32 %32, 12 - br i1 %33, label %then19, label %else20 + br i1 %33, label %then16, label %else17 -then19: ; preds = %ifcont18 +then16: ; preds = %ifcont15 %34 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 %35 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i8* %34, i8* %35) call void @exit(i32 1) - br label %ifcont21 + br label %ifcont18 -else20: ; preds = %ifcont18 - br label %ifcont21 +else17: ; preds = %ifcont15 + br label %ifcont18 -ifcont21: ; preds = %else20, %then19 - br i1 false, label %then22, label %else23 +ifcont18: ; preds = %else17, %then16 + br i1 false, label %then19, label %ifcont20 -then22: ; preds = %ifcont21 +then19: ; preds = %ifcont18 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @11, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @10, i32 0, i32 0), i32 3, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont24 - -else23: ; preds = %ifcont21 - br label %ifcont24 + unreachable -ifcont24: ; preds = %else23, %then22 +ifcont20: ; preds = %ifcont18 %36 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 2 %37 = load i32, i32* %36, align 4 %38 = icmp ne i32 %37, 13 - br i1 %38, label %then25, label %else26 + br i1 %38, label %then21, label %else22 -then25: ; preds = %ifcont24 +then21: ; preds = %ifcont20 %39 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 %40 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i8* %39, i8* %40) call void @exit(i32 1) - br label %ifcont27 + br label %ifcont23 -else26: ; preds = %ifcont24 - br label %ifcont27 +else22: ; preds = %ifcont20 + br label %ifcont23 -ifcont27: ; preds = %else26, %then25 +ifcont23: ; preds = %else22, %then21 store i32 10, i32* %i1, align 4 - br label %loop.head28 + br label %loop.head24 -loop.head28: ; preds = %ifcont32, %ifcont27 +loop.head24: ; preds = %ifcont27, %ifcont23 %41 = load i32, i32* %i1, align 4 %42 = add i32 %41, 1 %43 = load i32, i32* %size_b3, align 4 %44 = add i32 10, %43 %45 = icmp sle i32 %42, %44 - br i1 %45, label %loop.body29, label %loop.end33 + br i1 %45, label %loop.body25, label %loop.end28 -loop.body29: ; preds = %loop.head28 +loop.body25: ; preds = %loop.head24 %46 = load i32, i32* %i1, align 4 %47 = add i32 %46, 1 store i32 %47, i32* %i1, align 4 @@ -306,142 +294,127 @@ loop.body29: ; preds = %loop.head28 %53 = icmp slt i32 %49, 1 %54 = icmp sgt i32 %49, 4 %55 = or i1 %53, %54 - br i1 %55, label %then30, label %else31 + br i1 %55, label %then26, label %ifcont27 -then30: ; preds = %loop.body29 +then26: ; preds = %loop.body25 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @14, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @13, i32 0, i32 0), i32 %49, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont32 + unreachable -else31: ; preds = %loop.body29 - br label %ifcont32 - -ifcont32: ; preds = %else31, %then30 +ifcont27: ; preds = %loop.body25 %56 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %52 %57 = load i32, i32* %i1, align 4 store i32 %57, i32* %56, align 4 - br label %loop.head28 + br label %loop.head24 -loop.end33: ; preds = %loop.head28 - br i1 false, label %then34, label %else35 +loop.end28: ; preds = %loop.head24 + br i1 false, label %then29, label %ifcont30 -then34: ; preds = %loop.end33 +then29: ; preds = %loop.end28 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont36 - -else35: ; preds = %loop.end33 - br label %ifcont36 + unreachable -ifcont36: ; preds = %else35, %then34 +ifcont30: ; preds = %loop.end28 %58 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 %59 = load i32, i32* %58, align 4 %60 = icmp ne i32 %59, 11 - br i1 %60, label %then37, label %else38 + br i1 %60, label %then31, label %else32 -then37: ; preds = %ifcont36 +then31: ; preds = %ifcont30 %61 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 %62 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @17, i32 0, i32 0), i8* %61, i8* %62) call void @exit(i32 1) - br label %ifcont39 + br label %ifcont33 -else38: ; preds = %ifcont36 - br label %ifcont39 +else32: ; preds = %ifcont30 + br label %ifcont33 -ifcont39: ; preds = %else38, %then37 - br i1 false, label %then40, label %else41 +ifcont33: ; preds = %else32, %then31 + br i1 false, label %then34, label %ifcont35 -then40: ; preds = %ifcont39 +then34: ; preds = %ifcont33 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @19, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @18, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont42 + unreachable -else41: ; preds = %ifcont39 - br label %ifcont42 - -ifcont42: ; preds = %else41, %then40 +ifcont35: ; preds = %ifcont33 %63 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 %64 = load i32, i32* %63, align 4 %65 = icmp ne i32 %64, 12 - br i1 %65, label %then43, label %else44 + br i1 %65, label %then36, label %else37 -then43: ; preds = %ifcont42 +then36: ; preds = %ifcont35 %66 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.24, i32 0, i32 0), align 8 %67 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.26, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @20, i32 0, i32 0), i8* %66, i8* %67) call void @exit(i32 1) - br label %ifcont45 + br label %ifcont38 -else44: ; preds = %ifcont42 - br label %ifcont45 +else37: ; preds = %ifcont35 + br label %ifcont38 -ifcont45: ; preds = %else44, %then43 - br i1 false, label %then46, label %else47 +ifcont38: ; preds = %else37, %then36 + br i1 false, label %then39, label %ifcont40 -then46: ; preds = %ifcont45 +then39: ; preds = %ifcont38 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @22, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @21, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont48 - -else47: ; preds = %ifcont45 - br label %ifcont48 + unreachable -ifcont48: ; preds = %else47, %then46 +ifcont40: ; preds = %ifcont38 %68 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 %69 = load i32, i32* %68, align 4 %70 = icmp ne i32 %69, 13 - br i1 %70, label %then49, label %else50 + br i1 %70, label %then41, label %else42 -then49: ; preds = %ifcont48 +then41: ; preds = %ifcont40 %71 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.28, i32 0, i32 0), align 8 %72 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.30, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @23, i32 0, i32 0), i8* %71, i8* %72) call void @exit(i32 1) - br label %ifcont51 + br label %ifcont43 -else50: ; preds = %ifcont48 - br label %ifcont51 +else42: ; preds = %ifcont40 + br label %ifcont43 -ifcont51: ; preds = %else50, %then49 - br i1 false, label %then52, label %else53 +ifcont43: ; preds = %else42, %then41 + br i1 false, label %then44, label %ifcont45 -then52: ; preds = %ifcont51 +then44: ; preds = %ifcont43 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @25, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @24, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont54 - -else53: ; preds = %ifcont51 - br label %ifcont54 + unreachable -ifcont54: ; preds = %else53, %then52 +ifcont45: ; preds = %ifcont43 %73 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 %74 = load i32, i32* %73, align 4 %75 = icmp ne i32 %74, 14 - br i1 %75, label %then55, label %else56 + br i1 %75, label %then46, label %else47 -then55: ; preds = %ifcont54 +then46: ; preds = %ifcont45 %76 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.32, i32 0, i32 0), align 8 %77 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.34, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @26, i32 0, i32 0), i8* %76, i8* %77) call void @exit(i32 1) - br label %ifcont57 + br label %ifcont48 -else56: ; preds = %ifcont54 - br label %ifcont57 +else47: ; preds = %ifcont45 + br label %ifcont48 -ifcont57: ; preds = %else56, %then55 +ifcont48: ; preds = %else47, %then46 store i32 0, i32* %i1, align 4 - br label %loop.head58 + br label %loop.head49 -loop.head58: ; preds = %ifcont65, %ifcont57 +loop.head49: ; preds = %ifcont54, %ifcont48 %78 = load i32, i32* %i1, align 4 %79 = add i32 %78, 1 %80 = load i32, i32* %size_a2, align 4 %81 = icmp sle i32 %79, %80 - br i1 %81, label %loop.body59, label %loop.end66 + br i1 %81, label %loop.body50, label %loop.end55 -loop.body59: ; preds = %loop.head58 +loop.body50: ; preds = %loop.head49 %82 = load i32, i32* %i1, align 4 %83 = add i32 %82, 1 store i32 %83, i32* %i1, align 4 @@ -452,17 +425,14 @@ loop.body59: ; preds = %loop.head58 %88 = icmp slt i32 %84, 1 %89 = icmp sgt i32 %84, 4 %90 = or i1 %88, %89 - br i1 %90, label %then60, label %else61 + br i1 %90, label %then51, label %ifcont52 -then60: ; preds = %loop.body59 +then51: ; preds = %loop.body50 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @28, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @27, i32 0, i32 0), i32 %84, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont62 + unreachable -else61: ; preds = %loop.body59 - br label %ifcont62 - -ifcont62: ; preds = %else61, %then60 +ifcont52: ; preds = %loop.body50 %91 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 %87 %92 = load i32, i32* %i1, align 4 %93 = sub i32 %92, 1 @@ -471,257 +441,218 @@ ifcont62: ; preds = %else61, %then60 %96 = icmp slt i32 %92, 1 %97 = icmp sgt i32 %92, 3 %98 = or i1 %96, %97 - br i1 %98, label %then63, label %else64 + br i1 %98, label %then53, label %ifcont54 -then63: ; preds = %ifcont62 +then53: ; preds = %ifcont52 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @30, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @29, i32 0, i32 0), i32 %92, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont65 - -else64: ; preds = %ifcont62 - br label %ifcont65 + unreachable -ifcont65: ; preds = %else64, %then63 +ifcont54: ; preds = %ifcont52 %99 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 %95 %100 = load i32, i32* %99, align 4 %101 = sub i32 %100, 10 store i32 %101, i32* %91, align 4 - br label %loop.head58 + br label %loop.head49 -loop.end66: ; preds = %loop.head58 - br i1 false, label %then67, label %else68 +loop.end55: ; preds = %loop.head49 + br i1 false, label %then56, label %ifcont57 -then67: ; preds = %loop.end66 +then56: ; preds = %loop.end55 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @32, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @31, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont69 - -else68: ; preds = %loop.end66 - br label %ifcont69 + unreachable -ifcont69: ; preds = %else68, %then67 +ifcont57: ; preds = %loop.end55 %102 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 %103 = load i32, i32* %102, align 4 %104 = icmp ne i32 %103, 1 - br i1 %104, label %then70, label %else71 + br i1 %104, label %then58, label %else59 -then70: ; preds = %ifcont69 +then58: ; preds = %ifcont57 %105 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.36, i32 0, i32 0), align 8 %106 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.38, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @33, i32 0, i32 0), i8* %105, i8* %106) call void @exit(i32 1) - br label %ifcont72 + br label %ifcont60 -else71: ; preds = %ifcont69 - br label %ifcont72 +else59: ; preds = %ifcont57 + br label %ifcont60 -ifcont72: ; preds = %else71, %then70 - br i1 false, label %then73, label %else74 +ifcont60: ; preds = %else59, %then58 + br i1 false, label %then61, label %ifcont62 -then73: ; preds = %ifcont72 +then61: ; preds = %ifcont60 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @35, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @34, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont75 - -else74: ; preds = %ifcont72 - br label %ifcont75 + unreachable -ifcont75: ; preds = %else74, %then73 +ifcont62: ; preds = %ifcont60 %107 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 %108 = load i32, i32* %107, align 4 %109 = icmp ne i32 %108, 2 - br i1 %109, label %then76, label %else77 + br i1 %109, label %then63, label %else64 -then76: ; preds = %ifcont75 +then63: ; preds = %ifcont62 %110 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.40, i32 0, i32 0), align 8 %111 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.42, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @36, i32 0, i32 0), i8* %110, i8* %111) call void @exit(i32 1) - br label %ifcont78 + br label %ifcont65 -else77: ; preds = %ifcont75 - br label %ifcont78 +else64: ; preds = %ifcont62 + br label %ifcont65 -ifcont78: ; preds = %else77, %then76 - br i1 false, label %then79, label %else80 +ifcont65: ; preds = %else64, %then63 + br i1 false, label %then66, label %ifcont67 -then79: ; preds = %ifcont78 +then66: ; preds = %ifcont65 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @38, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @37, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont81 - -else80: ; preds = %ifcont78 - br label %ifcont81 + unreachable -ifcont81: ; preds = %else80, %then79 +ifcont67: ; preds = %ifcont65 %112 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 %113 = load i32, i32* %112, align 4 %114 = icmp ne i32 %113, 3 - br i1 %114, label %then82, label %else83 + br i1 %114, label %then68, label %else69 -then82: ; preds = %ifcont81 +then68: ; preds = %ifcont67 %115 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.44, i32 0, i32 0), align 8 %116 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.46, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @39, i32 0, i32 0), i8* %115, i8* %116) call void @exit(i32 1) - br label %ifcont84 + br label %ifcont70 -else83: ; preds = %ifcont81 - br label %ifcont84 +else69: ; preds = %ifcont67 + br label %ifcont70 -ifcont84: ; preds = %else83, %then82 - br i1 false, label %then85, label %else86 +ifcont70: ; preds = %else69, %then68 + br i1 false, label %then71, label %ifcont72 -then85: ; preds = %ifcont84 +then71: ; preds = %ifcont70 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @41, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @40, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont87 + unreachable -else86: ; preds = %ifcont84 - br label %ifcont87 - -ifcont87: ; preds = %else86, %then85 +ifcont72: ; preds = %ifcont70 %117 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - br i1 false, label %then88, label %else89 + br i1 false, label %then73, label %ifcont74 -then88: ; preds = %ifcont87 +then73: ; preds = %ifcont72 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @43, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @42, i32 0, i32 0), i32 1, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont90 - -else89: ; preds = %ifcont87 - br label %ifcont90 + unreachable -ifcont90: ; preds = %else89, %then88 +ifcont74: ; preds = %ifcont72 %118 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 0 %119 = load i32, i32* %118, align 4 - br i1 false, label %then91, label %else92 + br i1 false, label %then75, label %ifcont76 -then91: ; preds = %ifcont90 +then75: ; preds = %ifcont74 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @45, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @44, i32 0, i32 0), i32 2, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont93 + unreachable -else92: ; preds = %ifcont90 - br label %ifcont93 - -ifcont93: ; preds = %else92, %then91 +ifcont76: ; preds = %ifcont74 %120 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 1 %121 = load i32, i32* %120, align 4 %122 = add i32 %119, %121 - br i1 false, label %then94, label %else95 + br i1 false, label %then77, label %ifcont78 -then94: ; preds = %ifcont93 +then77: ; preds = %ifcont76 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @47, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @46, i32 0, i32 0), i32 3, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont96 - -else95: ; preds = %ifcont93 - br label %ifcont96 + unreachable -ifcont96: ; preds = %else95, %then94 +ifcont78: ; preds = %ifcont76 %123 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 2 %124 = load i32, i32* %123, align 4 %125 = add i32 %122, %124 - br i1 false, label %then97, label %else98 + br i1 false, label %then79, label %ifcont80 -then97: ; preds = %ifcont96 +then79: ; preds = %ifcont78 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @49, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @48, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont99 - -else98: ; preds = %ifcont96 - br label %ifcont99 + unreachable -ifcont99: ; preds = %else98, %then97 +ifcont80: ; preds = %ifcont78 %126 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 %127 = load i32, i32* %126, align 4 %128 = add i32 %125, %127 store i32 %128, i32* %117, align 4 - br i1 false, label %then100, label %else101 + br i1 false, label %then81, label %ifcont82 -then100: ; preds = %ifcont99 +then81: ; preds = %ifcont80 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @51, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @50, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont102 + unreachable -else101: ; preds = %ifcont99 - br label %ifcont102 - -ifcont102: ; preds = %else101, %then100 +ifcont82: ; preds = %ifcont80 %129 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 %130 = load i32, i32* %129, align 4 %131 = icmp ne i32 %130, 17 - br i1 %131, label %then103, label %else104 + br i1 %131, label %then83, label %else84 -then103: ; preds = %ifcont102 +then83: ; preds = %ifcont82 %132 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.48, i32 0, i32 0), align 8 %133 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.50, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @52, i32 0, i32 0), i8* %132, i8* %133) call void @exit(i32 1) - br label %ifcont105 + br label %ifcont85 -else104: ; preds = %ifcont102 - br label %ifcont105 +else84: ; preds = %ifcont82 + br label %ifcont85 -ifcont105: ; preds = %else104, %then103 - br i1 false, label %then106, label %else107 +ifcont85: ; preds = %else84, %then83 + br i1 false, label %then86, label %ifcont87 -then106: ; preds = %ifcont105 +then86: ; preds = %ifcont85 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @54, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @53, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont108 - -else107: ; preds = %ifcont105 - br label %ifcont108 + unreachable -ifcont108: ; preds = %else107, %then106 +ifcont87: ; preds = %ifcont85 %134 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 - br i1 false, label %then109, label %else110 + br i1 false, label %then88, label %ifcont89 -then109: ; preds = %ifcont108 +then88: ; preds = %ifcont87 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @56, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @55, i32 0, i32 0), i32 1, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont111 - -else110: ; preds = %ifcont108 - br label %ifcont111 + unreachable -ifcont111: ; preds = %else110, %then109 +ifcont89: ; preds = %ifcont87 %135 = getelementptr [3 x i32], [3 x i32]* %a, i32 0, i32 0 %136 = load i32, i32* %135, align 4 store i32 %136, i32* %134, align 4 - br i1 false, label %then112, label %else113 + br i1 false, label %then90, label %ifcont91 -then112: ; preds = %ifcont111 +then90: ; preds = %ifcont89 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @58, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @57, i32 0, i32 0), i32 4, i32 1, i32 1, i32 4) call void @exit(i32 1) - br label %ifcont114 - -else113: ; preds = %ifcont111 - br label %ifcont114 + unreachable -ifcont114: ; preds = %else113, %then112 +ifcont91: ; preds = %ifcont89 %137 = getelementptr [4 x i32], [4 x i32]* %b, i32 0, i32 3 %138 = load i32, i32* %137, align 4 %139 = icmp ne i32 %138, 11 - br i1 %139, label %then115, label %else116 + br i1 %139, label %then92, label %else93 -then115: ; preds = %ifcont114 +then92: ; preds = %ifcont91 %140 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.52, i32 0, i32 0), align 8 %141 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.54, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @59, i32 0, i32 0), i8* %140, i8* %141) call void @exit(i32 1) - br label %ifcont117 + br label %ifcont94 -else116: ; preds = %ifcont114 - br label %ifcont117 +else93: ; preds = %ifcont91 + br label %ifcont94 -ifcont117: ; preds = %else116, %then115 +ifcont94: ; preds = %else93, %then92 call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont117 +return: ; preds = %ifcont94 ret i32 0 } diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.json b/tests/reference/llvm-implicit_interface_04-9b6786e.json index 5d17598fd43..d1680b2f216 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.json +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-implicit_interface_04-9b6786e.stdout", - "stdout_hash": "40978903c72afdb9aa82bcf257ef31594db8a83c1b3195a4596f1b3f", + "stdout_hash": "b26c2ba6f5d79648b162866039e92e48b082a8c44723c13b576c7a89", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout index 2db5d054bf2..bdb5e1573c5 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout @@ -63,17 +63,14 @@ define i32 @main(i32 %0, i8** %1) { %6 = icmp slt i32 %2, 1 %7 = icmp sgt i32 %2, 3 %8 = or i1 %6, %7 - br i1 %8, label %then, label %else + br i1 %8, label %then, label %ifcont then: ; preds = %.entry call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @16, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @15, i32 0, i32 0), i32 %2, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont - -else: ; preds = %.entry - br label %ifcont + unreachable -ifcont: ; preds = %else, %then +ifcont: ; preds = %.entry %9 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %5 store i32 10, i32* %9, align 4 store i32 2, i32* %__1_k1, align 4 @@ -84,17 +81,14 @@ ifcont: ; preds = %else, %then %14 = icmp slt i32 %10, 1 %15 = icmp sgt i32 %10, 3 %16 = or i1 %14, %15 - br i1 %16, label %then2, label %else3 + br i1 %16, label %then2, label %ifcont3 then2: ; preds = %ifcont call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @18, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @17, i32 0, i32 0), i32 %10, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont4 - -else3: ; preds = %ifcont - br label %ifcont4 + unreachable -ifcont4: ; preds = %else3, %then2 +ifcont3: ; preds = %ifcont %17 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %13 store i32 20, i32* %17, align 4 store i32 3, i32* %__1_k1, align 4 @@ -105,37 +99,31 @@ ifcont4: ; preds = %else3, %then2 %22 = icmp slt i32 %18, 1 %23 = icmp sgt i32 %18, 3 %24 = or i1 %22, %23 - br i1 %24, label %then5, label %else6 + br i1 %24, label %then4, label %ifcont5 -then5: ; preds = %ifcont4 +then4: ; preds = %ifcont3 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @20, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @19, i32 0, i32 0), i32 %18, i32 1, i32 1, i32 3) call void @exit(i32 1) - br label %ifcont7 + unreachable -else6: ; preds = %ifcont4 - br label %ifcont7 - -ifcont7: ; preds = %else6, %then5 +ifcont5: ; preds = %ifcont3 %25 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %21 store i32 30, i32* %25, align 4 %26 = load i32, i32* @main.n, align 4 %27 = icmp ne i32 3, %26 - br i1 %27, label %then8, label %else9 + br i1 %27, label %then6, label %ifcont7 -then8: ; preds = %ifcont7 +then6: ; preds = %ifcont5 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @22, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @21, i32 0, i32 0), i32 3, i32 1, i32 2, i32 %26) call void @exit(i32 1) - br label %ifcont10 - -else9: ; preds = %ifcont7 - br label %ifcont10 + unreachable -ifcont10: ; preds = %else9, %then8 +ifcont7: ; preds = %ifcont5 call void @driver(void (i32*, i32*, i32*)* @implicit_interface_check, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @main.b, i32 0, i32 0), i32* @main.n) call void @_lpython_free_argv() br label %return -return: ; preds = %ifcont10 +return: ; preds = %ifcont7 ret i32 0 } @@ -159,17 +147,14 @@ define void @driver(void (i32*, i32*, i32*)* %fnc, i32* %arr, i32* %m) { %10 = sub i32 %9, 1 %11 = icmp sgt i32 3, %10 %12 = or i1 false, %11 - br i1 %12, label %then, label %else + br i1 %12, label %then, label %ifcont then: ; preds = %.entry call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @2, i32 0, i32 0), i32 3, i32 1, i32 1, i32 %10) call void @exit(i32 1) - br label %ifcont + unreachable -else: ; preds = %.entry - br label %ifcont - -ifcont: ; preds = %else, %then +ifcont: ; preds = %.entry %13 = mul i32 1, %8 %14 = getelementptr inbounds i32, i32* %arr, i32 2 call void %fnc(i32* %arr, i32* %m, i32* %14) @@ -218,103 +203,94 @@ ifcont3: ; preds = %else2, %then1 %10 = sub i32 %9, 1 %11 = icmp sgt i32 1, %10 %12 = or i1 false, %11 - br i1 %12, label %then4, label %else5 + br i1 %12, label %then4, label %ifcont5 then4: ; preds = %ifcont3 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @7, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i32 1, i32 1, i32 1, i32 %10) call void @exit(i32 1) - br label %ifcont6 + unreachable -else5: ; preds = %ifcont3 - br label %ifcont6 - -ifcont6: ; preds = %else5, %then4 +ifcont5: ; preds = %ifcont3 %13 = mul i32 1, %8 %14 = getelementptr inbounds i32, i32* %arr1, i32 0 %15 = load i32, i32* %14, align 4 %16 = icmp ne i32 %15, 10 - br i1 %16, label %then7, label %else8 + br i1 %16, label %then6, label %else7 -then7: ; preds = %ifcont6 +then6: ; preds = %ifcont5 %17 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 %18 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @8, i32 0, i32 0), i8* %17, i8* %18) call void @exit(i32 1) - br label %ifcont9 + br label %ifcont8 -else8: ; preds = %ifcont6 - br label %ifcont9 +else7: ; preds = %ifcont5 + br label %ifcont8 -ifcont9: ; preds = %else8, %then7 +ifcont8: ; preds = %else7, %then6 %19 = load i32, i32* %m, align 4 %20 = add i32 1, %19 %21 = sub i32 %20, 1 %22 = icmp sgt i32 2, %21 %23 = or i1 false, %22 - br i1 %23, label %then10, label %else11 + br i1 %23, label %then9, label %ifcont10 -then10: ; preds = %ifcont9 +then9: ; preds = %ifcont8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @9, i32 0, i32 0), i32 2, i32 1, i32 1, i32 %21) call void @exit(i32 1) - br label %ifcont12 - -else11: ; preds = %ifcont9 - br label %ifcont12 + unreachable -ifcont12: ; preds = %else11, %then10 +ifcont10: ; preds = %ifcont8 %24 = mul i32 1, %19 %25 = getelementptr inbounds i32, i32* %arr1, i32 1 %26 = load i32, i32* %25, align 4 %27 = icmp ne i32 %26, 20 - br i1 %27, label %then13, label %else14 + br i1 %27, label %then11, label %else12 -then13: ; preds = %ifcont12 +then11: ; preds = %ifcont10 %28 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 %29 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8* %28, i8* %29) call void @exit(i32 1) - br label %ifcont15 + br label %ifcont13 -else14: ; preds = %ifcont12 - br label %ifcont15 +else12: ; preds = %ifcont10 + br label %ifcont13 -ifcont15: ; preds = %else14, %then13 +ifcont13: ; preds = %else12, %then11 %30 = load i32, i32* %m, align 4 %31 = add i32 1, %30 %32 = sub i32 %31, 1 %33 = icmp sgt i32 3, %32 %34 = or i1 false, %33 - br i1 %34, label %then16, label %else17 + br i1 %34, label %then14, label %ifcont15 -then16: ; preds = %ifcont15 +then14: ; preds = %ifcont13 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @13, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @12, i32 0, i32 0), i32 3, i32 1, i32 1, i32 %32) call void @exit(i32 1) - br label %ifcont18 - -else17: ; preds = %ifcont15 - br label %ifcont18 + unreachable -ifcont18: ; preds = %else17, %then16 +ifcont15: ; preds = %ifcont13 %35 = mul i32 1, %30 %36 = getelementptr inbounds i32, i32* %arr1, i32 2 %37 = load i32, i32* %36, align 4 %38 = icmp ne i32 %37, 30 - br i1 %38, label %then19, label %else20 + br i1 %38, label %then16, label %else17 -then19: ; preds = %ifcont18 +then16: ; preds = %ifcont15 %39 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 %40 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @14, i32 0, i32 0), i8* %39, i8* %40) call void @exit(i32 1) - br label %ifcont21 + br label %ifcont18 -else20: ; preds = %ifcont18 - br label %ifcont21 +else17: ; preds = %ifcont15 + br label %ifcont18 -ifcont21: ; preds = %else20, %then19 +ifcont18: ; preds = %else17, %then16 br label %return -return: ; preds = %ifcont21 +return: ; preds = %ifcont18 ret void } diff --git a/tests/reference/llvm-modules_36-53c9a79.json b/tests/reference/llvm-modules_36-53c9a79.json index 3545d25cbd8..efd19f66dd1 100644 --- a/tests/reference/llvm-modules_36-53c9a79.json +++ b/tests/reference/llvm-modules_36-53c9a79.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-modules_36-53c9a79.stdout", - "stdout_hash": "ed7d419157bdc3660d495db9457633eb70ef577ee53d495cf992c014", + "stdout_hash": "277317a4a39c685db5ebe83ececb2ac298dc918d7e9e40cb7fcfcb75", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-modules_36-53c9a79.stdout b/tests/reference/llvm-modules_36-53c9a79.stdout index 7e30064d23e..db55779f8a2 100644 --- a/tests/reference/llvm-modules_36-53c9a79.stdout +++ b/tests/reference/llvm-modules_36-53c9a79.stdout @@ -50,17 +50,14 @@ loop.body: ; preds = %loop.head %16 = icmp slt i32 %9, 1 %17 = icmp sgt i32 %9, %15 %18 = or i1 %16, %17 - br i1 %18, label %then, label %else + br i1 %18, label %then, label %ifcont then: ; preds = %loop.body call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @7, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @6, i32 0, i32 0), i32 %9, i32 1, i32 1, i32 %15) call void @exit(i32 1) - br label %ifcont - -else: ; preds = %loop.body - br label %ifcont + unreachable -ifcont: ; preds = %else, %then +ifcont: ; preds = %loop.body %19 = mul i32 1, %10 %20 = getelementptr inbounds i1, i1* %mask, i32 %13 %21 = load i1, i1* %20, align 1 @@ -119,7 +116,7 @@ ifcont4: ; preds = %else3, %then2 store i32 %4, i32* %__libasr_index_0_, align 4 br label %loop.head -loop.head: ; preds = %ifcont14, %ifcont4 +loop.head: ; preds = %ifcont12, %ifcont4 %5 = load i32, i32* %__libasr_index_0_, align 4 %6 = add i32 %5, 1 br i1 true, label %then6, label %else7 @@ -147,17 +144,14 @@ loop.body: ; preds = %ifcont8 %15 = icmp slt i32 %11, 1 %16 = icmp sgt i32 %11, 2 %17 = or i1 %15, %16 - br i1 %17, label %then9, label %else10 + br i1 %17, label %then9, label %ifcont10 then9: ; preds = %loop.body call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @1, i32 0, i32 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @0, i32 0, i32 0), i32 %11, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont11 + unreachable -else10: ; preds = %loop.body - br label %ifcont11 - -ifcont11: ; preds = %else10, %then9 +ifcont10: ; preds = %loop.body %18 = getelementptr [2 x i1], [2 x i1]* %__libasr_created__intrinsic_array_function_Any, i32 0, i32 %14 %19 = load i32, i32* %__libasr_index_0_1, align 4 %20 = sub i32 %19, 1 @@ -166,17 +160,14 @@ ifcont11: ; preds = %else10, %then9 %23 = icmp slt i32 %19, 1 %24 = icmp sgt i32 %19, 2 %25 = or i1 %23, %24 - br i1 %25, label %then12, label %else13 + br i1 %25, label %then11, label %ifcont12 -then12: ; preds = %ifcont11 +then11: ; preds = %ifcont10 call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([120 x i8], [120 x i8]* @3, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @2, i32 0, i32 0), i32 %19, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont14 - -else13: ; preds = %ifcont11 - br label %ifcont14 + unreachable -ifcont14: ; preds = %else13, %then12 +ifcont12: ; preds = %ifcont10 %26 = getelementptr [2 x i1], [2 x i1]* %found, i32 0, i32 %22 %27 = load i1, i1* %26, align 1 %28 = xor i1 %27, true @@ -187,17 +178,14 @@ ifcont14: ; preds = %else13, %then12 br label %loop.head loop.end: ; preds = %ifcont8 - br i1 false, label %then15, label %else16 + br i1 false, label %then13, label %ifcont14 -then15: ; preds = %loop.end +then13: ; preds = %loop.end call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([143 x i8], [143 x i8]* @5, i32 0, i32 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @4, i32 0, i32 0), i32 2, i32 1, i32 1, i32 2) call void @exit(i32 1) - br label %ifcont17 + unreachable -else16: ; preds = %loop.end - br label %ifcont17 - -ifcont17: ; preds = %else16, %then15 +ifcont14: ; preds = %loop.end %31 = getelementptr [2 x i1], [2 x i1]* %__libasr_created__intrinsic_array_function_Any, i32 0, i32 0 store i32 2, i32* %call_arg_value, align 4 %32 = call i1 @_lcompilers_Any_4_1_0_logical____0(i1* %31, i32* %call_arg_value) @@ -231,18 +219,18 @@ ifcont17: ; preds = %else16, %then15 %59 = select i1 %58, i1 %51, i1 %57 %60 = icmp eq i1 %33, false %61 = select i1 %60, i1 %59, i1 %33 - br i1 %61, label %then18, label %else19 + br i1 %61, label %then15, label %else16 -then18: ; preds = %ifcont17 - br label %ifcont20 +then15: ; preds = %ifcont14 + br label %ifcont17 -else19: ; preds = %ifcont17 - br label %ifcont20 +else16: ; preds = %ifcont14 + br label %ifcont17 -ifcont20: ; preds = %else19, %then18 +ifcont17: ; preds = %else16, %then15 br label %return -return: ; preds = %ifcont20 +return: ; preds = %ifcont17 ret void } From 313fe099d3fbfa128d729119f9b4e369c0259c75 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Mon, 28 Jul 2025 09:28:46 +0000 Subject: [PATCH 091/119] tests: mark format_20 as NO_FAST --- integration_tests/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 786962d206e..7c7a6965689 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -796,7 +796,8 @@ RUN(NAME format_16 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME format_17 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME format_18 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME format_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME format_20 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +# FIXME: Make this work with --fast for llvm >= 17, https://github.com/lfortran/lfortran/issues/8155 +RUN(NAME format_20 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc NO_FAST) RUN(NAME format_21 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME format_22 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME format_23 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) From fc25dcdefc8eb4632eab1898e2b27299876a9db1 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Mon, 28 Jul 2025 09:34:50 +0000 Subject: [PATCH 092/119] refactor: rename compiler_options.enable_bounds_checking to compiler_options.bounds_checking --- src/bin/lfortran_command_line_parser.cpp | 9 +++++---- src/libasr/codegen/asr_to_llvm.cpp | 14 +++++++------- src/libasr/utils.h | 3 +-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/bin/lfortran_command_line_parser.cpp b/src/bin/lfortran_command_line_parser.cpp index d6895da7abd..cebe646b782 100644 --- a/src/bin/lfortran_command_line_parser.cpp +++ b/src/bin/lfortran_command_line_parser.cpp @@ -40,6 +40,7 @@ namespace LCompilers::CommandLineInterface { std::string group_mangling_options = "Mangling Options"; std::string group_miscellaneous_options = "Miscellaneous Options"; std::string group_lsp_options = "LSP Options"; + bool disable_bounds_checking = false; // Standard options compatible with gfortran, gcc or clang // We follow the established conventions @@ -162,8 +163,8 @@ namespace LCompilers::CommandLineInterface { app.add_flag("--realloc-lhs", compiler_options.po.realloc_lhs, "Reallocate left hand side automatically")->group(group_miscellaneous_options); app.add_flag("--ignore-pragma", compiler_options.ignore_pragma, "Ignores all the pragmas")->group(group_miscellaneous_options); app.add_flag("--stack-arrays", compiler_options.stack_arrays, "Allocate memory for arrays on stack")->group(group_miscellaneous_options); - app.add_flag("--array-bounds-checking", compiler_options.enable_bounds_checking, "Enables runtime array bounds checking")->group(group_miscellaneous_options); - app.add_flag("--no-array-bounds-checking", compiler_options.disable_bounds_checking, "Disables runtime array bounds checking")->group(group_miscellaneous_options); + app.add_flag("--array-bounds-checking", compiler_options.bounds_checking, "Enables runtime array bounds checking")->group(group_miscellaneous_options); + app.add_flag("--no-array-bounds-checking", disable_bounds_checking, "Disables runtime array bounds checking")->group(group_miscellaneous_options); // LSP specific options app.add_flag("--show-errors", opts.show_errors, "Show errors when LSP is running in the background")->group(group_lsp_options); @@ -241,8 +242,8 @@ namespace LCompilers::CommandLineInterface { ); } - if (compiler_options.disable_bounds_checking) { - compiler_options.enable_bounds_checking = false; + if (disable_bounds_checking) { + compiler_options.bounds_checking = false; } compiler_options.use_colors = !opts.arg_no_color; diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index c962f4fe82f..75aa2def1ef 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -2004,7 +2004,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor visit_expr_load_wrapper(x.m_pos, 1, true); llvm::Value *pos = tmp; - tmp = list_api->read_item_using_ttype(el_type, plist, pos, compiler_options.enable_bounds_checking, module.get(), + tmp = list_api->read_item_using_ttype(el_type, plist, pos, compiler_options.bounds_checking, module.get(), (LLVM::is_llvm_struct(el_type) || ptr_loads == 0)); } @@ -2033,7 +2033,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } else { llvm_utils->set_dict_api(dict_type); tmp = llvm_utils->dict_api->read_item(x.m_a, pdict, key, module.get(), dict_type, - compiler_options.enable_bounds_checking, + compiler_options.bounds_checking, LLVM::is_llvm_struct(dict_type->m_value_type)); } } @@ -2810,7 +2810,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor #endif } llvm::Type* type = llvm_utils->get_type_from_ttype_t_util(x.m_v, ASRUtils::extract_type(x_mv_type), module.get()); - if (compiler_options.enable_bounds_checking && ASRUtils::is_allocatable(x_mv_type)) { + if (compiler_options.bounds_checking && ASRUtils::is_allocatable(x_mv_type)) { llvm::Value* is_allocated = arr_descr->get_is_allocated_flag(array, type, x.m_v); llvm::Value* cond = builder->CreateNot(is_allocated); llvm_utils->generate_runtime_error(cond, @@ -2874,7 +2874,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor array_t->m_physical_type == ASR::array_physical_typeType::PointerToDataArray, is_fixed_size, llvm_diminfo.p, is_polymorphic, current_select_type_block_type, false, - compiler_options.enable_bounds_checking, array_name); + compiler_options.bounds_checking, array_name); } } if( ASR::is_a(*ASRUtils::extract_type(x.m_type)) && !ASRUtils::is_class_type(x.m_type) ) { @@ -6445,7 +6445,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_expr_wrapper(asr_target0->m_pos, true); llvm::Value* pos = tmp; - target = list_api->read_item_using_ttype(asr_target0->m_type, list, pos, compiler_options.enable_bounds_checking, + target = list_api->read_item_using_ttype(asr_target0->m_type, list, pos, compiler_options.bounds_checking, module.get(), true); } } else { @@ -11540,7 +11540,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } // Generate runtime error if array arguments' shape doesn't match - if (compiler_options.enable_bounds_checking) { + if (compiler_options.bounds_checking) { bounds_check_call(x); } @@ -12111,7 +12111,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } // Generate runtime error if array arguments' shape doesn't match - if (compiler_options.enable_bounds_checking) { + if (compiler_options.bounds_checking) { bounds_check_call(x); } diff --git a/src/libasr/utils.h b/src/libasr/utils.h index af559a74e28..35e3c121fb4 100644 --- a/src/libasr/utils.h +++ b/src/libasr/utils.h @@ -115,8 +115,7 @@ struct CompilerOptions { bool disable_style = false; bool logical_casting = false; bool no_error_banner = false; - bool enable_bounds_checking = true; - bool disable_bounds_checking = false; + bool bounds_checking = true; std::string error_format = "human"; bool new_parser = false; bool implicit_typing = false; From 2e8a50ccc5ae2edfa13f8a76afded24167845ec2 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Tue, 29 Jul 2025 09:02:43 +0000 Subject: [PATCH 093/119] revert: realloc_lhs fix --- ci/test_third_party_codes.sh | 18 +++++++++--------- integration_tests/CMakeLists.txt | 14 +++++++------- src/libasr/pass/array_op.cpp | 5 +---- .../run-array_bounds_check_01-713dbcf.json | 6 +++--- .../run-array_bounds_check_01-713dbcf.stderr | 3 --- .../run-array_bounds_check_03-15fcd63.json | 6 +++--- .../run-array_bounds_check_03-15fcd63.stderr | 1 - 7 files changed, 23 insertions(+), 30 deletions(-) delete mode 100644 tests/reference/run-array_bounds_check_01-713dbcf.stderr delete mode 100644 tests/reference/run-array_bounds_check_03-15fcd63.stderr diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index a9c3838e5e1..b0b8960d14b 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -291,7 +291,7 @@ time_section "🧪 Testing Numerical Methods Fortran" ' git checkout a252989e64b3f8d5d2f930dca18411c104ea85f8 print_subsection "Building project" - FC="$FC --realloc-lhs" make + FC=$FC make run_test test_fix_point.exe run_test test_integrate_one.exe @@ -335,7 +335,7 @@ time_section "🧪 Testing Numerical Methods Fortran" ' git clean -dfx print_subsection "Building Numerical Methods Fortran with separate compilation" - FC="$FC --realloc-lhs --separate-compilation" make + FC="$FC --separate-compilation" make run_test test_fix_point.exe run_test test_integrate_one.exe run_test test_linear.exe @@ -702,7 +702,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf cd lf - FC="$FC --realloc-lhs --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -727,7 +727,7 @@ time_section "🧪 Testing fastGPT" ' git checkout -t origin/lf6 git checkout bc04dbf476b6173b0bb945ff920119ffaf4a290d echo $CONDA_PREFIX - FC="$FC --realloc-lhs --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS . + FC="$FC --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS . make ls -l ./gpt2 ./chat ./test_basic_input ./test_chat ./test_more_inputs file ./gpt2 ./chat ./test_basic_input ./test_chat ./test_more_inputs @@ -748,7 +748,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf cd lf - FC="$FC --realloc-lhs --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -760,7 +760,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf-goc cd lf-goc - FC="$FC --realloc-lhs --no-array-bounds-checking --separate-compilation --rtlib" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --no-array-bounds-checking --separate-compilation --rtlib" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -771,7 +771,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf-fast cd lf-fast - FC="$FC --realloc-lhs --no-array-bounds-checking --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. + FC="$FC --no-array-bounds-checking --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -785,7 +785,7 @@ time_section "🧪 Testing fastGPT" ' cd lf git clean -dfx - FC="$FC --realloc-lhs --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -795,7 +795,7 @@ time_section "🧪 Testing fastGPT" ' cd lf-fast git clean -dfx - FC="$FC --realloc-lhs --no-array-bounds-checking --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. + FC="$FC --no-array-bounds-checking --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 7c7a6965689..de4ccb9b7ab 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1636,7 +1636,7 @@ RUN(NAME allocate_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_04 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_05 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME allocate_06 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) +RUN(NAME allocate_06 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_10 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_11 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) @@ -1649,7 +1649,7 @@ RUN(NAME allocate_15 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_16 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_17 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_18 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME allocate_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) +RUN(NAME allocate_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_20 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_21 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocate_22 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) @@ -1755,7 +1755,7 @@ RUN(NAME string_39 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_40 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME string_41 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME string_42 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME string_43 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) +RUN(NAME string_43 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_44 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_45 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_46 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -1768,7 +1768,7 @@ RUN(NAME string_52 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_53 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_54 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_55 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -RUN(NAME string_56 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran EXTRA_ARGS --realloc-lhs) +RUN(NAME string_56 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME string_57 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_58 LABELS llvm llvm_wasm llvm_wasm_emcc) RUN(NAME string_59 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -2506,11 +2506,11 @@ RUN(NAME openmp_60 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_61 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_62 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_63 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) -RUN(NAME openmp_64 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp EXTRA_ARGS --no-array-bounds-checking) -RUN(NAME openmp_65 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME openmp_64 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) +RUN(NAME openmp_65 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_66 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_67 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) -RUN(NAME openmp_68 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME openmp_68 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_69 LABELS llvm_omp gfortran GFORTRAN_ARGS -fopenmp) RUN(NAME openmp_70 LABELS target_offload) RUN(NAME openmp_71 LABELS target_offload) diff --git a/src/libasr/pass/array_op.cpp b/src/libasr/pass/array_op.cpp index 591e7d63eea..5947d1c464f 100644 --- a/src/libasr/pass/array_op.cpp +++ b/src/libasr/pass/array_op.cpp @@ -856,10 +856,7 @@ class ArrayOpVisitor: public ASR::CallReplacerOnExpressionsVisitor& vars) { ASR::ttype_t* target_type = ASRUtils::expr_type(target); bool array_copy = ASR::is_a(*value) && ASR::is_a(*target); - if (!realloc_lhs) { - return; - } - if( (!ASRUtils::is_allocatable(target_type) || vars.size() == 1) && + if( (realloc_lhs == false || !ASRUtils::is_allocatable(target_type) || vars.size() == 1) && !(array_copy && ASRUtils::is_allocatable(target_type)) ) { return ; } diff --git a/tests/reference/run-array_bounds_check_01-713dbcf.json b/tests/reference/run-array_bounds_check_01-713dbcf.json index 1ffac9b4351..c66d48bc487 100644 --- a/tests/reference/run-array_bounds_check_01-713dbcf.json +++ b/tests/reference/run-array_bounds_check_01-713dbcf.json @@ -7,7 +7,7 @@ "outfile_hash": null, "stdout": null, "stdout_hash": null, - "stderr": "run-array_bounds_check_01-713dbcf.stderr", - "stderr_hash": "161fd647a5f1eb6fa952ec46b4ce934c8e4f4e63f4887923754cbe71", - "returncode": 1 + "stderr": null, + "stderr_hash": null, + "returncode": 0 } \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_01-713dbcf.stderr b/tests/reference/run-array_bounds_check_01-713dbcf.stderr deleted file mode 100644 index 893a718bf5e..00000000000 --- a/tests/reference/run-array_bounds_check_01-713dbcf.stderr +++ /dev/null @@ -1,3 +0,0 @@ -Runtime error: Array '__libasr__created__var__0__array_constant_' index out of bounds. - -Tried to access index 4 of dimension 1, but valid range is 1 to 3. diff --git a/tests/reference/run-array_bounds_check_03-15fcd63.json b/tests/reference/run-array_bounds_check_03-15fcd63.json index 6b686fb8161..f7e95e8ecda 100644 --- a/tests/reference/run-array_bounds_check_03-15fcd63.json +++ b/tests/reference/run-array_bounds_check_03-15fcd63.json @@ -7,7 +7,7 @@ "outfile_hash": null, "stdout": null, "stdout_hash": null, - "stderr": "run-array_bounds_check_03-15fcd63.stderr", - "stderr_hash": "b102aecb81a33633a9517ac81d3855b83948b65c027104b30fcf575b", - "returncode": 1 + "stderr": null, + "stderr_hash": null, + "returncode": 0 } \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_03-15fcd63.stderr b/tests/reference/run-array_bounds_check_03-15fcd63.stderr deleted file mode 100644 index f0da5414041..00000000000 --- a/tests/reference/run-array_bounds_check_03-15fcd63.stderr +++ /dev/null @@ -1 +0,0 @@ -Runtime Error: Array 'x' is not allocated. From 37898311e46c1119e522adc1b95bd367a0f93101 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 31 Jul 2025 12:01:01 +0000 Subject: [PATCH 094/119] ci: remove unnecessary --no-array-bounds-checking in third party codes --- ci/test_third_party_codes.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index b0b8960d14b..b87364b090a 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -702,7 +702,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf cd lf - FC="$FC --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC=$FC CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -727,7 +727,7 @@ time_section "🧪 Testing fastGPT" ' git checkout -t origin/lf6 git checkout bc04dbf476b6173b0bb945ff920119ffaf4a290d echo $CONDA_PREFIX - FC="$FC --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS . + FC=$FC CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS . make ls -l ./gpt2 ./chat ./test_basic_input ./test_chat ./test_more_inputs file ./gpt2 ./chat ./test_basic_input ./test_chat ./test_more_inputs @@ -748,7 +748,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf cd lf - FC="$FC --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC=$FC CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -760,7 +760,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf-goc cd lf-goc - FC="$FC --no-array-bounds-checking --separate-compilation --rtlib" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC="$FC --separate-compilation --rtlib" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -771,7 +771,7 @@ time_section "🧪 Testing fastGPT" ' mkdir lf-fast cd lf-fast - FC="$FC --no-array-bounds-checking --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. + FC="$FC --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -785,7 +785,7 @@ time_section "🧪 Testing fastGPT" ' cd lf git clean -dfx - FC="$FC --no-array-bounds-checking" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. + FC=$FC CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Debug .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 @@ -795,7 +795,7 @@ time_section "🧪 Testing fastGPT" ' cd lf-fast git clean -dfx - FC="$FC --no-array-bounds-checking --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. + FC="$FC --fast" CMAKE_PREFIX_PATH=$CONDA_PREFIX cmake -DFASTGPT_BLAS=OpenBLAS -DCMAKE_BUILD_TYPE=Release .. make VERBOSE=1 ln -s ../model.dat . ./gpt2 From 4e8091b5ac9e9bc5695d2733a234f699c126528f Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 31 Jul 2025 12:04:06 +0000 Subject: [PATCH 095/119] fix: disable bounds checking when fast is enabled --- ci/test_third_party_codes.sh | 4 ++-- src/bin/lfortran_command_line_parser.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index b87364b090a..bc016087c6e 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -198,7 +198,7 @@ time_section "🧪 Testing POT3D with fortran_mpi" ' FC="$FC --cpp -DOPEN_MPI=yes --no-array-bounds-checking" ./build_and_run_lfortran.sh print_subsection "Building with optimization flags" - # FC="$FC --cpp --fast --skip-pass=dead_code_removal --no-array-bounds-checking -DOPEN_MPI=yes" ./build_and_run_lfortran.sh + # FC="$FC --cpp --fast --skip-pass=dead_code_removal -DOPEN_MPI=yes" ./build_and_run_lfortran.sh print_subsection "Building POT3D in separate compilation mode" FC="$FC --cpp --separate-compilation --no-array-bounds-checking -DOPEN_MPI=yes" ./build_and_run_lfortran.sh @@ -844,7 +844,7 @@ time_section "🧪 Testing SNAP" ' ./gsnap ../qasnap/sample/inp out make clean - make -j8 FORTRAN=$FC FFLAGS="--fast --no-array-bounds-checking" MPI=no OPENMP=no + make -j8 FORTRAN=$FC FFLAGS="--fast" MPI=no OPENMP=no ./gsnap ../qasnap/sample/inp out ' diff --git a/src/bin/lfortran_command_line_parser.cpp b/src/bin/lfortran_command_line_parser.cpp index cebe646b782..62078c21e2d 100644 --- a/src/bin/lfortran_command_line_parser.cpp +++ b/src/bin/lfortran_command_line_parser.cpp @@ -242,7 +242,7 @@ namespace LCompilers::CommandLineInterface { ); } - if (disable_bounds_checking) { + if (disable_bounds_checking || compiler_options.po.fast) { compiler_options.bounds_checking = false; } From 9a619aa3ea5d18bcd76201c0791e123ba5699121 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 31 Jul 2025 12:05:29 +0000 Subject: [PATCH 096/119] fix: when variable has intent_in then don't load deep copy --- ci/test_third_party_codes.sh | 6 +++--- src/libasr/codegen/asr_to_llvm.cpp | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index bc016087c6e..3b0b4f65e3e 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -225,7 +225,7 @@ time_section "🧪 Testing stdlib (Less Workarounds)" ' FC=$FC cmake . \ -DTEST_DRIVE_BUILD_TESTING=OFF \ -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE \ - -DCMAKE_Fortran_FLAGS="--cpp --realloc-lhs --no-warnings --use-loop-variable-after-loop --no-array-bounds-checking -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" + -DCMAKE_Fortran_FLAGS="--cpp --realloc-lhs --no-warnings --use-loop-variable-after-loop -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" make -j8 ctest @@ -236,7 +236,7 @@ time_section "🧪 Testing stdlib (Less Workarounds)" ' FC=$FC cmake . \ -DTEST_DRIVE_BUILD_TESTING=OFF \ -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE \ - -DCMAKE_Fortran_FLAGS="--cpp --separate-compilation --realloc-lhs --no-warnings --use-loop-variable-after-loop --no-array-bounds-checking -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" + -DCMAKE_Fortran_FLAGS="--cpp --separate-compilation --realloc-lhs --no-warnings --use-loop-variable-after-loop -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" make -j8 ctest @@ -821,7 +821,7 @@ time_section "🧪 Testing stdlib" ' micromamba install -c conda-forge fypp git clean -fdx - FC=$FC cmake . -DTEST_DRIVE_BUILD_TESTING=OFF -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE -DCMAKE_Fortran_FLAGS="--cpp --realloc-lhs --no-array-bounds-checking" + FC=$FC cmake . -DTEST_DRIVE_BUILD_TESTING=OFF -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE -DCMAKE_Fortran_FLAGS="--cpp --realloc-lhs" make -j8 ctest ' diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 75aa2def1ef..e978eeadd0d 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -2731,11 +2731,15 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::ttype_t* x_mv_type = ASRUtils::expr_type(x.m_v); llvm::Value* array = nullptr; ASR::Variable_t *v = nullptr; + bool is_intent_in = false; std::string array_name; if( ASR::is_a(*x.m_v) ) { v = ASRUtils::EXPR2VAR(x.m_v); array_name = v->m_name; uint32_t v_h = get_hash((ASR::asr_t*)v); + if (v->m_intent == ASRUtils::intent_in) { + is_intent_in = true; + } array = llvm_symtab[v_h]; if (ASR::is_a(*ASRUtils::extract_type(v->m_type))) { ASR::Struct_t* der_symbol = ASR::down_cast( @@ -2830,7 +2834,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor this->visit_expr_wrapper(m_dims[idim].m_start, true); llvm::Value* dim_start = tmp; ptr_loads = 2 - !LLVM::is_llvm_pointer(*ASRUtils::expr_type(m_dims[idim].m_length)); - load_array_size_deep_copy(m_dims[idim].m_length); + if (is_intent_in) { + this->visit_expr_wrapper(m_dims[idim].m_length, true); + } else { + load_array_size_deep_copy(m_dims[idim].m_length); + } llvm::Value* dim_size = tmp; llvm_diminfo.push_back(al, dim_start); llvm_diminfo.push_back(al, dim_size); From dd50c97c6feba88ab58e7492e8b960762fa93825 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 31 Jul 2025 12:20:21 +0000 Subject: [PATCH 097/119] tests: fix some tests --- integration_tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index de4ccb9b7ab..3433be18621 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -560,7 +560,7 @@ RUN(NAME arrays_04_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackA RUN(NAME arrays_05_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_06_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_07_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -RUN(NAME arrays_08_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) +RUN(NAME arrays_08_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran EXTRA_ARGS --no-array-bounds-checking) RUN(NAME arrays_09_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_10_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_11_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) From 22efbcd58b46ac52735adec1028aac8e339e9c36 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 31 Jul 2025 12:28:06 +0000 Subject: [PATCH 098/119] tests: update references --- tests/reference/asr-associate_08-570ac7d.json | 2 +- tests/reference/asr-modules_37-7eba027.json | 2 +- tests/reference/asr-template_array_01-691b151.json | 2 +- tests/reference/asr-template_array_02-85b6b2e.json | 2 +- ...ransform_optional_argument_functions-modules_37-1456cdb.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/reference/asr-associate_08-570ac7d.json b/tests/reference/asr-associate_08-570ac7d.json index 7f344263b99..fa8a7650cee 100644 --- a/tests/reference/asr-associate_08-570ac7d.json +++ b/tests/reference/asr-associate_08-570ac7d.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-associate_08-570ac7d.stdout", - "stdout_hash": "2e5e00ae916e3594345b0043443adc5008ca7c95fe131cd66cf60b6b", + "stdout_hash": "2b75a0b47c9f56ede4cc9c7c66c749cfca3c9966ac1aa8c0dcd8d82c", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-modules_37-7eba027.json b/tests/reference/asr-modules_37-7eba027.json index 211fb67017b..3eac3d07458 100644 --- a/tests/reference/asr-modules_37-7eba027.json +++ b/tests/reference/asr-modules_37-7eba027.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-modules_37-7eba027.stdout", - "stdout_hash": "e9e2e1b52b4db4ad0c5ee043c021a70f12bd5f8c470dfd56cfee3165", + "stdout_hash": "ca3855f2cea15ca461fee4b8eeda5125a9ae223f16c89349c447a9f1", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-template_array_01-691b151.json b/tests/reference/asr-template_array_01-691b151.json index 57309298f3a..d387ca52c9c 100644 --- a/tests/reference/asr-template_array_01-691b151.json +++ b/tests/reference/asr-template_array_01-691b151.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-template_array_01-691b151.stdout", - "stdout_hash": "7df5ab050d6a3170063abdb6d018cd23b227f43f8fcadac55f3b0dac", + "stdout_hash": "36634bcdd077fac14bd692d65660fc293958d6c04b9f0b0a31c0ed5a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-template_array_02-85b6b2e.json b/tests/reference/asr-template_array_02-85b6b2e.json index 68e620cd463..75972323bb1 100644 --- a/tests/reference/asr-template_array_02-85b6b2e.json +++ b/tests/reference/asr-template_array_02-85b6b2e.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-template_array_02-85b6b2e.stdout", - "stdout_hash": "c3bd99ecb1b4cbeb64900086a7ed78ea86c7f3e1b90c7befcb6d2ab2", + "stdout_hash": "ee723dba872a0553582380226505051c02db2419c6e074e672d7db47", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.json b/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.json index 5096f6e7a8d..c1cb82fa17b 100644 --- a/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.json +++ b/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.stdout", - "stdout_hash": "1f93d496d4483aadff98e5e7e48ef3d30aeb93ae8cca57cb58525cc6", + "stdout_hash": "a6057ff43991fc47d6b522bf808725b686ff391eba95a29548057b72", "stderr": null, "stderr_hash": null, "returncode": 0 From 0ee4f010891f6b7264d8e593806cc555b8f0a10a Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 31 Jul 2025 13:09:08 +0000 Subject: [PATCH 099/119] ci: remove bounds checking from stdlib separate compilation --- ci/test_third_party_codes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index 3b0b4f65e3e..a198889f777 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -236,7 +236,7 @@ time_section "🧪 Testing stdlib (Less Workarounds)" ' FC=$FC cmake . \ -DTEST_DRIVE_BUILD_TESTING=OFF \ -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE \ - -DCMAKE_Fortran_FLAGS="--cpp --separate-compilation --realloc-lhs --no-warnings --use-loop-variable-after-loop -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" + -DCMAKE_Fortran_FLAGS="--cpp --separate-compilation --realloc-lhs --no-warnings --use-loop-variable-after-loop --no-array-bounds-checking -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" make -j8 ctest From 339c5985b8768e8a92c52ff2ec21d3d18514aca7 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Sat, 2 Aug 2025 11:34:09 +0000 Subject: [PATCH 100/119] feat: implement rank checking and size checking --- ci/test_third_party_codes.sh | 8 +- src/libasr/codegen/asr_to_llvm.cpp | 110 ++++++++++++++---- .../llvm-implicit_interface_04-9b6786e.json | 2 +- .../llvm-implicit_interface_04-9b6786e.stdout | 2 +- .../run-array_bounds_check_04-2e3d8fb.json | 6 +- .../run-array_bounds_check_04-2e3d8fb.stderr | 3 - 6 files changed, 95 insertions(+), 36 deletions(-) delete mode 100644 tests/reference/run-array_bounds_check_04-2e3d8fb.stderr diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index a198889f777..6ca82d604ef 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -195,13 +195,13 @@ time_section "🧪 Testing POT3D with fortran_mpi" ' cd .. print_subsection "Building with default flags" - FC="$FC --cpp -DOPEN_MPI=yes --no-array-bounds-checking" ./build_and_run_lfortran.sh + FC="$FC --cpp -DOPEN_MPI=yes" ./build_and_run_lfortran.sh print_subsection "Building with optimization flags" # FC="$FC --cpp --fast --skip-pass=dead_code_removal -DOPEN_MPI=yes" ./build_and_run_lfortran.sh print_subsection "Building POT3D in separate compilation mode" - FC="$FC --cpp --separate-compilation --no-array-bounds-checking -DOPEN_MPI=yes" ./build_and_run_lfortran.sh + FC="$FC --cpp --separate-compilation -DOPEN_MPI=yes" ./build_and_run_lfortran.sh print_success "Done with POT3D" cd .. @@ -836,11 +836,11 @@ time_section "🧪 Testing SNAP" ' git checkout lf11 git checkout 169a9216f2c922e94065a519efbb0a6c8b55149e cd ./src - make -j8 FORTRAN=$FC FFLAGS="--no-array-bounds-checking" MPI=no OPENMP=no + make -j8 FORTRAN=$FC FFLAGS= MPI=no OPENMP=no ./gsnap ../qasnap/sample/inp out make clean - make -j8 FORTRAN=$FC FFLAGS="--separate-compilation --no-array-bounds-checking" MPI=no OPENMP=no + make -j8 FORTRAN=$FC FFLAGS="--separate-compilation" MPI=no OPENMP=no ./gsnap ../qasnap/sample/inp out make clean diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index e978eeadd0d..1185471a1de 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -11471,6 +11471,28 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor return dt; } + llvm::Value* get_array_size_from_asr_type(ASR::ttype_t* type) { + ASR::dimension_t* m_dims = nullptr; + int n_dims = ASRUtils::extract_dimensions_from_ttype(type, m_dims); + if( ASRUtils::extract_physical_type(type) == ASR::array_physical_typeType::FixedSizeArray ) { + int64_t size = ASRUtils::get_fixed_size_of_array(m_dims, n_dims); + return llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, size)); + } else { + llvm::Value* llvm_size = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, 1)); + int ptr_loads_copy = ptr_loads; + ptr_loads = 2; + for( int i = 0; i < n_dims; i++ ) { + if (m_dims[i].m_length) { + load_array_size_deep_copy(m_dims[i].m_length); + tmp = builder->CreateSExtOrTrunc(tmp, llvm_utils->getIntType(4)); + llvm_size = builder->CreateMul(tmp, llvm_size); + } + } + ptr_loads = ptr_loads_copy; + return llvm_size; + } + } + template void bounds_check_call(T& x) { for (size_t i = 0; i < x.n_args; i++) { @@ -11482,24 +11504,36 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ptr_loads = 2 - LLVM::is_llvm_pointer(*ASRUtils::expr_type(arr_cast->m_arg)); this->visit_expr_wrapper(arr_cast->m_arg, false); ptr_loads = ptr_loads_copy; - llvm::Value* arg = tmp; - -#if LLVM_VERSION_MAJOR > 16 llvm::Type* arr_type = llvm_utils->get_type_from_ttype_t_util(arr_cast->m_arg, ASRUtils::type_get_past_allocatable_pointer(ASRUtils::expr_type(arr_cast->m_arg)), module.get(), ASRUtils::expr_abi(arr_cast->m_arg)); + if (is_a(*arr_cast->m_arg)) { + tmp = llvm_utils->CreateLoad2(arr_type->getPointerTo(), tmp); + } + llvm::Value* arg = tmp; + +#if LLVM_VERSION_MAJOR > 16 ptr_type[tmp] = arr_type; #endif - int n_dims = ASRUtils::extract_n_dims_from_ttype(arr_cast->m_type); ASR::dimension_t* m_dims = nullptr; - ASRUtils::extract_dimensions_from_ttype(arr_cast->m_type, m_dims); + int n_dims = ASRUtils::extract_dimensions_from_ttype(arr_cast->m_type, m_dims); + llvm::Value* desc_rank = arr_descr->get_rank(arg); + llvm::Value* pointer_rank = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, n_dims)); + llvm::Function *fn = builder->GetInsertBlock()->getParent(); + + llvm::BasicBlock *thenBB = llvm::BasicBlock::Create(context, "then", fn); + llvm::BasicBlock *elseBB = llvm::BasicBlock::Create(context, "else"); + llvm::BasicBlock *mergeBB = llvm::BasicBlock::Create(context, "ifcont"); + + builder->CreateCondBr(builder->CreateICmpEQ(desc_rank, pointer_rank), thenBB, elseBB); + builder->SetInsertPoint(thenBB); for (int j = 0; j < n_dims; j++) { if (m_dims[j].m_length) { llvm::Value* dim = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)); llvm::Value* descriptor_length = arr_descr->get_array_size(arg, dim, 4); load_array_size_deep_copy(m_dims[j].m_length); llvm::Value* pointer_length = tmp; - llvm_utils->generate_runtime_error(builder->CreateICmpNE(descriptor_length, pointer_length), + llvm_utils->generate_runtime_error(builder->CreateICmpSLT(descriptor_length, pointer_length), "Runtime error: Array shape mismatch in subroutine '%s'\n\n" "Tried to match size %d of dimension %d of argument number %d, but expected size is %d\n", builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), @@ -11509,28 +11543,54 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor pointer_length); } } + builder->CreateBr(mergeBB); + start_new_block(elseBB); + llvm::Value* desc_size = arr_descr->get_array_size(arg, nullptr, 4); + llvm::Value* pointer_size = get_array_size_from_asr_type(arr_cast->m_type); + llvm_utils->generate_runtime_error(builder->CreateICmpNE(desc_size, pointer_size), + "Runtime error: Array size mismatch in subroutine '%s'\n\n" + "Tried to match size %d of argument number %d, but expected size is %d\n", + builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), + desc_size, + llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, i + 1)), + pointer_size); + builder->CreateBr(mergeBB); + start_new_block(mergeBB); } else if (arr_cast->m_old == ASR::FixedSizeArray && arr_cast->m_new == ASR::PointerToDataArray) { + ASR::ttype_t* fixed_size_type = ASRUtils::expr_type(arr_cast->m_arg); ASR::dimension_t* m_dims_fixed = nullptr; - int n_dims = ASRUtils::extract_dimensions_from_ttype(ASRUtils::expr_type(arr_cast->m_arg), m_dims_fixed); + int n_dims_fixed = ASRUtils::extract_dimensions_from_ttype(fixed_size_type, m_dims_fixed); ASR::dimension_t* m_dims_pointer = nullptr; - ASRUtils::extract_dimensions_from_ttype(arr_cast->m_type, m_dims_pointer); - - for (int j = 0; j < n_dims; j++) { - if (m_dims_pointer[j].m_length) { - llvm::Value* dim = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)); - llvm::Value* fixed_length = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, ASRUtils::extract_dim_value_int(m_dims_fixed[j].m_length))); - load_array_size_deep_copy(m_dims_pointer[j].m_length); - llvm::Value* pointer_length = tmp; - llvm_utils->generate_runtime_error(builder->CreateICmpNE(fixed_length, pointer_length), - "Runtime error: Array shape mismatch in subroutine '%s'\n\n" - "Tried to match size %d of dimension %d of argument number %d, but expected size is %d\n", - builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), - fixed_length, - dim, - llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, i + 1)), - pointer_length); + int n_dims_pointer = ASRUtils::extract_dimensions_from_ttype(arr_cast->m_type, m_dims_pointer); + + if (n_dims_fixed == n_dims_pointer) { + for (int j = 0; j < n_dims_fixed; j++) { + if (m_dims_pointer[j].m_length) { + llvm::Value* dim = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, j + 1)); + llvm::Value* fixed_length = llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, ASRUtils::extract_dim_value_int(m_dims_fixed[j].m_length))); + load_array_size_deep_copy(m_dims_pointer[j].m_length); + llvm::Value* pointer_length = tmp; + llvm_utils->generate_runtime_error(builder->CreateICmpSLT(fixed_length, pointer_length), + "Runtime error: Array shape mismatch in subroutine '%s'\n\n" + "Tried to match size %d of dimension %d of argument number %d, but expected size is %d\n", + builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), + fixed_length, + dim, + llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, i + 1)), + pointer_length); + } } + } else { + llvm::Value* fixed_size = llvm::ConstantInt::get(llvm_utils->getIntType(4), ASRUtils::get_fixed_size_of_array(fixed_size_type)); + llvm::Value* pointer_size = get_array_size_from_asr_type(arr_cast->m_type); + llvm_utils->generate_runtime_error(builder->CreateICmpNE(fixed_size, pointer_size), + "Runtime error: Array size mismatch in subroutine '%s'\n\n" + "Tried to match size %d of argument number %d, but expected size is %d\n", + builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), + fixed_size, + llvm::ConstantInt::get(llvm_utils->getIntType(4), llvm::APInt(32, i + 1)), + pointer_size); } } } @@ -12409,8 +12469,10 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } else { this->visit_expr_wrapper(x, true); } - } else { + } else if (x != nullptr) { this->visit_expr_wrapper(x, true); + } else { + throw CodeGenError("x is nullptr in load_array_size_deep_copy()"); } } diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.json b/tests/reference/llvm-implicit_interface_04-9b6786e.json index d1680b2f216..f029840bb98 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.json +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-implicit_interface_04-9b6786e.stdout", - "stdout_hash": "b26c2ba6f5d79648b162866039e92e48b082a8c44723c13b576c7a89", + "stdout_hash": "3130d424244b9c652ee2405f8b2fcff37a71c2bdfabfdaa2891e78e6", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout index bdb5e1573c5..1afb6d31ece 100644 --- a/tests/reference/llvm-implicit_interface_04-9b6786e.stdout +++ b/tests/reference/llvm-implicit_interface_04-9b6786e.stdout @@ -110,7 +110,7 @@ ifcont5: ; preds = %ifcont3 %25 = getelementptr [3 x i32], [3 x i32]* @main.b, i32 0, i32 %21 store i32 30, i32* %25, align 4 %26 = load i32, i32* @main.n, align 4 - %27 = icmp ne i32 3, %26 + %27 = icmp slt i32 3, %26 br i1 %27, label %then6, label %ifcont7 then6: ; preds = %ifcont5 diff --git a/tests/reference/run-array_bounds_check_04-2e3d8fb.json b/tests/reference/run-array_bounds_check_04-2e3d8fb.json index 7d14824aec7..610282c4b00 100644 --- a/tests/reference/run-array_bounds_check_04-2e3d8fb.json +++ b/tests/reference/run-array_bounds_check_04-2e3d8fb.json @@ -7,7 +7,7 @@ "outfile_hash": null, "stdout": null, "stdout_hash": null, - "stderr": "run-array_bounds_check_04-2e3d8fb.stderr", - "stderr_hash": "8a026a9009f4d0fba284c241930bbd9f47a05f7d33c37e10ce20442c", - "returncode": 1 + "stderr": null, + "stderr_hash": null, + "returncode": 0 } \ No newline at end of file diff --git a/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr b/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr deleted file mode 100644 index 3d2688830e9..00000000000 --- a/tests/reference/run-array_bounds_check_04-2e3d8fb.stderr +++ /dev/null @@ -1,3 +0,0 @@ -Runtime error: Array shape mismatch in subroutine 'my' - -Tried to match size 4 of dimension 2 of argument number 1, but expected size is 1 From b610b3fd159f9ceb6bf892cb4bb1d2e1915d846f Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Sun, 3 Aug 2025 13:53:49 +0000 Subject: [PATCH 101/119] fix: ptr_loads and integer bin op type --- src/lfortran/semantics/ast_common_visitor.h | 2 +- src/libasr/codegen/asr_to_llvm.cpp | 6 +++--- tests/reference/asr-associate_08-570ac7d.json | 2 +- tests/reference/asr-modules_37-7eba027.json | 2 +- ...form_optional_argument_functions-modules_37-1456cdb.json | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 47a60c818db..54826c31630 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -10379,7 +10379,7 @@ class CommonVisitor : public AST::BaseVisitor { ASRUtils::make_ArrayBroadcast_t_util(al, x.base.base.loc, left, right); value = value ? value : extract_value(ASRUtils::expr_value(left), ASRUtils::expr_value(right), op, dest_type, x.base.base.loc); - asr = ASR::make_IntegerBinOp_t(al, x.base.base.loc, left, op, right, dest_type, value); + asr = ASR::make_IntegerBinOp_t(al, x.base.base.loc, left, op, right, ASRUtils::type_get_past_allocatable_pointer(dest_type), value); } else if (ASRUtils::is_unsigned_integer(*dest_type)) { diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 1185471a1de..bd03325082d 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -7908,7 +7908,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *str {}; { // Set proper load + Visit + Revert load int64_t ptr_loads_copy = ptr_loads; - ptr_loads = 1; this->visit_expr_wrapper(x.m_idx, true); + ptr_loads = LLVM::is_llvm_pointer(*expr_type(x.m_idx)) ? 2 : 1; this->visit_expr_wrapper(x.m_idx, true); idx = tmp; ptr_loads = 0; this->visit_expr_wrapper(x.m_arg, true); str = tmp; @@ -7976,11 +7976,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor llvm::Value *str = tmp; llvm::Value *left{}, *right{}; if (x.m_start) { - this->visit_expr_load_wrapper(x.m_start, 1, true); + this->visit_expr_load_wrapper(x.m_start, LLVM::is_llvm_pointer(*expr_type(x.m_start)) ? 2 : 1, true); left = tmp; } if (x.m_end) { - this->visit_expr_load_wrapper(x.m_end, 1, true); + this->visit_expr_load_wrapper(x.m_end, LLVM::is_llvm_pointer(*expr_type(x.m_end)) ? 2 : 1, true); right = tmp; } LCOMPILERS_ASSERT(x.m_step) diff --git a/tests/reference/asr-associate_08-570ac7d.json b/tests/reference/asr-associate_08-570ac7d.json index fa8a7650cee..e24a3cd0713 100644 --- a/tests/reference/asr-associate_08-570ac7d.json +++ b/tests/reference/asr-associate_08-570ac7d.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-associate_08-570ac7d.stdout", - "stdout_hash": "2b75a0b47c9f56ede4cc9c7c66c749cfca3c9966ac1aa8c0dcd8d82c", + "stdout_hash": "afe234eb4fbf33b1091b63fc3f2686d5f999a5e3f1f7d535a44cb7b8", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-modules_37-7eba027.json b/tests/reference/asr-modules_37-7eba027.json index 3eac3d07458..466b6ab1253 100644 --- a/tests/reference/asr-modules_37-7eba027.json +++ b/tests/reference/asr-modules_37-7eba027.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-modules_37-7eba027.stdout", - "stdout_hash": "ca3855f2cea15ca461fee4b8eeda5125a9ae223f16c89349c447a9f1", + "stdout_hash": "ddd45a53ed6c05506582b8bd31098f9d5fc9bf431cb39fb26ddb5411", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.json b/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.json index c1cb82fa17b..135ae54662d 100644 --- a/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.json +++ b/tests/reference/pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "pass_pass_array_by_data_transform_optional_argument_functions-modules_37-1456cdb.stdout", - "stdout_hash": "a6057ff43991fc47d6b522bf808725b686ff391eba95a29548057b72", + "stdout_hash": "c6c20b2ab5cf9b51ba6622f679f0c134e068a220396a7be87993eabc", "stderr": null, "stderr_hash": null, "returncode": 0 From 4e320e852dd6b4070d8ac6fca8a517c93397d022 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Sun, 3 Aug 2025 16:30:16 +0000 Subject: [PATCH 102/119] ci: remove --no-array-bounds-checking flags --- .github/workflows/Exhaustive-Checks-CI.yml | 2 +- ci/test_third_party_codes.sh | 32 +++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/Exhaustive-Checks-CI.yml b/.github/workflows/Exhaustive-Checks-CI.yml index 646c70d8450..b8c7646c642 100644 --- a/.github/workflows/Exhaustive-Checks-CI.yml +++ b/.github/workflows/Exhaustive-Checks-CI.yml @@ -440,7 +440,7 @@ jobs: mkdir lfortran-build/ cd lfortran-build/ LIBRARY_PATH="`pwd`/../../src/runtime/" - FC="$(pwd)/../../src/bin/lfortran --no-array-bounds-checking" cmake \ + FC=$(pwd)/../../src/bin/lfortran cmake \ -DCMAKE_Fortran_FLAGS=--verbose \ -DLFORTRAN_RUNTIME_LIBRARY_PATH=$LIBRARY_PATH \ .. diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index 6ca82d604ef..c2d4b8443c2 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -624,17 +624,17 @@ time_section "🧪 Testing Modern Minpack (Fortran-Lang)" ' $FC ./src/minpack.f90 -c --legacy-array-sections $FC ./examples/example_hybrd.f90 --legacy-array-sections - $FC ./examples/example_hybrd1.f90 --legacy-array-sections --no-array-bounds-checking - $FC ./examples/example_lmdif1.f90 --legacy-array-sections --no-array-bounds-checking - $FC ./examples/example_lmder1.f90 --legacy-array-sections --no-array-bounds-checking + $FC ./examples/example_hybrd1.f90 --legacy-array-sections + $FC ./examples/example_lmdif1.f90 --legacy-array-sections + $FC ./examples/example_lmder1.f90 --legacy-array-sections print_subsection "Testing with separate compilation" git clean -dfx - $FC ./src/minpack.f90 -c --legacy-array-sections --separate-compilation --no-array-bounds-checking - $FC ./examples/example_hybrd.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o - $FC ./examples/example_hybrd1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o - $FC ./examples/example_lmdif1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o - $FC ./examples/example_lmder1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o + $FC ./src/minpack.f90 -c --legacy-array-sections --separate-compilation + $FC ./examples/example_hybrd.f90 --legacy-array-sections --separate-compilation minpack.o + $FC ./examples/example_hybrd1.f90 --legacy-array-sections --separate-compilation minpack.o + $FC ./examples/example_lmdif1.f90 --legacy-array-sections --separate-compilation minpack.o + $FC ./examples/example_lmder1.f90 --legacy-array-sections --separate-compilation minpack.o ' time_section "🧪 Testing Modern Minpack (Result Check)" ' @@ -645,17 +645,17 @@ time_section "🧪 Testing Modern Minpack (Result Check)" ' $FC ./src/minpack.f90 -c --legacy-array-sections $FC ./examples/example_hybrd.f90 --legacy-array-sections - $FC ./examples/example_hybrd1.f90 --legacy-array-sections --no-array-bounds-checking - $FC ./examples/example_lmdif1.f90 --legacy-array-sections --no-array-bounds-checking - $FC ./examples/example_lmder1.f90 --legacy-array-sections --no-array-bounds-checking + $FC ./examples/example_hybrd1.f90 --legacy-array-sections + $FC ./examples/example_lmdif1.f90 --legacy-array-sections + $FC ./examples/example_lmder1.f90 --legacy-array-sections print_subsection "Testing with separate compilation" git clean -dfx - $FC ./src/minpack.f90 -c --legacy-array-sections --separate-compilation --no-array-bounds-checking - $FC ./examples/example_hybrd.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o - $FC ./examples/example_hybrd1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o - $FC ./examples/example_lmdif1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o - $FC ./examples/example_lmder1.f90 --legacy-array-sections --separate-compilation --no-array-bounds-checking minpack.o + $FC ./src/minpack.f90 -c --legacy-array-sections --separate-compilation + $FC ./examples/example_hybrd.f90 --legacy-array-sections --separate-compilation minpack.o + $FC ./examples/example_hybrd1.f90 --legacy-array-sections --separate-compilation minpack.o + $FC ./examples/example_lmdif1.f90 --legacy-array-sections --separate-compilation minpack.o + $FC ./examples/example_lmder1.f90 --legacy-array-sections --separate-compilation minpack.o ' ########################## From 6492328a24ee982d5a597c28f0fdc8b543b402f1 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Mon, 4 Aug 2025 04:11:09 +0000 Subject: [PATCH 103/119] ci: update stdlib --- ci/test_third_party_codes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index c2d4b8443c2..b23939bfef1 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -236,7 +236,7 @@ time_section "🧪 Testing stdlib (Less Workarounds)" ' FC=$FC cmake . \ -DTEST_DRIVE_BUILD_TESTING=OFF \ -DBUILD_EXAMPLE=ON -DCMAKE_Fortran_COMPILER_WORKS=TRUE \ - -DCMAKE_Fortran_FLAGS="--cpp --separate-compilation --realloc-lhs --no-warnings --use-loop-variable-after-loop --no-array-bounds-checking -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" + -DCMAKE_Fortran_FLAGS="--cpp --separate-compilation --realloc-lhs --no-warnings --use-loop-variable-after-loop -I$(pwd)/src -I$(pwd)/subprojects/test-drive/" make -j8 ctest From daac676f0689aa6e4167a0e681aa8f2aff184741 Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Mon, 4 Aug 2025 16:53:12 +0000 Subject: [PATCH 104/119] fix: throw size error if passed in size is strictly less than expected size in function --- src/libasr/codegen/asr_to_llvm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index bd03325082d..91c5ceef0f4 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -11547,7 +11547,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor start_new_block(elseBB); llvm::Value* desc_size = arr_descr->get_array_size(arg, nullptr, 4); llvm::Value* pointer_size = get_array_size_from_asr_type(arr_cast->m_type); - llvm_utils->generate_runtime_error(builder->CreateICmpNE(desc_size, pointer_size), + llvm_utils->generate_runtime_error(builder->CreateICmpSLT(desc_size, pointer_size), "Runtime error: Array size mismatch in subroutine '%s'\n\n" "Tried to match size %d of argument number %d, but expected size is %d\n", builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), @@ -11584,7 +11584,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } else { llvm::Value* fixed_size = llvm::ConstantInt::get(llvm_utils->getIntType(4), ASRUtils::get_fixed_size_of_array(fixed_size_type)); llvm::Value* pointer_size = get_array_size_from_asr_type(arr_cast->m_type); - llvm_utils->generate_runtime_error(builder->CreateICmpNE(fixed_size, pointer_size), + llvm_utils->generate_runtime_error(builder->CreateICmpSLT(fixed_size, pointer_size), "Runtime error: Array size mismatch in subroutine '%s'\n\n" "Tried to match size %d of argument number %d, but expected size is %d\n", builder->CreateGlobalStringPtr(ASRUtils::symbol_name(x.m_name)), From 7bb245771163adeca8aeca9f8ee65d8eb5c67bab Mon Sep 17 00:00:00 2001 From: Gauravsingh Sisodia Date: Thu, 7 Aug 2025 11:38:48 +0000 Subject: [PATCH 105/119] tests: remove --no-array-bounds-checking from some tests --- integration_tests/CMakeLists.txt | 25 ++++++++++++------------- integration_tests/arrays_op_20.f90 | 4 ++-- integration_tests/fortuno_01.f90 | 7 ++----- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 3433be18621..eea7975963b 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -560,7 +560,7 @@ RUN(NAME arrays_04_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackA RUN(NAME arrays_05_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_06_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_07_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -RUN(NAME arrays_08_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME arrays_08_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_09_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME arrays_10_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_11_size LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) @@ -583,7 +583,7 @@ RUN(NAME arrays_01_real LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackA RUN(NAME arrays_01_complex LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME arrays_01_logical LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm) RUN(NAME arrays_01_multi_dim LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) -RUN(NAME integer_bin_op_dim_external_module LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME integer_bin_op_dim_external_module LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray) RUN(NAME array_bound_1 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME array_bound_2 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray wasm fortran) RUN(NAME array_bound_3 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray fortran) @@ -665,11 +665,11 @@ RUN(NAME arrays_44 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran RUN(NAME arrays_45 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_46 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_47 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME arrays_48 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME arrays_48 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_49 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_50 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRAFILES arrays_50_mod.f90) RUN(NAME arrays_51 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME arrays_52 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME arrays_52 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_53 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_54 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_55 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -731,7 +731,8 @@ RUN(NAME array_section_is_non_allocatable LABELS gfortran llvm llvm_wasm llvm_wa RUN(NAME array_indices_array_section LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME array_indices_array_section_assignment LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME arrays_constructor_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) -RUN(NAME array_constructor_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) +# FIXME: fails with bounds checking +RUN(NAME array_constructor_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran EXTRA_ARGS --no-array-bounds-checking) RUN(NAME allocatble_c_ptr LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME hashmap_struct_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME hashmap_nested_dealloc_derived_pointer LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) @@ -796,8 +797,7 @@ RUN(NAME format_16 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME format_17 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME format_18 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME format_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -# FIXME: Make this work with --fast for llvm >= 17, https://github.com/lfortran/lfortran/issues/8155 -RUN(NAME format_20 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc NO_FAST) +RUN(NAME format_20 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME format_21 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME format_22 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME format_23 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) @@ -988,8 +988,7 @@ RUN(NAME intrinsics_144 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # RUN(NAME intrinsics_145 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # dot_product RUN(NAME intrinsics_146 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # dprod RUN(NAME intrinsics_147 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack -# FIXME: Fails with array bounds checking. Multi dimensional ArrayConstant is not supported. -RUN(NAME intrinsics_148 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) # pack +RUN(NAME intrinsics_148 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # pack RUN(NAME intrinsics_149 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # unpack RUN(NAME intrinsics_150 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # maskr RUN(NAME intrinsics_151 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # maskl @@ -1243,10 +1242,10 @@ RUN(NAME integer_boz_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME test_dshiftr LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) -RUN(NAME passing_array_01 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) -RUN(NAME passing_array_02 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) -RUN(NAME passing_array_03 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) -RUN(NAME passing_array_04 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --no-array-bounds-checking) +RUN(NAME passing_array_01 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME passing_array_02 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME passing_array_03 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME passing_array_04 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME parameter_01 LABELS gfortran llvm) RUN(NAME parameter_02 LABELS gfortran llvm) diff --git a/integration_tests/arrays_op_20.f90 b/integration_tests/arrays_op_20.f90 index 2674f0bcfa9..a2b5423dc4d 100644 --- a/integration_tests/arrays_op_20.f90 +++ b/integration_tests/arrays_op_20.f90 @@ -3,7 +3,7 @@ program arrays_op_20 real, allocatable :: array(:, :), arrayoutput(:, :) -allocate(array(5, 5)) +allocate(array(3, 3)) arrayoutput = f(5, array) print *, size(arrayoutput) if( size(arrayoutput) /= 24 ) error stop @@ -12,7 +12,7 @@ program arrays_op_20 function f(m, input) result(output) integer :: m -real :: input(m, m) +real :: input(m) real :: output(2:m, m:2*m) end function diff --git a/integration_tests/fortuno_01.f90 b/integration_tests/fortuno_01.f90 index e39eab42deb..f5cf9b95bf6 100644 --- a/integration_tests/fortuno_01.f90 +++ b/integration_tests/fortuno_01.f90 @@ -7,7 +7,7 @@ module fortuno_basetypes type :: test_ptr_item - class(test_base), pointer :: item + class(test_base), pointer :: item => null() end type test_ptr_item @@ -25,9 +25,6 @@ module fortuno_basetypes subroutine test_list_free(this) class(test_list), intent(inout) :: this - type(test_ptr_item), target :: d(1) - this%storage_ => d - select type (item => this%storage_(1)%item) class default end select @@ -43,4 +40,4 @@ program fortuno_01 call my_list%free() print *, "Test list has been freed successfully." -end program +end program \ No newline at end of file From beb3a31b6e0832cf382831efa322b9c6f6dc3793 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sat, 9 Aug 2025 02:45:43 +0530 Subject: [PATCH 106/119] fix: do not return struct symbol past external Signed-off-by: Saurabh Kumar --- src/libasr/asr_utils.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libasr/asr_utils.cpp b/src/libasr/asr_utils.cpp index dc1f1867910..8da9c0c57d5 100644 --- a/src/libasr/asr_utils.cpp +++ b/src/libasr/asr_utils.cpp @@ -135,7 +135,7 @@ ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression) } else if (ASR::is_a(*ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v))) { ASR::Function_t* func = ASR::down_cast(ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v)); if (func->m_return_var != nullptr && ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(func->m_return_var))) { - return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(func->m_return_var)); + return ASRUtils::get_struct_sym_from_struct_expr(func->m_return_var); } else { for (size_t i = 0; i < func->n_args; i++) { ASR::expr_t* arg = func->m_args[i]; @@ -150,7 +150,7 @@ ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression) } } else if (ASR::is_a(*ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v))) { // If the Var is a Struct, we return the symbol of the Struct. - return ASRUtils::symbol_get_past_external(ASR::down_cast(expression)->m_v); + return ASR::down_cast(expression)->m_v; } else { throw LCompilersException("Expected Var to be either Variable or Function type, but found: " + std::to_string(ASR::down_cast(expression)->m_v->type)); @@ -163,7 +163,7 @@ ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression) // parent struct of the struct used to declare `var`. // Please see assignment `c%parent_t = p` in // `integration_tests/derived_types_73.f90` for an example. - return ASRUtils::symbol_get_past_external(struct_instance_member->m_m); + return struct_instance_member->m_m; } else { LCOMPILERS_ASSERT(ASR::is_a(*ASRUtils::symbol_get_past_external(struct_instance_member->m_m))); ASR::Variable_t* var = ASR::down_cast(ASRUtils::symbol_get_past_external(struct_instance_member->m_m)); @@ -190,16 +190,16 @@ ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression) } case ASR::exprType::ArrayItem: { ASR::ArrayItem_t* array_item = ASR::down_cast(expression); - return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(array_item->m_v)); + return ASRUtils::get_struct_sym_from_struct_expr(array_item->m_v); } case ASR::exprType::ArraySection: { ASR::ArraySection_t* array_section = ASR::down_cast(expression); - return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(array_section->m_v)); + return ASRUtils::get_struct_sym_from_struct_expr(array_section->m_v); } case ASR::exprType::FunctionCall: { ASR::FunctionCall_t* func_call = ASR::down_cast(expression); ASR::Function_t* func = get_function(func_call->m_name); - return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(func->m_return_var)); + return ASRUtils::get_struct_sym_from_struct_expr(func->m_return_var); } case ASR::exprType::StructConstant: { ASR::StructConstant_t* struct_constant = ASR::down_cast(expression); @@ -209,7 +209,7 @@ ASR::symbol_t* get_struct_sym_from_struct_expr(ASR::expr_t* expression) ASR::ArrayPhysicalCast_t* array_physical_cast = ASR::down_cast(expression); // `array_physical_cast->m_arg` will be non-null for Struct expressions LCOMPILERS_ASSERT(array_physical_cast->m_arg != nullptr); - return ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(array_physical_cast->m_arg)); + return ASRUtils::get_struct_sym_from_struct_expr(array_physical_cast->m_arg); } case ASR::exprType::IntegerCompare: { ASR::IntegerCompare_t* int_compare = ASR::down_cast(expression); From c1e3ddcca6fa6a47f3fc88f9a14596de0452e7be Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sat, 9 Aug 2025 02:46:06 +0530 Subject: [PATCH 107/119] tests: add and register integration test Signed-off-by: Saurabh Kumar --- integration_tests/CMakeLists.txt | 1 + integration_tests/class_63.f90 | 9 +++++++++ integration_tests/class_63_module_1.f90 | 6 ++++++ integration_tests/class_63_module_2.f90 | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 integration_tests/class_63.f90 create mode 100644 integration_tests/class_63_module_1.f90 create mode 100644 integration_tests/class_63_module_2.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index eea7975963b..af35cd85898 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1932,6 +1932,7 @@ RUN(NAME class_59 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME class_60 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME class_61 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS --realloc-lhs) RUN(NAME class_62 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME class_63 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_ARGS -c --cpp EXTRAFILES class_63_module_1.f90 class_63_module_2.f90) RUN(NAME class_procedure_args_01 LABELS gfortran llvm) diff --git a/integration_tests/class_63.f90 b/integration_tests/class_63.f90 new file mode 100644 index 00000000000..a3ef15df1d0 --- /dev/null +++ b/integration_tests/class_63.f90 @@ -0,0 +1,9 @@ +module class_63_module + + use class_63_module_2, only: MyType + +end module + +program class_63 + use class_63_module +end program \ No newline at end of file diff --git a/integration_tests/class_63_module_1.f90 b/integration_tests/class_63_module_1.f90 new file mode 100644 index 00000000000..00bb3defef4 --- /dev/null +++ b/integration_tests/class_63_module_1.f90 @@ -0,0 +1,6 @@ +module class_63_module_1 + + type, abstract :: AbsType + end type AbsType + +end module diff --git a/integration_tests/class_63_module_2.f90 b/integration_tests/class_63_module_2.f90 new file mode 100644 index 00000000000..0363568d253 --- /dev/null +++ b/integration_tests/class_63_module_2.f90 @@ -0,0 +1,19 @@ +module class_63_module_2 + + use class_63_module_1, only: AbsType + + type :: MyType + class(AbsType), allocatable :: arr(:) + contains + procedure :: method + end type MyType + +contains + + subroutine method(self) + class(MyType), intent(inout) :: self + associate ( element => self%arr(size(self%arr)) ) + end associate + end subroutine method + +end module From 85f1b85bfbd99edc81ea179c5fd3a8143b558c30 Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Fri, 8 Aug 2025 15:04:16 +0530 Subject: [PATCH 108/119] fix: get correct struct sym which creating associated var --- src/lfortran/semantics/ast_body_visitor.cpp | 6 +++++- src/libasr/asr_utils.h | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/lfortran/semantics/ast_body_visitor.cpp b/src/lfortran/semantics/ast_body_visitor.cpp index 3684347f5ec..68f53917263 100644 --- a/src/lfortran/semantics/ast_body_visitor.cpp +++ b/src/lfortran/semantics/ast_body_visitor.cpp @@ -1435,6 +1435,9 @@ class BodyVisitor : public CommonVisitor { } } tmp_type = ASRUtils::duplicate_type(al, variable->m_type, &tmp_dims); + } else if (ASR::is_a(*tmp_expr) || + ASR::is_a(*tmp_expr)) { + create_associate_stmt = true; } if ( create_associate_stmt && !ASR::is_a(*tmp_type) ) { tmp_type = ASRUtils::duplicate_type_with_empty_dims(al, tmp_type); @@ -1447,9 +1450,10 @@ class BodyVisitor : public CommonVisitor { SetChar variable_dependencies_vec; variable_dependencies_vec.reserve(al, 1); ASRUtils::collect_variable_dependencies(al, variable_dependencies_vec, tmp_type, nullptr, nullptr, name); + ASR::symbol_t* struct_sym = ASRUtils::import_struct_sym_as_external(al, x.base.base.loc, tmp_expr, current_scope); ASR::asr_t *v = ASRUtils::make_Variable_t_util(al, x.base.base.loc, new_scope, name_c, variable_dependencies_vec.p, variable_dependencies_vec.size(), - ASR::intentType::Local, nullptr, nullptr, tmp_storage, tmp_type, ASRUtils::get_struct_sym_from_struct_expr(tmp_expr), + ASR::intentType::Local, nullptr, nullptr, tmp_storage, tmp_type, struct_sym, ASR::abiType::Source, ASR::accessType::Private, ASR::presenceType::Required, false); new_scope->add_symbol(name, ASR::down_cast(v)); diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index c141a13b099..09d2beb620a 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -5824,7 +5824,22 @@ static inline void import_struct_t(Allocator& al, } } - +static inline ASR::symbol_t* import_struct_sym_as_external(Allocator& al, + const Location& loc, ASR::expr_t* v_expr, SymbolTable* current_scope) { + ASR::symbol_t* struct_sym = get_struct_sym_from_struct_expr(v_expr); + if (struct_sym == nullptr) return nullptr; + std::string struct_name = symbol_name(struct_sym); + if (current_scope->resolve_symbol(struct_name) == nullptr) { + struct_sym = ASR::down_cast(ASR::make_ExternalSymbol_t( + al, loc, current_scope, s2c(al, struct_name), struct_sym, + ASRUtils::symbol_name(ASRUtils::get_asr_owner(struct_sym)), nullptr, 0, + s2c(al, struct_name), ASR::accessType::Public)); + current_scope->add_symbol(struct_name, struct_sym); + } else { + struct_sym = current_scope->resolve_symbol(struct_name); + } + return struct_sym; +} static inline ASR::asr_t* make_ArrayPhysicalCast_t_util(Allocator &al, const Location &a_loc, ASR::expr_t* a_arg, ASR::array_physical_typeType a_old, ASR::array_physical_typeType a_new, From eb775a6e881ba0f09d630b92b2827a5a6a025cc8 Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Fri, 8 Aug 2025 15:04:50 +0530 Subject: [PATCH 109/119] tests: add tests and update test references --- integration_tests/CMakeLists.txt | 1 + integration_tests/associate_21.f90 | 10 +++++ integration_tests/associate_21_mod.f90 | 33 ++++++++++++++++ src/lfortran/semantics/ast_body_visitor.cpp | 4 +- tests/reference/asr-associate_08-570ac7d.json | 2 +- .../reference/asr-associate_08-570ac7d.stdout | 38 +++++++++---------- 6 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 integration_tests/associate_21.f90 create mode 100644 integration_tests/associate_21_mod.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index af35cd85898..c1ee7c2f687 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1690,6 +1690,7 @@ RUN(NAME associate_17 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_18 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRAFILES associate_18_module.f90) RUN(NAME associate_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME associate_20 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME associate_21 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRAFILES associate_21_mod.f90) RUN(NAME attr_dim_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME attr_dim_02 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME attr_dim_03 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) diff --git a/integration_tests/associate_21.f90 b/integration_tests/associate_21.f90 new file mode 100644 index 00000000000..da93ca26cec --- /dev/null +++ b/integration_tests/associate_21.f90 @@ -0,0 +1,10 @@ +program associate_21 + use associate_21_mod_b + type(model_t) :: tmp_model + allocate(tmp_model%dependency(1)) + call tmp_model%update_dependency(1, 5) + + !!! TODO: Need to associate properly and handle integer pointer + ! if (tmp_model%dependency(1)%name /= "LFortran") error stop + ! if (tmp_model%dependency(1)%key /= 5) error stop +end program \ No newline at end of file diff --git a/integration_tests/associate_21_mod.f90 b/integration_tests/associate_21_mod.f90 new file mode 100644 index 00000000000..024b5700a5f --- /dev/null +++ b/integration_tests/associate_21_mod.f90 @@ -0,0 +1,33 @@ +module associate_21_mod_a + implicit none + type :: dependency_t + character(len=:), allocatable :: name + integer :: key + end type dependency_t +end module associate_21_mod_a + + +module associate_21_mod_b + use associate_21_mod_a + implicit none + + type :: model_t + type(dependency_t), allocatable :: dependency(:) + contains + procedure :: update_dependency + end type model_t + +contains + + subroutine update_dependency(self, ii, key) + class(model_t), intent(inout) :: self + integer, intent(in) :: ii + integer, intent(in) :: key + + associate (dep => self%dependency(ii)) + dep%name = "LFortran" + dep%key = key + end associate + end subroutine update_dependency + +end module associate_21_mod_b \ No newline at end of file diff --git a/src/lfortran/semantics/ast_body_visitor.cpp b/src/lfortran/semantics/ast_body_visitor.cpp index 68f53917263..76685901b90 100644 --- a/src/lfortran/semantics/ast_body_visitor.cpp +++ b/src/lfortran/semantics/ast_body_visitor.cpp @@ -1435,10 +1435,10 @@ class BodyVisitor : public CommonVisitor { } } tmp_type = ASRUtils::duplicate_type(al, variable->m_type, &tmp_dims); - } else if (ASR::is_a(*tmp_expr) || - ASR::is_a(*tmp_expr)) { + } else if (ASR::is_a(*tmp_expr)) { create_associate_stmt = true; } + if ( create_associate_stmt && !ASR::is_a(*tmp_type) ) { tmp_type = ASRUtils::duplicate_type_with_empty_dims(al, tmp_type); tmp_type = ASRUtils::TYPE(ASR::make_Pointer_t(al, tmp_type->base.loc, diff --git a/tests/reference/asr-associate_08-570ac7d.json b/tests/reference/asr-associate_08-570ac7d.json index e24a3cd0713..9c6d17ddd02 100644 --- a/tests/reference/asr-associate_08-570ac7d.json +++ b/tests/reference/asr-associate_08-570ac7d.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-associate_08-570ac7d.stdout", - "stdout_hash": "afe234eb4fbf33b1091b63fc3f2686d5f999a5e3f1f7d535a44cb7b8", + "stdout_hash": "4959b85a39e9002bb1bc90591f6984a9099ac6153675c4f7593d1367", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-associate_08-570ac7d.stdout b/tests/reference/asr-associate_08-570ac7d.stdout index 678120cfa56..f70cda8dc02 100644 --- a/tests/reference/asr-associate_08-570ac7d.stdout +++ b/tests/reference/asr-associate_08-570ac7d.stdout @@ -544,23 +544,25 @@ () () Default - (StructType - [(Pointer - (Array - (StructType - [(Integer 4)] - [] - .true. - .false. + (Pointer + (StructType + [(Pointer + (Array + (StructType + [(Integer 4)] + [] + .true. + .false. + ) + [(() + ())] + DescriptorArray ) - [(() - ())] - DescriptorArray - ) - )] - [] - .false. - .false. + )] + [] + .false. + .false. + ) ) 2 t_2 Source @@ -575,7 +577,7 @@ ) }) associate_block - [(Assignment + [(Associate (Var 9 target) (ArrayItem (Var 6 progress) @@ -603,8 +605,6 @@ ColMajor () ) - () - .false. ) (Assignment (StructInstanceMember From 3bb4439581a798a75e0b05e7079d9f378c52baa1 Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Sat, 9 Aug 2025 02:01:14 +0530 Subject: [PATCH 110/119] ci: update fpm ci (remove 6 workarounds) --- ci/test_third_party_codes.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/test_third_party_codes.sh b/ci/test_third_party_codes.sh index b23939bfef1..817a6b081c0 100755 --- a/ci/test_third_party_codes.sh +++ b/ci/test_third_party_codes.sh @@ -252,9 +252,9 @@ time_section "🧪 Testing FPM" ' git clone https://github.com/jinangshah21/fpm.git cd fpm export PATH="$(pwd)/../src/bin:$PATH" - git checkout lf-6 + git checkout lf-7 micromamba install -c conda-forge fpm - git checkout b946c489ef575e8103b6f5b07bfdfe0171e1dac5 + git checkout 0495209655831f5a13f643feaa790e08851adf8a fpm --compiler=$FC build print_success "Done with FPM" cd .. From b0b912b947b2f4bdb22ae14bc35df02dfb8edd06 Mon Sep 17 00:00:00 2001 From: Hitesh Ghanchi Date: Thu, 7 Aug 2025 17:32:38 +0530 Subject: [PATCH 111/119] Solved and added testcase --- src/lfortran/semantics/ast_common_visitor.h | 25 ++++++++++--------- tests/errors/continue_compilation_2.f90 | 2 ++ .../asr-continue_compilation_2-a6145a1.json | 4 +-- .../asr-continue_compilation_2-a6145a1.stderr | 6 +++++ .../asr-continue_compilation_3-435a232.json | 2 +- .../asr-continue_compilation_3-435a232.stderr | 6 ++--- tests/reference/asr-subroutine3-9c6f5d1.json | 2 +- .../reference/asr-subroutine3-9c6f5d1.stderr | 6 ++--- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 54826c31630..49af285e4d2 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -7241,7 +7241,19 @@ class CommonVisitor : public AST::BaseVisitor { Vec args; std::vector kwarg_names = {"array", "dim", "kind"}; handle_intrinsic_node_args(x, args, kwarg_names, 1, 3, std::string("size")); - ASR::expr_t *v_Var = args[0], *dim = args[1], *kind = args[2]; + ASR::expr_t *v_Var = args[0], *dim = args[1], *kind = args[2]; + + // general check for all arguments other than array + if (!ASRUtils::is_array(ASRUtils::expr_type(v_Var))) { + diag.add(Diagnostic( + "Argument of 'size' must be an array", + Level::Error, Stage::Semantic, { + Label("", {v_Var->base.loc}) + } + )); + throw SemanticAbort(); + } + int64_t kind_const = handle_kind(kind); ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, kind_const)); ASR::dimension_t* m_dims = nullptr; @@ -7281,17 +7293,6 @@ class CommonVisitor : public AST::BaseVisitor { size_compiletime = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, x.base.base.loc, compile_time_size, type)); } - //if v_Var is a Function, give error - if(ASR::is_a(*v_Var)) { - ASR::Var_t* var = ASR::down_cast(v_Var); - ASR::symbol_t* sym = var->m_v; - if(ASR::is_a(*sym)) { - diag.add(Diagnostic("Argument of `size` must be an array", - Level::Error, Stage::Semantic, {Label("", {x.base.base.loc})})); - throw SemanticAbort(); - } - } - return ASRUtils::make_ArraySize_t_util(al, x.base.base.loc, v_Var, dim, type, size_compiletime, false); } diff --git a/tests/errors/continue_compilation_2.f90 b/tests/errors/continue_compilation_2.f90 index b3f5e4f0a80..9094bc48b62 100644 --- a/tests/errors/continue_compilation_2.f90 +++ b/tests/errors/continue_compilation_2.f90 @@ -459,6 +459,8 @@ program continue_compilation_2 !nested intent call sub_a(intent_bug_sub_x) print *, outer_func(intent_bug_sub_x) + !size_intrinsic_check + print *, size(ichar_runtime) contains logical function f(x) diff --git a/tests/reference/asr-continue_compilation_2-a6145a1.json b/tests/reference/asr-continue_compilation_2-a6145a1.json index 5e6ece83045..968d4ea8538 100644 --- a/tests/reference/asr-continue_compilation_2-a6145a1.json +++ b/tests/reference/asr-continue_compilation_2-a6145a1.json @@ -2,12 +2,12 @@ "basename": "asr-continue_compilation_2-a6145a1", "cmd": "lfortran --semantics-only --continue-compilation --no-color {infile}", "infile": "tests/errors/continue_compilation_2.f90", - "infile_hash": "39fff6cc6440be3f6da56521be465bd4251f236e932793710711424f", + "infile_hash": "fda46f322bdce146209563a0b73fab4fb9e50dac92d1b26a6d803465", "outfile": null, "outfile_hash": null, "stdout": null, "stdout_hash": null, "stderr": "asr-continue_compilation_2-a6145a1.stderr", - "stderr_hash": "73cdc8ebd2c5a2750103da9668f28410b45f45aaa46da1349167b343", + "stderr_hash": "6ed0127648397627944a73ec4892119e2f22beefd7e739801cf59b06", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/asr-continue_compilation_2-a6145a1.stderr b/tests/reference/asr-continue_compilation_2-a6145a1.stderr index 104005a71e1..7521cc30206 100644 --- a/tests/reference/asr-continue_compilation_2-a6145a1.stderr +++ b/tests/reference/asr-continue_compilation_2-a6145a1.stderr @@ -844,3 +844,9 @@ semantic error: Arguments to min0 must be of real, integer or character type | 458 | print *, max(min_max, min_max) | ^^^^^^^^^^^^^^^^^^^^^ + +semantic error: Argument of 'size' must be an array + --> tests/errors/continue_compilation_2.f90:463:19 + | +463 | print *, size(ichar_runtime) + | ^^^^^^^^^^^^^ diff --git a/tests/reference/asr-continue_compilation_3-435a232.json b/tests/reference/asr-continue_compilation_3-435a232.json index e87b772f716..ed4b9c4ff86 100644 --- a/tests/reference/asr-continue_compilation_3-435a232.json +++ b/tests/reference/asr-continue_compilation_3-435a232.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-continue_compilation_3-435a232.stderr", - "stderr_hash": "ab5be0cd1ff8893c8249352f49b67f9632620dfd529f801860545014", + "stderr_hash": "c09c286db8aa153ea7a4674447a171d10aef1c0214037988c4a7d03b", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/asr-continue_compilation_3-435a232.stderr b/tests/reference/asr-continue_compilation_3-435a232.stderr index 22cbff641b6..2f8076864c1 100644 --- a/tests/reference/asr-continue_compilation_3-435a232.stderr +++ b/tests/reference/asr-continue_compilation_3-435a232.stderr @@ -271,11 +271,11 @@ semantic error: Kind of all the arguments of Mergebits must be the same 177 | print *, merge_bits(merge_i,merge_j,merge_k) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -semantic error: Argument of `size` must be an array - --> tests/errors/continue_compilation_3.f90:181:18 +semantic error: Argument of 'size' must be an array + --> tests/errors/continue_compilation_3.f90:181:23 | 181 | print *, size(bpe) - | ^^^^^^^^^ + | ^^^ semantic error: Variable 'd' is not declared --> tests/errors/continue_compilation_3.f90:182:15 diff --git a/tests/reference/asr-subroutine3-9c6f5d1.json b/tests/reference/asr-subroutine3-9c6f5d1.json index a4130d3e58e..a9f18a0e607 100644 --- a/tests/reference/asr-subroutine3-9c6f5d1.json +++ b/tests/reference/asr-subroutine3-9c6f5d1.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-subroutine3-9c6f5d1.stderr", - "stderr_hash": "8e31d5e32daddabcab5b7e0df3d859340f822ecc1c86d4e1cc667450", + "stderr_hash": "ffe0a4412cffe166df5f25b690125e6886c03e45343fb76b900fd1fa", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-subroutine3-9c6f5d1.stderr b/tests/reference/asr-subroutine3-9c6f5d1.stderr index 6e3ad7455b8..f96e54625b2 100644 --- a/tests/reference/asr-subroutine3-9c6f5d1.stderr +++ b/tests/reference/asr-subroutine3-9c6f5d1.stderr @@ -1,5 +1,5 @@ -semantic error: Argument of `size` must be an array - --> tests/errors/subroutine3.f90:5:14 +semantic error: Argument of 'size' must be an array + --> tests/errors/subroutine3.f90:5:19 | 5 | print *, size(f) - | ^^^^^^^ + | ^ From 1610a7f0a74c5fec5a50f897169f8447b7463ddb Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Sat, 9 Aug 2025 17:19:24 +0530 Subject: [PATCH 112/119] fix: correctly check argument matching for struct/class type --- integration_tests/CMakeLists.txt | 1 + integration_tests/procedure_23.f90 | 55 ++++++++++++++++++++++++++++++ src/libasr/asr_utils.cpp | 9 ++++- src/libasr/asr_utils.h | 13 +++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 integration_tests/procedure_23.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index c1ee7c2f687..bd1438f066c 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2181,6 +2181,7 @@ RUN(NAME procedure_19 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME procedure_20 LABELS gfortran llvm) RUN(NAME procedure_21 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME procedure_22 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRAFILES procedure_22_a.f90) +RUN(NAME procedure_23 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME allocated_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) diff --git a/integration_tests/procedure_23.f90 b/integration_tests/procedure_23.f90 new file mode 100644 index 00000000000..8a30545040e --- /dev/null +++ b/integration_tests/procedure_23.f90 @@ -0,0 +1,55 @@ +module procedure_23_mod + implicit none + + type :: dependency_config_t + integer :: id = -1 + end type dependency_config_t + + type, extends(dependency_config_t) :: dependency_node_t + character(:), allocatable :: name + end type dependency_node_t + + type :: dependency_tree_t + integer :: key + contains + procedure :: add_dependency + procedure :: add_dependency_node + generic :: add => add_dependency, add_dependency_node + end type dependency_tree_t + +contains + + subroutine add_dependency(this, cfg) + class(dependency_tree_t), intent(inout) :: this + type(dependency_config_t), intent(inout) :: cfg + cfg%id = 101 + this%key = 2 + end subroutine add_dependency + + subroutine add_dependency_node(this, node) + class(dependency_tree_t), intent(inout) :: this + type(dependency_node_t), intent(inout) :: node + node%id = 202 + this%key = 3 + node%name = "LFortran" + end subroutine add_dependency_node + +end module procedure_23_mod + + +program procedure_23 + use procedure_23_mod + implicit none + + type(dependency_tree_t) :: tree + type(dependency_config_t) :: cfg + type(dependency_node_t) :: node + + call tree%add(cfg) + if (cfg%id /= 101) error stop + if (tree%key /= 2) error stop + call tree%add(node) + if (node%id /= 202) error stop + if (node%name /= "LFortran") error stop + if (tree%key /= 3) error stop +end program procedure_23 diff --git a/src/libasr/asr_utils.cpp b/src/libasr/asr_utils.cpp index 8da9c0c57d5..dfd365fb5ed 100644 --- a/src/libasr/asr_utils.cpp +++ b/src/libasr/asr_utils.cpp @@ -2214,7 +2214,14 @@ bool argument_types_match(const Vec& args, s2 = ASRUtils::symbol_get_past_external(ASRUtils::get_struct_sym_from_struct_expr(sub.m_args[i])); } if (s1 && s2) { - if (!ASRUtils::is_derived_type_similar(ASR::down_cast(s1), ASR::down_cast(s2))) return false; + bool is_arg_class = ASRUtils::is_class_type(arg2_ext); + if (!is_arg_class) { // if argument is c_struct we need exact matching types + if (s1 != s2) { + return false; + } + } else if (!ASRUtils::check_class_assignment_compatibility(s2, s1)) { + return false; + } } else if (!types_equal(arg1, arg2, args[i].m_value, sub.m_args[i], !ASRUtils::get_FunctionType(sub)->m_elemental)) { return false; } diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 09d2beb620a..595cc533b1a 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -4262,6 +4262,19 @@ inline bool check_class_assignment_compatibility(ASR::expr_t* target, ASR::expr_ return is_class_same; } +inline bool check_class_assignment_compatibility(ASR::symbol_t* target, ASR::symbol_t* value) { + target = ASRUtils::symbol_get_past_external(target); + value = ASRUtils::symbol_get_past_external(value); + bool is_class_same = false; + if (ASR::is_a(*target) && ASR::is_a(*value)) { + ASR::Struct_t* tar_struct = ASR::down_cast(target); + ASR::Struct_t* val_struct = ASR::down_cast(value); + is_class_same = (target == value); + is_class_same = is_class_same || ASRUtils::is_parent(tar_struct, val_struct); + } + return is_class_same; +} + static inline bool is_elemental(ASR::symbol_t* x) { ASR::symbol_t* proc = ASRUtils::symbol_get_past_external(x); if (ASR::is_a(*proc)) { From 706ba5d82a0958c4b1e6831e1425e70fa6cd5655 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 9 Aug 2025 19:40:54 +0530 Subject: [PATCH 113/119] fix: skip scalar promotion for elemental functions --- src/lfortran/semantics/ast_common_visitor.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index 49af285e4d2..a3e7047ee69 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -6646,7 +6646,10 @@ class CommonVisitor : public AST::BaseVisitor { // bool visit_required = false; for ( auto it: array_arg_idx ) { ASR::expr_t* func_arg = f->m_args[it.first]; - if ( !ASRUtils::is_array(ASRUtils::EXPR2VAR(func_arg)->m_type) ) { + ASR::FunctionType_t* f_type = + ASR::down_cast(f->m_function_signature); + bool is_elemental = (f_type->m_abi == ASR::abiType::Source && f_type->m_elemental); + if (!is_elemental && !ASRUtils::is_array(ASRUtils::EXPR2VAR(func_arg)->m_type)) { // create array type with empty dimensions and physical type as PointerToDataArray ASR::ttype_t* new_type = ASRUtils::duplicate_type_with_empty_dims(al, it.second, ASR::array_physical_typeType::PointerToDataArray, true); ASRUtils::EXPR2VAR(func_arg)->m_type = new_type; From 5f70ab8cba0f6b0c3a6f3bd63aa903751e5af61b Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 9 Aug 2025 19:41:07 +0530 Subject: [PATCH 114/119] test: add and register test --- integration_tests/CMakeLists.txt | 1 + integration_tests/legacy_array_sections_08.f90 | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 integration_tests/legacy_array_sections_08.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index bd1438f066c..131026b71d1 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2342,6 +2342,7 @@ RUN(NAME legacy_array_sections_04 LABELS gfortran llvm2 EXTRA_ARGS --implicit-in RUN(NAME legacy_array_sections_05 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --legacy-array-sections) RUN(NAME legacy_array_sections_06 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --legacy-array-sections) RUN(NAME legacy_array_sections_07 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --legacy-array-sections) +RUN(NAME legacy_array_sections_08 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc llvmStackArray EXTRA_ARGS --legacy-array-sections) RUN(NAME cmake_minimal_test_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME char_array_initialization_declaration LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) diff --git a/integration_tests/legacy_array_sections_08.f90 b/integration_tests/legacy_array_sections_08.f90 new file mode 100644 index 00000000000..9ec485d36a0 --- /dev/null +++ b/integration_tests/legacy_array_sections_08.f90 @@ -0,0 +1,13 @@ +program legacy_array_sections_08 + implicit none + real(4) :: x(2) + x = [1.0, 2.0] + print *, f1(x) + if (any(f1(x) - [0.841470957, 0.909297407] > 1e-6)) error stop + contains + pure elemental real(4) function f1(x) + implicit none + real(4),intent(in) :: x + f1 = sin(x) + end function f1 +end program legacy_array_sections_08 From fe088c97ba5e80442ad70de49dd27d857854cabc Mon Sep 17 00:00:00 2001 From: Sri Ganesh Thota Date: Sun, 10 Aug 2025 03:34:55 +0530 Subject: [PATCH 115/119] refactor: some of the string runtime functions (#8289) --- src/libasr/runtime/lfortran_intrinsics.c | 287 +++++++++++++---------- 1 file changed, 166 insertions(+), 121 deletions(-) diff --git a/src/libasr/runtime/lfortran_intrinsics.c b/src/libasr/runtime/lfortran_intrinsics.c index d8e8243f396..78bdee84146 100644 --- a/src/libasr/runtime/lfortran_intrinsics.c +++ b/src/libasr/runtime/lfortran_intrinsics.c @@ -3552,85 +3552,118 @@ void get_unique_ID(char buffer[ID_LEN + 1]) { buffer[ID_LEN] = '\0'; } -LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, - char* f_name, int64_t f_name_len, - char* status, int64_t status_len, - char* form, int64_t form_len, - char* access, int64_t access_len, - char* iomsg, int64_t iomsg_len, - int32_t *iostat, - char* action, int64_t action_len){ +static void +trim_trailing_spaces(char** str, int64_t* len, bool init) +{ + if (!init) + return; // If the string is initialized manually, we do not trim it + int64_t i = 0; + int64_t last_non_space = -1; + while (i < *len && (*str)[i] != '\0') { + if (!isspace((unsigned char) (*str)[i])) { + last_non_space = i; + } + i++; + } + *len = last_non_space + 1; + // Null terminate if there's room + if (*len < i) { + (*str)[*len] = '\0'; + } +} + + +static char* +to_c_string(char* src, int64_t len) +{ + char* buf = (char*) malloc(len + 1); + if (!buf) + return NULL; + memcpy(buf, src, len); + buf[len] = '\0'; + return buf; +} + +static void +pad_with_spaces(char* dest, int64_t orig_len, int64_t total_len) +{ + for (int64_t i = orig_len; i < total_len; i++) { + dest[i] = ' '; + } + dest[total_len] = '\0'; +} + +LFORTRAN_API int64_t +_lfortran_open(int32_t unit_num, + char* f_name, + int64_t f_name_len, + char* status, + int64_t status_len, + char* form, + int64_t form_len, + char* access, + int64_t access_len, + char* iomsg, + int64_t iomsg_len, + int32_t* iostat, + char* action, + int64_t action_len) +{ if (iostat != NULL) { *iostat = 0; } - if (f_name == NULL) { // Not Provided + bool ini_file = true; + if (f_name == NULL) { // Not Provided char *prefix = "_lfortran_generated_file", *format = "txt"; char unique_id[ID_LEN + 1]; get_unique_ID(unique_id); int length = ID_LEN + strlen(prefix) + strlen(format) + 3; - f_name = (char *)malloc(length); + f_name = (char*) malloc(length); snprintf(f_name, length, "%s_%s.%s", prefix, unique_id, format); + ini_file = false; } - + bool ini_status = true; if (status == NULL) { status = "unknown"; + status_len = 7; + ini_status = false; } - + bool ini_form = true; if (form == NULL) { form = "formatted"; + form_len = 9; + ini_form = false; } - + bool ini_access = true; if (access == NULL) { access = "sequential"; - - } if (action == NULL) { - action = "readwrite"; - } - bool file_exists[1] = {false}; - FILE *already_open = get_file_pointer_from_unit(unit_num, NULL, NULL, NULL, NULL); - - size_t len = strlen(f_name); - if (*(f_name + len - 1) == ' ') { - // trim trailing spaces - char* end = f_name + len - 1; - while (end > f_name && isspace((unsigned char) *end)) { - end--; - } - *(end + 1) = '\0'; + access_len = 10; + ini_access = false; } - - len = strlen(status); - if (*(status + len - 1) == ' ') { - // trim trailing spaces - char* end = status + len - 1; - while (end > status && isspace((unsigned char) *end)) { - end--; - } - *(end + 1) = '\0'; - } - - len = strlen(form); - if (*(form + len - 1) == ' ') { - // trim trailing spaces - char* end = form + len - 1; - while (end > form && isspace((unsigned char) *end)) { - end--; - } - *(end + 1) = '\0'; - } - - len = strlen(action); - if (*(action + len - 1) == ' ') { - // trim trailing spaces - char* end = action + len - 1; - while (end > action && isspace((unsigned char) *end)) { - end--; - } - *(end + 1) = '\0'; - } - - _lfortran_inquire(f_name, f_name_len, file_exists, -1, NULL, NULL, NULL, NULL, 0, NULL, 0, NULL, 0); - char *access_mode = NULL; + bool ini_action = true; + if (action == NULL) { + action = "readwrite"; + action_len = 9; + ini_action = false; + } + bool file_exists[1] = { false }; + FILE* already_open = get_file_pointer_from_unit(unit_num, NULL, NULL, NULL, NULL); + + trim_trailing_spaces(&f_name, &f_name_len, ini_file); + trim_trailing_spaces(&status, &status_len, ini_status); + trim_trailing_spaces(&form, &form_len, ini_form); + trim_trailing_spaces(&action, &action_len, ini_action); + + // Prepare null-terminated names for C APIs + char* f_name_c = to_c_string(f_name, f_name_len); + char* status_c = to_c_string(status, status_len); + char* form_c = to_c_string(form, form_len); + char* access_c = to_c_string(access, access_len); + char* action_c = to_c_string(action, action_len); + + _lfortran_inquire( + f_name, f_name_len, file_exists, -1, NULL, NULL, NULL, NULL, 0, NULL, 0, NULL, 0); + char* access_mode = NULL; /* STATUS=`specifier` in the OPEN statement The following are the available specifiers: @@ -3645,16 +3678,15 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, if (iostat != NULL) { *iostat = 2; if ((iomsg != NULL) && (iomsg_len > 0)) { - char *temp = "File `%s` does not exists! Cannot open a file with the `status=old`"; + char* temp + = "File `%s` does not exists! Cannot open a file with the `status=old`"; snprintf(iomsg, iomsg_len + 1, temp, f_name); - for (size_t i = strlen(iomsg); i < iomsg_len; i++) { // Pad - (iomsg)[i] = ' '; - } - (iomsg)[iomsg_len] = '\0'; + pad_with_spaces(iomsg, strlen(iomsg), iomsg_len); } } else { printf("Runtime error: File `%s` does not exists!\nCannot open a " - "file with the `status=old`\n", f_name); + "file with the `status=old`\n", + f_name); exit(1); } } @@ -3664,16 +3696,14 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, if (iostat != NULL) { *iostat = 17; if ((iomsg != NULL) && (iomsg_len > 0)) { - char *temp = "File `%s` exists! Cannot open a file with the `status=new`"; + char* temp = "File `%s` exists! Cannot open a file with the `status=new`"; snprintf(iomsg, iomsg_len + 1, temp, f_name); - for (size_t i = strlen(iomsg); i < iomsg_len; i++) { // Pad - (iomsg)[i] = ' '; - } - (iomsg)[iomsg_len] = '\0'; + pad_with_spaces(iomsg, strlen(iomsg), iomsg_len); } } else { printf("Runtime error: File `%s` exists!\nCannot open a file with " - "the `status=new`\n", f_name); + "the `status=new`\n", + f_name); exit(1); } } @@ -3682,7 +3712,7 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, access_mode = "w+"; } else if (streql(status, "unknown")) { if (!*file_exists && !already_open) { - FILE *fd = fopen(f_name, "w"); + FILE* fd = fopen(f_name, "w"); if (fd) { fclose(fd); } @@ -3692,16 +3722,14 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, if (iostat != NULL) { *iostat = 5002; if ((iomsg != NULL) && (iomsg_len > 0)) { - char *temp = "STATUS specifier in OPEN statement has invalid value."; + char* temp = "STATUS specifier in OPEN statement has invalid value."; snprintf(iomsg, iomsg_len + 1, "%s", temp); - for (size_t i = strlen(iomsg); i < iomsg_len; i++) { // Pad - (iomsg)[i] = ' '; - } - (iomsg)[iomsg_len] = '\0'; + pad_with_spaces(iomsg, strlen(iomsg), iomsg_len); } } else { printf("Runtime error: STATUS specifier in OPEN statement has " - "invalid value '%s'\n", status); + "invalid value '%s'\n", + status); exit(1); } } @@ -3718,16 +3746,14 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, if (iostat != NULL) { *iostat = 5002; if ((iomsg != NULL) && (iomsg_len > 0)) { - char *temp = "FORM specifier in OPEN statement has invalid value."; - snprintf(iomsg, iomsg_len+1/*\0*/, "%s", temp); - for (size_t i = strlen(iomsg); i < iomsg_len; i++) { // Pad - (iomsg)[i] = ' '; - } - (iomsg)[iomsg_len] = '\0'; + char* temp = "FORM specifier in OPEN statement has invalid value."; + snprintf(iomsg, iomsg_len + 1 /*\0*/, "%s", temp); + pad_with_spaces(iomsg, strlen(iomsg), iomsg_len); } } else { printf("Runtime error: FORM specifier in OPEN statement has " - "invalid value '%s'\n", form); + "invalid value '%s'\n", + form); exit(1); } } @@ -3736,27 +3762,25 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, access_id = 1; } else if (streql(access, "sequential")) { access_id = 0; - } else if (streql(access, "direct")) { //TODO: Handle 'direct' as access while reading or writing + } else if (streql(access, + "direct")) { // TODO: Handle 'direct' as access while reading or writing access_id = 2; } else { if (iostat != NULL) { *iostat = 5002; - if ((iomsg != NULL)&& (iomsg_len > 0)) { - char *temp = "ACCESS specifier in OPEN statement has invalid value."; - snprintf(iomsg, iomsg_len+1/*\0*/, "%s", temp); - for (size_t i = strlen(iomsg); i < iomsg_len; i++) { // Pad - (iomsg)[i] = ' '; - } - (iomsg)[iomsg_len] = '\0'; + if ((iomsg != NULL) && (iomsg_len > 0)) { + char* temp = "ACCESS specifier in OPEN statement has invalid value."; + snprintf(iomsg, iomsg_len + 1 /*\0*/, "%s", temp); + pad_with_spaces(iomsg, strlen(iomsg), iomsg_len); } } else { printf("Runtime error: ACCESS specifier in OPEN statement has " - "invalid value '%s'\n", access); + "invalid value '%s'\n", + access); exit(1); } } if (streql(action, "readwrite")) { - } else if (streql(action, "write")) { read_access = false; } else if (streql(action, "read")) { @@ -3765,21 +3789,18 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, if (iostat != NULL) { *iostat = 5002; if ((iomsg != NULL) && (iomsg_len > 0)) { - char *temp = "ACTION specifier in OPEN statement has invalid value."; - snprintf(iomsg, iomsg_len+1/*\0*/, "%s", temp); - for (size_t i = strlen(iomsg); i < iomsg_len; i++) { // Pad - (iomsg)[i] = ' '; - } - (iomsg)[iomsg_len] = '\0'; + char* temp = "ACTION specifier in OPEN statement has invalid value."; + snprintf(iomsg, iomsg_len + 1 /*\0*/, "%s", temp); + pad_with_spaces(iomsg, strlen(iomsg), iomsg_len); } } else { printf("Runtime error: ACTION specifier in OPEN statement has " - "invalid value '%s'\n", action); + "invalid value '%s'\n", + action); exit(1); } } if (streql(action, "readwrite")) { - } else if (streql(action, "write")) { read_access = false; } else if (streql(action, "read")) { @@ -3788,21 +3809,20 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, if (iostat != NULL) { *iostat = 5002; if ((iomsg != NULL) && (iomsg_len > 0)) { - char *temp = "ACTION specifier in OPEN statement has invalid value."; - snprintf(iomsg, iomsg_len+1/*\0*/, "%s", temp); - for (size_t i = strlen(iomsg); i < iomsg_len; i++) { - iomsg[i] = ' '; - } - iomsg[iomsg_len] = '\0'; + char* temp = "ACTION specifier in OPEN statement has invalid value."; + snprintf(iomsg, iomsg_len + 1 /*\0*/, "%s", temp); + pad_with_spaces(iomsg, strlen(iomsg), iomsg_len); } } else { printf("Runtime error: ACTION specifier in OPEN statement has " - "invalid value '%s'\n", action); + "invalid value '%s'\n", + action); exit(1); } } - if (access_mode == NULL && iostat != NULL) { // Case: when iostat is present we don't want to terminate + if (access_mode == NULL + && iostat != NULL) { // Case: when iostat is present we don't want to terminate access_mode = "r"; } @@ -3810,16 +3830,20 @@ LFORTRAN_API int64_t _lfortran_open(int32_t unit_num, if (already_open) { return (int64_t) already_open; } - FILE *fd = fopen(f_name, access_mode); - if (!fd && iostat == NULL) - { + FILE* fd = fopen(f_name, access_mode); + if (!fd && iostat == NULL) { printf("Runtime error: Error in opening the file!\n"); perror(f_name); exit(1); } store_unit_file(unit_num, f_name, fd, unit_file_bin, access_id, read_access, write_access); - return (int64_t)fd; + return (int64_t) fd; } + free(f_name_c); + free(status_c); + free(form_c); + free(access_c); + free(action_c); return 0; } @@ -5082,19 +5106,40 @@ LFORTRAN_API void _lfortran_string_write(char **str_holder, bool is_allocatable, } LFORTRAN_API void _lfortran_string_read_i32(char *str, int64_t len, char *format, int32_t *i) { - sscanf(str, format, i); + char *buf = (char*)malloc(len + 1); + if (!buf) return; + memcpy(buf, str, len); + buf[len] = '\0'; + sscanf(buf, format, i); + free(buf); } + LFORTRAN_API void _lfortran_string_read_i64(char *str, int64_t len, char *format, int64_t *i) { - sscanf(str, format, i); + char *buf = (char*)malloc(len + 1); + if (!buf) return; // allocation failure + memcpy(buf, str, len); + buf[len] = '\0'; + sscanf(buf, format, i); + free(buf); } LFORTRAN_API void _lfortran_string_read_f32(char *str, int64_t len, char *format, float *f) { - sscanf(str, format, f); + char *buf = (char*)malloc(len + 1); + if (!buf) return; + memcpy(buf, str, len); + buf[len] = '\0'; + sscanf(buf, format, f); + free(buf); } LFORTRAN_API void _lfortran_string_read_f64(char *str, int64_t len, char *format, double *f) { - sscanf(str, format, f); + char *buf = (char*)malloc(len + 1); + if (!buf) return; + memcpy(buf, str, len); + buf[len] = '\0'; + sscanf(buf, format, f); + free(buf); } char *remove_whitespace(char *str) { From f800975a7e2542225dbf17c0e92d25d97fcd10dd Mon Sep 17 00:00:00 2001 From: Yash Nagda <79076376+YashNagda17@users.noreply.github.com> Date: Sun, 10 Aug 2025 11:11:30 +0530 Subject: [PATCH 116/119] Solving Long BOZ Strings Truncations (#8304) --- integration_tests/boz_01.f90 | 14 +- src/lfortran/semantics/ast_common_visitor.h | 13 +- tests/errors/continue_compilation_1.f90 | 2 +- tests/reference/asr-boz_01-dedad59.json | 8 +- tests/reference/asr-boz_01-dedad59.stderr | 5 + tests/reference/asr-boz_01-dedad59.stdout | 154 ++++++++++++++++- .../asr-continue_compilation_1-04b6d40.json | 4 +- .../asr-continue_compilation_1-04b6d40.stderr | 6 - tests/reference/llvm-boz_01-def9db5.json | 8 +- tests/reference/llvm-boz_01-def9db5.stderr | 5 + tests/reference/llvm-boz_01-def9db5.stdout | 159 ++++++++++++++++-- 11 files changed, 340 insertions(+), 38 deletions(-) create mode 100644 tests/reference/asr-boz_01-dedad59.stderr create mode 100644 tests/reference/llvm-boz_01-def9db5.stderr diff --git a/integration_tests/boz_01.f90 b/integration_tests/boz_01.f90 index 6e545d54079..fd335a36c49 100644 --- a/integration_tests/boz_01.f90 +++ b/integration_tests/boz_01.f90 @@ -1,11 +1,21 @@ program boz_01 implicit none -integer :: boz_1, boz_2, boz_3 +integer :: boz_1, boz_2, boz_3, boz_4, boz_5 boz_1 = int(b'01011101') boz_2 = int(o'2347') boz_3 = int(z'ABC') +!Testing Truncation of BOZ +boz_4 = int(Z'234567890abcdef1') +boz_5 = int(Z'2234567890abcdef1') +!Check with Integer Equivalent Values +if (boz_4 /= boz_5) error stop +if (boz_1 /= 93) error stop +if (boz_2 /= 1255) error stop +if (boz_3 /= 2748) error stop +if (boz_4 /= 180150001) error stop +if (boz_5 /= 180150001) error stop -print *, boz_1, boz_2, boz_3 +print *, boz_1, boz_2, boz_3, boz_4, boz_5 end program diff --git a/src/lfortran/semantics/ast_common_visitor.h b/src/lfortran/semantics/ast_common_visitor.h index a3e7047ee69..574f9d3409a 100644 --- a/src/lfortran/semantics/ast_common_visitor.h +++ b/src/lfortran/semantics/ast_common_visitor.h @@ -11142,14 +11142,19 @@ class CommonVisitor : public AST::BaseVisitor { } std::string boz_str = s.substr(2, s.size() - 2); //Check if BOZ string has more than 64 Bits, else stoull Throws Error + //Truncate to Maximum allowed size, dropping most significant bits if ((((s[0]=='b') || (s[0]=='B')) && (boz_str.size()> 65)) || (((s[0]=='o') || (s[0]=='O')) && (boz_str.size()> 22)) || (((s[0]=='z') || (s[0]=='Z')) && (boz_str.size()> 17))) { std::string char_length = (s[0] == 'b' || s[0] == 'B') ? "64" : (s[0] == 'o' || s[0] == 'O') ? "21" : "16"; - diag.add(Diagnostic("BOZ literal constants with '" + std::string(1, s[0]) + - "' prefix are only supported yet with at most '" + char_length + "' characters", - Level::Error, Stage::Semantic, {Label("", {x.base.base.loc})})); - throw SemanticAbort(); + //Last character is single quote ', so we need to subtract 1 further from the length + boz_str = boz_str.substr(boz_str.size() - std::stoi(char_length) - 1, boz_str.size()); + diag.semantic_warning_label( + "BOZ literal constant with '" + std::string(1, s[0]) + + "' prefix truncated to maximum " + char_length + " characters from left to fit data type", + {x.base.base.loc}, + "BOZ truncation" + ); } uint64_t boz_unsigned_int = std::stoull(boz_str, nullptr, base); //If current_variable_type is Real Type, convert BOZ String to ASR::Real diff --git a/tests/errors/continue_compilation_1.f90 b/tests/errors/continue_compilation_1.f90 index 88ed3e944f4..a8827c2a70e 100644 --- a/tests/errors/continue_compilation_1.f90 +++ b/tests/errors/continue_compilation_1.f90 @@ -115,7 +115,7 @@ program continue_compilation_1 integer :: elements(n) end type type(bspline_3d) :: s3_in_program - integer:: boz_1 = int(Z'1234567890ABCDEF1') + diff --git a/tests/reference/asr-boz_01-dedad59.json b/tests/reference/asr-boz_01-dedad59.json index f633917d73c..45473840869 100644 --- a/tests/reference/asr-boz_01-dedad59.json +++ b/tests/reference/asr-boz_01-dedad59.json @@ -2,12 +2,12 @@ "basename": "asr-boz_01-dedad59", "cmd": "lfortran --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/boz_01.f90", - "infile_hash": "8e091bbd52a5702875798d155d4afae10c1e224347998a6033a51379", + "infile_hash": "c39ee395eba975ffba7c003260ba1b67393a5b06bb519c9e3a5f2442", "outfile": null, "outfile_hash": null, "stdout": "asr-boz_01-dedad59.stdout", - "stdout_hash": "64bd902b909a4d7fe1583c43ddf361ddf3b48b292b1b9f10d0259f21", - "stderr": null, - "stderr_hash": null, + "stdout_hash": "60b2c8ba3b98d1fb44ba5d85d49963f87c99d3de03a38d8caddaac81", + "stderr": "asr-boz_01-dedad59.stderr", + "stderr_hash": "e47b37976e07fa74de67cbf8929d0974adaba30e067be31729bb6426", "returncode": 0 } \ No newline at end of file diff --git a/tests/reference/asr-boz_01-dedad59.stderr b/tests/reference/asr-boz_01-dedad59.stderr new file mode 100644 index 00000000000..c53cb6c92e8 --- /dev/null +++ b/tests/reference/asr-boz_01-dedad59.stderr @@ -0,0 +1,5 @@ +warning: BOZ literal constant with 'Z' prefix truncated to maximum 16 characters from left to fit data type + --> tests/../integration_tests/boz_01.f90:11:13 + | +11 | boz_5 = int(Z'2234567890abcdef1') + | ^^^^^^^^^^^^^^^^^^^^ BOZ truncation diff --git a/tests/reference/asr-boz_01-dedad59.stdout b/tests/reference/asr-boz_01-dedad59.stdout index 6eae7b1f23f..f0c5febf346 100644 --- a/tests/reference/asr-boz_01-dedad59.stdout +++ b/tests/reference/asr-boz_01-dedad59.stdout @@ -69,6 +69,48 @@ () .false. .false. + ), + boz_4: + (Variable + 2 + boz_4 + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + .false. + .false. + () + .false. + .false. + ), + boz_5: + (Variable + 2 + boz_5 + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + .false. + .false. + () + .false. + .false. ) }) boz_01 @@ -109,12 +151,122 @@ () .false. ) + (Assignment + (Var 2 boz_4) + (IntrinsicElementalFunction + Int + [(IntegerConstant 2541551403008843505 (Integer 4) Hex)] + 0 + (Integer 4) + (IntegerConstant 2541551403008843505 (Integer 4) Decimal) + ) + () + .false. + ) + (Assignment + (Var 2 boz_5) + (IntrinsicElementalFunction + Int + [(IntegerConstant 2541551403008843505 (Integer 4) Hex)] + 0 + (Integer 4) + (IntegerConstant 2541551403008843505 (Integer 4) Decimal) + ) + () + .false. + ) + (If + () + (IntegerCompare + (Var 2 boz_4) + NotEq + (Var 2 boz_5) + (Logical 4) + () + ) + [(ErrorStop + () + )] + [] + ) + (If + () + (IntegerCompare + (Var 2 boz_1) + NotEq + (IntegerConstant 93 (Integer 4) Decimal) + (Logical 4) + () + ) + [(ErrorStop + () + )] + [] + ) + (If + () + (IntegerCompare + (Var 2 boz_2) + NotEq + (IntegerConstant 1255 (Integer 4) Decimal) + (Logical 4) + () + ) + [(ErrorStop + () + )] + [] + ) + (If + () + (IntegerCompare + (Var 2 boz_3) + NotEq + (IntegerConstant 2748 (Integer 4) Decimal) + (Logical 4) + () + ) + [(ErrorStop + () + )] + [] + ) + (If + () + (IntegerCompare + (Var 2 boz_4) + NotEq + (IntegerConstant 180150001 (Integer 4) Decimal) + (Logical 4) + () + ) + [(ErrorStop + () + )] + [] + ) + (If + () + (IntegerCompare + (Var 2 boz_5) + NotEq + (IntegerConstant 180150001 (Integer 4) Decimal) + (Logical 4) + () + ) + [(ErrorStop + () + )] + [] + ) (Print (StringFormat () [(Var 2 boz_1) (Var 2 boz_2) - (Var 2 boz_3)] + (Var 2 boz_3) + (Var 2 boz_4) + (Var 2 boz_5)] FormatFortran (Allocatable (String 1 () DeferredLength DescriptorString) diff --git a/tests/reference/asr-continue_compilation_1-04b6d40.json b/tests/reference/asr-continue_compilation_1-04b6d40.json index d6a8ee67e2b..15852ec880d 100644 --- a/tests/reference/asr-continue_compilation_1-04b6d40.json +++ b/tests/reference/asr-continue_compilation_1-04b6d40.json @@ -2,12 +2,12 @@ "basename": "asr-continue_compilation_1-04b6d40", "cmd": "lfortran --semantics-only --continue-compilation --no-color {infile}", "infile": "tests/errors/continue_compilation_1.f90", - "infile_hash": "2e2fb994bddda528e5f24b94d3a9477d840b43c16d8573c475154151", + "infile_hash": "7ead5d6a8359aac47a70f16b554980ef09869ad83fe5ef73ab85c73f", "outfile": null, "outfile_hash": null, "stdout": null, "stdout_hash": null, "stderr": "asr-continue_compilation_1-04b6d40.stderr", - "stderr_hash": "9ee0a8339530271d5d5de924e82d09c98d6b31347f02815cea0aa9dc", + "stderr_hash": "f82f35cb4623bd17d36033c5e81a070a68ae8aae412eb7a96df791a0", "returncode": 1 } \ No newline at end of file diff --git a/tests/reference/asr-continue_compilation_1-04b6d40.stderr b/tests/reference/asr-continue_compilation_1-04b6d40.stderr index 5a65d104e31..dd3d6f6e5cb 100644 --- a/tests/reference/asr-continue_compilation_1-04b6d40.stderr +++ b/tests/reference/asr-continue_compilation_1-04b6d40.stderr @@ -123,12 +123,6 @@ semantic error: Derived type `bspline_3d` is not defined 117 | type(bspline_3d) :: s3_in_program | ^^^^^^^^^^^^^^^^ Type used here is not defined in any scope -semantic error: BOZ literal constants with 'Z' prefix are only supported yet with at most '16' characters - --> tests/errors/continue_compilation_1.f90:118:27 - | -118 | integer:: boz_1 = int(Z'1234567890ABCDEF1') - | ^^^^^^^^^^^^^^^^^^^^ - semantic error: Assignment to loop variable `i` is not allowed --> tests/errors/continue_compilation_1.f90:136:8 | diff --git a/tests/reference/llvm-boz_01-def9db5.json b/tests/reference/llvm-boz_01-def9db5.json index 75e37b162d9..2d7fcfec53d 100644 --- a/tests/reference/llvm-boz_01-def9db5.json +++ b/tests/reference/llvm-boz_01-def9db5.json @@ -2,12 +2,12 @@ "basename": "llvm-boz_01-def9db5", "cmd": "lfortran --no-color --show-llvm {infile} -o {outfile}", "infile": "tests/../integration_tests/boz_01.f90", - "infile_hash": "8e091bbd52a5702875798d155d4afae10c1e224347998a6033a51379", + "infile_hash": "c39ee395eba975ffba7c003260ba1b67393a5b06bb519c9e3a5f2442", "outfile": null, "outfile_hash": null, "stdout": "llvm-boz_01-def9db5.stdout", - "stdout_hash": "8e498adc37c951fe67cd227b827918b6f3b79eb4ea11845e5d3472dc", - "stderr": null, - "stderr_hash": null, + "stdout_hash": "cc89b24d7fb66c0e2457313a13a186096e36b0fac5f56dfa9e444e84", + "stderr": "llvm-boz_01-def9db5.stderr", + "stderr_hash": "e47b37976e07fa74de67cbf8929d0974adaba30e067be31729bb6426", "returncode": 0 } \ No newline at end of file diff --git a/tests/reference/llvm-boz_01-def9db5.stderr b/tests/reference/llvm-boz_01-def9db5.stderr new file mode 100644 index 00000000000..c53cb6c92e8 --- /dev/null +++ b/tests/reference/llvm-boz_01-def9db5.stderr @@ -0,0 +1,5 @@ +warning: BOZ literal constant with 'Z' prefix truncated to maximum 16 characters from left to fit data type + --> tests/../integration_tests/boz_01.f90:11:13 + | +11 | boz_5 = int(Z'2234567890abcdef1') + | ^^^^^^^^^^^^^^^^^^^^ BOZ truncation diff --git a/tests/reference/llvm-boz_01-def9db5.stdout b/tests/reference/llvm-boz_01-def9db5.stdout index 37e11938c51..11cd94b7870 100644 --- a/tests/reference/llvm-boz_01-def9db5.stdout +++ b/tests/reference/llvm-boz_01-def9db5.stdout @@ -3,42 +3,173 @@ source_filename = "LFortran" %string_descriptor = type <{ i8*, i64 }> -@0 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 -@serialization_info = private unnamed_addr constant [9 x i8] c"I4,I4,I4\00", align 1 +@string_const_data = private constant [11 x i8] c"ERROR STOP\00" +@string_const = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data, i32 0, i32 0), i64 10 }> +@string_const_data.1 = private constant [2 x i8] c"\0A\00" +@string_const.2 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.1, i32 0, i32 0), i64 1 }> +@0 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@string_const_data.3 = private constant [11 x i8] c"ERROR STOP\00" +@string_const.4 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.3, i32 0, i32 0), i64 10 }> +@string_const_data.5 = private constant [2 x i8] c"\0A\00" +@string_const.6 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.5, i32 0, i32 0), i64 1 }> @1 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@string_const_data.7 = private constant [11 x i8] c"ERROR STOP\00" +@string_const.8 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.7, i32 0, i32 0), i64 10 }> +@string_const_data.9 = private constant [2 x i8] c"\0A\00" +@string_const.10 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.9, i32 0, i32 0), i64 1 }> +@2 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@string_const_data.11 = private constant [11 x i8] c"ERROR STOP\00" +@string_const.12 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.11, i32 0, i32 0), i64 10 }> +@string_const_data.13 = private constant [2 x i8] c"\0A\00" +@string_const.14 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.13, i32 0, i32 0), i64 1 }> +@3 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@string_const_data.15 = private constant [11 x i8] c"ERROR STOP\00" +@string_const.16 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.15, i32 0, i32 0), i64 10 }> +@string_const_data.17 = private constant [2 x i8] c"\0A\00" +@string_const.18 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.17, i32 0, i32 0), i64 1 }> +@4 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@string_const_data.19 = private constant [11 x i8] c"ERROR STOP\00" +@string_const.20 = private global %string_descriptor <{ i8* getelementptr inbounds ([11 x i8], [11 x i8]* @string_const_data.19, i32 0, i32 0), i64 10 }> +@string_const_data.21 = private constant [2 x i8] c"\0A\00" +@string_const.22 = private global %string_descriptor <{ i8* getelementptr inbounds ([2 x i8], [2 x i8]* @string_const_data.21, i32 0, i32 0), i64 1 }> +@5 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 +@6 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@serialization_info = private unnamed_addr constant [15 x i8] c"I4,I4,I4,I4,I4\00", align 1 +@7 = private unnamed_addr constant [5 x i8] c"%s%s\00", align 1 define i32 @main(i32 %0, i8** %1) { .entry: %boz_1 = alloca i32, align 4 %boz_2 = alloca i32, align 4 %boz_3 = alloca i32, align 4 + %boz_4 = alloca i32, align 4 + %boz_5 = alloca i32, align 4 call void @_lpython_call_initial_functions(i32 %0, i8** %1) %boz_11 = alloca i32, align 4 %boz_22 = alloca i32, align 4 %boz_33 = alloca i32, align 4 + %boz_44 = alloca i32, align 4 + %boz_55 = alloca i32, align 4 store i32 93, i32* %boz_11, align 4 store i32 1255, i32* %boz_22, align 4 store i32 2748, i32* %boz_33, align 4 - %2 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @serialization_info, i32 0, i32 0), i32 0, i32 0, i32* %boz_11, i32* %boz_22, i32* %boz_33) - %3 = call i64 @_lfortran_str_len(i8* %2) - %4 = call i8* @_lfortran_malloc(i64 16) - %stringFormat_desc = bitcast i8* %4 to %string_descriptor* - %5 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 - store i8* %2, i8** %5, align 8 - %6 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 1 - store i64 %3, i64* %6, align 4 - %7 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 - %8 = load i8*, i8** %7, align 8 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @0, i32 0, i32 0)) + store i32 180150001, i32* %boz_44, align 4 + store i32 180150001, i32* %boz_55, align 4 + %2 = load i32, i32* %boz_44, align 4 + %3 = load i32, i32* %boz_55, align 4 + %4 = icmp ne i32 %2, %3 + br i1 %4, label %then, label %else + +then: ; preds = %.entry + %5 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const, i32 0, i32 0), align 8 + %6 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.2, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0), i8* %5, i8* %6) + call void @exit(i32 1) + br label %ifcont + +else: ; preds = %.entry + br label %ifcont + +ifcont: ; preds = %else, %then + %7 = load i32, i32* %boz_11, align 4 + %8 = icmp ne i32 %7, 93 + br i1 %8, label %then6, label %else7 + +then6: ; preds = %ifcont + %9 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.4, i32 0, i32 0), align 8 + %10 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.6, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0), i8* %9, i8* %10) + call void @exit(i32 1) + br label %ifcont8 + +else7: ; preds = %ifcont + br label %ifcont8 + +ifcont8: ; preds = %else7, %then6 + %11 = load i32, i32* %boz_22, align 4 + %12 = icmp ne i32 %11, 1255 + br i1 %12, label %then9, label %else10 + +then9: ; preds = %ifcont8 + %13 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.8, i32 0, i32 0), align 8 + %14 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.10, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i8* %13, i8* %14) + call void @exit(i32 1) + br label %ifcont11 + +else10: ; preds = %ifcont8 + br label %ifcont11 + +ifcont11: ; preds = %else10, %then9 + %15 = load i32, i32* %boz_33, align 4 + %16 = icmp ne i32 %15, 2748 + br i1 %16, label %then12, label %else13 + +then12: ; preds = %ifcont11 + %17 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.12, i32 0, i32 0), align 8 + %18 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.14, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @3, i32 0, i32 0), i8* %17, i8* %18) + call void @exit(i32 1) + br label %ifcont14 + +else13: ; preds = %ifcont11 + br label %ifcont14 + +ifcont14: ; preds = %else13, %then12 + %19 = load i32, i32* %boz_44, align 4 + %20 = icmp ne i32 %19, 180150001 + br i1 %20, label %then15, label %else16 + +then15: ; preds = %ifcont14 + %21 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.16, i32 0, i32 0), align 8 + %22 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.18, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8* %21, i8* %22) + call void @exit(i32 1) + br label %ifcont17 + +else16: ; preds = %ifcont14 + br label %ifcont17 + +ifcont17: ; preds = %else16, %then15 + %23 = load i32, i32* %boz_55, align 4 + %24 = icmp ne i32 %23, 180150001 + br i1 %24, label %then18, label %else19 + +then18: ; preds = %ifcont17 + %25 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.20, i32 0, i32 0), align 8 + %26 = load i8*, i8** getelementptr inbounds (%string_descriptor, %string_descriptor* @string_const.22, i32 0, i32 0), align 8 + call void (i8*, ...) @_lcompilers_print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i8* %25, i8* %26) + call void @exit(i32 1) + br label %ifcont20 + +else19: ; preds = %ifcont17 + br label %ifcont20 + +ifcont20: ; preds = %else19, %then18 + %27 = call i8* (i8*, i64, i8*, i32, i32, ...) @_lcompilers_string_format_fortran(i8* null, i64 0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @serialization_info, i32 0, i32 0), i32 0, i32 0, i32* %boz_11, i32* %boz_22, i32* %boz_33, i32* %boz_44, i32* %boz_55) + %28 = call i64 @_lfortran_str_len(i8* %27) + %29 = call i8* @_lfortran_malloc(i64 16) + %stringFormat_desc = bitcast i8* %29 to %string_descriptor* + %30 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 + store i8* %27, i8** %30, align 8 + %31 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 1 + store i64 %28, i64* %31, align 4 + %32 = getelementptr %string_descriptor, %string_descriptor* %stringFormat_desc, i32 0, i32 0 + %33 = load i8*, i8** %32, align 8 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @7, i32 0, i32 0), i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @6, i32 0, i32 0)) call void @_lpython_free_argv() br label %return -return: ; preds = %.entry +return: ; preds = %ifcont20 ret i32 0 } declare void @_lpython_call_initial_functions(i32, i8**) +declare void @_lcompilers_print_error(i8*, ...) + +declare void @exit(i32) + declare i8* @_lcompilers_string_format_fortran(i8*, i64, i8*, i32, i32, ...) declare i64 @_lfortran_str_len(i8*) From 0a9fed6c49d44c56a6f351bf60ab9f6706f4d4b4 Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Sun, 10 Aug 2025 11:58:54 +0530 Subject: [PATCH 117/119] fix: check for elemental function in type bound op overload --- integration_tests/CMakeLists.txt | 1 + integration_tests/elemental_15.f90 | 22 ++++++++++++++++++++++ src/libasr/asr_utils.cpp | 7 ++++--- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 integration_tests/elemental_15.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index bd1438f066c..8ef5c33f902 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -2419,6 +2419,7 @@ RUN(NAME elemental_11 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME elemental_12 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME elemental_13 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME elemental_14 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME elemental_15 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME types_21 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) RUN(NAME types_22 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) diff --git a/integration_tests/elemental_15.f90 b/integration_tests/elemental_15.f90 new file mode 100644 index 00000000000..cd0f7deb8b4 --- /dev/null +++ b/integration_tests/elemental_15.f90 @@ -0,0 +1,22 @@ +module elemental_15_mod + implicit none + type :: t + integer :: v + contains + procedure, pass :: neq + generic :: operator(/=) => neq + end type +contains + elemental logical function neq(a,b) + class(t), intent(in) :: a, b + neq = a%v /= b%v + end +end module + +program elemental_15 + use elemental_15_mod + type(t) :: a(2) = [t(1), t(2)], b(2) = [t(1), t(2)] + if (any(a /= b)) error stop + a(1)%v = 2 + if (.not. any(a /= b)) error stop +end program diff --git a/src/libasr/asr_utils.cpp b/src/libasr/asr_utils.cpp index dfd365fb5ed..3ee08a9a284 100644 --- a/src/libasr/asr_utils.cpp +++ b/src/libasr/asr_utils.cpp @@ -1828,6 +1828,7 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right, switch(proc->type) { case ASR::symbolType::Function: { ASR::Function_t* func = ASR::down_cast(proc); + bool is_elemental = ASRUtils::is_elemental(proc); std::string matched_func_name = ""; if( func->n_args == 2 ) { ASR::ttype_t* left_arg_type = ASRUtils::expr_type(func->m_args[0]); @@ -1843,9 +1844,9 @@ bool use_overloaded(ASR::expr_t* left, ASR::expr_t* right, ASR::ttype_t* right_arg_type2 = ASRUtils::type_get_past_allocatable_pointer(right_arg_type); // Check for array type - not_matching = not_matching || - (left_arg_type2->type != left_type2->type) || - (right_arg_type2->type != right_type2->type); + not_matching = not_matching || (!is_elemental && + ((left_arg_type2->type != left_type2->type) || + (right_arg_type2->type != right_type2->type))); // Get element type and compare left_type2 = ASRUtils::type_get_past_array(left_type2); From 92583e1d31cd1b01f334cb2f957792b8ec6576dc Mon Sep 17 00:00:00 2001 From: jinangshah21 Date: Sun, 10 Aug 2025 20:56:25 +0530 Subject: [PATCH 118/119] fix: create load for nested llvm_pointer SIM --- integration_tests/CMakeLists.txt | 1 + integration_tests/derived_types_76.f90 | 21 +++++++++++++++++++++ src/libasr/codegen/asr_to_llvm.cpp | 14 ++++++++------ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 integration_tests/derived_types_76.f90 diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index b1a1ac4f19b..7a8fd291eb1 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -1615,6 +1615,7 @@ RUN(NAME derived_types_72 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc EXTRA_AR RUN(NAME derived_types_73 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME derived_types_74 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME derived_types_75 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) +RUN(NAME derived_types_76 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME derived_type_with_default_init LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) RUN(NAME derived_type_with_default_init_01 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) diff --git a/integration_tests/derived_types_76.f90 b/integration_tests/derived_types_76.f90 new file mode 100644 index 00000000000..bd3a8bd5858 --- /dev/null +++ b/integration_tests/derived_types_76.f90 @@ -0,0 +1,21 @@ +module derived_type_76_mod + implicit none + type, abstract :: toml_value + integer :: origin = -1 + end type + type, extends(toml_value) :: toml_table + logical :: l1 = .true. + end type + type :: parser + type(toml_table), allocatable :: s1 + end type +end module + +program derived_type_76 +use derived_type_76_mod + type(parser) :: v1 + allocate(v1%s1) + v1%s1 = toml_table() + if (v1%s1%origin /= -1) error stop + if (.not. v1%s1%l1) error stop +end program diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 91c5ceef0f4..ce4f6871280 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -3207,6 +3207,13 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor ASR::Variable_t* member = down_cast(symbol_get_past_external(x.m_m)); std::string member_name = std::string(member->m_name); LCOMPILERS_ASSERT(current_der_type_name.size() != 0); + + llvm::Type *xtype = name2dertype[current_der_type_name]; + if (LLVM::is_llvm_pointer(*x_m_v_type) && ASR::is_a(*x.m_v) && + !ASRUtils::is_class_type(ASRUtils::extract_type(x_m_v_type))) { + tmp = llvm_utils->CreateLoad2(xtype->getPointerTo(), tmp); + } + while( name2memidx[current_der_type_name].find(member_name) == name2memidx[current_der_type_name].end() ) { if( dertype2parent.find(current_der_type_name) == dertype2parent.end() ) { throw CodeGenError(current_der_type_name + " doesn't have any member named " + member_name, @@ -3217,12 +3224,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } int member_idx = name2memidx[current_der_type_name][member_name]; - llvm::Type *xtype = name2dertype[current_der_type_name]; - if ((ASRUtils::is_allocatable(x_m_v_type) || ASRUtils::is_pointer(x_m_v_type)) && - ASR::is_a(*x.m_v) && - !ASRUtils::is_class_type(ASRUtils::extract_type(x_m_v_type))) { - tmp = llvm_utils->CreateLoad2(xtype->getPointerTo(), tmp); - } + xtype = name2dertype[current_der_type_name]; tmp = llvm_utils->create_gep2(xtype, tmp, member_idx); ASR::ttype_t* member_type = ASRUtils::type_get_past_pointer( ASRUtils::type_get_past_allocatable(member->m_type)); From 18d0c645bef9650dd69a6431134554caad7bc70a Mon Sep 17 00:00:00 2001 From: Assem Date: Sat, 9 Aug 2025 22:32:02 +0300 Subject: [PATCH 119/119] Tests : minor change to trigger the pull-request whenever commit history changes --- .github/workflows/Exhaustive-Checks-CI.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/Exhaustive-Checks-CI.yml b/.github/workflows/Exhaustive-Checks-CI.yml index b8c7646c642..4b7fbf63623 100644 --- a/.github/workflows/Exhaustive-Checks-CI.yml +++ b/.github/workflows/Exhaustive-Checks-CI.yml @@ -9,6 +9,10 @@ on: pull_request: types: - labeled + - unlabeled + - synchronize + - opened + - reopened branches: - main