[flang-commits] [flang] [flang][OpenMP] Skip implicit typing for DeclareSimdConstruct (PR #142415)

Kajetan Puchalski via flang-commits flang-commits at lists.llvm.org
Mon Jun 2 08:44:08 PDT 2025


https://github.com/mrkajetanp created https://github.com/llvm/llvm-project/pull/142415

DeclareSimdConstruct currently can implicitly declare variables regardless of whether the source code contains "implicit none" or not. This causes semantic analysis issues if the implicit type does not match the declared type. To solve it, skip implicit typing for declare simd. Fixes issue #140754.

>From 6a60b053e8cff374804c9e598e5e222466300061 Mon Sep 17 00:00:00 2001
From: Kajetan Puchalski <kajetan.puchalski at arm.com>
Date: Mon, 2 Jun 2025 15:28:51 +0000
Subject: [PATCH] [flang][OpenMP] Skip implicit typing for DeclareSimdConstruct

DeclareSimdConstruct currently can implicitly declare variables
regardless of whether the source code contains "implicit none" or not.
This causes semantic analysis issues if the implicit type does not match
the declared type. To solve it, skip implicit typing for declare simd.
Fixes issue #140754.

Signed-off-by: Kajetan Puchalski <kajetan.puchalski at arm.com>
---
 flang/lib/Semantics/resolve-names.cpp          |  1 +
 .../Semantics/OpenMP/declare-simd-linear.f90   | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 flang/test/Semantics/OpenMP/declare-simd-linear.f90

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 7bea6fdb00e55..93096442329e9 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1513,6 +1513,7 @@ class OmpVisitor : public virtual DeclarationVisitor {
 
   bool Pre(const parser::OpenMPDeclareSimdConstruct &x) {
     AddOmpSourceRange(x.source);
+    SkipImplicitTyping(true);
     return true;
   }
 
diff --git a/flang/test/Semantics/OpenMP/declare-simd-linear.f90 b/flang/test/Semantics/OpenMP/declare-simd-linear.f90
new file mode 100644
index 0000000000000..681cac7f02e0f
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/declare-simd-linear.f90
@@ -0,0 +1,18 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+! Test declare simd with linear clause
+
+module mod
+contains
+subroutine sub(m,i)
+!$omp declare simd linear(i:1)
+  implicit none
+  integer*8 i,n
+  value i
+  parameter(n=10000)
+  real*4 a,b,m
+  common/com1/a(n)
+  common/com2/b(n)
+  a(i) = b(i) + m
+  i=i+2
+end subroutine
+end module



More information about the flang-commits mailing list