diff --git a/clang/lib/AST/SelectorLocationsKind.cpp b/clang/lib/AST/SelectorLocationsKind.cpp --- a/clang/lib/AST/SelectorLocationsKind.cpp +++ b/clang/lib/AST/SelectorLocationsKind.cpp @@ -27,7 +27,7 @@ if (EndLoc.isInvalid()) return SourceLocation(); IdentifierInfo *II = Sel.getIdentifierInfoForSlot(0); - unsigned Len = II ? II->getLength() : 0; + SourceLocation::UIntTy Len = II ? II->getLength() : 0; return EndLoc.getLocWithOffset(-Len); } @@ -35,7 +35,8 @@ if (ArgLoc.isInvalid()) return SourceLocation(); IdentifierInfo *II = Sel.getIdentifierInfoForSlot(Index); - unsigned Len = /* selector id */ (II ? II->getLength() : 0) + /* ':' */ 1; + SourceLocation::UIntTy Len = + /* selector id */ (II ? II->getLength() : 0) + /* ':' */ 1; if (WithArgSpace) ++Len; return ArgLoc.getLocWithOffset(-Len); diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -232,8 +232,10 @@ /// Return the start location of an included file or expanded macro. SourceLocation getStartOfFileOrMacro(SourceLocation Loc) { - if (Loc.isMacroID()) - return Loc.getLocWithOffset(-SM.getFileOffset(Loc)); + if (Loc.isMacroID()) { + SourceLocation::UIntTy FileOffset = SM.getFileOffset(Loc); + return Loc.getLocWithOffset(-FileOffset); + } return SM.getLocForStartOfFile(SM.getFileID(Loc)); } diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -832,7 +832,8 @@ FormatTok = new (Allocator.Allocate()) FormatToken; readRawToken(*FormatTok); SourceLocation WhitespaceStart = - FormatTok->Tok.getLocation().getLocWithOffset(-TrailingWhitespace); + FormatTok->Tok.getLocation().getLocWithOffset( + -static_cast(TrailingWhitespace)); FormatTok->IsFirst = IsFirstToken; IsFirstToken = false; diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -510,24 +510,29 @@ const SourceManager &SM, const LangOptions &LangOpts) { assert(Loc.isFileID()); - std::pair LocInfo = SM.getDecomposedLoc(Loc); - if (LocInfo.first.isInvalid()) + FileID LocFileID; + SourceLocation::UIntTy LocOffset; + std::tie(LocFileID, LocOffset) = SM.getDecomposedLoc(Loc); + if (LocFileID.isInvalid()) return Loc; bool Invalid = false; - StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid); + StringRef Buffer = SM.getBufferData(LocFileID, &Invalid); if (Invalid) return Loc; + if (LocOffset > Buffer.size()) + return Loc; + // Back up from the current location until we hit the beginning of a line // (or the buffer). We'll relex from that point. - const char *StrData = Buffer.data() + LocInfo.second; - const char *LexStart = findBeginningOfLine(Buffer, LocInfo.second); + const char *StrData = Buffer.data() + LocOffset; + const char *LexStart = findBeginningOfLine(Buffer, LocOffset); if (!LexStart || LexStart == StrData) return Loc; // Create a lexer starting at the beginning of this token. - SourceLocation LexerStartLoc = Loc.getLocWithOffset(-LocInfo.second); + SourceLocation LexerStartLoc = Loc.getLocWithOffset(-LocOffset); Lexer TheLexer(LexerStartLoc, LangOpts, Buffer.data(), LexStart, Buffer.end()); TheLexer.SetCommentRetentionState(true); @@ -565,12 +570,12 @@ SourceLocation FileLoc = SM.getSpellingLoc(Loc); SourceLocation BeginFileLoc = getBeginningOfFileToken(FileLoc, SM, LangOpts); - std::pair FileLocInfo = SM.getDecomposedLoc(FileLoc); - std::pair BeginFileLocInfo = - SM.getDecomposedLoc(BeginFileLoc); - assert(FileLocInfo.first == BeginFileLocInfo.first && - FileLocInfo.second >= BeginFileLocInfo.second); - return Loc.getLocWithOffset(BeginFileLocInfo.second - FileLocInfo.second); + FileID FID, BeginFID; + SourceLocation::UIntTy FileOffset, BeginFileOffset; + std::tie(FID, FileOffset) = SM.getDecomposedLoc(FileLoc); + std::tie(BeginFID, BeginFileOffset) = SM.getDecomposedLoc(BeginFileLoc); + assert(FID == BeginFID && FileOffset >= BeginFileOffset); + return Loc.getLocWithOffset(BeginFileOffset - FileOffset); } namespace { diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp --- a/clang/lib/Parse/ParseStmtAsm.cpp +++ b/clang/lib/Parse/ParseStmtAsm.cpp @@ -185,7 +185,8 @@ if (TokIndex < AsmToks.size()) { const Token &Tok = AsmToks[TokIndex]; Loc = Tok.getLocation(); - Loc = Loc.getLocWithOffset(Offset - TokOffset); + Loc = Loc.getLocWithOffset(static_cast(Offset) - + TokOffset); } return Loc; } diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp --- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -1081,8 +1081,8 @@ // Highlight the range. Make the span tag the outermost tag for the // selected range. - SourceLocation E = - InstantiationEnd.getLocWithOffset(EndColNo - OldEndColNo); + SourceLocation E = InstantiationEnd.getLocWithOffset( + static_cast(EndColNo) - OldEndColNo); html::HighlightRange(R, InstantiationStart, E, HighlightStart, HighlightEnd); }