Skip to content

Commit

Permalink
[flang] Respect !DIR$ IGNORE_TKR in generic matching
Browse files Browse the repository at this point in the history
Generic matching needs to relax argument compatibility checks when
dummy arguments have !DIR$ IGNORE_TKR directives.

Differential Revision: https://reviews.llvm.org/D150806
  • Loading branch information
klausler committed May 18, 2023
1 parent e7b9c2f commit e5ccfbb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
3 changes: 3 additions & 0 deletions flang/lib/Evaluate/characteristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ llvm::raw_ostream &DummyDataObject::Dump(llvm::raw_ostream &o) const {
sep = ',';
}
}
if (!ignoreTKR.empty()) {
ignoreTKR.Dump(o << ' ', common::EnumToString);
}
return o;
}

Expand Down
5 changes: 3 additions & 2 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2307,10 +2307,11 @@ static bool CheckCompatibleArgument(bool isElemental,
return true;
} else if (!isElemental && actual.Rank() != x.type.Rank() &&
!x.type.attrs().test(
characteristics::TypeAndShape::Attr::AssumedRank)) {
characteristics::TypeAndShape::Attr::AssumedRank) &&
!x.ignoreTKR.test(common::IgnoreTKR::Rank)) {
return false;
} else if (auto actualType{actual.GetType()}) {
return x.type.type().IsTkCompatibleWith(*actualType);
return x.type.type().IsTkCompatibleWith(*actualType, x.ignoreTKR);
}
return false;
},
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Semantics/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ llvm::raw_ostream &operator<<(
os << " (has unanalyzedPDTComponentInit)";
}
if (!x.ignoreTKR_.empty()) {
os << ' ';
x.ignoreTKR_.Dump(os, common::EnumToString);
x.ignoreTKR_.Dump(os << ' ', common::EnumToString);
}
return os;
}
Expand Down
38 changes: 38 additions & 0 deletions flang/test/Semantics/ignore_tkr02.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
program main
interface generic
subroutine sub1(j, k)
integer(1) j
integer k
!dir$ ignore_tkr(kr) k
end
subroutine sub2(j, k)
integer(2) j
integer k
!dir$ ignore_tkr(kr) k
end
subroutine sub4(j, k)
integer(4) j
integer k
!dir$ ignore_tkr(kr) k
end
end interface
!CHECK: CALL sub1(1_1,int(1_1,kind=4))
call generic(1_1,1_1)
!CHECK: CALL sub1(1_1,int(1_2,kind=4))
call generic(1_1,1_2)
!CHECK: CALL sub1(1_1,[INTEGER(1)::1_1])
call generic(1_1,[1_1])
!CHECK: CALL sub2(1_2,int(1_1,kind=4))
call generic(1_2,1_1)
!CHECK: CALL sub2(1_2,int(1_2,kind=4))
call generic(1_2,1_2)
!CHECK: CALL sub2(1_2,[INTEGER(1)::1_1])
call generic(1_2,[1_1])
!CHECK: CALL sub4(1_4,int(1_1,kind=4))
call generic(1_4,1_1)
!CHECK: CALL sub4(1_4,int(1_2,kind=4))
call generic(1_4,1_2)
!CHECK: CALL sub4(1_4,[INTEGER(1)::1_1])
call generic(1_4,[1_1])
end

0 comments on commit e5ccfbb

Please sign in to comment.