Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -1463,8 +1463,11 @@ // 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)); } Index: clang/test/Misc/no-warn-in-system-macro.c =================================================================== --- clang/test/Misc/no-warn-in-system-macro.c +++ clang/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; + + MACRO(isnan(foo)); + return 0; }