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

Kajetan Puchalski via flang-commits flang-commits at lists.llvm.org
Tue Jun 3 03:45:35 PDT 2025


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

>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 1/2] [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

>From 244e0297bcfb2ad9adac0fdf578a54855e5bb8bf Mon Sep 17 00:00:00 2001
From: Kajetan Puchalski <kajetan.puchalski at arm.com>
Date: Mon, 2 Jun 2025 16:30:42 +0000
Subject: [PATCH 2/2] Fix tests, re-enable implicit typing in Post, handle
 DeclarativeConstructs

---
 flang/lib/Semantics/resolve-names.cpp            |   5 +++++
 .../Semantics/OpenMP/declare-simd-linear.f90     |  10 ++--------
 .../test/Semantics/OpenMP/declare-simd-linear.o  | Bin 0 -> 1048 bytes
 flang/test/Semantics/OpenMP/linear-clause01.f90  |   2 --
 4 files changed, 7 insertions(+), 10 deletions(-)
 create mode 100644 flang/test/Semantics/OpenMP/declare-simd-linear.o

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 93096442329e9..82b389f4f6271 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1516,6 +1516,9 @@ class OmpVisitor : public virtual DeclarationVisitor {
     SkipImplicitTyping(true);
     return true;
   }
+  void Post(const parser::OpenMPDeclareSimdConstruct &x) {
+    SkipImplicitTyping(false);
+  }
 
   bool Pre(const parser::OmpInitializerProc &x) {
     auto &procDes = std::get<parser::ProcedureDesignator>(x.t);
@@ -1662,9 +1665,11 @@ class OmpVisitor : public virtual DeclarationVisitor {
   }
   bool Pre(const parser::OpenMPDeclarativeConstruct &x) {
     AddOmpSourceRange(x.source);
+    SkipImplicitTyping(true);
     return true;
   }
   void Post(const parser::OpenMPDeclarativeConstruct &) {
+    SkipImplicitTyping(false);
     messageHandler().set_currStmtSource(std::nullopt);
   }
   bool Pre(const parser::OpenMPDepobjConstruct &x) {
diff --git a/flang/test/Semantics/OpenMP/declare-simd-linear.f90 b/flang/test/Semantics/OpenMP/declare-simd-linear.f90
index 681cac7f02e0f..c534f23fcb3da 100644
--- a/flang/test/Semantics/OpenMP/declare-simd-linear.f90
+++ b/flang/test/Semantics/OpenMP/declare-simd-linear.f90
@@ -3,16 +3,10 @@
 
 module mod
 contains
-subroutine sub(m,i)
+subroutine test(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
+  integer*8 i
   i=i+2
 end subroutine
 end module
diff --git a/flang/test/Semantics/OpenMP/declare-simd-linear.o b/flang/test/Semantics/OpenMP/declare-simd-linear.o
new file mode 100644
index 0000000000000000000000000000000000000000..4f46d461cc7b9d9d571eaea164a75cc7adb75884
GIT binary patch
literal 1048
zcmb`FJ5R$f5XUbRXh8 at e280BH4h%3fX-XetL6LZihj at qyq$;E?1(K#p+zJp9pMh_{
z$TxtI55NEmGb1Y-OmI$Z65JIJzW at F1&gWcwy|l61r6?el0{0Mkf&z?oMcNFd2`S9{
zUVxXkBz(Om&977++`OYkcJr7hze3fq>c{C8 at q-hup3doNR?ViTwVLM=?aVrDH0`Xe
zIZn$Bw at kzLPKix3K5>W at 5UpKa)Jt}$Xz0aiUY|7#!#*nJ^*K^0kWwL!(wMVz#46-w
z!dngTYbuw!pj=HTV*``G*eK`Y%q|X!G)^NkkFpy+z9SN;1jL5GaeG#sd^L<GqGGPv
zyr+ZrBN>jJAKnw0uszu5PnW54P$@a5P~O>ey~;Kv0R`3eT$j{Q)ICbnm970uKrQ<W
zRGg`$l3KayTP}g+wcSmx(sT$+RX`1>Ppu=g7cR5^vexmG&aVe};E(G->LS0nZj3Y5
zE9IHo7jqF|mLFdu=&<^19HKttenaA-zp#@S7doE$6nA1;&du}sKmQEbGq0JB)iRlq
od<}i}O{T<ec_Z<jlNe{ONz at CzhfMCxj{0O9uDiDRov~d10}fhUHUIzs

literal 0
HcmV?d00001

diff --git a/flang/test/Semantics/OpenMP/linear-clause01.f90 b/flang/test/Semantics/OpenMP/linear-clause01.f90
index 286def2dba119..2f499ac892a48 100644
--- a/flang/test/Semantics/OpenMP/linear-clause01.f90
+++ b/flang/test/Semantics/OpenMP/linear-clause01.f90
@@ -24,12 +24,10 @@ subroutine linear_clause_02(arg_01, arg_02)
     !$omp declare simd linear(uval(arg_02))
     integer, value, intent(in) :: arg_02
 
-    !ERROR: The list item 'var' specified without the REF 'linear-modifier' must be of INTEGER type
     !ERROR: If the `linear-modifier` is REF or UVAL, the list item 'var' must be a dummy argument without the VALUE attribute
     !ERROR: The list item `var` must be a dummy argument
     !ERROR: The list item `var` in a LINEAR clause must not be Cray Pointer or a variable with POINTER attribute
     !$omp declare simd linear(uval(var))
-    !ERROR: The type of 'var' has already been implicitly declared
     integer, pointer :: var
 end subroutine linear_clause_02
 



More information about the flang-commits mailing list