]> granicus.if.org Git - clang/commitdiff
fix a bug in SourceManager::getInstantiationLocSlowCase, where
authorChris Lattner <sabre@nondot.org>
Fri, 12 Feb 2010 19:31:35 +0000 (19:31 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 12 Feb 2010 19:31:35 +0000 (19:31 +0000)
we'd add an offset from the spelling location space to the
instantiation location, which doesn't make sense and would
lead up to the text diagnostics crashing when presented with
non-sensical locations.

This fixes rdar://7597492, a crash on 255.vortex.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96004 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/SourceManager.cpp
test/Misc/caret-diags-macros.c

index 354bf7befbb3b99fa41692d1eed53139489c8a1a..b91671ad17b1c456a173ab83d8e635f8866a9888 100644 (file)
@@ -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;
index 80371a94eb38542fcaafd78f26435efd681fb54b..e138f59d608c9a1af917e353442c358c697f1bd2 100644 (file)
@@ -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);
+}
+