Skip to content
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

[flang] Fix crash when handling benign USE conflict #121977

Merged
merged 1 commit into from
Jan 8, 2025
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
6 changes: 6 additions & 0 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3162,6 +3162,10 @@ ModuleVisitor::SymbolRename ModuleVisitor::AddUse(
// Convert it to a UseError with this additional location.
static bool ConvertToUseError(
Symbol &symbol, const SourceName &location, const Scope &module) {
if (auto *ued{symbol.detailsIf<UseErrorDetails>()}) {
ued->add_occurrence(location, module);
return true;
}
const auto *useDetails{symbol.detailsIf<UseDetails>()};
if (!useDetails) {
if (auto *genericDetails{symbol.detailsIf<GenericDetails>()}) {
Expand Down Expand Up @@ -3319,6 +3323,8 @@ void ModuleVisitor::DoAddUse(SourceName location, SourceName localName,
combinedDerivedType = CreateLocalUseError();
} else {
ConvertToUseError(*localSymbol, location, *useModuleScope_);
localDerivedType = nullptr;
localGeneric = nullptr;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we got to the else clause, then localGeneric should already be null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but this makes it explicit that the localXXXX pointers into the contents of localSymbol are being invalidated.

combinedDerivedType = localSymbol;
}
}
Expand Down
31 changes: 31 additions & 0 deletions flang/test/Semantics/bug121718.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
! RUN: %flang_fc1 2>&1 | FileCheck %s --allow-empty
! CHECK-NOT: error
! Regression test simplified from LLVM bug 121718.
! Ensure no crash and no spurious error message.
module m1
type foo
integer x
end type
contains
subroutine test
print *, foo(123)
end
end
module m2
interface foo
procedure f
end interface
type foo
real x
end type
contains
complex function f(x)
complex, intent(in) :: x
f = x
end
end
program main
use m1
use m2
call test
end
Loading