serge-sans-paille updated this revision to Diff 184275.
serge-sans-paille added a comment.
Patch updated to take into account @rsmith remarks. Test case added as an
illustration.
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
test/Misc/warn-in-system-macro-def.c
test/Misc/warn-in-system-macro-def.c.inc
Index: test/Misc/warn-in-system-macro-def.c.inc
===================================================================
--- /dev/null
+++ test/Misc/warn-in-system-macro-def.c.inc
@@ -0,0 +1,4 @@
+extern int __isnanf(float f);
+extern int __isnan(double f);
+extern int __isnanl(long double f);
+#define ISNAN isnan
Index: test/Misc/warn-in-system-macro-def.c
===================================================================
--- /dev/null
+++ test/Misc/warn-in-system-macro-def.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -isystem %S -Wdouble-promotion -fsyntax-only %s 2>&1 | FileCheck -allow-empty %s
+// CHECK: warning:
+// CHECK: expanded from macro 'ISNAN'
+// CHECK: expanded from macro 'isnan'
+
+#include <warn-in-system-macro-def.c.inc>
+
+#define isnan(x) \
+ (sizeof (x) == sizeof (float) \
+ ? __isnanf (x) \
+ : sizeof (x) == sizeof (double) \
+ ? __isnan (x) : __isnanl (x))
+
+int main(void)
+{
+ double foo = 1.0;
+
+ if (ISNAN(foo))
+ return 1;
+ return 0;
+}
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
@@ -1440,6 +1440,12 @@
return Filename.equals("<command line>");
}
+ /// Returns whether \p Loc is located in a <scratch space> file.
+ bool isWrittenInScratchSpace(SourceLocation Loc) const {
+ StringRef Filename(getPresumedLoc(Loc).getFilename());
+ return Filename.equals("<scratch space>");
+ }
+
/// Returns if a SourceLocation is in a system header.
bool isInSystemHeader(SourceLocation Loc) const {
return isSystem(getFileCharacteristic(Loc));
@@ -1452,7 +1458,17 @@
/// Returns whether \p Loc is expanded from a macro in a system header.
bool isInSystemMacro(SourceLocation loc) const {
- return loc.isMacroID() && isInSystemHeader(getSpellingLoc(loc));
+ if(!loc.isMacroID())
+ return false;
+
+ // 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)));
+ }
+ else {
+ return isInSystemHeader(getSpellingLoc(loc));
+ }
}
/// The size of the SLocEntry that \p FID represents.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits