From 3eb0f55c2626d98b95cee1c8f7574718d8d0f0cd Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Tue, 26 Jan 2016 02:51:55 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258778 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/Lexer.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/clang/Lex/Lexer.h') diff --git a/include/clang/Lex/Lexer.h b/include/clang/Lex/Lexer.h index 12565d0b14..830c25a2e4 100644 --- a/include/clang/Lex/Lexer.h +++ b/include/clang/Lex/Lexer.h @@ -410,6 +410,26 @@ public: const SourceManager &SM, const LangOptions &LangOpts); + /// \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 getImmediateMacroNameForDiagnostics( + SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts); + /// \brief Compute the preamble of the given file. /// /// The preamble of a file contains the initial comments, include directives, -- cgit v1.2.3