Closed
Description
Reproducible on Godbolt:
https://godbolt.org/z/47GhYzYx4
Reproducer:
$ cat test.f90
real,parameter,dimension(3) :: x = 1.0
integer,parameter,dimension(3,1) :: y = 2
real,parameter,dimension(3) :: z = x(y)
end
Stack dump:
fatal internal error: CHECK(ss.Rank() <= 1) failed at /root/llvm-project/flang/lib/Evaluate/fold-implementation.h(204)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new -fc1 -triple x86_64-unknown-linux-gnu -S -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
#0 0x00000000036aab18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x36aab18)
#1 0x00000000036a848c SignalHandler(int) Signals.cpp:0:0
#2 0x00007ff413442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x00007ff4134969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x00007ff413442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x00007ff4134287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x0000000004b22439 (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x4b22439)
#7 0x00000000045e389c Fortran::evaluate::Folder<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>::ApplySubscripts(Fortran::evaluate::Constant<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>> const&, std::vector<Fortran::evaluate::Constant<Fortran::evaluate::Type<(Fortran::common::TypeCategory)0, 8>>, std::allocator<Fortran::evaluate::Constant<Fortran::evaluate::Type<(Fortran::common::TypeCategory)0, 8>>>> const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x45e389c)
#8 0x0000000004688fdb Fortran::evaluate::Folder<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>::Folding(Fortran::evaluate::ArrayRef&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x4688fdb)
#9 0x000000000468924d Fortran::evaluate::Folder<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>::Folding(Fortran::evaluate::Designator<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x468924d)
#10 0x0000000004681a5b Fortran::evaluate::ExpressionBase<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::Type<(Fortran::common::TypeCategory)1, 4>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x4681a5b)
#11 0x000000000465e078 Fortran::evaluate::ExpressionBase<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)1>>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)1>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x465e078)
#12 0x000000000434c210 Fortran::evaluate::ExpressionBase<Fortran::evaluate::SomeType>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x434c210)
#13 0x0000000003f19cab std::optional<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> Fortran::evaluate::ExpressionAnalyzer::ExprOrVariable<Fortran::parser::Expr>(Fortran::parser::Expr const&, Fortran::parser::CharBlock) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3f19cab)
#14 0x0000000003f1a9ff Fortran::evaluate::ExpressionAnalyzer::IterativelyAnalyzeSubexpressions(Fortran::parser::Expr const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3f1a9ff)
#15 0x0000000003f1ad95 Fortran::evaluate::ExpressionAnalyzer::Analyze(Fortran::parser::Expr const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3f1ad95)
#16 0x0000000003e80fd4 std::optional<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> Fortran::evaluate::ExpressionAnalyzer::Analyze<Fortran::common::Indirection<Fortran::parser::Expr, false>>(Fortran::parser::Constant<Fortran::common::Indirection<Fortran::parser::Expr, false>> const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3e80fd4)
#17 0x0000000003f96db3 std::optional<Fortran::evaluate::Expr<Fortran::evaluate::SomeType>> Fortran::semantics::AnalyzeExpr<Fortran::parser::Constant<Fortran::common::Indirection<Fortran::parser::Expr, false>>>(Fortran::semantics::SemanticsContext&, Fortran::parser::Constant<Fortran::common::Indirection<Fortran::parser::Expr, false>> const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3f96db3)
#18 0x0000000003f97032 Fortran::semantics::DeclarationVisitor::NonPointerInitialization(Fortran::parser::Name const&, Fortran::parser::Constant<Fortran::common::Indirection<Fortran::parser::Expr, false>> const&) (.part.0) resolve-names.cpp:0:0
#19 0x0000000003fb2826 Fortran::semantics::DeclarationVisitor::Initialization(Fortran::parser::Name const&, Fortran::parser::Initialization const&, bool) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fb2826)
#20 0x0000000003fb4793 Fortran::semantics::DeclarationVisitor::Post(Fortran::parser::EntityDecl const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fb4793)
#21 0x0000000003fb4992 void Fortran::parser::ForEachInTuple<1ul, void Fortran::parser::Walk<Fortran::semantics::ResolveNamesVisitor, Fortran::parser::DeclarationTypeSpec, std::__cxx11::list<Fortran::parser::AttrSpec, std::allocator<Fortran::parser::AttrSpec>>, std::__cxx11::list<Fortran::parser::EntityDecl, std::allocator<Fortran::parser::EntityDecl>>>(std::tuple<Fortran::parser::DeclarationTypeSpec, std::__cxx11::list<Fortran::parser::AttrSpec, std::allocator<Fortran::parser::AttrSpec>>, std::__cxx11::list<Fortran::parser::EntityDecl, std::allocator<Fortran::parser::EntityDecl>>> const&, Fortran::semantics::ResolveNamesVisitor&)::'lambda'(Fortran::semantics::ResolveNamesVisitor const&), std::tuple<Fortran::parser::DeclarationTypeSpec, std::__cxx11::list<Fortran::parser::AttrSpec, std::allocator<Fortran::parser::AttrSpec>>, std::__cxx11::list<Fortran::parser::EntityDecl, std::allocator<Fortran::parser::EntityDecl>>>>(std::tuple<Fortran::parser::DeclarationTypeSpec, std::__cxx11::list<Fortran::parser::AttrSpec, std::allocator<Fortran::parser::AttrSpec>>, std::__cxx11::list<Fortran::parser::EntityDecl, std::allocator<Fortran::parser::EntityDecl>>> const&, void Fortran::parser::Walk<Fortran::semantics::ResolveNamesVisitor, Fortran::parser::DeclarationTypeSpec, std::__cxx11::list<Fortran::parser::AttrSpec, std::allocator<Fortran::parser::AttrSpec>>, std::__cxx11::list<Fortran::parser::EntityDecl, std::allocator<Fortran::parser::EntityDecl>>>(std::tuple<Fortran::parser::DeclarationTypeSpec, std::__cxx11::list<Fortran::parser::AttrSpec, std::allocator<Fortran::parser::AttrSpec>>, std::__cxx11::list<Fortran::parser::EntityDecl, std::allocator<Fortran::parser::EntityDecl>>> const&, Fortran::semantics::ResolveNamesVisitor&)::'lambda'(Fortran::semantics::ResolveNamesVisitor const&)) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fb4992)
#22 0x0000000003fb4d17 void Fortran::parser::Walk<Fortran::common::Indirection<Fortran::parser::TypeDeclarationStmt, false>, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::Statement<Fortran::common::Indirection<Fortran::parser::TypeDeclarationStmt, false>> const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fb4d17)
#23 0x0000000003fbecac void Fortran::parser::Walk<Fortran::parser::DeclarationConstruct, Fortran::semantics::ResolveNamesVisitor>(std::__cxx11::list<Fortran::parser::DeclarationConstruct, std::allocator<Fortran::parser::DeclarationConstruct>> const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fbecac)
#24 0x0000000003fbd9bd Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::SpecificationPart const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fbd9bd)
#25 0x0000000003fbe1a9 std::enable_if<TupleTrait<Fortran::parser::SpecificationPart>, void>::type Fortran::parser::Walk<Fortran::parser::SpecificationPart, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::SpecificationPart const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fbe1a9)
#26 0x0000000003fe3104 Fortran::semantics::ResolveNamesVisitor::ResolveSpecificationParts(Fortran::semantics::ProgramTree&) (.part.0) resolve-names.cpp:0:0
#27 0x0000000003fe3786 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fe3786)
#28 0x0000000003fe4c84 Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&, Fortran::semantics::Scope&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3fe4c84)
#29 0x000000000403c8f1 Fortran::semantics::Semantics::Perform() (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x403c8f1)
#30 0x00000000036eef67 Fortran::frontend::FrontendAction::runSemanticChecks() (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x36eef67)
#31 0x0000000003a192e0 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x3a192e0)
#32 0x00000000036ee545 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x36ee545)
#33 0x00000000036de2f7 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x36de2f7)
#34 0x00000000036f47cd Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x36f47cd)
#35 0x0000000001e82878 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x1e82878)
#36 0x0000000001d7366d main (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x1d7366d)
#37 0x00007ff413429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x00007ff413429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000001e817de _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin/flang-new+0x1e817de)
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git 1c4ec8def6bb18934f300f6e630e92e7efdb60be)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240409/bin
Gfortran properly rejects this program.
$ gfortran test.f90
test.f90:3:37:
3 | real,parameter,dimension(3) :: z = x(y)
| 1
Error: Array index at (1) is an array of rank 2