[cfe-commits] r64604 - /cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Chris Lattner sabre at nondot.org
Sun Feb 15 13:06:39 PST 2009


Author: lattner
Date: Sun Feb 15 15:06:39 2009
New Revision: 64604

URL: http://llvm.org/viewvc/llvm-project?rev=64604&view=rev
Log:
fix PR3579: __LINE__ expands to the presumed location of the 
*end* of a macro instantiation, not the start of it.  This is
really all about bug-for-bug compatibility with GCC, but not
doing this breaks the FreeBSD kernel.

Modified:
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=64604&r1=64603&r2=64604&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sun Feb 15 15:06:39 2009
@@ -464,7 +464,17 @@
     // C99 6.10.8: "__LINE__: The presumed line number (within the current
     // source file) of the current source line (an integer constant)".  This can
     // be affected by #line.
-    PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
+    SourceLocation Loc = Tok.getLocation();
+    
+    // One wrinkle here is that GCC expands __LINE__ to location of the *end* of
+    // a macro instantiation.  This doesn't matter for object-like macros, but
+    // can matter for a function-like macro that expands to contain __LINE__.
+    // Skip down through instantiation points until we find a file loc for the
+    // end of the instantiation history.
+    while (!Loc.isFileID())
+      Loc = SourceMgr.getImmediateInstantiationRange(Loc).second;
+    
+    PresumedLoc PLoc = SourceMgr.getPresumedLoc(Loc);
     
     // __LINE__ expands to a simple numeric value.  Add a space after it so that
     // it will tokenize as a number (and not run into stuff after it in the temp





More information about the cfe-commits mailing list