[flang-commits] [PATCH] D142766: [flang] Diagnose invalid initializations
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Sat Jan 28 17:00:50 PST 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG034bab4cc83d: [flang] Diagnose invalid initializations (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142766/new/
https://reviews.llvm.org/D142766
Files:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/init01.f90
Index: flang/test/Semantics/init01.f90
===================================================================
--- flang/test/Semantics/init01.f90
+++ flang/test/Semantics/init01.f90
@@ -95,3 +95,14 @@
end block
end associate
end subroutine
+
+subroutine notObjects
+!ERROR: 'x1' is not an object that can be initialized
+ real, external :: x1 = 1.
+!ERROR: 'x2' is not a pointer but is initialized like one
+ real, external :: x2 => sin
+!ERROR: 'x3' is not an object that can be initialized
+ real, intrinsic :: x3 = 1.
+!ERROR: 'x4' is not a pointer but is initialized like one
+ real, intrinsic :: x4 => cos
+end subroutine
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -2510,8 +2510,16 @@
if (symbol.has<ObjectEntityDetails>()) {
// nothing to do
} else if (symbol.has<UnknownDetails>()) {
+ // These are attributes that a name could have picked up from
+ // an attribute statement or type declaration statement.
+ if (symbol.attrs().HasAny({Attr::EXTERNAL, Attr::INTRINSIC})) {
+ return false;
+ }
symbol.set_details(ObjectEntityDetails{});
} else if (auto *details{symbol.detailsIf<EntityDetails>()}) {
+ if (symbol.attrs().HasAny({Attr::EXTERNAL, Attr::INTRINSIC})) {
+ return false;
+ }
funcResultStack_.CompleteTypeIfFunctionResult(symbol);
symbol.set_details(ObjectEntityDetails{std::move(*details)});
} else if (auto *useDetails{symbol.detailsIf<UseDetails>()}) {
@@ -6970,10 +6978,6 @@
return;
}
Symbol &ultimate{name.symbol->GetUltimate()};
- if (IsAllocatable(ultimate)) {
- Say(name, "Allocatable object '%s' cannot be initialized"_err_en_US);
- return;
- }
// TODO: check C762 - all bounds and type parameters of component
// are colons or constant expressions if component is initialized
common::visit(
@@ -7074,6 +7078,10 @@
"'%s' is a pointer but is not initialized like one"_err_en_US);
} else if (auto *details{ultimate.detailsIf<ObjectEntityDetails>()}) {
CHECK(!details->init());
+ if (IsAllocatable(ultimate)) {
+ Say(name, "Allocatable object '%s' cannot be initialized"_err_en_US);
+ return;
+ }
Walk(expr);
if (ultimate.owner().IsParameterizedDerivedType()) {
// Save the expression for per-instantiation analysis.
@@ -7084,6 +7092,8 @@
details->set_init(std::move(*folded));
}
}
+ } else {
+ Say(name, "'%s' is not an object that can be initialized"_err_en_US);
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142766.493046.patch
Type: text/x-patch
Size: 2698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230129/65e6d8e7/attachment.bin>
More information about the flang-commits
mailing list