[flang] Fix bug merging generics on USE

When we use-associate the same generic name from two different modules
they are merged together. If the same specific procedure occurs in both
generics it should only occur once in the merged one.

Similarly, it's not an error if they both have a derived type or
specific procedure named the same as the generic, as long as they are
the same symbol.

Fixes flang-compiler/f18#733.

Original-commit: flang-compiler/f18@d37db07691
Reviewed-on: https://github.com/flang-compiler/f18/pull/741
Tree-same-pre-rewrite: false
This commit is contained in:
Tim Keith 2019-09-12 17:38:40 -07:00
parent 6f9ae14b27
commit d43405e4e6
2 changed files with 36 additions and 4 deletions

View file

@ -179,15 +179,19 @@ Symbol *GenericDetails::CheckSpecific() {
void GenericDetails::CopyFrom(const GenericDetails &from) {
if (from.specific_) {
CHECK(!specific_);
CHECK(!specific_ || specific_ == from.specific_);
specific_ = from.specific_;
}
if (from.derivedType_) {
CHECK(!derivedType_);
CHECK(!derivedType_ || derivedType_ == from.derivedType_);
derivedType_ = from.derivedType_;
}
auto &procs{from.specificProcs_};
specificProcs_.insert(specificProcs_.end(), procs.begin(), procs.end());
for (const Symbol *symbol : from.specificProcs_) {
auto it{std::find(specificProcs_.begin(), specificProcs_.end(), symbol)};
if (it == specificProcs_.end()) {
specificProcs_.push_back(symbol);
}
}
}
// The name of the kind of details for this symbol.

View file

@ -175,3 +175,31 @@ subroutine s8
!ERROR: Reference to 'g' is ambiguous
g = 1
end
module m9a
interface g
module procedure s1
module procedure g
end interface
contains
subroutine g()
end
subroutine s1(x)
integer :: x
end
end module
module m9b
use m9a
interface g
module procedure s2
end interface
contains
subroutine s2(x)
real :: x
end
end module
! Merge use-associated generics that have the same symbol (s1)
subroutine s9
use m9a
use m9b
end