[flang-commits] [PATCH] D123718: [flang] Inner INTRINSIC must not shadow host generic
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Wed Apr 13 12:51:51 PDT 2022
klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
A generic interface (however spelled) can have the same name as
an intrinsic procedure in the same scope. When an explicit INTRINSIC
attribute statement appears in a nested scope, semantics was
unconditionally declaring a new symbol that hid the generic entirely.
Catch this case and create instead a host association symbol for
the generic that can then be decorated with the INTRINSIC attribute.
https://reviews.llvm.org/D123718
Files:
flang/lib/Semantics/resolve-names.cpp
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -3809,7 +3809,9 @@
HandleAttributeStmt(Attr::INTRINSIC, x.v);
for (const auto &name : x.v) {
auto &symbol{DEREF(FindSymbol(name))};
- if (!ConvertToProcEntity(symbol)) {
+ if (symbol.has<GenericDetails>()) {
+ // Generic interface is extending intrinsic; ok
+ } else if (!symbol.has<HostAssocDetails>() && !ConvertToProcEntity(symbol)) {
SayWithDecl(
name, symbol, "INTRINSIC attribute not allowed on '%s'"_err_en_US);
} else if (symbol.attrs().test(Attr::EXTERNAL)) { // C840
@@ -3853,8 +3855,24 @@
}
Symbol &DeclarationVisitor::HandleAttributeStmt(
Attr attr, const parser::Name &name) {
- if (attr == Attr::INTRINSIC && !IsIntrinsic(name.source, std::nullopt)) {
- Say(name.source, "'%s' is not a known intrinsic procedure"_err_en_US);
+ if (attr == Attr::INTRINSIC) {
+ if (!IsIntrinsic(name.source, std::nullopt)) {
+ Say(name.source, "'%s' is not a known intrinsic procedure"_err_en_US);
+ } else if (currScope().kind() == Scope::Kind::Subprogram ||
+ currScope().kind() == Scope::Kind::Block) {
+ if (auto *symbol{FindSymbol(name)}) {
+ if (symbol->GetUltimate().has<GenericDetails>() &&
+ symbol->owner() != currScope()) {
+ // Declaring a name INTRINSIC when there is a generic
+ // interface of the same name in the host scope.
+ // Host-associate the generic and mark it INTRINSIC
+ // rather than completely overriding the generic.
+ symbol = &MakeHostAssocSymbol(name, *symbol);
+ symbol->attrs().set(Attr::INTRINSIC);
+ return *symbol;
+ }
+ }
+ }
}
auto *symbol{FindInScope(name)};
if (attr == Attr::ASYNCHRONOUS || attr == Attr::VOLATILE) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123718.422614.patch
Type: text/x-patch
Size: 1945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220413/a23cc21e/attachment-0001.bin>
More information about the flang-commits
mailing list