From 09654593bd7dcdcb836babcb68f36f1cefb28d20 Mon Sep 17 00:00:00 2001 From: sergesanspaille Date: Wed, 22 May 2019 11:36:40 +0000 Subject: [PATCH] Fix for rhbz#1674031 --- ...nSystemMacro-to-handle-pasted-macros.patch | 137 ++++++++++++++++++ ...-Format-isInSystemMacro-after-D55782.patch | 39 +++++ ...cro-in-presence-of-macro-and-pasted-.patch | 63 ++++++++ clang.spec | 11 +- 4 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 0001-Fix-isInSystemMacro-to-handle-pasted-macros.patch create mode 100644 0002-Format-isInSystemMacro-after-D55782.patch create mode 100644 0003-Fix-isInSystemMacro-in-presence-of-macro-and-pasted-.patch diff --git a/0001-Fix-isInSystemMacro-to-handle-pasted-macros.patch b/0001-Fix-isInSystemMacro-to-handle-pasted-macros.patch new file mode 100644 index 0000000..9480f42 --- /dev/null +++ b/0001-Fix-isInSystemMacro-to-handle-pasted-macros.patch @@ -0,0 +1,137 @@ +From cb7fd3caeee52fe94461b717294c4db4056853e3 Mon Sep 17 00:00:00 2001 +From: Serge Guelton +Date: Fri, 1 Feb 2019 06:11:44 +0000 +Subject: [PATCH 1/3] Fix isInSystemMacro to handle pasted macros + +Token pasted by the preprocessor (through ##) have a Spelling pointing to scratch buffer. +As a result they are not recognized at system macro, even though the pasting happened in +a system macro. Fix that by looking into the parent macro if the original lookup finds a +scratch buffer. + +Differential Revision: https://reviews.llvm.org/D55782 + +This effectively fixes https://bugs.llvm.org/show_bug.cgi?id=35268, + +git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352838 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + include/clang/Basic/SourceManager.h | 18 +++++++++++++++++- + test/Misc/no-warn-in-system-macro.c | 13 +++++++++++++ + test/Misc/no-warn-in-system-macro.c.inc | 9 +++++++++ + test/Misc/warn-in-system-macro-def.c | 21 +++++++++++++++++++++ + test/Misc/warn-in-system-macro-def.c.inc | 4 ++++ + 5 files changed, 64 insertions(+), 1 deletion(-) + create mode 100644 test/Misc/no-warn-in-system-macro.c + create mode 100644 test/Misc/no-warn-in-system-macro.c.inc + create mode 100644 test/Misc/warn-in-system-macro-def.c + create mode 100644 test/Misc/warn-in-system-macro-def.c.inc + +diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h +index dcc4a37e23..c6b92f9000 100644 +--- a/include/clang/Basic/SourceManager.h ++++ b/include/clang/Basic/SourceManager.h +@@ -1441,6 +1441,12 @@ public: + return Filename.equals(""); + } + ++ /// Returns whether \p Loc is located in a file. ++ bool isWrittenInScratchSpace(SourceLocation Loc) const { ++ StringRef Filename(getPresumedLoc(Loc).getFilename()); ++ return Filename.equals(""); ++ } ++ + /// Returns if a SourceLocation is in a system header. + bool isInSystemHeader(SourceLocation Loc) const { + return isSystem(getFileCharacteristic(Loc)); +@@ -1453,7 +1459,17 @@ public: + + /// 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. +diff --git a/test/Misc/no-warn-in-system-macro.c b/test/Misc/no-warn-in-system-macro.c +new file mode 100644 +index 0000000000..a319b14c9c +--- /dev/null ++++ b/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 ++ ++int main(void) ++{ ++ double foo = 1.0; ++ ++ if (isnan(foo)) ++ return 1; ++ return 0; ++} +diff --git a/test/Misc/no-warn-in-system-macro.c.inc b/test/Misc/no-warn-in-system-macro.c.inc +new file mode 100644 +index 0000000000..3cbe7dfc16 +--- /dev/null ++++ b/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)) ++ +diff --git a/test/Misc/warn-in-system-macro-def.c b/test/Misc/warn-in-system-macro-def.c +new file mode 100644 +index 0000000000..b295130702 +--- /dev/null ++++ b/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 ++ ++#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; ++} +diff --git a/test/Misc/warn-in-system-macro-def.c.inc b/test/Misc/warn-in-system-macro-def.c.inc +new file mode 100644 +index 0000000000..5c7e60275a +--- /dev/null ++++ b/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 +-- +2.20.1 + diff --git a/0002-Format-isInSystemMacro-after-D55782.patch b/0002-Format-isInSystemMacro-after-D55782.patch new file mode 100644 index 0000000..e5004fb --- /dev/null +++ b/0002-Format-isInSystemMacro-after-D55782.patch @@ -0,0 +1,39 @@ +From 49b29ff9feafd8b9041e2a76cbe843115d263ced Mon Sep 17 00:00:00 2001 +From: Fangrui Song +Date: Mon, 11 Feb 2019 13:30:04 +0000 +Subject: [PATCH 2/3] Format isInSystemMacro after D55782 + +git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@353697 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + include/clang/Basic/SourceManager.h | 10 ++++------ + 1 file changed, 4 insertions(+), 6 deletions(-) + +diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h +index c6b92f9000..f44239d9ce 100644 +--- a/include/clang/Basic/SourceManager.h ++++ b/include/clang/Basic/SourceManager.h +@@ -1459,17 +1459,15 @@ public: + + /// Returns whether \p Loc is expanded from a macro in a system header. + bool isInSystemMacro(SourceLocation loc) const { +- if(!loc.isMacroID()) ++ 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))) { ++ if (isWrittenInScratchSpace(getSpellingLoc(loc))) + return isInSystemHeader(getSpellingLoc(getImmediateMacroCallerLoc(loc))); +- } +- else { +- return isInSystemHeader(getSpellingLoc(loc)); +- } ++ ++ return isInSystemHeader(getSpellingLoc(loc)); + } + + /// The size of the SLocEntry that \p FID represents. +-- +2.20.1 + diff --git a/0003-Fix-isInSystemMacro-in-presence-of-macro-and-pasted-.patch b/0003-Fix-isInSystemMacro-in-presence-of-macro-and-pasted-.patch new file mode 100644 index 0000000..c27dfd9 --- /dev/null +++ b/0003-Fix-isInSystemMacro-in-presence-of-macro-and-pasted-.patch @@ -0,0 +1,63 @@ +From a6b7f0946df82ca207b27f1931d4b430ab77e5e0 Mon Sep 17 00:00:00 2001 +From: Serge Guelton +Date: Thu, 16 May 2019 12:40:00 +0000 +Subject: [PATCH 3/3] 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 +--- + include/clang/Basic/SourceManager.h | 9 +++++++-- + test/Misc/no-warn-in-system-macro.c | 7 ++++++- + 2 files changed, 13 insertions(+), 3 deletions(-) + +diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h +index f44239d9ce..c964c64faf 100644 +--- a/include/clang/Basic/SourceManager.h ++++ b/include/clang/Basic/SourceManager.h +@@ -1464,8 +1464,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)); + } +diff --git a/test/Misc/no-warn-in-system-macro.c b/test/Misc/no-warn-in-system-macro.c +index a319b14c9c..a351b89256 100644 +--- a/test/Misc/no-warn-in-system-macro.c ++++ b/test/Misc/no-warn-in-system-macro.c +@@ -3,11 +3,16 @@ + + #include + ++#define MACRO(x) x ++ + int main(void) + { + double foo = 1.0; + + if (isnan(foo)) + return 1; +- return 0; ++ ++ MACRO(isnan(foo)); ++ ++ return 0; + } +-- +2.20.1 + diff --git a/clang.spec b/clang.spec index 143e5a2..aef4e2b 100644 --- a/clang.spec +++ b/clang.spec @@ -61,7 +61,7 @@ Name: %pkg_name Version: %{maj_ver}.%{min_ver}.%{patch_ver} -Release: 2%{?rc_ver:.rc%{rc_ver}}%{?dist} +Release: 3%{?rc_ver:.rc%{rc_ver}}%{?dist} Summary: A C language family front-end for LLVM License: NCSA @@ -74,6 +74,9 @@ Source1: http://%{?rc_ver:pre}releases.llvm.org/%{version}/%{?rc_ver:rc%{rc_ver} Patch4: 0002-gtest-reorg.patch Patch9: 0001-Fix-uninitialized-value-in-ABIArgInfo.patch Patch11: 0001-ToolChain-Add-lgcc_s-to-the-linker-flags-when-using-.patch +Patch12: 0001-Fix-isInSystemMacro-to-handle-pasted-macros.patch +Patch13: 0002-Format-isInSystemMacro-after-D55782.patch +Patch14: 0003-Fix-isInSystemMacro-in-presence-of-macro-and-pasted-.patch BuildRequires: gcc BuildRequires: gcc-c++ @@ -216,6 +219,9 @@ pathfix.py -i %{__python3} -pn \ %patch4 -p1 -b .gtest %patch9 -p1 -b .abi-arginfo %patch11 -p1 -b .libcxx-fix +%patch12 -p1 -b .double-promotion-0 +%patch13 -p1 -b .double-promotion-1 +%patch14 -p1 -b .double-promotion-2 mv ../%{clang_tools_srcdir} tools/extra @@ -418,6 +424,9 @@ false %endif %changelog +* Thu May 16 2019 sguelton@redhat.com - 8.0.0-3 +- Fix for rhbz#1674031 + * Fri Apr 12 2019 sguelton@redhat.com - 8.0.0-2 - Remove useless patch thanks to GCC upgrade