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) {
|
||||
if (name.symbol) {
|
||||
Symbol &ultimate{name.symbol->GetUltimate()};
|
||||
if (IsPointer(ultimate)) {
|
||||
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);
|
||||
// TODO: check C762 - all bounds and type parameters of component
|
||||
// are colons or constant expressions if component is initialized
|
||||
if (inComponentDecl) {
|
||||
// Can't convert to type of component, which might not yet
|
||||
// be known; that's done later during instantiation.
|
||||
if (MaybeExpr value{EvaluateExpr(expr)}) {
|
||||
details->set_init(std::move(*value));
|
||||
if (!context().HasError(ultimate)) {
|
||||
if (IsPointer(ultimate)) {
|
||||
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);
|
||||
// TODO: check C762 - all bounds and type parameters of component
|
||||
// are colons or constant expressions if component is initialized
|
||||
if (inComponentDecl) {
|
||||
// Can't convert to type of component, which might not yet
|
||||
// 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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue