-
Notifications
You must be signed in to change notification settings - Fork 15.9k
release/22.x: [flang] Remove AmbiguousStructureConstructor warnings (#178088)
#178485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+12
−74
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remove `AmbiguousStructureConstructor` warnings. This removes harmless warnings about standards-conforming generic function references that are never ambiguous with structure constructors. (cherry picked from commit 5136b04)
Member
|
@llvm/pr-subscribers-flang-semantics Author: Katherine Rasmussen (ktras) ChangesBackport 5136b04 Full diff: https://github.com/llvm/llvm-project/pull/178485.diff 9 Files Affected:
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");
|
bonachea
approved these changes
Jan 28, 2026
Contributor
bonachea
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Collaborator
|
merged bc063ff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 5136b04