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. :)

llvm-svn: 39465
This commit is contained in:
Chris Lattner 2007-05-20 18:08:36 +00:00
parent ada7d4298b
commit 5ab15f154d
1 changed files with 2 additions and 1 deletions

View File

@ -429,7 +429,8 @@ void DiagnosticPrinterSTDERR::HighlightRange(const SourceRange &R,
/// 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.