diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-05 11:04:55 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-05 11:04:55 +0000 |
commit | f89e2e2583ce57df74c0a35bfeff1da2aca508c6 (patch) | |
tree | ee4eee55a5d3055eb4698b06c51655cbbb908bcb /clang/lib/Frontend/DiagnosticRenderer.cpp | |
parent | 95b089e28722a25f6c1513694d80bbcf43478eef (diff) | |
download | bcm5719-llvm-f89e2e2583ce57df74c0a35bfeff1da2aca508c6.tar.gz bcm5719-llvm-f89e2e2583ce57df74c0a35bfeff1da2aca508c6.zip |
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.
llvm-svn: 169373
Diffstat (limited to 'clang/lib/Frontend/DiagnosticRenderer.cpp')
-rw-r--r-- | clang/lib/Frontend/DiagnosticRenderer.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Frontend/DiagnosticRenderer.cpp b/clang/lib/Frontend/DiagnosticRenderer.cpp index 1bc940c9409..89d3867aadd 100644 --- a/clang/lib/Frontend/DiagnosticRenderer.cpp +++ b/clang/lib/Frontend/DiagnosticRenderer.cpp @@ -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); |