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">; 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 Consumer = CreateWrappedASTConsumer(CI, PresumedInputFile); 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