Skip to content

Commit

Permalink
D34059: Get the file name for the symbol from the Module, not the Sou…
Browse files Browse the repository at this point in the history
…rceManager.

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
  • Loading branch information
vgvassilev committed Aug 27, 2017
1 parent 105edcf commit 8d20c96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/CodeGen/CGDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions unittests/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS

add_clang_unittest(ClangCodeGenTests
BufferSourceTest.cpp
IncrementalProcessingTest.cpp
)

target_link_libraries(ClangCodeGenTests
Expand Down

0 comments on commit 8d20c96

Please sign in to comment.