Skip to content

[flang][Semantics] set scope even for module subroutines outside modules #109009

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

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4344,15 +4344,18 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
Symbol::Flag subpFlag, bool hasModulePrefix,
const parser::LanguageBindingSpec *bindingSpec,
const ProgramTree::EntryStmtList *entryStmts) {
bool isValid{true};
if (hasModulePrefix && !currScope().IsModule() &&
!currScope().IsSubmodule()) { // C1547
Say(name,
"'%s' is a MODULE procedure which must be declared within a "
"MODULE or SUBMODULE"_err_en_US);
return false;
// Don't return here because it can be useful to have the scope set for
// other semantic checks run before we print the errors
isValid = false;
}
Symbol *moduleInterface{nullptr};
if (hasModulePrefix && !inInterfaceBlock()) {
if (isValid && hasModulePrefix && !inInterfaceBlock()) {
moduleInterface = FindSeparateModuleProcedureInterface(name);
if (moduleInterface && &moduleInterface->owner() == &currScope()) {
// Subprogram is MODULE FUNCTION or MODULE SUBROUTINE with an interface
Expand Down
6 changes: 6 additions & 0 deletions flang/test/Semantics/OpenMP/bad_module_subroutine.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
! Test that we don't crash on this code inside of openmp semantics checks

!ERROR: 'e' is a MODULE procedure which must be declared within a MODULE or SUBMODULE
impure elemental module subroutine e()
end subroutine
Loading