summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorKeno Fischer <kfischer@college.harvard.edu>2014-08-26 22:10:15 +0000
committerKeno Fischer <kfischer@college.harvard.edu>2014-08-26 22:10:15 +0000
commit84778b2a1c124fe87f11c9cd72848a68f570e784 (patch)
tree667e199554775b6aaed23f88be9686adbefb91c7 /clang/lib/CodeGen
parent9455c5ab81a15b67309d08e18a19fb22172d5cca (diff)
downloadbcm5719-llvm-84778b2a1c124fe87f11c9cd72848a68f570e784.tar.gz
bcm5719-llvm-84778b2a1c124fe87f11c9cd72848a68f570e784.zip
Don't segfault in EmitCXXGlobalInitFunc when main file is a membuf
Summary: When the main file is created from a membuffer, there is no file entry that can be retrieved. This uses "__GLOBAL_I_a" in that case which is what was always used before r208128. Reviewers: majnemer, thakis Reviewed By: thakis Subscribers: yaron.keren, rsmith, cfe-commits Differential Revision: http://reviews.llvm.org/D5043 llvm-svn: 216495
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGDeclCXX.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 94cfe211601..af5919c157f 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -409,19 +409,25 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
AddGlobalCtor(Fn, Priority);
}
}
-
- // 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;
SourceManager &SM = Context.getSourceManager();
- SmallString<128> FileName(llvm::sys::path::filename(
- SM.getFileEntryForID(SM.getMainFileID())->getName()));
+ 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 {
+ FileName = SmallString<128>("<null>");
+ }
+
for (size_t i = 0; i < FileName.size(); ++i) {
// Replace everything that's not [a-zA-Z0-9._] with a _. This set happens
// to be the set of C preprocessing numbers.
if (!isPreprocessingNumberBody(FileName[i]))
FileName[i] = '_';
}
+
llvm::Function *Fn = CreateGlobalInitOrDestructFunction(
*this, FTy, llvm::Twine("_GLOBAL__sub_I_", FileName));
OpenPOWER on IntegriCloud