[flang-commits] [flang] [flang] Handle duplicate backslashes in preprocessor. (PR #115822)
via flang-commits
flang-commits at lists.llvm.org
Mon Nov 11 22:19:07 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-parser
Author: Lake (olee7)
<details>
<summary>Changes</summary>
Fixes:
[112604](https://github.com/llvm/llvm-project/issues/112604)
Fixes the issue where preprocessor will escape the backslashes but the compiler will not re-combine them.
---
Full diff: https://github.com/llvm/llvm-project/pull/115822.diff
2 Files Affected:
- (modified) flang/lib/Parser/prescan.cpp (+1-1)
- (added) flang/test/Parser/duplicate-backslashes.f90 (+23)
``````````diff
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 1d2f1e97668792..8c991678047ecd 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -843,7 +843,7 @@ void Prescanner::QuotedCharacterLiteral(
if (*at_ == '\\') {
if (escapesEnabled) {
isEscaped = !isEscaped;
- } else {
+ } else if (!preprocessingOnly_) {
// The parser always processes escape sequences, so don't confuse it
// when escapes are disabled.
insert('\\');
diff --git a/flang/test/Parser/duplicate-backslashes.f90 b/flang/test/Parser/duplicate-backslashes.f90
new file mode 100644
index 00000000000000..896a5e864bc93d
--- /dev/null
+++ b/flang/test/Parser/duplicate-backslashes.f90
@@ -0,0 +1,23 @@
+! RUN: %flang -cpp -E %s -o %t.f90
+! RUN: %flang %t.f90 -o %t
+! RUN: %t | FileCheck %s
+
+program main
+ implicit none
+
+ ! Test single backslash
+ write(*, '(A)') "\" ! Expected single backslash in output
+ ! CHECK: \
+ ! CHECK-NOT: \\
+
+ ! Test double backslash
+ write(*, '(A)') "\\" ! Expected double backslashes in output
+ ! CHECK: \\
+ ! CHECK-NOT: \\\\
+
+ ! Test quadruple backslash
+ write(*, '(A)') "\\\\" ! Expected quadruple backslashes in output
+ ! CHECK: \\\\
+ ! CHECK-NOT: \\\\\\\\
+
+end program main
``````````
</details>
https://github.com/llvm/llvm-project/pull/115822
More information about the flang-commits
mailing list