From: Ted Kremenek Date: Wed, 17 Dec 2008 18:38:19 +0000 (+0000) Subject: Shadow CurPtr with a local variable in ReadToken. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c13c4f87ebdf4309d9b9b75336f15301b8ec8ce;p=clang Shadow CurPtr with a local variable in ReadToken. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61145 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index 49c7078b75..2ec01b27eb 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -271,21 +271,27 @@ void PTHLexer::ReadToken(Token& T) { // FIXME: Setting the flags directly should obviate this step. T.startToken(); + // Shadow CurPtr into an automatic variable so that Read8 doesn't load and + // store back into the instance variable. + const char *CurPtrShadow = CurPtr; + // Read the type of the token. - T.setKind((tok::TokenKind) Read8(CurPtr)); + T.setKind((tok::TokenKind) Read8(CurPtrShadow)); // Set flags. This is gross, since we are really setting multiple flags. - T.setFlag((Token::TokenFlags) Read8(CurPtr)); + T.setFlag((Token::TokenFlags) Read8(CurPtrShadow)); // Set the IdentifierInfo* (if any). - T.setIdentifierInfo(PTHMgr.ReadIdentifierInfo(CurPtr)); + T.setIdentifierInfo(PTHMgr.ReadIdentifierInfo(CurPtrShadow)); // Set the SourceLocation. Since all tokens are constructed using a - // raw lexer, they will all be offseted from the same FileID. - T.setLocation(SourceLocation::getFileLoc(FileID, Read32(CurPtr))); + // raw, they will all be offseted from the same FileID. + T.setLocation(SourceLocation::getFileLoc(FileID, Read32(CurPtrShadow))); // Finally, read and set the length of the token. - T.setLength(Read32(CurPtr)); + T.setLength(Read32(CurPtrShadow)); + + CurPtr = CurPtrShadow; } //===----------------------------------------------------------------------===//