Skip to content

[flang] Flang goes into infinite loop when compiling gfortran test: strictly-structured-block-1.f90 #138950

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

Open
tarunprabhu opened this issue May 7, 2025 · 4 comments
Assignees
Labels
flang Flang issues not falling into any other category hang Compiler hang (infinite loop)

Comments

@tarunprabhu
Copy link
Contributor

Steps to reproduce:

Assuming that the LLVM test suite is checked out in ./llvm-test-suite, compile the test as follows

$ flang -fopenmp ./llvm-test-suite/Fortran/gfortran/regression/gomp/strictly-structured-block-1.f90

Actual behavior: the compiler seems to be in an infinite loop. The memory usage as reported by top seems to be insignificant. Compilation did not terminate even after at least 5 minutes on both x86_64 and aarch64.

Expected behavior: Compilation should terminate successfully. If some OpenMP construct used in the test is not supported yet, flang should crash with a TODO message.

@llvmbot llvmbot added the flang Flang issues not falling into any other category label May 7, 2025
@EugeneZelenko EugeneZelenko added the hang Compiler hang (infinite loop) label May 7, 2025
@eugeneepshteyn
Copy link
Contributor

I started flang -fc1 -fopenmp strictly-structured-block-1.f90 in gdb, let it run for a while, then CTRL-C. I did this a couple times and both times it broke in parsing. The backtrace contained between 400 and 640 calls, so something strange is going on with the parser in this case. The source file strictly-structured-block-1.f90 doesn't seem to be very complicated.

@eugeneepshteyn
Copy link
Contributor

Partial backtrace:

#0  std::__1::__compressed_pair<unsigned long, std::__1::allocator<std::__1::__list_node<Fortran::parser::Message, void*> > >::second[abi:nn190106]() (this=0x7ffffffdc928)
    at /home/eepshteyn/compilers/clang-19.1.6/bin/../include/c++/v1/__memory/compressed_pair.h:138
#1  0x0000555560e6e8d9 in std::__1::__list_imp<Fortran::parser::Message, std::__1::allocator<Fortran::parser::Message> >::__node_alloc[abi:nn190106]() (this=0x7ffffffdc918) at /home/eepshteyn/compilers/clang-19.1.6/bin/../include/c++/v1/list:508
#2  0x0000555563bfbcf1 in std::__1::list<Fortran::parser::Message, std::__1::allocator<Fortran::parser::Message> >::list (
    this=0x7ffffffda810, __c=...) at /home/eepshteyn/compilers/clang-19.1.6/bin/../include/c++/v1/list:1053
#3  0x0000555563bfba0d in Fortran::parser::Messages::Messages (this=0x7ffffffda810, that=...)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/include/flang/Parser/message.h:322
#4  0x0000555563c0766f in Fortran::parser::ParseState::ParseState (this=0x7ffffffda800, that=...)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/include/flang/Parser/parse-state.h:48
#5  0x0000555563cf9083 in Fortran::parser::AlternativesParser<Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::Parser<Fortran::parser::IntegerTypeSpec> >, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec::Real, Fortran::parser::SequenceParser<Fortran::parser::TokenStringMatch<false, false>, Fortran::parser::MaybeParser<Fortran::parser::Parser<Fortran::parser::KindSelector> > > > >, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::SequenceParser<Fortran::parser::TokenStringMatch<false, false>, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec::DoublePrecision> > >, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec::Complex, Fortran::parser::SequenceParser<Fortran::parser::TokenStringMatch<false, false>, Fortran::parser::MaybeParser<Fortran::parser::Parser<Fortran::parser::KindSelector> > > > >, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec::Character, Fortran::parser::SequenceParser<Fortran::parser::TokenStringMatch<false, false>, Fortran::parser::MaybeParser<Fortran::parser::Parser<Fortran::parser::CharSelector> > > > >, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec::Logical, Fortran::parser::SequenceParser<Fortran::parser::TokenStringMatch<false, false>, Fortran::parser::MaybeParser<Fortran::parser::Parser<Fortran::parser::KindSelector> > > > >, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::Parser<Fortran::parser::UnsignedTypeSpec> >, Fortran::parser::NonstandardParser<(Fortran::common::LanguageFeature)12, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::SequenceParser<Fortran::parser::TokenStringMatch<true, false>, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec::DoubleComplex> > > >, Fortran::parser::NonstandardParser<(Fortran::common::LanguageFeature)13, Fortran::parser::ApplyConstructor<Fortran::parser::IntrinsicTypeSpec, Fortran::parser::ApplyConstructor<Fortran::parser::IntegerTypeSpec, Fortran::parser::SequenceParser<Fortran::parser::TokenStringMatch<false, false>, Fortran::parser::ApplyConstructor<std::__1::optional<Fortran::parser::KindSelector>, Fortran::parser::PureParser<int> > > > > > >::ParseRest<8> (
    this=0x555569f8fb28 <Fortran::parser::Parser<Fortran::parser::IntrinsicTypeSpec>::Parse(Fortran::parser::ParseState&)::parser+48>, result=..., state=..., backtrack=...) at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Parser/basic-parsers.h:327
...
    this=0x555569f89768 <Fortran::parser::Parser<Fortran::parser::Program>::Parse(Fortran::parser::ParseState&)::parser>, 
    state=...) at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Parser/basic-parsers.h:316
#488 0x0000555563c092a8 in _ZNK7Fortran6parser16ApplyConstructorINS0_7ProgramEJNS0_18AlternativesParserINS0_17NonstandardParserILNS_6common15LanguageFeatureE55ENS0_14SequenceParserINS7_INS0_24SkipStuffBeforeStatementENS0_13NegatedParserINS0_6NextChEEEEENS0_17PureDefaultParserINSt3__14listINS0_11ProgramUnitENSE_9allocatorISG_EEEEEEEEEEJNS0_12FollowParserINS0_10SomeParserINS3_INS3_INS1_ISG_JNS1_INS5_11IndirectionINS0_17CompilerDirectiveELb0EEEJNS0_6ParserISQ_EEEEEEEEJNS1_ISG_JNS1_INSP_INS0_23OpenACCRoutineConstructELb0EEEJNS7_INS7_IS8_NS0_16TokenStringMatchILb1ELb0EEEEENSS_ISW_EEEEEEEEEEEEEJNS7_INS0_18StartNewSubprogramENSN_INSN_INSN_INS3_INS3_INS3_INS3_INS3_INS1_ISG_JNS1_INSP_INS0_6ModuleELb0EEEJNSS_IS17_EEEEEEEEJNS1_ISG_JNS1_INSP_INS0_20SubroutineSubprogramELb0EEEJNSS_IS1C_EEEEEEEEEEEJNS1_ISG_JNS1_INSP_INS0_9SubmoduleELb0EEEJNSS_IS1I_EEEEEEEEEEEJNS1_ISG_JNS1_INSP_INS0_9BlockDataELb0EEEJNSS_IS1O_EEEEEEEEEEEJNS7_INS0_15LookAheadParserINS7_INS0_11MaybeParserINS7_INS0_5SpaceENSN_INS0_13DigitString64ENS0_10SpaceCheckEEEEEEENS3_INSN_INS1_INS0_12FunctionStmtEJNS0_10ManyParserINSS_INS0_10PrefixSpecEEEEENS7_INSY_ILb0ELb0EEENSS_INS0_4NameEEEEENS7_IS27_NSN_INS0_15DefaultedParserINS0_17NonemptySeparatedIS29_S27_EEEES27_EEEENS1V_INSS_INS0_6SuffixEEEEEEEENS7_IS1W_NS0_17WithMessageParserINS1U_INS0_10AnyOfCharsEEEEEEEEEJNS1_IS22_JS26_NS7_IS27_NSN_IS29_S2P_EEEENS4_ILS6_33ENSD_INSF_IS28_NSH_IS28_EEEEEEEENSD_INSE_8optionalIS2H_EEEEEEEEEEEEEENS1_ISG_JNS1_INSP_INS0_18FunctionSubprogramELb0EEEJNSS_IS34_EEEEEEEEEEEEEJNS1_ISG_JNS1_INSP_INS0_11MainProgramELb0EEEJNSS_IS3B_EEEEEEEEEEENS0_14SkipManyParserIS27_EEEES1W_EENS0_14RecoveryParserINS3_INS7_IS2M_NS0_8OkParserEEEJNS0_10FailParserINS0_7SuccessEEEEEENS0_8SkipPastILc10EEEEEEEEEEEEEES8_EEEEEEE8ParseOneERNS0_10ParseStateE (
    this=0x555569f89768 <Fortran::parser::Parser<Fortran::parser::Program>::Parse(Fortran::parser::ParseState&)::parser>, 
    state=...) at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Parser/basic-parsers.h:748
#489 0x0000555563bf7f88 in _ZNK7Fortran6parser16ApplyConstructorINS0_7ProgramEJNS0_18AlternativesParserINS0_17NonstandardParserILNS_6common15LanguageFeatureE55ENS0_14SequenceParserINS7_INS0_24SkipStuffBeforeStatementENS0_13NegatedParserINS0_6NextChEEEEENS0_17PureDefaultParserINSt3__14listINS0_11ProgramUnitENSE_9allocatorISG_EEEEEEEEEEJNS0_12FollowParserINS0_10SomeParserINS3_INS3_INS1_ISG_JNS1_INS5_11IndirectionINS0_17CompilerDirectiveELb0EEEJNS0_6ParserISQ_EEEEEEEEJNS1_ISG_JNS1_INSP_INS0_23OpenACCRoutineConstructELb0EEEJNS7_INS7_IS8_NS0_16TokenStringMatchILb1ELb0EEEEENSS_ISW_EEEEEEEEEEEEEJNS7_INS0_18StartNewSubprogramENSN_INSN_INSN_INS3_INS3_INS3_INS3_INS3_INS1_ISG_JNS1_INSP_INS0_6ModuleELb0EEEJNSS_IS17_EEEEEEEEJNS1_ISG_JNS1_INSP_INS0_20SubroutineSubprogramELb0EEEJNSS_IS1C_EEEEEEEEEEEJNS1_ISG_JNS1_INSP_INS0_9SubmoduleELb0EEEJNSS_IS1I_EEEEEEEEEEEJNS1_ISG_JNS1_INSP_INS0_9BlockDataELb0EEEJNSS_IS1O_EEEEEEEEEEEJNS7_INS0_15LookAheadParserINS7_INS0_11MaybeParserINS7_INS0_5SpaceENSN_INS0_13DigitString64ENS0_10SpaceCheckEEEEEEENS3_INSN_INS1_INS0_12FunctionStmtEJNS0_10ManyParserINSS_INS0_10PrefixSpecEEEEENS7_INSY_ILb0ELb0EEENSS_INS0_4NameEEEEENS7_IS27_NSN_INS0_15DefaultedParserINS0_17NonemptySeparatedIS29_S27_EEEES27_EEEENS1V_INSS_INS0_6SuffixEEEEEEEENS7_IS1W_NS0_17WithMessageParserINS1U_INS0_10AnyOfCharsEEEEEEEEEJNS1_IS22_JS26_NS7_IS27_NSN_IS29_S2P_EEEENS4_ILS6_33ENSD_INSF_IS28_NSH_IS28_EEEEEEEENSD_INSE_8optionalIS2H_EEEEEEEEEEEEEENS1_ISG_JNS1_INSP_INS0_18FunctionSubprogramELb0EEEJNSS_IS34_EEEEEEEEEEEEEJNS1_ISG_JNS1_INSP_INS0_11MainProgramELb0EEEJNSS_IS3B_EEEEEEEEEEENS0_14SkipManyParserIS27_EEEES1W_EENS0_14RecoveryParserINS3_INS7_IS2M_NS0_8OkParserEEEJNS0_10FailParserINS0_7SuccessEEEEEENS0_8SkipPastILc10EEEEEEEEEEEEEES8_EEEEEEE5ParseERNS0_10ParseStateE (
    this=0x555569f89768 <Fortran::parser::Parser<Fortran::parser::Program>::Parse(Fortran::parser::ParseState&)::parser>, 
    state=...) at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Parser/basic-parsers.h:729
#490 0x0000555563bf7047 in Fortran::parser::Parser<Fortran::parser::Program>::Parse (state=...)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Parser/program-parsers.cpp:86
#491 0x0000555563bd0079 in Fortran::parser::Parsing::Parse (this=0x55556a186a60, out=...)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Parser/parsing.cpp:287
#492 0x000055555f17fd73 in Fortran::frontend::FrontendAction::runParse (this=0x55556a1ba080, emitMessages=false)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Frontend/FrontendAction.cpp:165
#493 0x000055555f18dea2 in Fortran::frontend::PrescanAndSemaAction::beginSourceFileAction (this=0x55556a1ba080)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Frontend/FrontendActions.cpp:140
#494 0x000055555f17fa55 in Fortran::frontend::FrontendAction::beginSourceFile (this=0x55556a1ba080, ci=..., realInput=...)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Frontend/FrontendAction.cpp:109
#495 0x000055555f147dca in Fortran::frontend::CompilerInstance::executeAction (this=0x55556a1b0220, act=...)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/Frontend/CompilerInstance.cpp:191
#496 0x000055555f18692c in Fortran::frontend::executeCompilerInvocation (flang=0x55556a1b0220)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:222
#497 0x000055555e7a5c4a in fc1_main (argv=..., argv0=0x7fffffffdeb7 "/home/eepshteyn/compilers/flang-upstream/bin/flang")
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/tools/flang-driver/fc1_main.cpp:91
#498 0x000055555e7a0441 in executeFC1Tool (argV=...)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/tools/flang-driver/driver.cpp:66
#499 0x000055555e79fcd6 in main (argc=4, argv=0x7fffffffdae8)
    at /home/eepshteyn/src/flang-upstream/llvm-project/flang/tools/flang-driver/driver.cpp:110
(gdb) 

@eugeneepshteyn
Copy link
Contributor

Next step: reduce strictly-structured-block-1.f90 to try and find the construct that causes the parser to choke.

@eugeneepshteyn eugeneepshteyn self-assigned this May 8, 2025
@klausler
Copy link
Contributor

klausler commented May 8, 2025

Kiran, please reassign to whomever takes care of OpenMP parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category hang Compiler hang (infinite loop)
Projects
None yet
Development

No branches or pull requests

6 participants