Skip to content

Conversation

@ktras
Copy link
Contributor

@ktras ktras commented Jan 28, 2026

Backport 5136b04

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)
@ktras ktras added this to the LLVM 22.x Release milestone Jan 28, 2026
@ktras ktras requested a review from bonachea January 28, 2026 19:00
@ktras ktras added the flang Flang issues not falling into any other category label Jan 28, 2026
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Jan 28, 2026
@ktras ktras marked this pull request as ready for review January 28, 2026 22:00
@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2026

@llvm/pr-subscribers-flang-semantics

Author: Katherine Rasmussen (ktras)

Changes

Backport 5136b04


Full diff: https://github.com/llvm/llvm-project/pull/178485.diff

9 Files Affected:

  • (modified) flang/include/flang/Support/Fortran-features.h (+4-4)
  • (modified) flang/lib/Semantics/expression.cpp (+1-52)
  • (modified) flang/lib/Support/Fortran-features.cpp (-1)
  • (modified) flang/test/Semantics/c7108.f90 (+2-4)
  • (modified) flang/test/Semantics/generic09.f90 (-3)
  • (modified) flang/test/Semantics/resolve11.f90 (+1-2)
  • (modified) flang/test/Semantics/resolve17.f90 (+2-4)
  • (modified) flang/test/Semantics/resolve18.f90 (+2-1)
  • (modified) flang/unittests/Common/FortranFeaturesTest.cpp (-3)
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");

Copy link
Contributor

@bonachea bonachea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@c-rhodes c-rhodes moved this from Needs Triage to Needs Merge in LLVM Release Status Jan 29, 2026
@c-rhodes c-rhodes moved this from Needs Merge to Done in LLVM Release Status Jan 29, 2026
@c-rhodes
Copy link
Collaborator

merged bc063ff

@c-rhodes c-rhodes closed this Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

Development

Successfully merging this pull request may close these issues.

4 participants