[cfe-commits] r96004 - in /cfe/trunk: lib/Basic/SourceManager.cpp test/Misc/caret-diags-macros.c
Chris Lattner
sabre at nondot.org
Fri Feb 12 11:31:35 PST 2010
Author: lattner
Date: Fri Feb 12 13:31:35 2010
New Revision: 96004
URL: http://llvm.org/viewvc/llvm-project?rev=96004&view=rev
Log:
fix a bug in SourceManager::getInstantiationLocSlowCase, where
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.
Modified:
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/test/Misc/caret-diags-macros.c
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=96004&r1=96003&r2=96004&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Fri Feb 12 13:31:35 2010
@@ -560,10 +560,14 @@
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;
Modified: cfe/trunk/test/Misc/caret-diags-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/caret-diags-macros.c?rev=96004&r1=96003&r2=96004&view=diff
==============================================================================
--- cfe/trunk/test/Misc/caret-diags-macros.c (original)
+++ cfe/trunk/test/Misc/caret-diags-macros.c Fri Feb 12 13:31:35 2010
@@ -24,3 +24,12 @@
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);
+}
+
More information about the cfe-commits
mailing list