blob: 2255dd1e296dd040e7c6d731f9ded58c7a0cc139 [file] [log] [blame]
James Kuszmaulcf324122023-01-14 14:07:17 -08001From 2c53d8ac36f378fda347f36ef2bc7fbc2038cb93 Mon Sep 17 00:00:00 2001
2From: PJ Reiniger <pj.reiniger@gmail.com>
3Date: Sun, 8 May 2022 13:34:07 -0400
4Subject: [PATCH 09/28] Add compiler warning pragmas
5
6---
7 llvm/include/llvm/ADT/FunctionExtras.h | 11 +++++++++++
8 llvm/include/llvm/ADT/Hashing.h | 9 +++++++++
9 llvm/include/llvm/ADT/SmallVector.h | 8 ++++++++
10 llvm/include/llvm/Support/MathExtras.h | 9 +++++++++
11 llvm/include/llvm/Support/MemAlloc.h | 13 +++++++++++++
12 llvm/lib/Support/raw_ostream.cpp | 4 ++++
13 llvm/unittests/ADT/DenseMapTest.cpp | 4 ++++
14 llvm/unittests/ADT/MapVectorTest.cpp | 7 +++++++
15 llvm/unittests/ADT/SmallVectorTest.cpp | 4 ++++
16 llvm/unittests/Support/AlignOfTest.cpp | 7 +++----
17 10 files changed, 72 insertions(+), 4 deletions(-)
18
19diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
20index 8a9d78f41..3efa73587 100644
21--- a/llvm/include/llvm/ADT/FunctionExtras.h
22+++ b/llvm/include/llvm/ADT/FunctionExtras.h
23@@ -55,6 +55,13 @@ namespace llvm {
24 /// It can hold functions with a non-const operator(), like mutable lambdas.
25 template <typename FunctionT> class unique_function;
26
27+// GCC warns on OutOfLineStorage
28+#if defined(__GNUC__) && !defined(__clang__)
29+#pragma GCC diagnostic push
30+#pragma GCC diagnostic ignored "-Warray-bounds"
31+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
32+#endif
33+
34 namespace detail {
35
36 template <typename T>
37@@ -411,6 +418,10 @@ public:
38 }
39 };
40
41+#if defined(__GNUC__) && !defined(__clang__)
42+#pragma GCC diagnostic pop
43+#endif
44+
45 } // end namespace llvm
46
47 #endif // LLVM_ADT_FUNCTIONEXTRAS_H
48diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
49index 74a87a3d8..47ff1b2bc 100644
50--- a/llvm/include/llvm/ADT/Hashing.h
51+++ b/llvm/include/llvm/ADT/Hashing.h
52@@ -55,6 +55,11 @@
53 #include <tuple>
54 #include <utility>
55
56+#ifdef _WIN32
57+#pragma warning(push)
58+#pragma warning(disable : 26495)
59+#endif
60+
61 namespace llvm {
62 template <typename T, typename Enable> struct DenseMapInfo;
63
64@@ -687,4 +692,8 @@ template <> struct DenseMapInfo<hash_code, void> {
65
66 } // namespace llvm
67
68+#ifdef _WIN32
69+#pragma warning(pop)
70+#endif
71+
72 #endif
73diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
74index 8686f7bb5..1e311ea56 100644
75--- a/llvm/include/llvm/ADT/SmallVector.h
76+++ b/llvm/include/llvm/ADT/SmallVector.h
77@@ -14,6 +14,14 @@
78 #ifndef LLVM_ADT_SMALLVECTOR_H
79 #define LLVM_ADT_SMALLVECTOR_H
80
81+// This file uses std::memcpy() to copy std::pair<unsigned int, unsigned int>.
82+// That type is POD, but the standard doesn't guarantee that. GCC doesn't treat
83+// the type as POD so it throws a warning. We want to consider this a warning
84+// instead of an error.
85+#if __GNUC__ >= 8
86+#pragma GCC diagnostic warning "-Wclass-memaccess"
87+#endif
88+
89 #include "llvm/Support/Compiler.h"
90 #include "llvm/Support/type_traits.h"
91 #include <algorithm>
92diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
93index da843ef79..fac12dd0e 100644
94--- a/llvm/include/llvm/Support/MathExtras.h
95+++ b/llvm/include/llvm/Support/MathExtras.h
96@@ -435,6 +435,11 @@ inline uint64_t maxUIntN(uint64_t N) {
97 return UINT64_MAX >> (64 - N);
98 }
99
100+#ifdef _WIN32
101+#pragma warning(push)
102+#pragma warning(disable : 4146)
103+#endif
104+
105 /// Gets the minimum value for a N-bit signed integer.
106 inline int64_t minIntN(int64_t N) {
107 assert(N > 0 && N <= 64 && "integer width out of range");
108@@ -442,6 +447,10 @@ inline int64_t minIntN(int64_t N) {
109 return UINT64_C(1) + ~(UINT64_C(1) << (N - 1));
110 }
111
112+#ifdef _WIN32
113+#pragma warning(pop)
114+#endif
115+
116 /// Gets the maximum value for a N-bit signed integer.
117 inline int64_t maxIntN(int64_t N) {
118 assert(N > 0 && N <= 64 && "integer width out of range");
119diff --git a/llvm/include/llvm/Support/MemAlloc.h b/llvm/include/llvm/Support/MemAlloc.h
120index d6012bd5a..01007deb8 100644
121--- a/llvm/include/llvm/Support/MemAlloc.h
122+++ b/llvm/include/llvm/Support/MemAlloc.h
123@@ -22,6 +22,14 @@
124
125 namespace llvm {
126
127+#ifdef _WIN32
128+#pragma warning(push)
129+// Warning on NONNULL, report is not known to abort
130+#pragma warning(disable : 6387)
131+#pragma warning(disable : 28196)
132+#pragma warning(disable : 28183)
133+#endif
134+
135 LLVM_ATTRIBUTE_RETURNS_NONNULL inline void *safe_malloc(size_t Sz) {
136 void *Result = std::malloc(Sz);
137 if (Result == nullptr) {
138@@ -84,4 +92,9 @@ allocate_buffer(size_t Size, size_t Alignment);
139 void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment);
140
141 } // namespace llvm
142+
143+#ifdef _WIN32
144+#pragma warning(pop)
145+#endif
146+
147 #endif
148diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
149index e4c318eb8..ee01a9522 100644
150--- a/llvm/lib/Support/raw_ostream.cpp
151+++ b/llvm/lib/Support/raw_ostream.cpp
152@@ -10,6 +10,10 @@
153 //
154 //===----------------------------------------------------------------------===//
155
156+#ifdef _WIN32
157+#define _CRT_NONSTDC_NO_WARNINGS
158+#endif
159+
160 #include "llvm/Support/raw_ostream.h"
161 #include "llvm/ADT/STLArrayExtras.h"
162 #include "llvm/ADT/StringExtras.h"
163diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp
164index e505b1907..9fe83a45d 100644
165--- a/llvm/unittests/ADT/DenseMapTest.cpp
166+++ b/llvm/unittests/ADT/DenseMapTest.cpp
167@@ -6,6 +6,10 @@
168 //
169 //===----------------------------------------------------------------------===//
170
171+#if defined(__GNUC__) && !defined(__clang__)
172+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
173+#endif
174+
175 #include "llvm/ADT/DenseMap.h"
176 #include "gtest/gtest.h"
177 #include <map>
178diff --git a/llvm/unittests/ADT/MapVectorTest.cpp b/llvm/unittests/ADT/MapVectorTest.cpp
179index 552f9956b..20ebcd753 100644
180--- a/llvm/unittests/ADT/MapVectorTest.cpp
181+++ b/llvm/unittests/ADT/MapVectorTest.cpp
182@@ -6,6 +6,13 @@
183 //
184 //===----------------------------------------------------------------------===//
185
186+#if defined(__GNUC__)
187+#pragma GCC diagnostic ignored "-Wpedantic"
188+#if !defined(__clang__)
189+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
190+#endif
191+#endif
192+
193 #include "llvm/ADT/MapVector.h"
194 #include "llvm/ADT/iterator_range.h"
195 #include "gtest/gtest.h"
196diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp
197index fe827546a..0e68bad6c 100644
198--- a/llvm/unittests/ADT/SmallVectorTest.cpp
199+++ b/llvm/unittests/ADT/SmallVectorTest.cpp
200@@ -17,6 +17,10 @@
201 #include <list>
202 #include <stdarg.h>
203
204+#if defined(__GNUC__)
205+#pragma GCC diagnostic ignored "-Wpedantic"
206+#endif
207+
208 using namespace llvm;
209
210 namespace {
211diff --git a/llvm/unittests/Support/AlignOfTest.cpp b/llvm/unittests/Support/AlignOfTest.cpp
212index f84895c18..6a50205b1 100644
213--- a/llvm/unittests/Support/AlignOfTest.cpp
214+++ b/llvm/unittests/Support/AlignOfTest.cpp
215@@ -31,10 +31,9 @@ namespace {
216 #pragma clang diagnostic ignored "-Wunknown-pragmas"
217 #pragma clang diagnostic ignored "-Winaccessible-base"
218 #elif ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
219-// Pragma based warning suppression was introduced in GGC 4.2. Additionally
220-// this warning is "enabled by default". The warning still appears if -Wall is
221-// suppressed. Apparently GCC suppresses it when -w is specifed, which is odd.
222-#pragma GCC diagnostic warning "-w"
223+#pragma GCC diagnostic warning "-Wunknown-pragmas"
224+#pragma GCC diagnostic warning "-Winaccessible-base"
225+#pragma GCC diagnostic warning "-Wunused-function"
226 #endif
227
228 // Define some fixed alignment types to use in these tests.