diff options
author | Peter Klausler <pklausler@nvidia.com> | 2024-11-05 13:18:27 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-05 13:18:27 -0800 |
commit | 850d42fb145c636a3b56a7616c3e3c5c188c1916 (patch) | |
tree | c9ef68428f0d671fb3b25130748600f499d727ff /flang/lib/Parser/token-sequence.cpp | |
parent | 07e053fb95e131244dafab04aae84650de383664 (diff) | |
download | llvm-850d42fb145c636a3b56a7616c3e3c5c188c1916.zip llvm-850d42fb145c636a3b56a7616c3e3c5c188c1916.tar.gz llvm-850d42fb145c636a3b56a7616c3e3c5c188c1916.tar.bz2 |
[flang] Handle "defined" in macro expansions (#114844)
The preprocessor implements "defined(X)" and "defined X" in if/elif
directive expressions in such a way that they only work at the top
level, not when they appear in macro expansions. Fix that, which is a
little tricky due to the need to detect the "defined" keyword before
applying any macro expansion to its argument, and add a bunch of tests.
Fixes https://github.com/llvm/llvm-project/issues/114064.
Diffstat (limited to 'flang/lib/Parser/token-sequence.cpp')
-rw-r--r-- | flang/lib/Parser/token-sequence.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/flang/lib/Parser/token-sequence.cpp b/flang/lib/Parser/token-sequence.cpp index c73bca1..cdbe89b 100644 --- a/flang/lib/Parser/token-sequence.cpp +++ b/flang/lib/Parser/token-sequence.cpp @@ -61,6 +61,16 @@ std::size_t TokenSequence::SkipBlanks(std::size_t at) const { return tokens; // even if at > tokens } +std::optional<std::size_t> TokenSequence::SkipBlanksBackwards( + std::size_t at) const { + while (at-- > 0) { + if (!TokenAt(at).IsBlank()) { + return at; + } + } + return std::nullopt; +} + // C-style /*comments*/ are removed from preprocessing directive // token sequences by the prescanner, but not C++ or Fortran // free-form line-ending comments (//... and !...) because |