blob: b3cca3cb11393583b561d804a36108ed7bc40759 [file] [log] [blame]
Ben Clayton9707e6b2022-05-25 19:28:55 +00001// Copyright 2022 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Ben Clayton572eaf22022-05-27 20:22:26 +000015#include "src/tint/utils/concat.h"
16
Ben Clayton9707e6b2022-05-25 19:28:55 +000017#ifndef SRC_TINT_UTILS_COMPILER_MACROS_H_
18#define SRC_TINT_UTILS_COMPILER_MACROS_H_
19
Ben Clayton572eaf22022-05-27 20:22:26 +000020#define TINT_REQUIRE_SEMICOLON static_assert(true)
Ben Clayton9707e6b2022-05-25 19:28:55 +000021
22#if defined(_MSC_VER)
Ben Clayton61537d32022-05-31 13:14:29 +000023////////////////////////////////////////////////////////////////////////////////
24// MSVC
25////////////////////////////////////////////////////////////////////////////////
26#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW __pragma(warning(disable : 4756))
27#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED /* currently no-op */
dan sinclair3a2a2792022-06-29 14:38:15 +000028#define TINT_DISABLE_WARNING_NEWLINE_EOF /* currently no-op */
29#define TINT_DISABLE_WARNING_OLD_STYLE_CAST /* currently no-op */
30#define TINT_DISABLE_WARNING_SIGN_CONVERSION /* currently no-op */
Ben Clayton61537d32022-05-31 13:14:29 +000031#define TINT_DISABLE_WARNING_UNREACHABLE_CODE __pragma(warning(disable : 4702))
dan sinclair3a2a2792022-06-29 14:38:15 +000032#define TINT_DISABLE_WARNING_WEAK_VTABLES /* currently no-op */
Ben Clayton572eaf22022-05-27 20:22:26 +000033
Ben Clayton9707e6b2022-05-25 19:28:55 +000034// clang-format off
Ben Clayton61537d32022-05-31 13:14:29 +000035#define TINT_BEGIN_DISABLE_WARNING(name) \
36 __pragma(warning(push)) \
37 TINT_CONCAT(TINT_DISABLE_WARNING_, name) \
Ben Clayton9707e6b2022-05-25 19:28:55 +000038 TINT_REQUIRE_SEMICOLON
Ben Clayton61537d32022-05-31 13:14:29 +000039#define TINT_END_DISABLE_WARNING(name) \
40 __pragma(warning(pop)) \
41 TINT_REQUIRE_SEMICOLON
42// clang-format on
43#elif defined(__clang__)
44////////////////////////////////////////////////////////////////////////////////
45// Clang
46////////////////////////////////////////////////////////////////////////////////
47#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW /* currently no-op */
48#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED /* currently no-op */
dan sinclair3a2a2792022-06-29 14:38:15 +000049#define TINT_DISABLE_WARNING_NEWLINE_EOF _Pragma("clang diagnostic ignored \"-Wnewline-eof\"")
50#define TINT_DISABLE_WARNING_OLD_STYLE_CAST _Pragma("clang diagnostic ignored \"-Wold-style-cast\"")
51#define TINT_DISABLE_WARNING_SIGN_CONVERSION \
52 _Pragma("clang diagnostic ignored \"-Wsign-conversion\"")
Ben Clayton61537d32022-05-31 13:14:29 +000053#define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */
dan sinclair3a2a2792022-06-29 14:38:15 +000054#define TINT_DISABLE_WARNING_WEAK_VTABLES _Pragma("clang diagnostic ignored \"-Wweak-vtables\"")
Ben Clayton61537d32022-05-31 13:14:29 +000055
56// clang-format off
57#define TINT_BEGIN_DISABLE_WARNING(name) \
58 _Pragma("clang diagnostic push") \
59 TINT_CONCAT(TINT_DISABLE_WARNING_, name) \
60 TINT_REQUIRE_SEMICOLON
61#define TINT_END_DISABLE_WARNING(name) \
62 _Pragma("clang diagnostic pop") \
63 TINT_REQUIRE_SEMICOLON
64// clang-format on
65#elif defined(__GNUC__)
66////////////////////////////////////////////////////////////////////////////////
67// GCC
68////////////////////////////////////////////////////////////////////////////////
69#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW /* currently no-op */
70#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED \
71 _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
dan sinclair3a2a2792022-06-29 14:38:15 +000072#define TINT_DISABLE_WARNING_NEWLINE_EOF /* currently no-op */
73#define TINT_DISABLE_WARNING_OLD_STYLE_CAST /* currently no-op */
74#define TINT_DISABLE_WARNING_SIGN_CONVERSION /* currently no-op */
Ben Clayton61537d32022-05-31 13:14:29 +000075#define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */
dan sinclair3a2a2792022-06-29 14:38:15 +000076#define TINT_DISABLE_WARNING_WEAK_VTABLES /* currently no-op */
Ben Clayton61537d32022-05-31 13:14:29 +000077
78// clang-format off
79#define TINT_BEGIN_DISABLE_WARNING(name) \
80 _Pragma("GCC diagnostic push") \
81 TINT_CONCAT(TINT_DISABLE_WARNING_, name) \
82 TINT_REQUIRE_SEMICOLON
83#define TINT_END_DISABLE_WARNING(name) \
84 _Pragma("GCC diagnostic pop") \
Ben Clayton9707e6b2022-05-25 19:28:55 +000085 TINT_REQUIRE_SEMICOLON
86// clang-format on
87#else
Ben Clayton61537d32022-05-31 13:14:29 +000088////////////////////////////////////////////////////////////////////////////////
89// Other
90////////////////////////////////////////////////////////////////////////////////
Ben Clayton572eaf22022-05-27 20:22:26 +000091#define TINT_BEGIN_DISABLE_WARNING(name) TINT_REQUIRE_SEMICOLON
92#define TINT_END_DISABLE_WARNING(name) TINT_REQUIRE_SEMICOLON
Ben Clayton61537d32022-05-31 13:14:29 +000093#endif
Ben Clayton9707e6b2022-05-25 19:28:55 +000094
95#endif // SRC_TINT_UTILS_COMPILER_MACROS_H_