[cfe-commits] r39465 - /cfe/cfe/trunk/Driver/clang.cpp

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:44:42 PDT 2007


Author: clattner
Date: Wed Jul 11 11:44:42 2007
New Revision: 39465

URL: http://llvm.org/viewvc/llvm-project?rev=39465&view=rev
Log:
Steve pointed out that testcases like this (with a macro expansion):

#define friendlystruct fs

  struct A { int X; };

  void test2(struct A friendlystruct, int C) {
    return friendlystruct + (C     *40);
  }

were getting diagnosed like this:

t.c:7:27: error: invalid operands to binary expression ('struct A' and 'int')
    return friendlystruct + (C     *40);
           ~~             ^ ~~~~~~~~~~~

The problem is that getCharacterData returns a pointer to the macro expansion,
not to the macro instantiation.  Instead, use getLogicalLoc to get a pointer
to the instatiation location, so we relex the macro id.  We now get:

t.c:7:27: error: invalid operands to binary expression ('struct A' and 'int')
    return friendlystruct + (C     *40);
           ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~

oooh ahh. :)

Modified:
    cfe/cfe/trunk/Driver/clang.cpp

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39465&r1=39464&r2=39465&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:44:42 2007
@@ -429,7 +429,8 @@
 /// GetTokenLength - Given the source location of a token, determine its length.
 /// This is a fully general function that uses a lexer to relex the token.
 unsigned DiagnosticPrinterSTDERR::GetTokenLength(SourceLocation Loc) {
-  const char *StrData = SourceMgr.getCharacterData(Loc);
+  const char *StrData = 
+    SourceMgr.getCharacterData(SourceMgr.getLogicalLoc(Loc));
   
   // Note, this could be special cased for common tokens like identifiers, ')',
   // etc to make this faster, if it mattered.





More information about the cfe-commits mailing list