PR14049: Don't say "expanded from macro 'foo'" when 'foo' just happens to be

the LHS of a token paste. Use "expanded from here" instead when we're not sure
it's actually a macro.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169373 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Richard Smith 2012-12-05 11:04:55 +00:00
Родитель 98cffc6b30
Коммит 5b10af7aa9
3 изменённых файлов: 26 добавлений и 5 удалений

Просмотреть файл

@ -47,6 +47,11 @@ static StringRef getImmediateMacroName(SourceLocation Loc,
while (SM.isMacroArgExpansion(Loc))
Loc = SM.getImmediateExpansionRange(Loc).first;
// If the macro's spelling has no FileID, then it's actually a token paste
// or stringization (or similar) and not a macro at all.
if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(Loc))))
return StringRef();
// Find the spelling location of the start of the non-argument expansion
// range. This is where the macro name was spelled in order to begin
// expanding this macro.
@ -448,8 +453,11 @@ void DiagnosticRenderer::emitMacroExpansions(SourceLocation Loc,
SmallString<100> MessageStorage;
llvm::raw_svector_ostream Message(MessageStorage);
Message << "expanded from macro '"
<< getImmediateMacroName(Loc, SM, LangOpts) << "'";
StringRef MacroName = getImmediateMacroName(Loc, SM, LangOpts);
if (MacroName.empty())
Message << "expanded from here";
else
Message << "expanded from macro '" << MacroName << "'";
emitDiagnostic(SpellingLoc, DiagnosticsEngine::Note,
Message.str(),
SpellingRanges, ArrayRef<FixItHint>(), &SM);

Просмотреть файл

@ -12,7 +12,7 @@
#define DROOL WAZ
#define FOOL DROOL
FOOL
FOOL;
// CHECK: :15:1: error: expected identifier or '('
// CHECK: FOOL
@ -50,4 +50,17 @@ FOOL
// CHECK: :3:13: note: expanded from macro 'FOO'
// CHECK: #define FOO 1+"hi"
// CHECK: ^
// CHECK: 1 error generated.
#define ADD(a, b) a ## #b
ADD(L, foo)
// CHECK: error: expected identifier or '('
// CHECK: ADD(L, foo)
// CHECK: {{^\^}}
// CHECK: note: expanded from macro 'ADD'
// CHECK: #define ADD(a, b) a ## #b
// CHECK: {{^ \^}}
// CHECK: note: expanded from here
// CHECK: L"foo"
// CHECK: {{^\^}}
// CHECK: 2 errors generated.

Просмотреть файл

@ -6,7 +6,7 @@
// CHECK: While building module 'Module' imported from
// CHECK: error: expected ';' after top level declarator
// CHECK: note: expanded from macro 'getModuleVersion'
// CHECK: note: expanded from here
// CHECK: fatal error: could not build module 'Module'
// CHECK: While building module 'DependsOnModule' imported from
// CHECK: fatal error: could not build module 'Module'