From: Robert Lytton Date: Fri, 23 May 2014 07:34:08 +0000 (+0000) Subject: Fix '-main-file-name ' so that it is used for the ModuleID. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1d67d0ce55d8ff0574341ec394c435828bf6ea4;p=clang Fix '-main-file-name ' so that it is used for the ModuleID. Summary: Previously, you could not specify the original file name when passing a preprocessed file into the compiler Now you can use 'clang -Xclang -main-file-name -Xclang ...' Or 'clang -cc1 -main-file-name ...' git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209503 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenAction.cpp b/lib/CodeGen/CodeGenAction.cpp index 2d08c22c51..5c0b6a9fd8 100644 --- a/lib/CodeGen/CodeGenAction.cpp +++ b/lib/CodeGen/CodeGenAction.cpp @@ -551,9 +551,12 @@ ASTConsumer *CodeGenAction::CreateASTConsumer(CompilerInstance &CI, LinkModuleToUse = ModuleOrErr.get(); } + StringRef MainFileName = getCompilerInstance().getCodeGenOpts().MainFileName; + if (MainFileName.empty()) + MainFileName = InFile; BEConsumer = new BackendConsumer(BA, CI.getDiagnostics(), CI.getCodeGenOpts(), CI.getTargetOpts(), CI.getLangOpts(), - CI.getFrontendOpts().ShowTimers, InFile, + CI.getFrontendOpts().ShowTimers, MainFileName, LinkModuleToUse, OS.release(), *VMContext); return BEConsumer; } diff --git a/test/CodeGen/main-file-name.c b/test/CodeGen/main-file-name.c new file mode 100644 index 0000000000..83e2fe3ac2 --- /dev/null +++ b/test/CodeGen/main-file-name.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -o - %s -main-file-name some.name | FileCheck -check-prefix NAMED %s + +// CHECK: ; ModuleID = '{{.*}}main-file-name.c' +// NAMED: ; ModuleID = 'some.name' +