[flang-commits] [flang] 11d8454 - [flang][OpenMP] Skip implicit typing for OpenMPDeclarativeConstruct (#142415)

via flang-commits flang-commits at lists.llvm.org
Wed Jun 4 06:18:30 PDT 2025


Author: Kajetan Puchalski
Date: 2025-06-04T14:18:26+01:00
New Revision: 11d84546265840f419a6cca81c362e4e5264300b

URL: https://github.com/llvm/llvm-project/commit/11d84546265840f419a6cca81c362e4e5264300b
DIFF: https://github.com/llvm/llvm-project/commit/11d84546265840f419a6cca81c362e4e5264300b.diff

LOG: [flang][OpenMP] Skip implicit typing for OpenMPDeclarativeConstruct (#142415)

DeclareSimdConstruct (and other declarative constructs) can currently
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 OpenMPDeclarativeConstruct. Fixes issue #140754.

---------

Signed-off-by: Kajetan Puchalski <kajetan.puchalski at arm.com>

Added: 
    flang/test/Semantics/OpenMP/declare-simd-linear.f90

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/OpenMP/linear-clause01.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 7bea6fdb00e55..297007bcbde67 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1661,9 +1661,14 @@ class OmpVisitor : public virtual DeclarationVisitor {
   }
   bool Pre(const parser::OpenMPDeclarativeConstruct &x) {
     AddOmpSourceRange(x.source);
+    // Without skipping implicit typing, declarative constructs
+    // can implicitly declare variables instead of only using the
+    // ones already declared in the Fortran sources.
+    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
new file mode 100644
index 0000000000000..2a6ef0081996c
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/declare-simd-linear.f90
@@ -0,0 +1,12 @@
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+! Test declare simd with linear clause does not cause an implicit declaration of i
+
+module mod
+contains
+subroutine test(i)
+!$omp declare simd linear(i:1)
+  implicit none
+  integer*8 i
+  i=i+2
+end subroutine
+end module

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