diff options
author | Teresa Johnson <tejohnson@google.com> | 2019-09-30 15:05:35 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2019-09-30 15:05:35 +0000 |
commit | 57dbfe194cb53b25246a40e8a73e5c77cc804619 (patch) | |
tree | f9bee83577707fa33ef90a7a1e0ee2d5edc3088f /clang/lib/CodeGen/ModuleBuilder.cpp | |
parent | 14945186c28ee41162eedc7fa89e04548f2bda6d (diff) | |
download | llvm-57dbfe194cb53b25246a40e8a73e5c77cc804619.zip llvm-57dbfe194cb53b25246a40e8a73e5c77cc804619.tar.gz llvm-57dbfe194cb53b25246a40e8a73e5c77cc804619.tar.bz2 |
[Clang] Use -main-file-name for source filename if not set
-main-file-name is currently used to set the source name used in debug
information.
If the source filename is "-" and -main-file-name is set, then use the
filename also for source_filename and ModuleID of the output.
The argument is generally used outside the internal clang calls when
running clang in a wrapper like icecc which gives the source via stdin
but still wants to get a object file with the original source filename
both in debug info and IR code.
Patch by: the_jk (Joel Klinghed)
Differential Revision: https://reviews.llvm.org/D67592
llvm-svn: 373217
Diffstat (limited to 'clang/lib/CodeGen/ModuleBuilder.cpp')
-rw-r--r-- | clang/lib/CodeGen/ModuleBuilder.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp index 414a6b8..4154f6eb 100644 --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/lib/CodeGen/ModuleBuilder.cpp @@ -65,6 +65,13 @@ namespace { private: SmallVector<FunctionDecl *, 8> DeferredInlineMemberFuncDefs; + static llvm::StringRef ExpandModuleName(llvm::StringRef ModuleName, + const CodeGenOptions &CGO) { + if (ModuleName == "-" && !CGO.MainFileName.empty()) + return CGO.MainFileName; + return ModuleName; + } + public: CodeGeneratorImpl(DiagnosticsEngine &diags, llvm::StringRef ModuleName, const HeaderSearchOptions &HSO, @@ -73,7 +80,8 @@ namespace { CoverageSourceInfo *CoverageInfo = nullptr) : Diags(diags), Ctx(nullptr), HeaderSearchOpts(HSO), PreprocessorOpts(PPO), CodeGenOpts(CGO), HandlingTopLevelDecls(0), - CoverageInfo(CoverageInfo), M(new llvm::Module(ModuleName, C)) { + CoverageInfo(CoverageInfo), + M(new llvm::Module(ExpandModuleName(ModuleName, CGO), C)) { C.setDiscardValueNames(CGO.DiscardValueNames); } @@ -121,7 +129,7 @@ namespace { llvm::Module *StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C) { assert(!M && "Replacing existing Module?"); - M.reset(new llvm::Module(ModuleName, C)); + M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C)); Initialize(*Ctx); return M.get(); } |