diff options
author | Richard Trieu <rtrieu@google.com> | 2016-01-26 02:51:55 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2016-01-26 02:51:55 +0000 |
commit | 3a5c958182021abe2c2293409720ce9262711ef3 (patch) | |
tree | bf65be011b5f82a17137de2350169e9fe5657dfb /clang/lib/Frontend/DiagnosticRenderer.cpp | |
parent | f1c00a22be2ddd68d9c372dc93ac4e1486134788 (diff) | |
download | bcm5719-llvm-3a5c958182021abe2c2293409720ce9262711ef3.tar.gz bcm5719-llvm-3a5c958182021abe2c2293409720ce9262711ef3.zip |
Fix -Wnull-conversion for long macros.
Move the function to get a macro name from DiagnosticRenderer.cpp to Lexer.cpp
so that other files can use it. Lexer now has two functions to get the
immediate macro name, the newly added one is better for diagnostic purposes.
Make -Wnull-conversion use this function for better NULL macro detection.
llvm-svn: 258778
Diffstat (limited to 'clang/lib/Frontend/DiagnosticRenderer.cpp')
-rw-r--r-- | clang/lib/Frontend/DiagnosticRenderer.cpp | 45 |
1 files changed, 2 insertions, 43 deletions
diff --git a/clang/lib/Frontend/DiagnosticRenderer.cpp b/clang/lib/Frontend/DiagnosticRenderer.cpp index caf1f0dce99..302067a2fb0 100644 --- a/clang/lib/Frontend/DiagnosticRenderer.cpp +++ b/clang/lib/Frontend/DiagnosticRenderer.cpp @@ -23,48 +23,6 @@ #include <algorithm> using namespace clang; -/// \brief Retrieve the name of the immediate macro expansion. -/// -/// This routine starts from a source location, and finds the name of the macro -/// responsible for its immediate expansion. It looks through any intervening -/// macro argument expansions to compute this. It returns a StringRef which -/// refers to the SourceManager-owned buffer of the source where that macro -/// name is spelled. Thus, the result shouldn't out-live that SourceManager. -/// -/// This differs from Lexer::getImmediateMacroName in that any macro argument -/// location will result in the topmost function macro that accepted it. -/// e.g. -/// \code -/// MAC1( MAC2(foo) ) -/// \endcode -/// for location of 'foo' token, this function will return "MAC1" while -/// Lexer::getImmediateMacroName will return "MAC2". -static StringRef getImmediateMacroName(SourceLocation Loc, - const SourceManager &SM, - const LangOptions &LangOpts) { - assert(Loc.isMacroID() && "Only reasonble to call this on macros"); - // Walk past macro argument expanions. - 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. - Loc = SM.getSpellingLoc(SM.getImmediateExpansionRange(Loc).first); - - // Dig out the buffer where the macro name was spelled and the extents of the - // name so that we can render it into the expansion note. - std::pair<FileID, unsigned> ExpansionInfo = SM.getDecomposedLoc(Loc); - unsigned MacroTokenLength = Lexer::MeasureTokenLength(Loc, SM, LangOpts); - StringRef ExpansionBuffer = SM.getBufferData(ExpansionInfo.first); - return ExpansionBuffer.substr(ExpansionInfo.second, MacroTokenLength); -} - DiagnosticRenderer::DiagnosticRenderer(const LangOptions &LangOpts, DiagnosticOptions *DiagOpts) : LangOpts(LangOpts), DiagOpts(DiagOpts), LastLevel() {} @@ -474,7 +432,8 @@ void DiagnosticRenderer::emitSingleMacroExpansion( SmallString<100> MessageStorage; llvm::raw_svector_ostream Message(MessageStorage); - StringRef MacroName = getImmediateMacroName(Loc, SM, LangOpts); + StringRef MacroName = + Lexer::getImmediateMacroNameForDiagnostics(Loc, SM, LangOpts); if (MacroName.empty()) Message << "expanded from here"; else |