Skip to content

[flang] Ensure directive sentinels are in cols 1-5 in pp output #119406

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 1 commit into from
Dec 16, 2024
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
8 changes: 5 additions & 3 deletions flang/lib/Parser/parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ void Parsing::EmitPreprocessedSource(
// which signifies a comment (directive) in both source forms.
inDirective = true;
}
if (inDirective && directive.size() < directiveNameLength &&
IsLetter(ch)) {
bool inDirectiveSentinel{
inDirective && directive.size() < directiveNameLength};
if (inDirectiveSentinel && IsLetter(ch)) {
directive += getOriginalChar(ch);
}

Expand Down Expand Up @@ -211,7 +212,8 @@ void Parsing::EmitPreprocessedSource(
out << ' ';
}
}
if (!inContinuation && position && position->column <= 72 && ch != ' ') {
if (!inContinuation && !inDirectiveSentinel && position &&
position->column <= 72 && ch != ' ') {
// Preserve original indentation
for (; column < position->column; ++column) {
out << ' ';
Expand Down
15 changes: 9 additions & 6 deletions flang/test/Preprocessing/pp132.f90
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
! RUN: %flang -E -fopenmp -fopenacc %s 2>&1 | FileCheck %s
! CHECK: !$OMP parallel default(shared) private(super_very_long_name_for_the_va&
! CHECK: !$OMP&riable)
! CHECK: !$acc data copyin(super_very_long_name_for_the_variable, another_super&
! CHECK: !$acc&_wordy_variable_to_test)
! Test correct continuations in compiler directives
! RUN: %flang -E -fopenmp -fopenacc %s 2>&1 | FileCheck --strict-whitespace %s
! CHECK: {{^}}!$OMP parallel default(shared) private(super_very_long_name_for_the_va&
! CHECK-NEXT: {{^}}!$OMP&riable)
! CHECK: {{^}}!$acc data copyin(super_very_long_name_for_the_variable, another_super&
! CHECK-NEXT: {{^}}!$acc&_wordy_variable_to_test)
! CHECK: {{^}}!$OMP something something
! Test correct continuations in compiler directives and left-alignment of sentinels
subroutine foo
integer :: super_very_long_name_for_the_variable
integer :: another_super_wordy_variable_to_test
Expand All @@ -15,4 +16,6 @@ subroutine foo

!$acc data copyin(super_very_long_name_for_the_variable, another_super_wordy_variable_to_test)
!$acc end data

!$OMP something something
end subroutine foo
Loading