[flang-commits] [flang] [flang][OpenMP] Warn that declare simd in an interface body has no effect (PR #199248)
via flang-commits
flang-commits at lists.llvm.org
Fri May 22 11:19:51 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
@llvm/pr-subscribers-flang-openmp
Author: Carlos Seo (ceseo)
<details>
<summary>Changes</summary>
Follow-up to the crash fix for #<!-- -->192581. A DECLARE SIMD directive may legally appear in the specification part of an interface body, but it applies to the external procedure being declared rather than to any definition in this compilation. Flang does not propagate the directive to callers, so it has no effect and is silently dropped during lowering.
Detect this in semantics by checking whether the program unit containing the directive is an interface body (SubprogramDetails::isInterface()) and emit an -Wopenmp-usage warning so the user knows the directive is ignored.
Updates #<!-- -->192581
---
Full diff: https://github.com/llvm/llvm-project/pull/199248.diff
3 Files Affected:
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+13)
- (added) flang/test/Semantics/OpenMP/declare-simd-interface-body.f90 (+29)
- (modified) flang/test/Semantics/OpenMP/linear-clause03.f90 (+1)
``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index 512de68d63e7e..856b342fd350f 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1643,6 +1643,19 @@ void OmpStructureChecker::Enter(const parser::OmpDeclareSimdDirective &x) {
const Scope &containingScope = context_.FindScope(dirName.source);
const Scope &progUnitScope = GetProgramUnitContaining(containingScope);
+ // A DECLARE SIMD directive may legally appear in an interface body, but it
+ // applies to the external procedure being declared rather than to any
+ // definition in this compilation. Flang does not propagate the directive to
+ // callers, so it has no effect; warn the user instead of silently ignoring
+ // it. See https://github.com/llvm/llvm-project/issues/192581.
+ if (const Symbol *progUnitSym{progUnitScope.symbol()}) {
+ if (const auto *subpDetails{progUnitSym->detailsIf<SubprogramDetails>()};
+ subpDetails && subpDetails->isInterface()) {
+ context_.Warn(common::UsageWarning::OpenMPUsage, dirName.source,
+ "'DECLARE SIMD' directive in an interface body has no effect"_warn_en_US);
+ }
+ }
+
for (const parser::OmpClause &clause : x.v.Clauses().v) {
const auto *u = std::get_if<parser::OmpClause::Uniform>(&clause.u);
if (!u) {
diff --git a/flang/test/Semantics/OpenMP/declare-simd-interface-body.f90 b/flang/test/Semantics/OpenMP/declare-simd-interface-body.f90
new file mode 100644
index 0000000000000..624afa8852f2e
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/declare-simd-interface-body.f90
@@ -0,0 +1,29 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp -Werror
+! A DECLARE SIMD directive in an interface body applies to the external
+! procedure being declared, not to any definition in this compilation, so
+! Flang ignores it. Warn that it has no effect.
+! See https://github.com/llvm/llvm-project/issues/192581.
+
+interface
+ subroutine add2(i)
+ !WARNING: 'DECLARE SIMD' directive in an interface body has no effect [-Wopenmp-usage]
+ !$omp declare simd(add2) linear(i:1)
+ integer :: i
+ end subroutine
+
+ subroutine add3(i)
+ !WARNING: 'DECLARE SIMD' directive in an interface body has no effect [-Wopenmp-usage]
+ !$omp declare simd
+ integer :: i
+ end subroutine
+end interface
+
+contains
+
+! A DECLARE SIMD in an actual definition is fine and must not warn.
+subroutine sub(i)
+!$omp declare simd(sub) linear(i:1)
+ integer :: i
+ i = i + 1
+end subroutine
+end
diff --git a/flang/test/Semantics/OpenMP/linear-clause03.f90 b/flang/test/Semantics/OpenMP/linear-clause03.f90
index 7143db5927d46..3c89f2e93b4ac 100644
--- a/flang/test/Semantics/OpenMP/linear-clause03.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause03.f90
@@ -6,6 +6,7 @@ module m
subroutine f(x, y)
integer, allocatable :: x
integer :: y
+ !WARNING: 'DECLARE SIMD' directive in an interface body has no effect [-Wopenmp-usage]
!$omp declare simd(f) linear(ref(x) : 1) linear(uval(y))
end
end interface
``````````
</details>
https://github.com/llvm/llvm-project/pull/199248
More information about the flang-commits
mailing list