https://github.com/ktras created https://github.com/llvm/llvm-project/pull/178485
Backport 5136b04dd2aaeb3cbc724c0015e7f06ed2408e1a >From 9227ea1788e65af888b8f8f44e421d0e7e2ae786 Mon Sep 17 00:00:00 2001 From: Katherine Rasmussen <[email protected]> Date: Wed, 28 Jan 2026 10:32:41 -0800 Subject: [PATCH] [flang] Remove `AmbiguousStructureConstructor` warnings (#178088) Remove `AmbiguousStructureConstructor` warnings. This removes harmless warnings about standards-conforming generic function references that are never ambiguous with structure constructors. (cherry picked from commit 5136b04dd2aaeb3cbc724c0015e7f06ed2408e1a) --- .../include/flang/Support/Fortran-features.h | 8 +-- flang/lib/Semantics/expression.cpp | 53 +------------------ flang/lib/Support/Fortran-features.cpp | 1 - flang/test/Semantics/c7108.f90 | 6 +-- flang/test/Semantics/generic09.f90 | 3 -- flang/test/Semantics/resolve11.f90 | 3 +- flang/test/Semantics/resolve17.f90 | 6 +-- flang/test/Semantics/resolve18.f90 | 3 +- .../unittests/Common/FortranFeaturesTest.cpp | 3 -- 9 files changed, 12 insertions(+), 74 deletions(-) diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h index 9c8d7e36b1ef4..2110e2456e62f 100644 --- a/flang/include/flang/Support/Fortran-features.h +++ b/flang/include/flang/Support/Fortran-features.h @@ -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, diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp index b3643e0d35d5f..8ae9b5b89d0e4 100644 --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -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. diff --git a/flang/lib/Support/Fortran-features.cpp b/flang/lib/Support/Fortran-features.cpp index 356050f22b443..521bf35294154 100644 --- a/flang/lib/Support/Fortran-features.cpp +++ b/flang/lib/Support/Fortran-features.cpp @@ -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); diff --git a/flang/test/Semantics/c7108.f90 b/flang/test/Semantics/c7108.f90 index 0b7148f4d6455..12b88fd0128e2 100644 --- a/flang/test/Semantics/c7108.f90 +++ b/flang/test/Semantics/c7108.f90 @@ -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 diff --git a/flang/test/Semantics/generic09.f90 b/flang/test/Semantics/generic09.f90 index d93d7453ed6dd..c3a8b49913e94 100644 --- a/flang/test/Semantics/generic09.f90 +++ b/flang/test/Semantics/generic09.f90 @@ -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 diff --git a/flang/test/Semantics/resolve11.f90 b/flang/test/Semantics/resolve11.f90 index 0c457f2c9f3f0..734cdcb7bafa1 100644 --- a/flang/test/Semantics/resolve11.f90 +++ b/flang/test/Semantics/resolve11.f90 @@ -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 diff --git a/flang/test/Semantics/resolve17.f90 b/flang/test/Semantics/resolve17.f90 index 173fb9c6c5b78..666a5a14eafcf 100644 --- a/flang/test/Semantics/resolve17.f90 +++ b/flang/test/Semantics/resolve17.f90 @@ -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 @@ -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 diff --git a/flang/test/Semantics/resolve18.f90 b/flang/test/Semantics/resolve18.f90 index 65c39931cc7cb..b0827f88996c7 100644 --- a/flang/test/Semantics/resolve18.f90 +++ b/flang/test/Semantics/resolve18.f90 @@ -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 diff --git a/flang/unittests/Common/FortranFeaturesTest.cpp b/flang/unittests/Common/FortranFeaturesTest.cpp index 9408da0361e1d..2caacb5f3dacf 100644 --- a/flang/unittests/Common/FortranFeaturesTest.cpp +++ b/flang/unittests/Common/FortranFeaturesTest.cpp @@ -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"); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
