diff --git a/flang/lib/Parser/preprocessor.cpp b/flang/lib/Parser/preprocessor.cpp --- a/flang/lib/Parser/preprocessor.cpp +++ b/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)); diff --git a/flang/test/Preprocessing/pp045.F b/flang/test/Preprocessing/pp045.F new file mode 100644 --- /dev/null +++ b/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 diff --git a/flang/test/Preprocessing/pp131.F90 b/flang/test/Preprocessing/pp131.F90 new file mode 100644 --- /dev/null +++ b/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