aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/PrintPreprocessedOutput.cpp
diff options
context:
space:
mode:
authorDmitry Polukhin <34227995+dmpolukhin@users.noreply.github.com>2024-10-24 08:20:43 +0100
committerGitHub <noreply@github.com>2024-10-24 08:20:43 +0100
commit0b7e8c25ece1ff0e0dc0b7d283600b49498e8162 (patch)
tree422709088a432998d65bb1cd3cb4c0f1df12b368 /clang/lib/Frontend/PrintPreprocessedOutput.cpp
parent60944177b8fa43d0d315af6b4827f94226e0aa01 (diff)
downloadllvm-0b7e8c25ece1ff0e0dc0b7d283600b49498e8162.zip
llvm-0b7e8c25ece1ff0e0dc0b7d283600b49498e8162.tar.gz
llvm-0b7e8c25ece1ff0e0dc0b7d283600b49498e8162.tar.bz2
[C++20][Modules] Quote header unit name in preprocessor output (-E) (#112883)
Summary: Before this change clang produced output with header unit names that may conaint path separators, dots and other non-identifier characters. This diff prints header unit name in quotes and -E output can be compiled again. Also remove unnecessary space between header unit name and semi. Test Plan: check-clang
Diffstat (limited to 'clang/lib/Frontend/PrintPreprocessedOutput.cpp')
-rw-r--r--clang/lib/Frontend/PrintPreprocessedOutput.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 383d435..1005825 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -952,13 +952,15 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
continue;
} else if (Tok.is(tok::annot_header_unit)) {
// This is a header-name that has been (effectively) converted into a
- // module-name.
+ // module-name, print them inside quote.
// FIXME: The module name could contain non-identifier module name
- // components. We don't have a good way to round-trip those.
+ // components and OS specific file paths components. We don't have a good
+ // way to round-trip those.
Module *M = reinterpret_cast<Module *>(Tok.getAnnotationValue());
std::string Name = M->getFullModuleName();
- Callbacks->OS->write(Name.data(), Name.size());
- Callbacks->HandleNewlinesInToken(Name.data(), Name.size());
+ *Callbacks->OS << '"';
+ Callbacks->OS->write_escaped(Name);
+ *Callbacks->OS << '"';
} else if (Tok.is(tok::annot_embed)) {
// Manually explode the binary data out to a stream of comma-delimited
// integer values. If the user passed -dE, that is handled by the