Skip to content

Commit

Permalink
[flang] Allow assignment between INTEGER and LOGICAL as extension
Browse files Browse the repository at this point in the history
Extend documentation

Original-commit: flang-compiler/f18@7a71919
Reviewed-on: flang-compiler/f18#856
  • Loading branch information
klausler committed Dec 6, 2019
1 parent 371399b commit 00c3c27
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
4 changes: 3 additions & 1 deletion flang/documentation/Extensions.md
Expand Up @@ -109,6 +109,8 @@ Extensions, deletions, and legacy features supported by default
* When a dummy argument is `POINTER` or `ALLOCATABLE` and is `INTENT(IN)`, we
relax enforcement of some requirements on actual arguments that must otherwise
hold true for definable arguments.
* Assignment of `LOGICAL` to `INTEGER` and vice versa (but not other types).
The values are normalized.

Extensions supported when enabled by options
--------------------------------------------
Expand Down Expand Up @@ -140,7 +142,7 @@ Extensions and legacy features deliberately not supported
* Defining an explicit interface for a subprogram within itself (PGI only)
* USE association of a procedure interface within that same procedure's definition
* NULL() as a structure constructor expression for an ALLOCATABLE component (PGI).
* Conversion of LOGICAL to INTEGER.
* Conversion of LOGICAL to INTEGER in expressions.
* IF (integer expression) THEN ... END IF (PGI/Intel)
* Comparsion of LOGICAL with ==/.EQ. rather than .EQV. (also .NEQV.) (PGI/Intel)
* Procedure pointers in COMMON blocks (PGI/Intel)
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/common/Fortran-features.h
Expand Up @@ -33,7 +33,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
Hollerith, ArithmeticIF, Assign, AssignedGOTO, Pause, OpenMP,
CruftAfterAmpersand, ClassicCComments, AdditionalFormats, BigIntLiterals,
RealDoControls, EquivalenceNumericWithCharacter, AdditionalIntrinsics,
AnonymousParents, OldLabelDoEndStatements)
AnonymousParents, OldLabelDoEndStatements, LogicalIntegerAssignment)

using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;

Expand Down
34 changes: 31 additions & 3 deletions flang/lib/semantics/expression.cc
Expand Up @@ -2578,16 +2578,44 @@ std::optional<ProcedureRef> ArgumentAnalyzer::TryDefinedAssignment() {
using semantics::Tristate;
const Expr<SomeType> &lhs{GetExpr(0)};
const Expr<SomeType> &rhs{GetExpr(1)};
Tristate isDefined{semantics::IsDefinedAssignment(
lhs.GetType(), lhs.Rank(), rhs.GetType(), rhs.Rank())};
std::optional<DynamicType> lhsType{lhs.GetType()};
std::optional<DynamicType> rhsType{rhs.GetType()};
int lhsRank{lhs.Rank()};
int rhsRank{rhs.Rank()};
Tristate isDefined{
semantics::IsDefinedAssignment(lhsType, lhsRank, rhsType, rhsRank)};
if (isDefined == Tristate::No) {
return std::nullopt; // user-defined assignment not allowed for these args
}
auto restorer{context_.GetContextualMessages().SetLocation(source_)};
auto procRef{GetDefinedAssignmentProc()};
if (!procRef) {
if (isDefined == Tristate::Yes) {
SayNoMatch("ASSIGNMENT(=)", true);
if (context_.context().languageFeatures().IsEnabled(
common::LanguageFeature::LogicalIntegerAssignment) &&
lhsType && rhsType && (lhsRank == rhsRank || rhsRank == 0)) {
if (lhsType->category() == TypeCategory::Integer &&
rhsType->category() == TypeCategory::Logical) {
// allow assignment to LOGICAL from INTEGER as a legacy extension
if (context_.context().languageFeatures().ShouldWarn(
common::LanguageFeature::LogicalIntegerAssignment)) {
context_.Say(
"nonstandard usage: assignment of LOGICAL to INTEGER"_en_US);
}
} else if (lhsType->category() == TypeCategory::Logical &&
rhsType->category() == TypeCategory::Integer) {
// ... and assignment to LOGICAL from INTEGER
if (context_.context().languageFeatures().ShouldWarn(
common::LanguageFeature::LogicalIntegerAssignment)) {
context_.Say(
"nonstandard usage: assignment of INTEGER to LOGICAL"_en_US);
}
} else {
SayNoMatch("ASSIGNMENT(=)", true);
}
} else {
SayNoMatch("ASSIGNMENT(=)", true);
}
}
return std::nullopt;
}
Expand Down

0 comments on commit 00c3c27

Please sign in to comment.