[flang-commits] [flang] 7a15447 - [Flang] bug: preprocessor increases backslash to double backslash (#191512)

via flang-commits flang-commits at lists.llvm.org
Wed Apr 22 02:37:00 PDT 2026


Author: SunilKuravinakop
Date: 2026-04-22T15:06:56+05:30
New Revision: 7a154470f51fef202a9a14e0618344a6a419579a

URL: https://github.com/llvm/llvm-project/commit/7a154470f51fef202a9a14e0618344a6a419579a
DIFF: https://github.com/llvm/llvm-project/commit/7a154470f51fef202a9a14e0618344a6a419579a.diff

LOG: [Flang] bug: preprocessor increases backslash to double backslash (#191512)

Correcting the preprocessing (-E) output when` '\'` is used in a string.
Prior to this fix it was being replaced with `"\\"`.

Fixes[191463](https://github.com/llvm/llvm-project/issues/191463)

Co-authored-by: Sunil Kuravinakop <kuravina at pe31.hpc.amslabs.hpecorp.net>

Added: 
    

Modified: 
    flang/lib/Parser/prescan.cpp
    flang/test/Driver/escaped-backslash.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 78537aef1fdfe..c1dd17400012a 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -1014,9 +1014,9 @@ void Prescanner::QuotedCharacterLiteral(
     if (*at_ == '\\') {
       if (escapesEnabled) {
         isEscaped = !isEscaped;
-      } else {
-        // The parser always processes escape sequences, so don't confuse it
-        // when escapes are disabled.
+      } else if (!preprocessingOnly_) {
+        // Except when -E is used, the parser always processes escape sequences,
+        // so don't confuse it when escapes are disabled.
         insert('\\');
       }
     } else {

diff  --git a/flang/test/Driver/escaped-backslash.f90 b/flang/test/Driver/escaped-backslash.f90
index 90dd1783dd115..75e4ff3beacdc 100644
--- a/flang/test/Driver/escaped-backslash.f90
+++ b/flang/test/Driver/escaped-backslash.f90
@@ -15,8 +15,8 @@
 ! RUN: %flang_fc1 -E -fbackslash %s  2>&1 | FileCheck %s --check-prefix=UNESCAPED
 
 ! ESCAPED:program Backslash
-! ESCAPED-NEXT:New\\nline
-! ESCAPED-NOT:New\nline
+! ESCAPED-NEXT:New\nline
+! ESCAPED-NOT:New\\nline
 
 ! UNESCAPED:program Backslash
 ! UNESCAPED-NEXT:New\nline


        


More information about the flang-commits mailing list