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