forked from OSchip/llvm-project
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:
parent
ada7d4298b
commit
5ab15f154d
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue