From: Douglas Gregor Date: Fri, 11 Feb 2011 18:08:15 +0000 (+0000) Subject: Don't compare llvm::Optional<> objects directly; compare their X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7a1841244418b658bcf64573ff0c00867fb9c5d;p=clang 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 --- 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 EntryInode = getActualFileInode(Entry)) { + if (*SourceFileInode == *EntryInode) { + FirstFID = FileID::get(I); + SourceFile = Entry; + break; + } + } } } }