[flang-commits] [flang] [Flang] bug: preprocessor increases backslash to double backslash (PR #191512)
via flang-commits
flang-commits at lists.llvm.org
Fri Apr 10 13:19:30 PDT 2026
https://github.com/SunilKuravinakop created https://github.com/llvm/llvm-project/pull/191512
Correcting the preprocessing (-E) output when '\' is used in a string.
Prior to this fix it was being replaced with "\\".
Issue is in [191463](https://github.com/llvm/llvm-project/issues/191463)
>From 3d5df863b8b0e85a5965b17b1d2199cf2418b7f0 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop <kuravina at pe31.hpc.amslabs.hpecorp.net>
Date: Fri, 10 Apr 2026 12:36:14 -0500
Subject: [PATCH] Correcting the preprocessing (-E) output when '\' is used in
a string. Prior to this fix it was being replaced with "\\".
---
flang/lib/Parser/prescan.cpp | 6 +++---
flang/test/Driver/escaped-backslash.f90 | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
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