[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:20:02 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-driver
Author: SunilKuravinakop
<details>
<summary>Changes</summary>
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)
---
Full diff: https://github.com/llvm/llvm-project/pull/191512.diff
2 Files Affected:
- (modified) flang/lib/Parser/prescan.cpp (+3-3)
- (modified) flang/test/Driver/escaped-backslash.f90 (+2-2)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/191512
More information about the flang-commits
mailing list