[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@arm.com>
This commit is contained in:
Kajetan Puchalski
2025-06-04 14:18:26 +01:00
committed by GitHub
parent 57500cd6a0
commit 11d8454626
3 changed files with 17 additions and 2 deletions

View File

@@ -1661,9 +1661,14 @@ public:
}
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) {

View File

@@ -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

View File

@@ -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