Skip to content

Commit c2e41be

Browse files
authored
[flang][Parser] Add whitespace token after the sentinel in fixed form (#148825)
Fixes #148386 The first time the line was classified (using `Prescanner::ClassifyLine(const char *)`) the line was correctly classified as a compiler directive. But then later on the token form is invoked (`Prescanner::ClassifyLine(TokenSequence, Provenance)`). This one incorrectly classified the line as a comment because there was no whitespace token right after the sentinel. This fixes the issue by ensuring this whitespace is added.
1 parent f5c676d commit c2e41be

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

flang/lib/Parser/prescan.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ void Prescanner::Statement() {
179179
EmitChar(tokens, *sp);
180180
}
181181
if (inFixedForm_) {
182-
while (column_ < 6) {
182+
// We need to add the whitespace after the sentinel because otherwise
183+
// the line cannot be re-categorised as a compiler directive.
184+
while (column_ <= 6) {
183185
if (*at_ == '\t') {
184186
tabInCurrentLine_ = true;
185187
++at_;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=50 %s | FileCheck %s
2+
3+
#define OMP_TARGET .true.
4+
#define OMP_SIMD .false.
5+
program test
6+
implicit none
7+
integer i,j,n
8+
n = 100
9+
! CHECK: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: TARGET TEAMS DISTRIBUTE PARALLEL&
10+
! CHECK: !$OMP& DO) DEFAULT(TARGET TEAMS LOOP)
11+
!$omp metadirective
12+
!$omp& when(user={condition(OMP_TARGET.or.OMP_SIMD)}:
13+
!$omp& target teams distribute parallel do )
14+
!$omp& default(target teams loop)
15+
do i=0,n
16+
do j=0,n
17+
write(*,*) "Test"
18+
enddo
19+
enddo
20+
return
21+
end program

0 commit comments

Comments
 (0)