Browse Source

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
Serge Guelton 6 năm trước cách đây
mục cha
commit
effb4994da

+ 7 - 2
include/clang/Basic/SourceManager.h

@@ -1466,8 +1466,13 @@ public:
 
 
     // This happens when the macro is the result of a paste, in that case
     // 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.
     // 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));
     return isInSystemHeader(getSpellingLoc(loc));
   }
   }

+ 6 - 1
test/Misc/no-warn-in-system-macro.c

@@ -3,11 +3,16 @@
 
 
 #include <no-warn-in-system-macro.c.inc>
 #include <no-warn-in-system-macro.c.inc>
 
 
+#define MACRO(x) x
+
 int main(void)
 int main(void)
 {
 {
 	double foo = 1.0;
 	double foo = 1.0;
 
 
 	if (isnan(foo))
 	if (isnan(foo))
 		return 1;
 		return 1;
-	return 0;
+
+        MACRO(isnan(foo));
+
+        return 0;
 }
 }