Skip to content

Commit 6422882

Browse files
[flang] Add support for -fimplicit-none-ext option (#125248)
When -fimplicit-none-ext is passed, flang behaves as if "implicit none(external)" was specified for all relevant constructs in Fortran source file. Note: implicit17.f90 was based on implicit07.f90 with `implicit none(external)` removed and `-fimplicit-none-ext` added.
1 parent 5f247e7 commit 6422882

File tree

7 files changed

+32
-8
lines changed

7 files changed

+32
-8
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6876,6 +6876,7 @@ defm backslash : OptInFC1FFlag<"backslash", "Specify that backslash in string in
68766876
defm xor_operator : OptInFC1FFlag<"xor-operator", "Enable .XOR. as a synonym of .NEQV.">;
68776877
defm logical_abbreviations : OptInFC1FFlag<"logical-abbreviations", "Enable logical abbreviations">;
68786878
defm implicit_none : OptInFC1FFlag<"implicit-none", "No implicit typing allowed unless overridden by IMPLICIT statements">;
6879+
defm implicit_none_ext : OptInFC1FFlag<"implicit-none-ext", "No implicit externals allowed">;
68796880
defm underscoring : OptInFC1FFlag<"underscoring", "Appends one trailing underscore to external names">;
68806881
defm ppc_native_vec_elem_order: BoolOptionWithoutMarshalling<"f", "ppc-native-vector-element-order",
68816882
PosFlag<SetTrue, [], [ClangOption], "Specifies PowerPC native vector element order (default)">,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
4242
options::OPT_fopenacc,
4343
options::OPT_finput_charset_EQ,
4444
options::OPT_fimplicit_none,
45+
options::OPT_fimplicit_none_ext,
4546
options::OPT_fno_implicit_none,
4647
options::OPT_fbackslash,
4748
options::OPT_fno_backslash,

flang/include/flang/Common/Fortran-features.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
3434
EquivalenceSameNonSequence, AdditionalIntrinsics, AnonymousParents,
3535
OldLabelDoEndStatements, LogicalIntegerAssignment, EmptySourceFile,
3636
ProgramReturn, ImplicitNoneTypeNever, ImplicitNoneTypeAlways,
37-
ForwardRefImplicitNone, OpenAccessAppend, BOZAsDefaultInteger,
38-
DistinguishableSpecifics, DefaultSave, PointerInSeqType, NonCharacterFormat,
39-
SaveMainProgram, SaveBigMainProgramVariables,
40-
DistinctArrayConstructorLengths, PPCVector, RelaxedIntentInChecking,
41-
ForwardRefImplicitNoneData, NullActualForAllocatable,
42-
ActualIntegerConvertedToSmallerKind, HollerithOrCharacterAsBOZ,
43-
BindingAsProcedure, StatementFunctionExtensions,
37+
ImplicitNoneExternal, ForwardRefImplicitNone, OpenAccessAppend,
38+
BOZAsDefaultInteger, DistinguishableSpecifics, DefaultSave,
39+
PointerInSeqType, NonCharacterFormat, SaveMainProgram,
40+
SaveBigMainProgramVariables, DistinctArrayConstructorLengths, PPCVector,
41+
RelaxedIntentInChecking, ForwardRefImplicitNoneData,
42+
NullActualForAllocatable, ActualIntegerConvertedToSmallerKind,
43+
HollerithOrCharacterAsBOZ, BindingAsProcedure, StatementFunctionExtensions,
4444
UseGenericIntrinsicWhenSpecificDoesntMatch, DataStmtExtensions,
4545
RedundantContiguous, RedundantAttribute, InitBlankCommon,
4646
EmptyBindCDerivedType, MiscSourceExtensions, AllocateToOtherLength,

flang/lib/Common/Fortran-features.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ LanguageFeatureControl::LanguageFeatureControl() {
2222
disable_.set(LanguageFeature::CudaUnified);
2323
disable_.set(LanguageFeature::ImplicitNoneTypeNever);
2424
disable_.set(LanguageFeature::ImplicitNoneTypeAlways);
25+
disable_.set(LanguageFeature::ImplicitNoneExternal);
2526
disable_.set(LanguageFeature::DefaultSave);
2627
disable_.set(LanguageFeature::SaveMainProgram);
2728
// These features, if enabled, conflict with valid standard usage,

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,12 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
740740
args.hasFlag(clang::driver::options::OPT_fimplicit_none,
741741
clang::driver::options::OPT_fno_implicit_none, false));
742742

743+
// -f{no-}implicit-none-ext
744+
opts.features.Enable(
745+
Fortran::common::LanguageFeature::ImplicitNoneExternal,
746+
args.hasFlag(clang::driver::options::OPT_fimplicit_none_ext,
747+
clang::driver::options::OPT_fno_implicit_none_ext, false));
748+
743749
// -f{no-}backslash
744750
opts.features.Enable(Fortran::common::LanguageFeature::BackslashEscapes,
745751
args.hasFlag(clang::driver::options::OPT_fbackslash,

flang/lib/Semantics/resolve-names.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class ImplicitRules {
8787
bool inheritFromParent_{false}; // look in parent if not specified here
8888
bool isImplicitNoneType_{
8989
context_.IsEnabled(common::LanguageFeature::ImplicitNoneTypeAlways)};
90-
bool isImplicitNoneExternal_{false};
90+
bool isImplicitNoneExternal_{
91+
context_.IsEnabled(common::LanguageFeature::ImplicitNoneExternal)};
9192
// map_ contains the mapping between letters and types that were defined
9293
// by the IMPLICIT statements of the related scope. It does not contain
9394
// the default Fortran mappings nor the mapping defined in parents.

flang/test/Semantics/implicit17.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1 -fimplicit-none-ext
2+
external x
3+
integer :: f, i, arr(1) = [0]
4+
call x
5+
!ERROR: 'y' is an external procedure without the EXTERNAL attribute in a scope with IMPLICIT NONE(EXTERNAL)
6+
call y
7+
!ERROR: 'f' is an external procedure without the EXTERNAL attribute in a scope with IMPLICIT NONE(EXTERNAL)
8+
i = f()
9+
block
10+
!ERROR: 'z' is an external procedure without the EXTERNAL attribute in a scope with IMPLICIT NONE(EXTERNAL)
11+
call z
12+
end block
13+
print *, arr(1) ! no error
14+
end

0 commit comments

Comments
 (0)