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 | 6a5be93b812d580e67361237e7076da77d962905 (patch) | |
tree | 83d7f032d14ab656fa9959cb348619b09860a8b7 /clang/lib/Basic | |
parent | 485b4d835258009d58f874946f593d8f6bba0fde (diff) | |
download | bcm5719-llvm-6a5be93b812d580e67361237e7076da77d962905.tar.gz bcm5719-llvm-6a5be93b812d580e67361237e7076da77d962905.zip |
Don't compare llvm::Optional<> objects directly; compare their
contents when it's safe. I just *love* C++ some days.
llvm-svn: 125378
Diffstat (limited to 'clang/lib/Basic')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 9d5569aa396..4b0a3925ca3 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/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; + } + } } } } |