From bd3306aecb3a15e8967143b8cdbbccf2b1b19b74 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 14 Jan 2017 19:55:43 +0000 Subject: Import LLVM 3.9.1 including clang and lld. --- gnu/llvm/tools/clang/lib/Basic/SourceManager.cpp | 45 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'gnu/llvm/tools/clang/lib/Basic/SourceManager.cpp') diff --git a/gnu/llvm/tools/clang/lib/Basic/SourceManager.cpp b/gnu/llvm/tools/clang/lib/Basic/SourceManager.cpp index 4c501616a3e..1e83b63cf82 100644 --- a/gnu/llvm/tools/clang/lib/Basic/SourceManager.cpp +++ b/gnu/llvm/tools/clang/lib/Basic/SourceManager.cpp @@ -1160,7 +1160,8 @@ unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, // isInvalid - Return the result of calling loc.isInvalid(), and // if Invalid is not null, set its value to same. -static bool isInvalid(SourceLocation Loc, bool *Invalid) { +template +static bool isInvalid(LocType Loc, bool *Invalid) { bool MyInvalid = Loc.isInvalid(); if (Invalid) *Invalid = MyInvalid; @@ -1183,8 +1184,9 @@ unsigned SourceManager::getExpansionColumnNumber(SourceLocation Loc, unsigned SourceManager::getPresumedColumnNumber(SourceLocation Loc, bool *Invalid) const { - if (isInvalid(Loc, Invalid)) return 0; - return getPresumedLoc(Loc).getColumn(); + PresumedLoc PLoc = getPresumedLoc(Loc); + if (isInvalid(PLoc, Invalid)) return 0; + return PLoc.getColumn(); } #ifdef __SSE2__ @@ -1258,15 +1260,19 @@ FoundSpecialChar: if (Buf[0] == '\n' || Buf[0] == '\r') { // If this is \n\r or \r\n, skip both characters. - if ((Buf[1] == '\n' || Buf[1] == '\r') && Buf[0] != Buf[1]) - ++Offs, ++Buf; - ++Offs, ++Buf; + if ((Buf[1] == '\n' || Buf[1] == '\r') && Buf[0] != Buf[1]) { + ++Offs; + ++Buf; + } + ++Offs; + ++Buf; LineOffsets.push_back(Offs); } else { // Otherwise, this is a null. If end of file, exit. if (Buf == End) break; // Otherwise, skip the null. - ++Offs, ++Buf; + ++Offs; + ++Buf; } } @@ -1388,8 +1394,9 @@ unsigned SourceManager::getExpansionLineNumber(SourceLocation Loc, } unsigned SourceManager::getPresumedLineNumber(SourceLocation Loc, bool *Invalid) const { - if (isInvalid(Loc, Invalid)) return 0; - return getPresumedLoc(Loc).getLine(); + PresumedLoc PLoc = getPresumedLoc(Loc); + if (isInvalid(PLoc, Invalid)) return 0; + return PLoc.getLine(); } /// getFileCharacteristic - return the file characteristic of the specified @@ -2089,10 +2096,10 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, // Clear the lookup cache, it depends on a common location. IsBeforeInTUCache.clear(); - llvm::MemoryBuffer *LBuf = getBuffer(LOffs.first); - llvm::MemoryBuffer *RBuf = getBuffer(ROffs.first); - bool LIsBuiltins = strcmp("", LBuf->getBufferIdentifier()) == 0; - bool RIsBuiltins = strcmp("", RBuf->getBufferIdentifier()) == 0; + const char *LB = getBuffer(LOffs.first)->getBufferIdentifier(); + const char *RB = getBuffer(ROffs.first)->getBufferIdentifier(); + bool LIsBuiltins = strcmp("", LB) == 0; + bool RIsBuiltins = strcmp("", RB) == 0; // Sort built-in before non-built-in. if (LIsBuiltins || RIsBuiltins) { if (LIsBuiltins != RIsBuiltins) @@ -2101,8 +2108,8 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, // lower IDs come first. return LOffs.first < ROffs.first; } - bool LIsAsm = strcmp("", LBuf->getBufferIdentifier()) == 0; - bool RIsAsm = strcmp("", RBuf->getBufferIdentifier()) == 0; + bool LIsAsm = strcmp("", LB) == 0; + bool RIsAsm = strcmp("", RB) == 0; // Sort assembler after built-ins, but before the rest. if (LIsAsm || RIsAsm) { if (LIsAsm != RIsAsm) @@ -2110,6 +2117,14 @@ bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, assert(LOffs.first == ROffs.first); return false; } + bool LIsScratch = strcmp("", LB) == 0; + bool RIsScratch = strcmp("", RB) == 0; + // Sort scratch after inline asm, but before the rest. + if (LIsScratch || RIsScratch) { + if (LIsScratch != RIsScratch) + return LIsScratch; + return LOffs.second < ROffs.second; + } llvm_unreachable("Unsortable locations found"); } -- cgit v1.2.3-59-g8ed1b