]> granicus.if.org Git - clang/commitdiff
D34059: Get the file name for the symbol from the Module, not the SourceManager.
authorVassil Vassilev <v.g.vassilev@gmail.com>
Sun, 27 Aug 2017 11:27:30 +0000 (11:27 +0000)
committerVassil Vassilev <v.g.vassilev@gmail.com>
Sun, 27 Aug 2017 11:27:30 +0000 (11:27 +0000)
This allows multi-module / incremental compilation environments to have unique
initializer symbols.

Patch by Axel Naumann with minor modifications by me!

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

lib/CodeGen/CGDeclCXX.cpp
unittests/CodeGen/CMakeLists.txt

index 98d9e364d9cc74e7c7896221cc50cbd32caf7091..4db207cc2daee9267adf37739a95de67a27d7740 100644 (file)
@@ -487,16 +487,12 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
     PrioritizedCXXGlobalInits.clear();
   }
 
-  SmallString<128> FileName;
-  SourceManager &SM = Context.getSourceManager();
-  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
-    // Include the filename in the symbol name. Including "sub_" matches gcc and
-    // makes sure these symbols appear lexicographically behind the symbols with
-    // priority emitted above.
-    FileName = llvm::sys::path::filename(MainFile->getName());
-  } else {
+  // Include the filename in the symbol name. Including "sub_" matches gcc and
+  // makes sure these symbols appear lexicographically behind the symbols with
+  // priority emitted above.
+  SmallString<128> FileName = llvm::sys::path::filename(getModule().getName());
+  if (FileName.empty())
     FileName = "<null>";
-  }
 
   for (size_t i = 0; i < FileName.size(); ++i) {
     // Replace everything that's not [a-zA-Z0-9._] with a _. This set happens
index 27a513a2f9828d7c69d83c50b94964379ab37415..a2a06dd785213978fc4b7d6bf10994d73a676f29 100644 (file)
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
 
 add_clang_unittest(ClangCodeGenTests
   BufferSourceTest.cpp
+  IncrementalProcessingTest.cpp
   )
 
 target_link_libraries(ClangCodeGenTests