Skip to content

[FLANG][OPENMP] Fix handling of continuation lines in mixed OpenMP an… #120714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,14 +1289,18 @@ const char *Prescanner::FreeFormContinuationLine(bool ampersand) {
return nullptr;
}
p = SkipWhiteSpace(p);
if (InCompilerDirective()) {
if (*p++ != '!') {
return nullptr;
}
for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
if (*s != ToLowerCaseLetter(*p)) {
return nullptr;
if (*p == '!') {
++p;
if (InCompilerDirective()) {
for (const char *s{directiveSentinel_}; *s != '\0'; ++p, ++s) {
if (*s != ToLowerCaseLetter(*p)) {
return nullptr;
}
}
} else if (features_.IsEnabled(LanguageFeature::OpenMP) && *p == '$') {
++p;
} else {
return nullptr;
}
p = SkipWhiteSpace(p);
if (*p == '&') {
Expand Down
44 changes: 44 additions & 0 deletions flang/test/Parser/OpenMP/compiler-directive-continuation.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
! RUN: %flang_fc1 -fopenmp -E %s 2>&1 | FileCheck %s --check-prefix=CHECK-OMP
! RUN: %flang_fc1 -E %s 2>&1 | FileCheck %s


! Test in mixed way, i.e., combination of Fortran free source form
! and free source form with conditional compilation sentinel.
! CHECK-LABEL: subroutine mixed_form1()
! CHECK-OMP: i = 1 +100+ 1000+ 10 + 1 +1000000000 + 1000000
! CHECK: i = 1 + 10 + 10000 + 1000000
subroutine mixed_form1()
i = 1 &
!$+100&
!$&+ 1000&
&+ 10 + 1&
!$& +100000&
&0000 + 1000000
end subroutine


! Testing continuation lines in only Fortran Free form Source
! CHECK-LABEL: subroutine mixed_form2()
! CHECK-OMP: i = 1 +10 +100 + 1000 + 10000
! CHECK: i = 1 +10 +100 + 1000 + 10000
subroutine mixed_form2()
i = 1 &
+10 &
&+100
& + 1000 &
+ 10000
end subroutine


! Testing continuation line in only free source form conditional compilation sentinel.
! CHECK-LABEL: subroutine mixed_form3()
! CHECK-OMP: i=0
! CHECK-OMP: i = 1 +10 +100+1000
subroutine mixed_form3()
!$ i=0
!$ i = 1 &
!$ & +10 &
!$&+100&
!$ +1000
end subroutine

Loading