[flang-commits] [flang] [llvm] [NFC] : Run clang-format on Attributor.h and AttributorAttributes.cpp (PR #94484)
Vidush Singhal via flang-commits
flang-commits at lists.llvm.org
Wed Jun 5 08:34:44 PDT 2024
https://github.com/vidsinghal updated https://github.com/llvm/llvm-project/pull/94484
>From 5f406924a1ae574f31a725395e78fdec57fad8ac Mon Sep 17 00:00:00 2001
From: Peter Klausler <35819229+klausler at users.noreply.github.com>
Date: Mon, 3 Jun 2024 14:49:08 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[flang]=20Propagate=20the=20BIND(C)=20attri?=
=?UTF-8?q?bute=20into=20procedures=20from=20their=20in=E2=80=A6=20(#93994?=
=?UTF-8?q?)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
…terfaces
In "PROCEDURE(iface) :: proc", if "iface" has the BIND(C) attribute,
then so should proc, as if the declaration had been "PROCEDURE(iface),
BIND(C) :: proc". This had been working in name resolution only in cases
where "iface" had been declared before "proc".
Note that if "iface" is declared with an empty binding name
("BIND(C,NAME='')"), "proc" does not inherit that property. Use an
explicit "BIND(C,NAME='')" on the "PROCEDURE" statement for that.
This behavior is not clearly defined in the standard, but seems to match
what some other Fortran compilers do.
---
flang/lib/Semantics/resolve-names.cpp | 27 ++++++---
flang/test/Semantics/bind-c02.f90 | 1 +
flang/test/Semantics/bind-c16.f90 | 86 +++++++++++++++++++++++++++
3 files changed, 107 insertions(+), 7 deletions(-)
create mode 100644 flang/test/Semantics/bind-c16.f90
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b49528b2df02f..7397c3a51b61e 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5072,13 +5072,6 @@ Symbol &DeclarationVisitor::DeclareProcEntity(
} else if (interface->test(Symbol::Flag::Subroutine)) {
symbol.set(Symbol::Flag::Subroutine);
}
- if (IsBindCProcedure(*interface) && !IsPointer(symbol) &&
- !IsDummy(symbol)) {
- // Inherit BIND_C attribute from the interface, but not the NAME="..."
- // if any. This is not clearly described in the standard, but matches
- // the behavior of other compilers.
- SetImplicitAttr(symbol, Attr::BIND_C);
- }
} else if (auto *type{GetDeclTypeSpec()}) {
SetType(name, *type);
symbol.set(Symbol::Flag::Function);
@@ -8653,6 +8646,20 @@ void ResolveNamesVisitor::FinishSpecificationPart(
if (!symbol.has<HostAssocDetails>()) {
CheckPossibleBadForwardRef(symbol);
}
+ // Propagate BIND(C) attribute to procedure entities from their interfaces,
+ // but not the NAME=, even if it is empty (which would be a reasonable
+ // and useful behavior, actually). This interpretation is not at all
+ // clearly described in the standard, but matches the behavior of several
+ // other compilers.
+ if (auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
+ !proc->isDummy() && !IsPointer(symbol) &&
+ !symbol.attrs().test(Attr::BIND_C)) {
+ if (const Symbol * iface{proc->procInterface()};
+ iface && IsBindCProcedure(*iface)) {
+ SetImplicitAttr(symbol, Attr::BIND_C);
+ SetBindNameOn(symbol);
+ }
+ }
}
currScope().InstantiateDerivedTypes();
for (const auto &decl : decls) {
@@ -9198,6 +9205,9 @@ void ResolveNamesVisitor::AddSubpNames(ProgramTree &node) {
if (child.HasModulePrefix()) {
SetExplicitAttr(symbol, Attr::MODULE);
}
+ if (child.bindingSpec()) {
+ SetExplicitAttr(symbol, Attr::BIND_C);
+ }
auto childKind{child.GetKind()};
if (childKind == ProgramTree::Kind::Function) {
symbol.set(Symbol::Flag::Function);
@@ -9214,6 +9224,9 @@ void ResolveNamesVisitor::AddSubpNames(ProgramTree &node) {
if (child.HasModulePrefix()) {
SetExplicitAttr(symbol, Attr::MODULE);
}
+ if (child.bindingSpec()) {
+ SetExplicitAttr(symbol, Attr::BIND_C);
+ }
}
}
for (const auto &generic : node.genericSpecs()) {
diff --git a/flang/test/Semantics/bind-c02.f90 b/flang/test/Semantics/bind-c02.f90
index d0c7940744131..416d071542fe6 100644
--- a/flang/test/Semantics/bind-c02.f90
+++ b/flang/test/Semantics/bind-c02.f90
@@ -15,6 +15,7 @@ subroutine proc()
!ERROR: Only variable and named common block can be in BIND statement
bind(c) :: pc1
+ !ERROR: BIND_C attribute was already specified on 'sub'
!ERROR: Only variable and named common block can be in BIND statement
bind(c) :: sub
diff --git a/flang/test/Semantics/bind-c16.f90 b/flang/test/Semantics/bind-c16.f90
new file mode 100644
index 0000000000000..b9dfb03e35eec
--- /dev/null
+++ b/flang/test/Semantics/bind-c16.f90
@@ -0,0 +1,86 @@
+!RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
+!CHECK: p1a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:p1a
+!CHECK: p1b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:p1b
+!CHECK: p1c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:P1c
+!CHECK: p2a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:p2a
+!CHECK: p2b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:p2b
+!CHECK: p2c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:P2c
+!CHECK: p3a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:p3a
+!CHECK: p3b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:p3b
+!CHECK: p3c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:P3c
+module m1
+ procedure(s1) :: p1a
+ procedure(s1), bind(c) :: p1b
+ procedure(s1), bind(c,name='P1c') :: p1c
+ procedure(s2) :: p2a
+ procedure(s2), bind(c) :: p2b
+ procedure(s2), bind(c,name='P2c') :: p2c
+ procedure(s3) :: p3a
+ procedure(s3), bind(c) :: p3b
+ procedure(s3), bind(c,name='P3c') :: p3c
+ contains
+ subroutine s1() bind(c)
+ end
+ subroutine s2() bind(c,name='')
+ end
+ subroutine s3() bind(c,name='foo')
+ end
+end
+
+!CHECK: p1a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:p1a
+!CHECK: p1b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:p1b
+!CHECK: p1c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:P1c
+!CHECK: p2a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:p2a
+!CHECK: p2b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:p2b
+!CHECK: p2c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:P2c
+!CHECK: p3a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:p3a
+!CHECK: p3b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:p3b
+!CHECK: p3c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:P3c
+module m2
+ interface
+ subroutine s1() bind(c)
+ end
+ subroutine s2() bind(c,name='')
+ end
+ subroutine s3() bind(c,name='foo')
+ end
+ end interface
+ procedure(s1) :: p1a
+ procedure(s1), bind(c) :: p1b
+ procedure(s1), bind(c,name='P1c') :: p1c
+ procedure(s2) :: p2a
+ procedure(s2), bind(c) :: p2b
+ procedure(s2), bind(c,name='P2c') :: p2c
+ procedure(s3) :: p3a
+ procedure(s3), bind(c) :: p3b
+ procedure(s3), bind(c,name='P3c') :: p3c
+end
+
+!CHECK: p1a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:p1a
+!CHECK: p1b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:p1b
+!CHECK: p1c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s1 bindName:P1c
+!CHECK: p2a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:p2a
+!CHECK: p2b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:p2b
+!CHECK: p2c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s2 bindName:P2c
+!CHECK: p3a, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:p3a
+!CHECK: p3b, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:p3b
+!CHECK: p3c, BIND(C), EXTERNAL, PUBLIC (Subroutine): ProcEntity s3 bindName:P3c
+module m3
+ procedure(s1) :: p1a
+ procedure(s1), bind(c) :: p1b
+ procedure(s1), bind(c,name='P1c') :: p1c
+ procedure(s2) :: p2a
+ procedure(s2), bind(c) :: p2b
+ procedure(s2), bind(c,name='P2c') :: p2c
+ procedure(s3) :: p3a
+ procedure(s3), bind(c) :: p3b
+ procedure(s3), bind(c,name='P3c') :: p3c
+ interface
+ subroutine s1() bind(c)
+ end
+ subroutine s2() bind(c,name='')
+ end
+ subroutine s3() bind(c,name='foo')
+ end
+ end interface
+end
>From ab0831701f22411aadbff608a66c2a77d175c51b Mon Sep 17 00:00:00 2001
From: Vidush Singhal <singhal2 at ruby964.llnl.gov>
Date: Wed, 5 Jun 2024 08:12:21 -0700
Subject: [PATCH 2/2] [NFC] : Attributor run clang format on Attributor.h and
AttributorAttributes.cpp
---
llvm/include/llvm/Transforms/IPO/Attributor.h | 12 +++---------
.../lib/Transforms/IPO/AttributorAttributes.cpp | 17 +++++++++--------
2 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 30c51250af61c..cbf1a89b6b9d6 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -5143,9 +5143,7 @@ struct DenormalFPMathState : public AbstractState {
return Mode != Other.Mode || ModeF32 != Other.ModeF32;
}
- bool isValid() const {
- return Mode.isValid() && ModeF32.isValid();
- }
+ bool isValid() const { return Mode.isValid() && ModeF32.isValid(); }
static DenormalMode::DenormalModeKind
unionDenormalKind(DenormalMode::DenormalModeKind Callee,
@@ -5185,9 +5183,7 @@ struct DenormalFPMathState : public AbstractState {
// state.
DenormalState getAssumed() const { return Known; }
- bool isValidState() const override {
- return Known.isValid();
- }
+ bool isValidState() const override { return Known.isValid(); }
/// Return true if there are no dynamic components to the denormal mode worth
/// specializing.
@@ -5198,9 +5194,7 @@ struct DenormalFPMathState : public AbstractState {
Known.ModeF32.Output != DenormalMode::Dynamic;
}
- bool isAtFixpoint() const override {
- return IsAtFixedpoint;
- }
+ bool isAtFixpoint() const override { return IsAtFixedpoint; }
ChangeStatus indicateFixpoint() {
bool Changed = !IsAtFixedpoint;
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 1b3bf3c732ed0..bfed72c9c3f73 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -419,7 +419,8 @@ struct AAReturnedFromReturnedValues : public BaseType {
/// See AbstractAttribute::updateImpl(...).
ChangeStatus updateImpl(Attributor &A) override {
StateType S(StateType::getBestState(this->getState()));
- clampReturnedValueStates<AAType, StateType, IRAttributeKind, RecurseForSelectAndPHI>(
+ clampReturnedValueStates<AAType, StateType, IRAttributeKind,
+ RecurseForSelectAndPHI>(
A, *this, S,
PropagateCallBaseContext ? this->getCallBaseContext() : nullptr);
// TODO: If we know we visited all returned values, thus no are assumed
@@ -6975,10 +6976,9 @@ ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) {
if (AI.LibraryFunctionId != LibFunc___kmpc_alloc_shared) {
Instruction *CtxI = isa<InvokeInst>(AI.CB) ? AI.CB : AI.CB->getNextNode();
if (!Explorer || !Explorer->findInContextOf(UniqueFree, CtxI)) {
- LLVM_DEBUG(
- dbgs()
- << "[H2S] unique free call might not be executed with the allocation "
- << *UniqueFree << "\n");
+ LLVM_DEBUG(dbgs() << "[H2S] unique free call might not be executed "
+ "with the allocation "
+ << *UniqueFree << "\n");
return false;
}
}
@@ -10431,11 +10431,12 @@ struct AANoFPClassFloating : public AANoFPClassImpl {
struct AANoFPClassReturned final
: AAReturnedFromReturnedValues<AANoFPClass, AANoFPClassImpl,
- AANoFPClassImpl::StateType, false, Attribute::None, false> {
+ AANoFPClassImpl::StateType, false,
+ Attribute::None, false> {
AANoFPClassReturned(const IRPosition &IRP, Attributor &A)
: AAReturnedFromReturnedValues<AANoFPClass, AANoFPClassImpl,
- AANoFPClassImpl::StateType, false, Attribute::None, false>(
- IRP, A) {}
+ AANoFPClassImpl::StateType, false,
+ Attribute::None, false>(IRP, A) {}
/// See AbstractAttribute::trackStatistics()
void trackStatistics() const override {
More information about the flang-commits
mailing list