[PATCH] D55782: Fix isInSystemMacro to handle pasted token

serge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 14 01:15:14 PST 2019


serge-sans-paille updated this revision to Diff 181498.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55782/new/

https://reviews.llvm.org/D55782

Files:
  include/clang/Basic/SourceManager.h
  test/Misc/no-warn-in-system-macro.c
  test/Misc/no-warn-in-system-macro.c.inc


Index: test/Misc/no-warn-in-system-macro.c.inc
===================================================================
--- /dev/null
+++ test/Misc/no-warn-in-system-macro.c.inc
@@ -0,0 +1,9 @@
+extern int __isnanf(float f);
+extern int __isnan(double f);
+extern int __isnanl(long double f);
+#define isnan(x) \
+	(sizeof (x) == sizeof (float)                \
+	? __isnanf (x)                    \
+	: sizeof (x) == sizeof (double)               \
+	? __isnan (x) : __isnanl (x))
+
Index: test/Misc/no-warn-in-system-macro.c
===================================================================
--- /dev/null
+++ test/Misc/no-warn-in-system-macro.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -isystem %S -Wdouble-promotion -fsyntax-only %s  2>&1 | FileCheck -allow-empty %s
+// CHECK-NOT: warning:
+
+#include <no-warn-in-system-macro.c.inc>
+
+int main(void)
+{
+	double foo = 1.0;
+
+	if (isnan(foo))
+		return 1;
+	return 0;
+}
Index: include/clang/Basic/SourceManager.h
===================================================================
--- include/clang/Basic/SourceManager.h
+++ include/clang/Basic/SourceManager.h
@@ -1453,7 +1453,11 @@
 
   /// Returns whether \p Loc is expanded from a macro in a system header.
   bool isInSystemMacro(SourceLocation loc) const {
-    return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc));
+    return loc.isMacroID() &&
+           (isInSystemHeader(getSpellingLoc(loc)) ||
+	    // 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.
+            isInSystemHeader(getSpellingLoc(getImmediateMacroCallerLoc(loc))));
   }
 
   /// The size of the SLocEntry that \p FID represents.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55782.181498.patch
Type: text/x-patch
Size: 1715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190114/1defece4/attachment-0001.bin>


More information about the cfe-commits mailing list