Ben Clayton | 9707e6b | 2022-05-25 19:28:55 +0000 | [diff] [blame] | 1 | // 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 Clayton | 572eaf2 | 2022-05-27 20:22:26 +0000 | [diff] [blame] | 15 | #include "src/tint/utils/concat.h" |
| 16 | |
Ben Clayton | 9707e6b | 2022-05-25 19:28:55 +0000 | [diff] [blame] | 17 | #ifndef SRC_TINT_UTILS_COMPILER_MACROS_H_ |
| 18 | #define SRC_TINT_UTILS_COMPILER_MACROS_H_ |
| 19 | |
Ben Clayton | 572eaf2 | 2022-05-27 20:22:26 +0000 | [diff] [blame] | 20 | #define TINT_REQUIRE_SEMICOLON static_assert(true) |
Ben Clayton | 9707e6b | 2022-05-25 19:28:55 +0000 | [diff] [blame] | 21 | |
| 22 | #if defined(_MSC_VER) |
Ben Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 23 | //////////////////////////////////////////////////////////////////////////////// |
| 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 sinclair | 3a2a279 | 2022-06-29 14:38:15 +0000 | [diff] [blame] | 28 | #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 Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 31 | #define TINT_DISABLE_WARNING_UNREACHABLE_CODE __pragma(warning(disable : 4702)) |
dan sinclair | 3a2a279 | 2022-06-29 14:38:15 +0000 | [diff] [blame] | 32 | #define TINT_DISABLE_WARNING_WEAK_VTABLES /* currently no-op */ |
Ben Clayton | 572eaf2 | 2022-05-27 20:22:26 +0000 | [diff] [blame] | 33 | |
Ben Clayton | 9707e6b | 2022-05-25 19:28:55 +0000 | [diff] [blame] | 34 | // clang-format off |
Ben Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 35 | #define TINT_BEGIN_DISABLE_WARNING(name) \ |
| 36 | __pragma(warning(push)) \ |
| 37 | TINT_CONCAT(TINT_DISABLE_WARNING_, name) \ |
Ben Clayton | 9707e6b | 2022-05-25 19:28:55 +0000 | [diff] [blame] | 38 | TINT_REQUIRE_SEMICOLON |
Ben Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 39 | #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 sinclair | 3a2a279 | 2022-06-29 14:38:15 +0000 | [diff] [blame] | 49 | #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 Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 53 | #define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */ |
dan sinclair | 3a2a279 | 2022-06-29 14:38:15 +0000 | [diff] [blame] | 54 | #define TINT_DISABLE_WARNING_WEAK_VTABLES _Pragma("clang diagnostic ignored \"-Wweak-vtables\"") |
Ben Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 55 | |
| 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 sinclair | 3a2a279 | 2022-06-29 14:38:15 +0000 | [diff] [blame] | 72 | #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 Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 75 | #define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */ |
dan sinclair | 3a2a279 | 2022-06-29 14:38:15 +0000 | [diff] [blame] | 76 | #define TINT_DISABLE_WARNING_WEAK_VTABLES /* currently no-op */ |
Ben Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 77 | |
| 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 Clayton | 9707e6b | 2022-05-25 19:28:55 +0000 | [diff] [blame] | 85 | TINT_REQUIRE_SEMICOLON |
| 86 | // clang-format on |
| 87 | #else |
Ben Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 88 | //////////////////////////////////////////////////////////////////////////////// |
| 89 | // Other |
| 90 | //////////////////////////////////////////////////////////////////////////////// |
Ben Clayton | 572eaf2 | 2022-05-27 20:22:26 +0000 | [diff] [blame] | 91 | #define TINT_BEGIN_DISABLE_WARNING(name) TINT_REQUIRE_SEMICOLON |
| 92 | #define TINT_END_DISABLE_WARNING(name) TINT_REQUIRE_SEMICOLON |
Ben Clayton | 61537d3 | 2022-05-31 13:14:29 +0000 | [diff] [blame] | 93 | #endif |
Ben Clayton | 9707e6b | 2022-05-25 19:28:55 +0000 | [diff] [blame] | 94 | |
| 95 | #endif // SRC_TINT_UTILS_COMPILER_MACROS_H_ |