Skip to content

Commit ce4a119

Browse files
mrkajetanprorth
authored andcommitted
[flang][OpenMP] Skip implicit typing for OpenMPDeclarativeConstruct (llvm#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 llvm#140754. --------- Signed-off-by: Kajetan Puchalski <[email protected]>
1 parent 7d0359e commit ce4a119

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,14 @@ class OmpVisitor : public virtual DeclarationVisitor {
16611661
}
16621662
bool Pre(const parser::OpenMPDeclarativeConstruct &x) {
16631663
AddOmpSourceRange(x.source);
1664+
// Without skipping implicit typing, declarative constructs
1665+
// can implicitly declare variables instead of only using the
1666+
// ones already declared in the Fortran sources.
1667+
SkipImplicitTyping(true);
16641668
return true;
16651669
}
16661670
void Post(const parser::OpenMPDeclarativeConstruct &) {
1671+
SkipImplicitTyping(false);
16671672
messageHandler().set_currStmtSource(std::nullopt);
16681673
}
16691674
bool Pre(const parser::OpenMPDepobjConstruct &x) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp
2+
! Test declare simd with linear clause does not cause an implicit declaration of i
3+
4+
module mod
5+
contains
6+
subroutine test(i)
7+
!$omp declare simd linear(i:1)
8+
implicit none
9+
integer*8 i
10+
i=i+2
11+
end subroutine
12+
end module

flang/test/Semantics/OpenMP/linear-clause01.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ subroutine linear_clause_02(arg_01, arg_02)
2424
!$omp declare simd linear(uval(arg_02))
2525
integer, value, intent(in) :: arg_02
2626

27-
!ERROR: The list item 'var' specified without the REF 'linear-modifier' must be of INTEGER type
2827
!ERROR: If the `linear-modifier` is REF or UVAL, the list item 'var' must be a dummy argument without the VALUE attribute
2928
!ERROR: The list item `var` must be a dummy argument
3029
!ERROR: The list item `var` in a LINEAR clause must not be Cray Pointer or a variable with POINTER attribute
3130
!$omp declare simd linear(uval(var))
32-
!ERROR: The type of 'var' has already been implicitly declared
3331
integer, pointer :: var
3432
end subroutine linear_clause_02
3533

0 commit comments

Comments
 (0)