Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: support visiting module in pass array by data #3741

Merged
merged 4 commits into from
Mar 30, 2024

Conversation

Pranavchiku
Copy link
Contributor

Fixes #3728.

With this we get stdlib_stats_var compiled to LLVM.

@Pranavchiku Pranavchiku added asr pass Issue or pull request specific to ASR pass stdlib Issues related to compiling fortran-lang/stdlib labels Mar 29, 2024
@Pranavchiku
Copy link
Contributor Author

CI Failure:

Test project /home/runner/work/lfortran/lfortran
    Start 1: test_cwrapper
1/3 Test #1: test_cwrapper ....................   Passed    0.00 sec
    Start 2: test_stacktrace
2/3 Test #2: test_stacktrace ..................   Passed    0.00 sec
    Start 3: test_lfortran
3/3 Test #3: test_lfortran ....................***Exception: SegFault  0.11 sec
[doctest] doctest version is "2.4.8"

I am not sure why it fails

@Pranavchiku
Copy link
Contributor Author

CI should pass now.

@Pranavchiku
Copy link
Contributor Author

This is weird, it works well for me now:

% ctest
Test project /Users/pranavchiku/repos/lfortran
    Start 1: test_cwrapper
1/3 Test #1: test_cwrapper ....................   Passed    0.02 sec
    Start 2: test_stacktrace
2/3 Test #2: test_stacktrace ..................   Passed    0.01 sec
    Start 3: test_lfortran
3/3 Test #3: test_lfortran ....................   Passed    0.30 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   0.35 sec

@certik
Copy link
Contributor

certik commented Mar 29, 2024

The failure is:

/home/runner/work/lfortran/lfortran/lfortran-0.34.0-76-gc1f6546c3/src/lfortran/tests/test_llvm.cpp:360:
TEST CASE:  ASR -> LLVM 1

/home/runner/work/lfortran/lfortran/lfortran-0.34.0-76-gc1f6546c3/src/lfortran/tests/test_llvm.cpp:360: FATAL ERROR: test case CRASHED: SIGSEGV - Segmentation violation signal

The relevant code:

TEST_CASE("ASR -> LLVM 1") {
    std::string source = R"(function f()
integer :: f
f = 5
end function)";
...

@certik
Copy link
Contributor

certik commented Mar 29, 2024

It fails for me too, here is the stacktrace:

(lf) lfortran/lfortran(gh3728) $ lldb ./src/lfortran/tests/test_lfortran
(lldb) target create "./src/lfortran/tests/test_lfortran"
Current executable set to '/Users/ondrej/repos/lfortran/lfortran/src/lfortran/tests/test_lfortran' (arm64).
(lldb) run
Process 14926 launched: '/Users/ondrej/repos/lfortran/lfortran/src/lfortran/tests/test_lfortran' (arm64)
[doctest] doctest version is "2.4.8"
[doctest] run with "--help" for options
Process 14926 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xfffffffffffff00c)
    frame #0: 0x00000001018860d0 test_lfortran`bool LCompilers::ASR::is_a<LCompilers::ASR::Class_t, LCompilers::ASR::ttype_t>(x=0xfffffffffffff000) at asr.h:32:31
   29  	template <class T, class U>
   30  	inline bool is_a(const U &x)
   31  	{
-> 32  	    return T::class_type == x.type;
   33  	}
   34  	
   35  	// Cast one level down
Target 0: (test_lfortran) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xfffffffffffff00c)
  * frame #0: 0x00000001018860d0 test_lfortran`bool LCompilers::ASR::is_a<LCompilers::ASR::Class_t, LCompilers::ASR::ttype_t>(x=0xfffffffffffff000) at asr.h:32:31
    frame #1: 0x00000001016a5fa0 test_lfortran`void LCompilers::RemoveArrayByDescriptorProceduresVisitor::visit_Unit<LCompilers::ASR::TranslationUnit_t>(this=0x000000016fdfde60, x=0x000000010782dcd8) at pass_array_by_data.cpp:649:54
    frame #2: 0x000000010166e1d4 test_lfortran`LCompilers::RemoveArrayByDescriptorProceduresVisitor::visit_TranslationUnit(this=0x000000016fdfde60, x=0x000000010782dcd8) at pass_array_by_data.cpp:678:13
    frame #3: 0x000000010166dca8 test_lfortran`LCompilers::pass_array_by_data(al=0x000000016fdfedb8, unit=0x000000010782dcd8, (null)=0x000000016fdfe988) at pass_array_by_data.cpp:713:7
    frame #4: 0x0000000101cecd08 test_lfortran`LCompilers::PassManager::apply_passes(this=0x000000016fdfeae0, al=0x000000016fdfedb8, asr=0x000000010782dcd8, passes=size=30, pass_options=0x000000016fdfe988, diagnostics=0x000000016fdfed90) at pass_manager.h:167:17
    frame #5: 0x0000000101cac0f8 test_lfortran`LCompilers::PassManager::apply_passes(this=0x000000016fdfeae0, al=0x000000016fdfedb8, asr=0x000000010782dcd8, pass_options=0x000000016fdfe988, diagnostics=0x000000016fdfed90) at pass_manager.h:311:21
    frame #6: 0x0000000101caba40 test_lfortran`LCompilers::asr_to_llvm(asr=0x000000010782dcd8, diagnostics=0x000000016fdfed90, context=0x00006000000042e0, al=0x000000016fdfedb8, pass_manager=0x000000016fdfeae0, co=0x000000016fdfe970, run_fn="f", infile="") at asr_to_llvm.cpp:9792:18
    frame #7: 0x000000010009f35c test_lfortran`DOCTEST_ANON_FUNC_18() at test_llvm.cpp:390:15
    frame #8: 0x00000001007a2360 test_lfortran`doctest::Context::run(this=0x000000016fdff5e8) at doctest.h:6727:21
    frame #9: 0x00000001007a4210 test_lfortran`main(argc=1, argv=0x000000016fdff778) at doctest.h:6805:71
    frame #10: 0x00000001070990f4 dyld`start + 520

@certik certik marked this pull request as ready for review March 29, 2024 13:43
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine.

@Pranavchiku
Copy link
Contributor Author

Aah, thanks for the fix! I’ll look into stdlib failure and get it fixed soon.

@certik
Copy link
Contributor

certik commented Mar 29, 2024

The stdlib failure is:

ASR verify pass error: ExternalSymbol::m_original_name ('gauss_legendre_fp64') + scope_names not found in a module 'stdlib_quadrature'
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
LCompilersException: Verify failed in the pass: pass_array_by_data

@Pranavchiku Pranavchiku marked this pull request as draft March 30, 2024 04:54
@Pranavchiku
Copy link
Contributor Author

Pranavchiku commented Mar 30, 2024

MRE:

module xx
interface gauss_legendre
procedure :: gauss_legendre_fp64
end interface gauss_legendre

contains
subroutine gauss_legendre_fp64(x)
    real, intent(out) :: x(:)
end subroutine
end module

subroutine test_gauss_analytic()
    use xx, only: gauss_legendre
    block
        real, dimension(5) :: x
        call gauss_legendre(x)
    end block
end subroutine

@Pranavchiku
Copy link
Contributor Author

I have CI changes ready, will open PR once this gets merged.

@Pranavchiku Pranavchiku mentioned this pull request Mar 30, 2024
6 tasks
@Pranavchiku Pranavchiku merged commit 3e19476 into lfortran:main Mar 30, 2024
21 checks passed
@certik
Copy link
Contributor

certik commented Mar 30, 2024

Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asr pass Issue or pull request specific to ASR pass stdlib Issues related to compiling fortran-lang/stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArraySize node is not replaced for function contained in module
2 participants