[flang-commits] [flang] 7964096 - [flang] Downgrade error to warning for IGNORE_TKR case (#180994)
via flang-commits
flang-commits at lists.llvm.org
Wed Feb 11 15:47:26 PST 2026
Author: Peter Klausler
Date: 2026-02-11T15:47:22-08:00
New Revision: 79640967dd75739c097a928663fbcf726985d65e
URL: https://github.com/llvm/llvm-project/commit/79640967dd75739c097a928663fbcf726985d65e
DIFF: https://github.com/llvm/llvm-project/commit/79640967dd75739c097a928663fbcf726985d65e.diff
LOG: [flang] Downgrade error to warning for IGNORE_TKR case (#180994)
The IGNORE_TKR directive has meaning only in the specification part of a
subroutine or function subprogram or interface. Presently, it is an
error when the directive appears elsewhere.
At user request, this patch softens the error to a warning for when this
directive appears in a program unit other than a subroutine or function,
and when it appears in a subroutine or function subprogram outside the
specification part of its top scope.
Added:
Modified:
flang/include/flang/Support/Fortran-features.h
flang/lib/Semantics/resolve-names.cpp
flang/lib/Support/Fortran-features.cpp
flang/test/Semantics/OpenMP/compiler-directive.f90
flang/test/Semantics/ignore_tkr01.f90
Removed:
################################################################################
diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
index fa300da48ffe1..f6c963d05fd54 100644
--- a/flang/include/flang/Support/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -81,7 +81,8 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
NullActualForDefaultIntentAllocatable, UseAssociationIntoSameNameSubprogram,
HostAssociatedIntentOutInSpecExpr, NonVolatilePointerToVolatile,
RealConstantWidening, VolatileOrAsynchronousTemporary, UnusedVariable,
- UsedUndefinedVariable, BadValueInDeadCode, AssumedTypeSizeDummy)
+ UsedUndefinedVariable, BadValueInDeadCode, AssumedTypeSizeDummy,
+ MisplacedIgnoreTKR)
using LanguageFeatures = EnumSet<LanguageFeature, LanguageFeature_enumSize>;
using UsageWarnings = EnumSet<UsageWarning, UsageWarning_enumSize>;
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 164a9bedcc393..9036defa0c711 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -10239,16 +10239,18 @@ void ResolveNamesVisitor::Post(const parser::CompilerDirective &x) {
}
if (const auto *tkr{
std::get_if<std::list<parser::CompilerDirective::IgnoreTKR>>(&x.u)}) {
- if (currScope().IsTopLevel() ||
- GetProgramUnitContaining(currScope()).kind() !=
- Scope::Kind::Subprogram) {
+ if (currScope().IsTopLevel()) {
Say(x.source,
- "!DIR$ IGNORE_TKR directive must appear in a subroutine or function"_err_en_US);
+ "!DIR$ IGNORE_TKR directive must appear in a program unit"_err_en_US);
return;
- }
- if (!inSpecificationPart_) {
- Say(x.source,
- "!DIR$ IGNORE_TKR directive must appear in the specification part"_err_en_US);
+ } else if (GetProgramUnitContaining(currScope()).kind() !=
+ Scope::Kind::Subprogram) {
+ context().Warn(common::UsageWarning::MisplacedIgnoreTKR, x.source,
+ "!DIR$ IGNORE_TKR directive should appear in a subroutine or function"_warn_en_US);
+ return;
+ } else if (!inSpecificationPart_) {
+ context().Warn(common::UsageWarning::MisplacedIgnoreTKR, x.source,
+ "!DIR$ IGNORE_TKR directive should appear in the specification part"_warn_en_US);
return;
}
if (tkr->empty()) {
diff --git a/flang/lib/Support/Fortran-features.cpp b/flang/lib/Support/Fortran-features.cpp
index 521bf35294154..83d1affba5ed2 100644
--- a/flang/lib/Support/Fortran-features.cpp
+++ b/flang/lib/Support/Fortran-features.cpp
@@ -152,6 +152,7 @@ LanguageFeatureControl::LanguageFeatureControl() {
warnLanguage_.set(LanguageFeature::SavedLocalInSpecExpr);
warnLanguage_.set(LanguageFeature::NullActualForAllocatable);
warnUsage_.set(UsageWarning::BadValueInDeadCode);
+ warnUsage_.set(UsageWarning::MisplacedIgnoreTKR);
}
std::optional<LanguageControlFlag> LanguageFeatureControl::FindWarning(
diff --git a/flang/test/Semantics/OpenMP/compiler-directive.f90 b/flang/test/Semantics/OpenMP/compiler-directive.f90
index 5d3e9bae27fd8..e882f26c85b53 100644
--- a/flang/test/Semantics/OpenMP/compiler-directive.f90
+++ b/flang/test/Semantics/OpenMP/compiler-directive.f90
@@ -1,7 +1,7 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
! CompilerDirective with openmp tests
-!ERROR: !DIR$ IGNORE_TKR directive must appear in a subroutine or function
+!ERROR: !DIR$ IGNORE_TKR directive must appear in a program unit
!dir$ ignore_tkr
program main
diff --git a/flang/test/Semantics/ignore_tkr01.f90 b/flang/test/Semantics/ignore_tkr01.f90
index d069c97331bf6..c1e1e5d25cd56 100644
--- a/flang/test/Semantics/ignore_tkr01.f90
+++ b/flang/test/Semantics/ignore_tkr01.f90
@@ -1,12 +1,12 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
! !DIR$ IGNORE_TKR tests
-!ERROR: !DIR$ IGNORE_TKR directive must appear in a subroutine or function
+!ERROR: !DIR$ IGNORE_TKR directive must appear in a program unit
!dir$ ignore_tkr
module m
-!ERROR: !DIR$ IGNORE_TKR directive must appear in a subroutine or function
+!WARNING: !DIR$ IGNORE_TKR directive should appear in a subroutine or function [-Wmisplaced-ignore-tkr]
!dir$ ignore_tkr
interface
@@ -115,7 +115,7 @@ subroutine t16(x)
subroutine t17(x)
real x
x = x + 1.
-!ERROR: !DIR$ IGNORE_TKR directive must appear in the specification part
+!WARNING: !DIR$ IGNORE_TKR directive should appear in the specification part [-Wmisplaced-ignore-tkr]
!dir$ ignore_tkr x
end
@@ -173,7 +173,7 @@ module subroutine t24(x)
program test
-!ERROR: !DIR$ IGNORE_TKR directive must appear in a subroutine or function
+!WARNING: !DIR$ IGNORE_TKR directive should appear in a subroutine or function [-Wmisplaced-ignore-tkr]
!dir$ ignore_tkr
use m
More information about the flang-commits
mailing list