summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/Rewrite
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Frontend/Rewrite')
-rw-r--r--clang/lib/Frontend/Rewrite/FrontendActions.cpp11
-rw-r--r--clang/lib/Frontend/Rewrite/InclusionRewriter.cpp10
2 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/Frontend/Rewrite/FrontendActions.cpp b/clang/lib/Frontend/Rewrite/FrontendActions.cpp
index 45feffbcb5b..2ccdc263951 100644
--- a/clang/lib/Frontend/Rewrite/FrontendActions.cpp
+++ b/clang/lib/Frontend/Rewrite/FrontendActions.cpp
@@ -9,6 +9,7 @@
#include "clang/Rewrite/Frontend/FrontendActions.h"
#include "clang/AST/ASTConsumer.h"
+#include "clang/Basic/CharInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
@@ -224,7 +225,15 @@ public:
auto OS = Out.lock();
assert(OS && "loaded module file after finishing rewrite action?");
- (*OS) << "#pragma clang module build " << MF->ModuleName << "\n";
+ (*OS) << "#pragma clang module build ";
+ if (isValidIdentifier(MF->ModuleName))
+ (*OS) << MF->ModuleName;
+ else {
+ (*OS) << '"';
+ OS->write_escaped(MF->ModuleName);
+ (*OS) << '"';
+ }
+ (*OS) << '\n';
// Rewrite the contents of the module in a separate compiler instance.
CompilerInstance Instance(CI.getPCHContainerOperations(),
diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
index 3564cebba8a..e0477069b34 100644
--- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
+++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
@@ -140,7 +140,7 @@ void InclusionRewriter::WriteLineInfo(StringRef Filename, int Line,
}
void InclusionRewriter::WriteImplicitModuleImport(const Module *Mod) {
- OS << "#pragma clang module import " << Mod->getFullModuleName()
+ OS << "#pragma clang module import " << Mod->getFullModuleName(true)
<< " /* clang -frewrite-includes: implicit import */" << MainEOL;
}
@@ -471,15 +471,15 @@ void InclusionRewriter::Process(FileID FileId,
else if (const IncludedFile *Inc = FindIncludeAtLocation(Loc)) {
const Module *Mod = FindEnteredModule(Loc);
if (Mod)
- OS << "#pragma clang module begin " << Mod->getFullModuleName()
- << "\n";
+ OS << "#pragma clang module begin "
+ << Mod->getFullModuleName(true) << "\n";
// Include and recursively process the file.
Process(Inc->Id, Inc->FileType);
if (Mod)
- OS << "#pragma clang module end /*" << Mod->getFullModuleName()
- << "*/\n";
+ OS << "#pragma clang module end /*"
+ << Mod->getFullModuleName(true) << "*/\n";
// Add line marker to indicate we're returning from an included
// file.
OpenPOWER on IntegriCloud