[flang-commits] [flang] 3c3094b - [flang] Ensure directive sentinels are in cols 1-5 in pp output (#119406)

via flang-commits flang-commits at lists.llvm.org
Mon Dec 16 06:25:43 PST 2024


Author: macurtis-amd
Date: 2024-12-16T08:25:37-06:00
New Revision: 3c3094b60d3587b1db8ef35b3bf54e73ac5894d9

URL: https://github.com/llvm/llvm-project/commit/3c3094b60d3587b1db8ef35b3bf54e73ac5894d9
DIFF: https://github.com/llvm/llvm-project/commit/3c3094b60d3587b1db8ef35b3bf54e73ac5894d9.diff

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

Preprocessor output is intended to be valid fixed form.

Added: 
    

Modified: 
    flang/lib/Parser/parsing.cpp
    flang/test/Preprocessing/pp132.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/parsing.cpp b/flang/lib/Parser/parsing.cpp
index e2381a6b8ffa3e..8fcac7b3cacb1c 100644
--- a/flang/lib/Parser/parsing.cpp
+++ b/flang/lib/Parser/parsing.cpp
@@ -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);
       }
 
@@ -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 << ' ';

diff  --git a/flang/test/Preprocessing/pp132.f90 b/flang/test/Preprocessing/pp132.f90
index 418defb2d553ce..76ffa3e21c1370 100644
--- a/flang/test/Preprocessing/pp132.f90
+++ b/flang/test/Preprocessing/pp132.f90
@@ -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
@@ -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


        


More information about the flang-commits mailing list