[flang-commits] [PATCH] D117148: [flang] Fix handling of space between # and name in preprocessor stringification

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Jan 12 16:02:50 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e811d3b66ff: [flang] Fix handling of space between # and name in preprocessor stringification (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117148/new/

https://reviews.llvm.org/D117148

Files:
  flang/lib/Parser/preprocessor.cpp
  flang/test/Preprocessing/pp045.F
  flang/test/Preprocessing/pp131.F90


Index: flang/test/Preprocessing/pp131.F90
===================================================================
--- /dev/null
+++ flang/test/Preprocessing/pp131.F90
@@ -0,0 +1,9 @@
+! RUN: %flang -E %s 2>&1 | FileCheck %s
+! CHECK: n = "foobar" // "baz"
+! # stringizing works in FLM
+#define STR(x) # x
+#define MAC(a,b) STR(a ## b)
+program main
+  character(6) n
+  n = MAC(foo, bar) // STR( baz )
+end
Index: flang/test/Preprocessing/pp045.F
===================================================================
--- /dev/null
+++ flang/test/Preprocessing/pp045.F
@@ -0,0 +1,9 @@
+! RUN: %flang -E %s 2>&1 | FileCheck %s
+! CHECK: n = "foobar" // "baz"
+* # stringizing works in FLM
+#define STR(x) # x
+#define MAC(a,b) STR(a ## b)
+      program main
+      character(6) n
+      n = MAC(foo, bar) // STR( baz )
+      end
Index: flang/lib/Parser/preprocessor.cpp
===================================================================
--- flang/lib/Parser/preprocessor.cpp
+++ flang/lib/Parser/preprocessor.cpp
@@ -169,8 +169,9 @@
           replacement_.TokenAt(prev - 1)[0] ==
               '#') { // stringify argument without macro replacement
         std::size_t resultSize{result.SizeInTokens()};
-        while (resultSize > 0 && result.TokenAt(resultSize - 1).empty()) {
+        while (resultSize > 0 && result.TokenAt(resultSize - 1).IsBlank()) {
           result.pop_back();
+          --resultSize;
         }
         CHECK(resultSize > 0 &&
             result.TokenAt(resultSize - 1) == replacement_.TokenAt(prev - 1));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117148.399504.patch
Type: text/x-patch
Size: 1536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220113/33f2ea12/attachment.bin>


More information about the flang-commits mailing list