From 57dd5cf441351531d26d7255a778430904c5288d Mon Sep 17 00:00:00 2001 From: Robert Lytton Date: Fri, 23 May 2014 07:34:08 +0000 Subject: [PATCH] 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 ...' llvm-svn: 209503 --- clang/lib/CodeGen/CodeGenAction.cpp | 5 ++++- clang/test/CodeGen/main-file-name.c | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGen/main-file-name.c diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 2d08c22..5c0b6a9 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/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/clang/test/CodeGen/main-file-name.c b/clang/test/CodeGen/main-file-name.c new file mode 100644 index 0000000..83e2fe3 --- /dev/null +++ b/clang/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' + -- 2.7.4