diff options
-rw-r--r-- | lib/Basic/SourceManager.cpp | 10 | ||||
-rw-r--r-- | test/Misc/caret-diags-macros.c | 9 |
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 354bf7befb..b91671ad17 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -560,10 +560,14 @@ FileID SourceManager::getFileIDSlow(unsigned SLocOffset) const { SourceLocation SourceManager:: getInstantiationLocSlowCase(SourceLocation Loc) const { do { - std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc); - Loc = getSLocEntry(LocInfo.first).getInstantiation() + // Note: If Loc indicates an offset into a token that came from a macro + // expansion (e.g. the 5th character of the token) we do not want to add + // this offset when going to the instantiation location. The instatiation + // location is the macro invocation, which the offset has nothing to do + // with. This is unlike when we get the spelling loc, because the offset + // directly correspond to the token whose spelling we're inspecting. + Loc = getSLocEntry(getFileID(Loc)).getInstantiation() .getInstantiationLocStart(); - Loc = Loc.getFileLocWithOffset(LocInfo.second); } while (!Loc.isFileID()); return Loc; diff --git a/test/Misc/caret-diags-macros.c b/test/Misc/caret-diags-macros.c index 80371a94eb..e138f59d60 100644 --- a/test/Misc/caret-diags-macros.c +++ b/test/Misc/caret-diags-macros.c @@ -24,3 +24,12 @@ void bar() { C; } + +// rdar://7597492 +#define sprintf(str, A, B) \ +__builtin___sprintf_chk (str, 0, 42, A, B) + +void baz(char *Msg) { + sprintf(Msg, " sizeof FoooLib : =%3u\n", 12LL); +} + |