From a6b7f0946df82ca207b27f1931d4b430ab77e5e0 Mon Sep 17 00:00:00 2001 From: Serge Guelton Date: Thu, 16 May 2019 12:40:00 +0000 Subject: [PATCH 3/3] Fix isInSystemMacro in presence of macro and pasted token When a warning is raised from the expansion of a system macro that involves pasted token, there was still situations were they were not skipped, as showcased by this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1472437 Differential Revision: https://reviews.llvm.org/D59413 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360885 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SourceManager.h | 9 +++++++-- test/Misc/no-warn-in-system-macro.c | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index f44239d9ce..c964c64faf 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -1464,8 +1464,13 @@ public: // This happens when the macro is the result of a paste, in that case // its spelling is the scratch memory, so we take the parent context. - if (isWrittenInScratchSpace(getSpellingLoc(loc))) - return isInSystemHeader(getSpellingLoc(getImmediateMacroCallerLoc(loc))); + // There can be several level of token pasting. + if (isWrittenInScratchSpace(getSpellingLoc(loc))) { + do { + loc = getImmediateMacroCallerLoc(loc); + } while (isWrittenInScratchSpace(getSpellingLoc(loc))); + return isInSystemMacro(loc); + } return isInSystemHeader(getSpellingLoc(loc)); } diff --git a/test/Misc/no-warn-in-system-macro.c b/test/Misc/no-warn-in-system-macro.c index a319b14c9c..a351b89256 100644 --- a/test/Misc/no-warn-in-system-macro.c +++ b/test/Misc/no-warn-in-system-macro.c @@ -3,11 +3,16 @@ #include +#define MACRO(x) x + int main(void) { double foo = 1.0; if (isnan(foo)) return 1; - return 0; + + MACRO(isnan(foo)); + + return 0; } -- 2.20.1