diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-02-11 18:08:15 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-02-11 18:08:15 +0000 |
commit | b7a1841244418b658bcf64573ff0c00867fb9c5d (patch) | |
tree | 5cfc2db6e7966a1d1bc2ed053e714521200bac1b /lib/Basic/SourceManager.cpp | |
parent | 5f740c68685eaa02b969e98365129f6fe1e3249b (diff) |
Don't compare llvm::Optional<> objects directly; compare their
contents when it's safe. I just *love* C++ some days.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
-rw-r--r-- | lib/Basic/SourceManager.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 9d5569aa39..4b0a3925ca 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -1145,16 +1145,19 @@ SourceLocation SourceManager::getLocation(const FileEntry *SourceFile, if (MainSLoc.isFile()) { const ContentCache *MainContentCache = MainSLoc.getFile().getContentCache(); - if (MainContentCache->Entry == SourceFile) + if (!MainContentCache) { + // Can't do anything + } else if (MainContentCache->Entry == SourceFile) { FirstFID = MainFileID; - else if (MainContentCache) { + } else { // Fall back: check whether we have the same base name and inode // as the main file. const FileEntry *MainFile = MainContentCache->Entry; SourceFileName = llvm::sys::path::filename(SourceFile->getName()); if (*SourceFileName == llvm::sys::path::filename(MainFile->getName())) { SourceFileInode = getActualFileInode(SourceFile); - if (SourceFileInode == getActualFileInode(MainFile)) { + if (SourceFileInode && + *SourceFileInode == getActualFileInode(MainFile)) { FirstFID = MainFileID; SourceFile = MainFile; } @@ -1192,11 +1195,14 @@ SourceLocation SourceManager::getLocation(const FileEntry *SourceFile, = SLoc.getFile().getContentCache(); const FileEntry *Entry =FileContentCache? FileContentCache->Entry : 0; if (Entry && - *SourceFileName == llvm::sys::path::filename(Entry->getName()) && - SourceFileInode == getActualFileInode(Entry)) { - FirstFID = FileID::get(I); - SourceFile = Entry; - break; + *SourceFileName == llvm::sys::path::filename(Entry->getName())) { + if (llvm::Optional<ino_t> EntryInode = getActualFileInode(Entry)) { + if (*SourceFileInode == *EntryInode) { + FirstFID = FileID::get(I); + SourceFile = Entry; + break; + } + } } } } |