diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-05-21 06:58:08 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-05-21 06:58:08 +0000 |
commit | d5f23b0b7528b5c3caed1ba14f897cc4aaa9e3c3 (patch) | |
tree | 133ab22e59f61162b7f8e8e794dd6458769e8e1a /lib/Basic/SourceManager.cpp | |
parent | 624e91b063cecc3671eeb40e4b0fa08d71b59284 (diff) |
Notes
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
-rw-r--r-- | lib/Basic/SourceManager.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 305dcd43960c7..118e3f32008b0 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -2076,22 +2076,33 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, return IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second); } - // This can happen if a location is in a built-ins buffer. - // But see PR5662. + // If we arrived here, the location is either in a built-ins buffer or + // associated with global inline asm. PR5662 and PR22576 are examples. + // Clear the lookup cache, it depends on a common location. IsBeforeInTUCache.clear(); - bool LIsBuiltins = strcmp("<built-in>", - getBuffer(LOffs.first)->getBufferIdentifier()) == 0; - bool RIsBuiltins = strcmp("<built-in>", - getBuffer(ROffs.first)->getBufferIdentifier()) == 0; - // built-in is before non-built-in - if (LIsBuiltins != RIsBuiltins) - return LIsBuiltins; - assert(LIsBuiltins && RIsBuiltins && - "Non-built-in locations must be rooted in the main file"); - // Both are in built-in buffers, but from different files. We just claim that - // lower IDs come first. - return LOffs.first < ROffs.first; + llvm::MemoryBuffer *LBuf = getBuffer(LOffs.first); + llvm::MemoryBuffer *RBuf = getBuffer(ROffs.first); + bool LIsBuiltins = strcmp("<built-in>", LBuf->getBufferIdentifier()) == 0; + bool RIsBuiltins = strcmp("<built-in>", RBuf->getBufferIdentifier()) == 0; + // Sort built-in before non-built-in. + if (LIsBuiltins || RIsBuiltins) { + if (LIsBuiltins != RIsBuiltins) + return LIsBuiltins; + // Both are in built-in buffers, but from different files. We just claim that + // lower IDs come first. + return LOffs.first < ROffs.first; + } + bool LIsAsm = strcmp("<inline asm>", LBuf->getBufferIdentifier()) == 0; + bool RIsAsm = strcmp("<inline asm>", RBuf->getBufferIdentifier()) == 0; + // Sort assembler after built-ins, but before the rest. + if (LIsAsm || RIsAsm) { + if (LIsAsm != RIsAsm) + return RIsAsm; + assert(LOffs.first == ROffs.first); + return false; + } + llvm_unreachable("Unsortable locations found"); } void SourceManager::PrintStats() const { |