forked from OSchip/llvm-project
[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:
parent
b4c7657ba6
commit
fac84536bc
|
@ -5680,22 +5680,25 @@ void DeclarationVisitor::NonPointerInitialization(const parser::Name &name,
|
||||||
const parser::ConstantExpr &expr, bool inComponentDecl) {
|
const parser::ConstantExpr &expr, bool inComponentDecl) {
|
||||||
if (name.symbol) {
|
if (name.symbol) {
|
||||||
Symbol &ultimate{name.symbol->GetUltimate()};
|
Symbol &ultimate{name.symbol->GetUltimate()};
|
||||||
if (IsPointer(ultimate)) {
|
if (!context().HasError(ultimate)) {
|
||||||
Say(name, "'%s' is a pointer but is not initialized like one"_err_en_US);
|
if (IsPointer(ultimate)) {
|
||||||
} else if (auto *details{ultimate.detailsIf<ObjectEntityDetails>()}) {
|
Say(name,
|
||||||
CHECK(!details->init());
|
"'%s' is a pointer but is not initialized like one"_err_en_US);
|
||||||
Walk(expr);
|
} else if (auto *details{ultimate.detailsIf<ObjectEntityDetails>()}) {
|
||||||
// TODO: check C762 - all bounds and type parameters of component
|
CHECK(!details->init());
|
||||||
// are colons or constant expressions if component is initialized
|
Walk(expr);
|
||||||
if (inComponentDecl) {
|
// TODO: check C762 - all bounds and type parameters of component
|
||||||
// Can't convert to type of component, which might not yet
|
// are colons or constant expressions if component is initialized
|
||||||
// be known; that's done later during instantiation.
|
if (inComponentDecl) {
|
||||||
if (MaybeExpr value{EvaluateExpr(expr)}) {
|
// Can't convert to type of component, which might not yet
|
||||||
details->set_init(std::move(*value));
|
// be known; that's done later during instantiation.
|
||||||
|
if (MaybeExpr value{EvaluateExpr(expr)}) {
|
||||||
|
details->set_init(std::move(*value));
|
||||||
|
}
|
||||||
|
} else if (MaybeExpr folded{EvaluateConvertedExpr(
|
||||||
|
ultimate, expr, expr.thing.value().source)}) {
|
||||||
|
details->set_init(std::move(*folded));
|
||||||
}
|
}
|
||||||
} else if (MaybeExpr folded{EvaluateConvertedExpr(
|
|
||||||
ultimate, expr, expr.thing.value().source)}) {
|
|
||||||
details->set_init(std::move(*folded));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,3 +63,14 @@ module m7
|
||||||
!ERROR: Derived type 'ubound' not found
|
!ERROR: Derived type 'ubound' not found
|
||||||
integer :: ivar = ubound(iarray)(1)
|
integer :: ivar = ubound(iarray)(1)
|
||||||
end module m7
|
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
|
||||||
|
|
Loading…
Reference in New Issue