[PATCH] D59413: Fix isInSystemMacro in presence of macro and pasted token
This revision was automatically updated to reflect the committed changes. Closed by commit rC360885: Fix isInSystemMacro in presence of macro and pasted token (authored by serge_sans_paille, committed by ). Changed prior to commit: https://reviews.llvm.org/D59413?vs=199585=199801#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59413/new/ https://reviews.llvm.org/D59413 Files: include/clang/Basic/SourceManager.h test/Misc/no-warn-in-system-macro.c Index: include/clang/Basic/SourceManager.h === --- include/clang/Basic/SourceManager.h +++ include/clang/Basic/SourceManager.h @@ -1466,8 +1466,13 @@ // 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: test/Misc/no-warn-in-system-macro.c === --- test/Misc/no-warn-in-system-macro.c +++ 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; } Index: include/clang/Basic/SourceManager.h === --- include/clang/Basic/SourceManager.h +++ include/clang/Basic/SourceManager.h @@ -1466,8 +1466,13 @@ // 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: test/Misc/no-warn-in-system-macro.c === --- test/Misc/no-warn-in-system-macro.c +++ 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; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59413: Fix isInSystemMacro in presence of macro and pasted token
serge-sans-paille updated this revision to Diff 199585. serge-sans-paille added a comment. Updated with clang-formated diff CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59413/new/ https://reviews.llvm.org/D59413 Files: clang/include/clang/Basic/SourceManager.h clang/test/Misc/no-warn-in-system-macro.c 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; - return 0; + +MACRO(isnan(foo)); + +return 0; } Index: clang/include/clang/Basic/SourceManager.h === --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -1466,8 +1466,13 @@ // 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; - return 0; + +MACRO(isnan(foo)); + +return 0; } Index: clang/include/clang/Basic/SourceManager.h === --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -1466,8 +1466,13 @@ // 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)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59413: Fix isInSystemMacro in presence of macro and pasted token
serge-sans-paille added a comment. @rsmith : up :-) Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59413/new/ https://reviews.llvm.org/D59413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59413: Fix isInSystemMacro in presence of macro and pasted token
serge-sans-paille added a comment. @rsmith : up :-) Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59413/new/ https://reviews.llvm.org/D59413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59413: Fix isInSystemMacro in presence of macro and pasted token
serge-sans-paille added a comment. @rsmith up! Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59413/new/ https://reviews.llvm.org/D59413 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59413: Fix isInSystemMacro in presence of macro and pasted token
serge-sans-paille created this revision. serge-sans-paille added a reviewer: rsmith. Herald added a project: clang. Herald added a subscriber: cfe-commits. 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 Repository: rC Clang https://reviews.llvm.org/D59413 Files: clang/include/clang/Basic/SourceManager.h clang/test/Misc/no-warn-in-system-macro.c 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; } 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; } 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)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits