diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 3f3f1bb65c2c19..73e6353109d921 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -900,22 +900,26 @@ class SourceManager : public RefCountedBase { FileID getOrCreateFileID(const FileEntry *SourceFile, SrcMgr::CharacteristicKind FileCharacter); - /// Return a new SourceLocation that encodes the - /// fact that a token from SpellingLoc should actually be referenced from - /// ExpansionLoc, and that it represents the expansion of a macro argument - /// into the function-like macro body. - SourceLocation createMacroArgExpansionLoc(SourceLocation Loc, + /// Creates an expansion SLocEntry for the substitution of an argument into a + /// function-like macro's body. Returns the start of the expansion. + /// + /// The macro argument was written at \p SpellingLoc with length \p Length. + /// \p ExpansionLoc is the parameter name in the (expanded) macro body. + SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, - unsigned TokLength); + unsigned Length); - /// Return a new SourceLocation that encodes the fact - /// that a token from SpellingLoc should actually be referenced from - /// ExpansionLoc. - SourceLocation - createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, - SourceLocation ExpansionLocEnd, unsigned TokLength, - bool ExpansionIsTokenRange = true, int LoadedID = 0, - SourceLocation::UIntTy LoadedOffset = 0); + /// Creates an expansion SLocEntry for a macro use. Returns its start. + /// + /// The macro body begins at \p SpellingLoc with length \p Length. + /// The macro use spans [ExpansionLocStart, ExpansionLocEnd]. + SourceLocation createExpansionLoc(SourceLocation SpellingLoc, + SourceLocation ExpansionLocStart, + SourceLocation ExpansionLocEnd, + unsigned Length, + bool ExpansionIsTokenRange = true, + int LoadedID = 0, + SourceLocation::UIntTy LoadedOffset = 0); /// Return a new SourceLocation that encodes that the token starting /// at \p TokenStart ends prematurely at \p TokenEnd. @@ -1803,7 +1807,7 @@ class SourceManager : public RefCountedBase { /// the SLocEntry table and producing a source location that refers to it. SourceLocation createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion, - unsigned TokLength, int LoadedID = 0, + unsigned Length, int LoadedID = 0, SourceLocation::UIntTy LoadedOffset = 0); /// Return true if the specified FileID contains the diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 537ccc22ed050a..e2294088908c53 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -9293,13 +9293,13 @@ Expected ASTImporter::Import(FileID FromID, bool IsBuiltin) { ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart()); if (!ToExLocS) return ToExLocS.takeError(); - unsigned TokenLen = FromSM.getFileIDSize(FromID); + unsigned ExLength = FromSM.getFileIDSize(FromID); SourceLocation MLoc; if (FromEx.isMacroArgExpansion()) { - MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, TokenLen); + MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength); } else { if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd())) - MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, TokenLen, + MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength, FromEx.isExpansionTokenRange()); else return ToExLocE.takeError(); diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index ec3e35595bb75c..98e731eb12e62f 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -629,23 +629,21 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename, return LastFileIDLookup = FID; } -SourceLocation -SourceManager::createMacroArgExpansionLoc(SourceLocation SpellingLoc, - SourceLocation ExpansionLoc, - unsigned TokLength) { +SourceLocation SourceManager::createMacroArgExpansionLoc( + SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length) { ExpansionInfo Info = ExpansionInfo::createForMacroArg(SpellingLoc, ExpansionLoc); - return createExpansionLocImpl(Info, TokLength); + return createExpansionLocImpl(Info, Length); } SourceLocation SourceManager::createExpansionLoc( SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, - SourceLocation ExpansionLocEnd, unsigned TokLength, + SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange, int LoadedID, SourceLocation::UIntTy LoadedOffset) { ExpansionInfo Info = ExpansionInfo::create( SpellingLoc, ExpansionLocStart, ExpansionLocEnd, ExpansionIsTokenRange); - return createExpansionLocImpl(Info, TokLength, LoadedID, LoadedOffset); + return createExpansionLocImpl(Info, Length, LoadedID, LoadedOffset); } SourceLocation SourceManager::createTokenSplitLoc(SourceLocation Spelling, @@ -660,7 +658,7 @@ SourceLocation SourceManager::createTokenSplitLoc(SourceLocation Spelling, SourceLocation SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, - unsigned TokLength, int LoadedID, + unsigned Length, int LoadedID, SourceLocation::UIntTy LoadedOffset) { if (LoadedID < 0) { assert(LoadedID != -1 && "Loading sentinel FileID"); @@ -672,12 +670,12 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, return SourceLocation::getMacroLoc(LoadedOffset); } LocalSLocEntryTable.push_back(SLocEntry::get(NextLocalOffset, Info)); - assert(NextLocalOffset + TokLength + 1 > NextLocalOffset && - NextLocalOffset + TokLength + 1 <= CurrentLoadedOffset && + assert(NextLocalOffset + Length + 1 > NextLocalOffset && + NextLocalOffset + Length + 1 <= CurrentLoadedOffset && "Ran out of source locations!"); // See createFileID for that +1. - NextLocalOffset += TokLength + 1; - return SourceLocation::getMacroLoc(NextLocalOffset - (TokLength + 1)); + NextLocalOffset += Length + 1; + return SourceLocation::getMacroLoc(NextLocalOffset - (Length + 1)); } llvm::Optional