[flang] Fix an assert on duplicate initializations

When declaring the same variable twice with an initialization, we were failing
an internal check.  I fixed this by checking to see if the associated symbol
already had an error.

I added tests for pointer and non-pointer initialization of duplicate names.

Differential Revision: https://reviews.llvm.org/D84969
This commit is contained in:
Peter Steinfeld 2020-07-30 10:51:44 -07:00
parent b4c7657ba6
commit fac84536bc
2 changed files with 29 additions and 15 deletions

View File

@ -5680,8 +5680,10 @@ void DeclarationVisitor::NonPointerInitialization(const parser::Name &name,
const parser::ConstantExpr &expr, bool inComponentDecl) {
if (name.symbol) {
Symbol &ultimate{name.symbol->GetUltimate()};
if (!context().HasError(ultimate)) {
if (IsPointer(ultimate)) {
Say(name, "'%s' is a pointer but is not initialized like one"_err_en_US);
Say(name,
"'%s' is a pointer but is not initialized like one"_err_en_US);
} else if (auto *details{ultimate.detailsIf<ObjectEntityDetails>()}) {
CHECK(!details->init());
Walk(expr);
@ -5700,6 +5702,7 @@ void DeclarationVisitor::NonPointerInitialization(const parser::Name &name,
}
}
}
}
void ResolveNamesVisitor::HandleCall(
Symbol::Flag procFlag, const parser::Call &call) {

View File

@ -63,3 +63,14 @@ module m7
!ERROR: Derived type 'ubound' not found
integer :: ivar = ubound(iarray)(1)
end module m7
module m8
integer :: iVar = 3
!ERROR: The type of 'ivar' has already been declared
integer :: iVar = 4
integer, target :: jVar = 5
integer, target :: kVar = 5
integer, pointer :: pVar => jVar
!ERROR: The type of 'pvar' has already been declared
integer, pointer :: pVar => kVar
end module m8