]> granicus.if.org Git - clang/commitdiff
Fix isInSystemMacro in presence of macro and pasted token
authorSerge Guelton <sguelton@redhat.com>
Thu, 16 May 2019 12:40:00 +0000 (12:40 +0000)
committerSerge Guelton <sguelton@redhat.com>
Thu, 16 May 2019 12:40:00 +0000 (12:40 +0000)
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
test/Misc/no-warn-in-system-macro.c

index 484889ea544411a3267c9665bc5f8f2120e9c59d..388fc1c1f862226e2929e6300a1dfefa3d1e0631 100644 (file)
@@ -1466,8 +1466,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));
   }
index a319b14c9c3f07b1087542fced922f2ff317cb97..a351b892565fa1f024b7df0d4743d0291f00edba 100644 (file)
@@ -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;
 }