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 | 5b10af7aa9e254a38d0a9f4d86caaccd61972124 (patch) | |
tree | c32fd8a727e3fdc02c168a709679d2518448c0fb /lib/Frontend/DiagnosticRenderer.cpp | |
parent | 98cffc6b30dacd71434530fee368b1f7d03bd565 (diff) |
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
Diffstat (limited to 'lib/Frontend/DiagnosticRenderer.cpp')
-rw-r--r-- | lib/Frontend/DiagnosticRenderer.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Frontend/DiagnosticRenderer.cpp b/lib/Frontend/DiagnosticRenderer.cpp index 1bc940c940..89d3867aad 100644 --- a/lib/Frontend/DiagnosticRenderer.cpp +++ b/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); |