Skip to content

Commit 41d5fed

Browse files
authored
[flang][Semantics] set scope even for module subroutines outside modules (#109009)
The missing scope information led to a crash in OpenMP semantic checks run before printing the error that was already discovered in the code. The following block has to be skipped for this invalid code so that we don't emit a second spurious error. Fixes #82913
1 parent edac1b2 commit 41d5fed

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,15 +4351,18 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name,
43514351
Symbol::Flag subpFlag, bool hasModulePrefix,
43524352
const parser::LanguageBindingSpec *bindingSpec,
43534353
const ProgramTree::EntryStmtList *entryStmts) {
4354+
bool isValid{true};
43544355
if (hasModulePrefix && !currScope().IsModule() &&
43554356
!currScope().IsSubmodule()) { // C1547
43564357
Say(name,
43574358
"'%s' is a MODULE procedure which must be declared within a "
43584359
"MODULE or SUBMODULE"_err_en_US);
4359-
return false;
4360+
// Don't return here because it can be useful to have the scope set for
4361+
// other semantic checks run before we print the errors
4362+
isValid = false;
43604363
}
43614364
Symbol *moduleInterface{nullptr};
4362-
if (hasModulePrefix && !inInterfaceBlock()) {
4365+
if (isValid && hasModulePrefix && !inInterfaceBlock()) {
43634366
moduleInterface = FindSeparateModuleProcedureInterface(name);
43644367
if (moduleInterface && &moduleInterface->owner() == &currScope()) {
43654368
// Subprogram is MODULE FUNCTION or MODULE SUBROUTINE with an interface
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
! Test that we don't crash on this code inside of openmp semantics checks
3+
4+
!ERROR: 'e' is a MODULE procedure which must be declared within a MODULE or SUBMODULE
5+
impure elemental module subroutine e()
6+
end subroutine

0 commit comments

Comments
 (0)