]> granicus.if.org Git - clang/commitdiff
Fix '-main-file-name <name>' so that it is used for the ModuleID.
authorRobert Lytton <robert@xmos.com>
Fri, 23 May 2014 07:34:08 +0000 (07:34 +0000)
committerRobert Lytton <robert@xmos.com>
Fri, 23 May 2014 07:34:08 +0000 (07:34 +0000)
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 <original file name> ...'
Or 'clang -cc1 -main-file-name <original file name> ...'

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209503 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenAction.cpp
test/CodeGen/main-file-name.c [new file with mode: 0644]

index 2d08c22c51da6f24ed5833fbde2a3b3847185eff..5c0b6a9fd8e8c850036b348823e3f03b3e41dc22 100644 (file)
@@ -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 (file)
index 0000000..83e2fe3
--- /dev/null
@@ -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'
+