Skip to content
Merged
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
5 changes: 5 additions & 0 deletions flang/docs/Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ end
to be constant will generate a compilation error. `ieee_support_standard`
depends in part on `ieee_support_halting`, so this also applies to
`ieee_support_standard` calls.
* F'2023 constraint C7108 prohibits the use of a structure constructor
that could also be interpreted as a generic function reference.
No other Fortran compiler enforces C7108 (to our knowledge);
they all resolve the ambiguity by interpreting the call as a function
reference. We do the same, with a portability warning.

## Extensions, deletions, and legacy features supported by default

Expand Down
13 changes: 13 additions & 0 deletions flang/include/flang/Semantics/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,19 @@ class ExpressionAnalyzer {
MaybeExpr AnalyzeComplex(MaybeExpr &&re, MaybeExpr &&im, const char *what);
std::optional<Chevrons> AnalyzeChevrons(const parser::CallStmt &);

// CheckStructureConstructor() is used for parsed structure constructors
// as well as for generic function references.
struct ComponentSpec {
ComponentSpec() = default;
ComponentSpec(ComponentSpec &&) = default;
parser::CharBlock source, exprSource;
bool hasKeyword{false};
const Symbol *keywordSymbol{nullptr};
MaybeExpr expr;
};
MaybeExpr CheckStructureConstructor(parser::CharBlock typeName,
const semantics::DerivedTypeSpec &, std::list<ComponentSpec> &&);

MaybeExpr IterativelyAnalyzeSubexpressions(const parser::Expr &);

semantics::SemanticsContext &context_;
Expand Down
3 changes: 2 additions & 1 deletion flang/include/flang/Support/Fortran-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank,
IgnoreIrrelevantAttributes, Unsigned, ContiguousOkForSeqAssociation)
IgnoreIrrelevantAttributes, Unsigned, AmbiguousStructureConstructor,
ContiguousOkForSeqAssociation)

// Portability and suspicious usage warnings
ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
Expand Down
454 changes: 269 additions & 185 deletions flang/lib/Semantics/expression.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions flang/lib/Support/Fortran-features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ LanguageFeatureControl::LanguageFeatureControl() {
warnLanguage_.set(LanguageFeature::HollerithPolymorphic);
warnLanguage_.set(LanguageFeature::ListDirectedSize);
warnLanguage_.set(LanguageFeature::IgnoreIrrelevantAttributes);
warnLanguage_.set(LanguageFeature::AmbiguousStructureConstructor);
warnUsage_.set(UsageWarning::ShortArrayActual);
warnUsage_.set(UsageWarning::FoldingException);
warnUsage_.set(UsageWarning::FoldingAvoidsRuntimeCrash);
Expand Down
41 changes: 41 additions & 0 deletions flang/test/Semantics/c7108.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
! F'2023 C7108 is portably unenforced.
module m
type foo
integer n
end type
interface foo
procedure bar0, bar1, bar2, bar3
end interface
contains
type(foo) function bar0(n)
integer, intent(in) :: n
print *, 'bar0'
bar0%n = n
end
type(foo) function bar1()
print *, 'bar1'
bar1%n = 1
end
type(foo) function bar2(a)
real, intent(in) :: a
print *, 'bar2'
bar2%n = a
end
type(foo) function bar3(L)
logical, intent(in) :: L
print *, 'bar3'
bar3%n = merge(4,5,L)
end
end

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
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
x = foo(3.); print *, x ! ambiguous due to data conversion
x = foo(.true.); print *, x ! ok, not ambigous
end
4 changes: 4 additions & 0 deletions flang/test/Semantics/generic09.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s

module m1
type foo
integer n
Expand Down Expand Up @@ -32,6 +33,9 @@ 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: 2 additions & 1 deletion flang/test/Semantics/resolve11.f90
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ subroutine s4
!ERROR: 'fun' is PRIVATE in 'm4'
use m4, only: foo, fun
type(foo) x ! ok
print *, foo() ! ok
!PORTABILITY: Reference to generic function 'foo' (resolving to specific 'fun') is ambiguous with a structure constructor of the same name
print *, foo()
end

module m5
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Semantics/resolve17.f90
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +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
y = foo(1.0)
x = foo(2)
end subroutine
Expand All @@ -301,6 +302,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
y = foo(1.0)
x = foo(2)
end subroutine
Expand Down
1 change: 1 addition & 0 deletions flang/test/Semantics/resolve18.f90
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ 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
print *, foo(1.) ! Intel error
print *, foo(1.,2.,3.) ! Intel error
call ext(foo) ! GNU and Intel error
Expand Down