[PATCH] D59413: Fix isInSystemMacro in presence of macro and pasted token

serge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 15 05:17:53 PDT 2019


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 <no-warn-in-system-macro.c.inc>
 
+#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));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59413.199585.patch
Type: text/x-patch
Size: 1287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190515/9fb9804f/attachment.bin>


More information about the cfe-commits mailing list