Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions flang/include/flang/Support/Fortran-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank,
IgnoreIrrelevantAttributes, Unsigned, AmbiguousStructureConstructor,
ContiguousOkForSeqAssociation, ForwardRefExplicitTypeDummy,
InaccessibleDeferredOverride, CudaWarpMatchFunction, DoConcurrentOffload,
TransferBOZ, Coarray, PointerPassObject)
IgnoreIrrelevantAttributes, Unsigned, ContiguousOkForSeqAssociation,
ForwardRefExplicitTypeDummy, InaccessibleDeferredOverride,
CudaWarpMatchFunction, DoConcurrentOffload, TransferBOZ, Coarray,
PointerPassObject)

// Portability and suspicious usage warnings
ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
Expand Down
53 changes: 1 addition & 52 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3011,58 +3011,7 @@ auto ExpressionAnalyzer::ResolveGeneric(const Symbol &symbol,
}
}
}
// F'2023 C7108 checking. No Fortran compiler actually enforces this
// constraint, so it's just a portability warning here.
if (derivedType && (explicitIntrinsic || nonElemental || elemental) &&
context_.ShouldWarn(
common::LanguageFeature::AmbiguousStructureConstructor)) {
// See whethr there's ambiguity with a structure constructor.
bool possiblyAmbiguous{true};
if (const semantics::Scope * dtScope{derivedType->scope()}) {
parser::Messages buffer;
auto restorer{GetContextualMessages().SetMessages(buffer)};
std::list<ComponentSpec> componentSpecs;
for (const auto &actual : actuals) {
if (actual) {
ComponentSpec compSpec;
if (const Expr<SomeType> *expr{actual->UnwrapExpr()}) {
compSpec.expr = *expr;
} else {
possiblyAmbiguous = false;
}
if (auto loc{actual->sourceLocation()}) {
compSpec.source = compSpec.exprSource = *loc;
}
if (auto kw{actual->keyword()}) {
compSpec.hasKeyword = true;
compSpec.keywordSymbol = dtScope->FindComponent(*kw);
}
componentSpecs.emplace_back(std::move(compSpec));
} else {
possiblyAmbiguous = false;
}
}
semantics::DerivedTypeSpec dtSpec{derivedType->name(), *derivedType};
dtSpec.set_scope(*dtScope);
possiblyAmbiguous = possiblyAmbiguous &&
CheckStructureConstructor(
derivedType->name(), dtSpec, std::move(componentSpecs))
.has_value() &&
!buffer.AnyFatalError();
}
if (possiblyAmbiguous) {
if (explicitIntrinsic) {
Warn(common::LanguageFeature::AmbiguousStructureConstructor,
"Reference to the intrinsic function '%s' is ambiguous with a structure constructor of the same name"_port_en_US,
symbol.name());
} else {
Warn(common::LanguageFeature::AmbiguousStructureConstructor,
"Reference to generic function '%s' (resolving to specific '%s') is ambiguous with a structure constructor of the same name"_port_en_US,
symbol.name(),
nonElemental ? nonElemental->name() : elemental->name());
}
}
}

// Return the right resolution, if there is one. Explicit intrinsics
// are preferred, then non-elements specifics, then elementals, and
// lastly structure constructors.
Expand Down
1 change: 0 additions & 1 deletion flang/lib/Support/Fortran-features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ LanguageFeatureControl::LanguageFeatureControl() {
warnLanguage_.set(LanguageFeature::HollerithPolymorphic);
warnLanguage_.set(LanguageFeature::ListDirectedSize);
warnLanguage_.set(LanguageFeature::IgnoreIrrelevantAttributes);
warnLanguage_.set(LanguageFeature::AmbiguousStructureConstructor);
warnLanguage_.set(LanguageFeature::TransferBOZ);
warnUsage_.set(UsageWarning::ShortArrayActual);
warnUsage_.set(UsageWarning::FoldingException);
Expand Down
6 changes: 2 additions & 4 deletions flang/test/Semantics/c7108.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ program p
use m
type(foo) x
x = foo(); print *, x ! ok, not ambiguous
!PORTABILITY: Reference to generic function 'foo' (resolving to specific 'bar0') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]
x = foo(2); print *, x ! ambigous
!PORTABILITY: Reference to generic function 'foo' (resolving to specific 'bar2') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]
x = foo(3.); print *, x ! ambiguous due to data conversion
x = foo(2); print *, x ! According to F23 C7108, not ambiguous
x = foo(3.); print *, x ! According to F23 C7108, not ambiguous
x = foo(.true.); print *, x ! ok, not ambigous
end
3 changes: 0 additions & 3 deletions flang/test/Semantics/generic09.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ type(foo) function f2(a)
end
end

!CHECK: portability: Reference to generic function 'foo' (resolving to specific 'f1') is ambiguous with a structure constructor of the same name
!CHECK: portability: Reference to generic function 'foo' (resolving to specific 'f2') is ambiguous with a structure constructor of the same name

program main
use m3
type(foo) x
Expand Down
3 changes: 1 addition & 2 deletions flang/test/Semantics/resolve11.f90
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ subroutine s4
!ERROR: 'fun' is PRIVATE in 'm4'
use m4, only: foo, fun
type(foo) x ! ok
!PORTABILITY: Reference to generic function 'foo' (resolving to specific 'fun') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]
print *, foo()
print *, foo() ! According to F23 C7108, not ambiguous
end

module m5
Expand Down
6 changes: 2 additions & 4 deletions flang/test/Semantics/resolve17.f90
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ module m14d
contains
subroutine test
real :: y
!PORTABILITY: Reference to generic function 'foo' (resolving to specific 'bar') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]
y = foo(1.0)
y = foo(1.0) ! According to F23 C7108, not ambiguous
x = foo(2)
end subroutine
end module
Expand All @@ -302,8 +301,7 @@ module m14e
contains
subroutine test
real :: y
!PORTABILITY: Reference to generic function 'foo' (resolving to specific 'bar') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]
y = foo(1.0)
y = foo(1.0) ! According to F23 C7108, not ambiguous
x = foo(2)
end subroutine
end module
Expand Down
3 changes: 2 additions & 1 deletion flang/test/Semantics/resolve18.f90
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ subroutine s_21_23
use m21
use m23
type(foo) x ! Intel and NAG error
!PORTABILITY: Reference to generic function 'foo' (resolving to specific 'f1') is ambiguous with a structure constructor of the same name [-Wambiguous-structure-constructor]

! According to F23 C7108, not ambiguous
print *, foo(1.) ! Intel error
print *, foo(1.,2.,3.) ! Intel error
call ext(foo) ! GNU and Intel error
Expand Down
3 changes: 0 additions & 3 deletions flang/unittests/Common/FortranFeaturesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ TEST(FortranFeaturesTest, CamelCaseToLowerCaseHyphenated) {
EXPECT_EQ(
CamelCaseToLowerCaseHyphenated(EnumToString(LanguageFeature::Unsigned)),
"unsigned");
EXPECT_EQ(CamelCaseToLowerCaseHyphenated(
EnumToString(LanguageFeature::AmbiguousStructureConstructor)),
"ambiguous-structure-constructor");
EXPECT_EQ(CamelCaseToLowerCaseHyphenated(
EnumToString(LanguageFeature::ContiguousOkForSeqAssociation)),
"contiguous-ok-for-seq-association");
Expand Down
Loading