r209503 - Fix '-main-file-name <name>' so that it is used for the ModuleID.

Robert Lytton robert at xmos.com
Fri May 23 00:34:09 PDT 2014


Author: rlytton
Date: Fri May 23 02:34:08 2014
New Revision: 209503

URL: http://llvm.org/viewvc/llvm-project?rev=209503&view=rev
Log:
Fix '-main-file-name <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 <original file name> ...'
Or 'clang -cc1 -main-file-name <original file name> ...'

Added:
    cfe/trunk/test/CodeGen/main-file-name.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenAction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=209503&r1=209502&r2=209503&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Fri May 23 02:34:08 2014
@@ -551,9 +551,12 @@ ASTConsumer *CodeGenAction::CreateASTCon
     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;
 }

Added: cfe/trunk/test/CodeGen/main-file-name.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/main-file-name.c?rev=209503&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/main-file-name.c (added)
+++ cfe/trunk/test/CodeGen/main-file-name.c Fri May 23 02:34:08 2014
@@ -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'
+





More information about the cfe-commits mailing list