Skip to content

Commit 3c3094b

Browse files
authored
[flang] Ensure directive sentinels are in cols 1-5 in pp output (#119406)
Preprocessor output is intended to be valid fixed form.
1 parent d866005 commit 3c3094b

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

flang/lib/Parser/parsing.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ void Parsing::EmitPreprocessedSource(
159159
// which signifies a comment (directive) in both source forms.
160160
inDirective = true;
161161
}
162-
if (inDirective && directive.size() < directiveNameLength &&
163-
IsLetter(ch)) {
162+
bool inDirectiveSentinel{
163+
inDirective && directive.size() < directiveNameLength};
164+
if (inDirectiveSentinel && IsLetter(ch)) {
164165
directive += getOriginalChar(ch);
165166
}
166167

@@ -211,7 +212,8 @@ void Parsing::EmitPreprocessedSource(
211212
out << ' ';
212213
}
213214
}
214-
if (!inContinuation && position && position->column <= 72 && ch != ' ') {
215+
if (!inContinuation && !inDirectiveSentinel && position &&
216+
position->column <= 72 && ch != ' ') {
215217
// Preserve original indentation
216218
for (; column < position->column; ++column) {
217219
out << ' ';

flang/test/Preprocessing/pp132.f90

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
! RUN: %flang -E -fopenmp -fopenacc %s 2>&1 | FileCheck %s
2-
! CHECK: !$OMP parallel default(shared) private(super_very_long_name_for_the_va&
3-
! CHECK: !$OMP&riable)
4-
! CHECK: !$acc data copyin(super_very_long_name_for_the_variable, another_super&
5-
! CHECK: !$acc&_wordy_variable_to_test)
6-
! Test correct continuations in compiler directives
1+
! RUN: %flang -E -fopenmp -fopenacc %s 2>&1 | FileCheck --strict-whitespace %s
2+
! CHECK: {{^}}!$OMP parallel default(shared) private(super_very_long_name_for_the_va&
3+
! CHECK-NEXT: {{^}}!$OMP&riable)
4+
! CHECK: {{^}}!$acc data copyin(super_very_long_name_for_the_variable, another_super&
5+
! CHECK-NEXT: {{^}}!$acc&_wordy_variable_to_test)
6+
! CHECK: {{^}}!$OMP something something
7+
! Test correct continuations in compiler directives and left-alignment of sentinels
78
subroutine foo
89
integer :: super_very_long_name_for_the_variable
910
integer :: another_super_wordy_variable_to_test
@@ -15,4 +16,6 @@ subroutine foo
1516

1617
!$acc data copyin(super_very_long_name_for_the_variable, another_super_wordy_variable_to_test)
1718
!$acc end data
19+
20+
!$OMP something something
1821
end subroutine foo

0 commit comments

Comments
 (0)