chromium/third_party/dawn/src/tint/utils/macros/compiler.h

// Copyright 2022 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "src/tint/utils/macros/concat.h"
#include "src/utils/compiler.h"

#ifndef SRC_TINT_UTILS_MACROS_COMPILER_H_
#define SRC_TINT_UTILS_MACROS_COMPILER_H_

#define TINT_REQUIRE_SEMICOLON

#if defined(_MSC_VER) && !defined(__clang__)
////////////////////////////////////////////////////////////////////////////////
// MSVC
////////////////////////////////////////////////////////////////////////////////
#define TINT_BUILD_IS_MSVC
#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW
#define TINT_DISABLE_WARNING_DEPRECATED
#define TINT_DISABLE_WARNING_DESTRUCTOR_NEVER_RETURNS
#define TINT_DISABLE_WARNING_EXTRA_SEMICOLON
#define TINT_DISABLE_WARNING_FLOAT_EQUAL
#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED
#define TINT_DISABLE_WARNING_MISSING_DESTRUCTOR_OVERRIDE
#define TINT_DISABLE_WARNING_NEWLINE_EOF
#define TINT_DISABLE_WARNING_OLD_STYLE_CAST
#define TINT_DISABLE_WARNING_RESERVED_IDENTIFIER
#define TINT_DISABLE_WARNING_RESERVED_MACRO_IDENTIFIER
#define TINT_DISABLE_WARNING_SHADOW_FIELD_IN_CONSTRUCTOR
#define TINT_DISABLE_WARNING_SIGN_CONVERSION
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE
#define TINT_DISABLE_WARNING_UNUSED_PARAMETER
#define TINT_DISABLE_WARNING_UNUSED_VALUE
#define TINT_DISABLE_WARNING_WEAK_VTABLES
#define TINT_DISABLE_WARNING_ZERO_AS_NULLPTR

#define TINT_BEGIN_DISABLE_OPTIMIZATIONS
#define TINT_END_DISABLE_OPTIMIZATIONS

#define TINT_BEGIN_DISABLE_ALL_WARNINGS
#define TINT_END_DISABLE_ALL_WARNINGS

// clang-format off
#define TINT_BEGIN_DISABLE_WARNING
#define TINT_END_DISABLE_WARNING
// clang-format on

#define TINT_BEGIN_DISABLE_PROTOBUF_WARNINGS
#define TINT_END_DISABLE_PROTOBUF_WARNINGS

#if defined(__SANITIZE_ADDRESS__)
#define TINT_ASAN_ENABLED
#endif

#elif defined(__clang__)
////////////////////////////////////////////////////////////////////////////////
// Clang
////////////////////////////////////////////////////////////////////////////////
#define TINT_BUILD_IS_CLANG
#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW
#define TINT_DISABLE_WARNING_DEPRECATED
#define TINT_DISABLE_WARNING_DESTRUCTOR_NEVER_RETURNS
#define TINT_DISABLE_WARNING_EXTRA_SEMICOLON
#define TINT_DISABLE_WARNING_FLOAT_EQUAL
#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED
#define TINT_DISABLE_WARNING_MISSING_DESTRUCTOR_OVERRIDE
#define TINT_DISABLE_WARNING_NEWLINE_EOF
#define TINT_DISABLE_WARNING_OLD_STYLE_CAST
#define TINT_DISABLE_WARNING_RESERVED_IDENTIFIER
#define TINT_DISABLE_WARNING_RESERVED_MACRO_IDENTIFIER
#define TINT_DISABLE_WARNING_SHADOW_FIELD_IN_CONSTRUCTOR
#define TINT_DISABLE_WARNING_SIGN_CONVERSION
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE
#define TINT_DISABLE_WARNING_UNUSED_PARAMETER
#define TINT_DISABLE_WARNING_UNUSED_VALUE
#define TINT_DISABLE_WARNING_WEAK_VTABLES
#define TINT_DISABLE_WARNING_ZERO_AS_NULLPTR

// clang-format off
#define TINT_BEGIN_DISABLE_PROTOBUF_WARNINGS()

#define TINT_END_DISABLE_PROTOBUF_WARNINGS()

#define TINT_BEGIN_DISABLE_OPTIMIZATIONS()
#define TINT_END_DISABLE_OPTIMIZATIONS()

#define TINT_BEGIN_DISABLE_ALL_WARNINGS()

#define TINT_END_DISABLE_ALL_WARNINGS()

#define TINT_BEGIN_DISABLE_WARNING(name)

#define TINT_END_DISABLE_WARNING(name)
// clang-format on

#if __has_feature(address_sanitizer)
#define TINT_ASAN_ENABLED
#endif

#elif defined(__GNUC__)
////////////////////////////////////////////////////////////////////////////////
// GCC
////////////////////////////////////////////////////////////////////////////////
#define TINT_BUILD_IS_GCC
#define TINT_DISABLE_WARNING_CONSTANT_OVERFLOW
#define TINT_DISABLE_WARNING_DEPRECATED
#define TINT_DISABLE_WARNING_DESTRUCTOR_NEVER_RETURNS
#define TINT_DISABLE_WARNING_EXTRA_SEMICOLON
#define TINT_DISABLE_WARNING_FLOAT_EQUAL
#define TINT_DISABLE_WARNING_MAYBE_UNINITIALIZED
#define TINT_DISABLE_WARNING_MISSING_DESTRUCTOR_OVERRIDE
#define TINT_DISABLE_WARNING_NEWLINE_EOF
#define TINT_DISABLE_WARNING_OLD_STYLE_CAST
#define TINT_DISABLE_WARNING_RESERVED_IDENTIFIER
#define TINT_DISABLE_WARNING_RESERVED_MACRO_IDENTIFIER
#define TINT_DISABLE_WARNING_SHADOW_FIELD_IN_CONSTRUCTOR
#define TINT_DISABLE_WARNING_SIGN_CONVERSION
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE
#define TINT_DISABLE_WARNING_UNUSED_PARAMETER
#define TINT_DISABLE_WARNING_UNUSED_VALUE
#define TINT_DISABLE_WARNING_WEAK_VTABLES
#define TINT_DISABLE_WARNING_ZERO_AS_NULLPTR

#define TINT_BEGIN_DISABLE_PROTOBUF_WARNINGS
#define TINT_END_DISABLE_PROTOBUF_WARNINGS

#define TINT_BEGIN_DISABLE_OPTIMIZATIONS
#define TINT_END_DISABLE_OPTIMIZATIONS

// clang-format off
#define TINT_BEGIN_DISABLE_ALL_WARNINGS
// clang-format on

#define TINT_END_DISABLE_ALL_WARNINGS

// clang-format off
#define TINT_BEGIN_DISABLE_WARNING
#define TINT_END_DISABLE_WARNING
// clang-format on

#if defined(__SANITIZE_ADDRESS__)
#define TINT_ASAN_ENABLED
#endif

#else
////////////////////////////////////////////////////////////////////////////////
// Other
////////////////////////////////////////////////////////////////////////////////
#define TINT_BEGIN_DISABLE_OPTIMIZATIONS
#define TINT_END_DISABLE_OPTIMIZATIONS
#define TINT_BEGIN_DISABLE_ALL_WARNINGS
#define TINT_END_DISABLE_ALL_WARNINGS
#define TINT_BEGIN_DISABLE_WARNING
#define TINT_END_DISABLE_WARNING
#define TINT_BEGIN_DISABLE_PROTOBUF_WARNINGS
#define TINT_END_DISABLE_PROTOBUF_WARNINGS

#endif

#ifndef TINT_BUILD_IS_MSVC
#define TINT_BUILD_IS_MSVC
#endif

#ifndef TINT_BUILD_IS_CLANG
#define TINT_BUILD_IS_CLANG
#endif

#ifndef TINT_BUILD_IS_GCC
#define TINT_BUILD_IS_GCC
#endif

#if TINT_BUILD_IS_MSVC
#define TINT_MSVC_ONLY
#else
#define TINT_MSVC_ONLY(x)
#endif

#if TINT_BUILD_IS_CLANG
#define TINT_CLANG_ONLY(x)
#else
#define TINT_CLANG_ONLY
#endif

#if TINT_BUILD_IS_GCC
#define TINT_GCC_ONLY
#else
#define TINT_GCC_ONLY(x)
#endif

#endif  // SRC_TINT_UTILS_MACROS_COMPILER_H_