Issue 234912
Summary [flang][openmp] Segfault in when a declare target function is defined twice
Labels flang
Assignees
Reporter VeeEM
    This program
```fortran
module m
contains

subroutine s()
!$omp declare target
end subroutine

subroutine s()
!$omp declare target
end subroutine

end module
```
prints an error like it should when compiled without OpenMP:
```
$ flang -c declare_target_segfault.f90
error: Semantic errors in declare_target_segfault.f90
declare_target_segfault.f90:8:12: error: 's' is already declared in this scoping unit
  subroutine s()
 ^
declare_target_segfault.f90:4:12: Previous declaration of 's'
 subroutine s()
             ^
```

If OpenMP is enabled, flang segfaults instead:
```
$ flang -fopenmp -c declare_target_segfault.f90
 #3 0x0000557d0c7e172b Fortran::semantics::omp::GetScopingUnit(Fortran::semantics::Scope const&) (/home/acc/Documents/flang_root/install/bin/flang-24+0x31f472b)
 #4 0x0000557d0d1de802 Fortran::semantics::OmpStructureChecker::Enter(Fortran::parser::OmpDeclareTargetDirective const&) (/home/acc/Documents/flang_root/install/bin/flang-24+0x3bf1802)
 #5 0x0000557d0c9e7d97 std::enable_if<UnionTrait<Fortran::parser::OpenMPDeclarativeConstruct>, void>::type Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk<Fortran::parser::OpenMPDeclarativeConstruct, Fortran::semantics::SemanticsVisitor<Fortran::semantics::OmpStructureChecker>>(Fortran::parser::OpenMPDeclarativeConstruct const&, Fortran::semantics::SemanticsVisitor<Fortran::semantics::OmpStructureChecker>&) (/home/acc/Documents/flang_root/install/bin/flang-24+0x33fad97)
 #6 0x0000557d0c9e9cec std::enable_if<TupleTrait<Fortran::parser::SpecificationPart>, void>::type Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk<Fortran::parser::SpecificationPart, Fortran::semantics::SemanticsVisitor<Fortran::semantics::OmpStructureChecker>>(Fortran::parser::SpecificationPart const&, Fortran::semantics::SemanticsVisitor<Fortran::semantics::OmpStructureChecker>&) (/home/acc/Documents/flang_root/install/bin/flang-24+0x33fccec)
 #7 0x0000557d0c9ec8e3 void Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk<Fortran::parser::SubroutineSubprogram, Fortran::semantics::SemanticsVisitor<Fortran::semantics::OmpStructureChecker>>(Fortran::common::Indirection<Fortran::parser::SubroutineSubprogram, false> const&, Fortran::semantics::SemanticsVisitor<Fortran::semantics::OmpStructureChecker>&) (.isra.0) semantics.cpp:0:0
 #8 0x0000557d0c9ef8f1 Fortran::semantics::Semantics::Perform() (/home/acc/Documents/flang_root/install/bin/flang-24+0x34028f1)
 #9 0x0000557d0bd84e25 Fortran::frontend::FrontendAction::runSemanticChecks() (/home/acc/Documents/flang_root/install/bin/flang-24+0x2797e25)
#10 0x0000557d0c0d040e Fortran::frontend::CodeGenAction::beginSourceFileAction() (/home/acc/Documents/flang_root/install/bin/flang-24+0x2ae340e)
#11 0x0000557d0bd8a295 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/home/acc/Documents/flang_root/install/bin/flang-24+0x279d295)
#12 0x0000557d0bd68243 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/home/acc/Documents/flang_root/install/bin/flang-24+0x277b243)
#13 0x0000557d0bd933ad Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/home/acc/Documents/flang_root/install/bin/flang-24+0x27a63ad)
#14 0x0000557d0b5a05d0 fc1_main(llvm::ArrayRef<char const*>, char const*) (/home/acc/Documents/flang_root/install/bin/flang-24+0x1fb35d0)
```

The crash site is here
https://github.com/llvm/llvm-project/blob/406dd1fc48cb1623c375bfa89d0e33cc13172f8f/flang/lib/Semantics/check-omp-structure.cpp#L2827-L2833
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to