[PATCH] D67592: [Clang] Use -main-file-name for source filename if not set
Joel Klinghed via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 15 11:08:24 PDT 2019
the_jk created this revision.
the_jk added a reviewer: rsmith.
the_jk added a project: clang.
Herald added subscribers: cfe-commits, aprantl.
-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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D67592
Files:
clang/include/clang/Driver/CC1Options.td
clang/lib/Frontend/FrontendAction.cpp
clang/test/Frontend/stdin-input
Index: clang/test/Frontend/stdin-input
===================================================================
--- /dev/null
+++ clang/test/Frontend/stdin-input
@@ -0,0 +1,7 @@
+// RUN: cat %s | %clang -emit-llvm -g -S \
+// RUN: -Xclang -main-file-name -Xclang test/foo.c -x c - -o - | FileCheck %s
+// CHECK: ; ModuleID = 'test/foo.c'
+// CHECK: source_filename = "test/foo.c"
+// CHECK: !1 = !DIFile(filename: "test/foo.c"
+
+int main() {}
\ No newline at end of file
Index: clang/lib/Frontend/FrontendAction.cpp
===================================================================
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -819,6 +819,10 @@
std::string PresumedInputFile = getCurrentFileOrBufferName();
if (Input.isPreprocessed())
ReadOriginalFileName(CI, PresumedInputFile);
+ else if (PresumedInputFile == "-" &&
+ !CI.getCodeGenOpts().MainFileName.empty()) {
+ PresumedInputFile = CI.getCodeGenOpts().MainFileName;
+ }
std::unique_ptr<ASTConsumer> Consumer =
CreateWrappedASTConsumer(CI, PresumedInputFile);
Index: clang/include/clang/Driver/CC1Options.td
===================================================================
--- clang/include/clang/Driver/CC1Options.td
+++ clang/include/clang/Driver/CC1Options.td
@@ -687,7 +687,7 @@
def version : Flag<["-"], "version">,
HelpText<"Print the compiler version">;
def main_file_name : Separate<["-"], "main-file-name">,
- HelpText<"Main file name to use for debug info">;
+ HelpText<"Main file name to use for debug info and source if missing">;
def split_dwarf_output : Separate<["-"], "split-dwarf-output">,
HelpText<"File name to use for split dwarf debug info output">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67592.220248.patch
Type: text/x-patch
Size: 1738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190915/48237d6a/attachment-0001.bin>
More information about the cfe-commits
mailing list