security/sandbox/chromium/base/compiler_specific.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/chromium/base/compiler_specific.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,184 @@
     1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#ifndef BASE_COMPILER_SPECIFIC_H_
     1.9 +#define BASE_COMPILER_SPECIFIC_H_
    1.10 +
    1.11 +#include "build/build_config.h"
    1.12 +
    1.13 +#if defined(COMPILER_MSVC)
    1.14 +
    1.15 +// Macros for suppressing and disabling warnings on MSVC.
    1.16 +//
    1.17 +// Warning numbers are enumerated at:
    1.18 +// http://msdn.microsoft.com/en-us/library/8x5x43k7(VS.80).aspx
    1.19 +//
    1.20 +// The warning pragma:
    1.21 +// http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx
    1.22 +//
    1.23 +// Using __pragma instead of #pragma inside macros:
    1.24 +// http://msdn.microsoft.com/en-us/library/d9x1s805.aspx
    1.25 +
    1.26 +// MSVC_SUPPRESS_WARNING disables warning |n| for the remainder of the line and
    1.27 +// for the next line of the source file.
    1.28 +#define MSVC_SUPPRESS_WARNING(n) __pragma(warning(suppress:n))
    1.29 +
    1.30 +// MSVC_PUSH_DISABLE_WARNING pushes |n| onto a stack of warnings to be disabled.
    1.31 +// The warning remains disabled until popped by MSVC_POP_WARNING.
    1.32 +#define MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \
    1.33 +                                     __pragma(warning(disable:n))
    1.34 +
    1.35 +// MSVC_PUSH_WARNING_LEVEL pushes |n| as the global warning level.  The level
    1.36 +// remains in effect until popped by MSVC_POP_WARNING().  Use 0 to disable all
    1.37 +// warnings.
    1.38 +#define MSVC_PUSH_WARNING_LEVEL(n) __pragma(warning(push, n))
    1.39 +
    1.40 +// Pop effects of innermost MSVC_PUSH_* macro.
    1.41 +#define MSVC_POP_WARNING() __pragma(warning(pop))
    1.42 +
    1.43 +#define MSVC_DISABLE_OPTIMIZE() __pragma(optimize("", off))
    1.44 +#define MSVC_ENABLE_OPTIMIZE() __pragma(optimize("", on))
    1.45 +
    1.46 +// Allows exporting a class that inherits from a non-exported base class.
    1.47 +// This uses suppress instead of push/pop because the delimiter after the
    1.48 +// declaration (either "," or "{") has to be placed before the pop macro.
    1.49 +//
    1.50 +// Example usage:
    1.51 +// class EXPORT_API Foo : NON_EXPORTED_BASE(public Bar) {
    1.52 +//
    1.53 +// MSVC Compiler warning C4275:
    1.54 +// non dll-interface class 'Bar' used as base for dll-interface class 'Foo'.
    1.55 +// Note that this is intended to be used only when no access to the base class'
    1.56 +// static data is done through derived classes or inline methods. For more info,
    1.57 +// see http://msdn.microsoft.com/en-us/library/3tdb471s(VS.80).aspx
    1.58 +#define NON_EXPORTED_BASE(code) MSVC_SUPPRESS_WARNING(4275) \
    1.59 +                                code
    1.60 +
    1.61 +#else  // Not MSVC
    1.62 +
    1.63 +#define MSVC_SUPPRESS_WARNING(n)
    1.64 +#define MSVC_PUSH_DISABLE_WARNING(n)
    1.65 +#define MSVC_PUSH_WARNING_LEVEL(n)
    1.66 +#define MSVC_POP_WARNING()
    1.67 +#define MSVC_DISABLE_OPTIMIZE()
    1.68 +#define MSVC_ENABLE_OPTIMIZE()
    1.69 +#define NON_EXPORTED_BASE(code) code
    1.70 +
    1.71 +#endif  // COMPILER_MSVC
    1.72 +
    1.73 +
    1.74 +// Annotate a variable indicating it's ok if the variable is not used.
    1.75 +// (Typically used to silence a compiler warning when the assignment
    1.76 +// is important for some other reason.)
    1.77 +// Use like:
    1.78 +//   int x ALLOW_UNUSED = ...;
    1.79 +#if defined(COMPILER_GCC)
    1.80 +#define ALLOW_UNUSED __attribute__((unused))
    1.81 +#else
    1.82 +#define ALLOW_UNUSED
    1.83 +#endif
    1.84 +
    1.85 +// Annotate a function indicating it should not be inlined.
    1.86 +// Use like:
    1.87 +//   NOINLINE void DoStuff() { ... }
    1.88 +#if defined(COMPILER_GCC)
    1.89 +#define NOINLINE __attribute__((noinline))
    1.90 +#elif defined(COMPILER_MSVC)
    1.91 +#define NOINLINE __declspec(noinline)
    1.92 +#else
    1.93 +#define NOINLINE
    1.94 +#endif
    1.95 +
    1.96 +// Specify memory alignment for structs, classes, etc.
    1.97 +// Use like:
    1.98 +//   class ALIGNAS(16) MyClass { ... }
    1.99 +//   ALIGNAS(16) int array[4];
   1.100 +#if defined(COMPILER_MSVC)
   1.101 +#define ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
   1.102 +#elif defined(COMPILER_GCC)
   1.103 +#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
   1.104 +#endif
   1.105 +
   1.106 +// Return the byte alignment of the given type (available at compile time).  Use
   1.107 +// sizeof(type) prior to checking __alignof to workaround Visual C++ bug:
   1.108 +// http://goo.gl/isH0C
   1.109 +// Use like:
   1.110 +//   ALIGNOF(int32)  // this would be 4
   1.111 +#if defined(COMPILER_MSVC)
   1.112 +#define ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
   1.113 +#elif defined(COMPILER_GCC)
   1.114 +#define ALIGNOF(type) __alignof__(type)
   1.115 +#endif
   1.116 +
   1.117 +// Annotate a virtual method indicating it must be overriding a virtual
   1.118 +// method in the parent class.
   1.119 +// Use like:
   1.120 +//   virtual void foo() OVERRIDE;
   1.121 +#if defined(COMPILER_MSVC)
   1.122 +#define OVERRIDE override
   1.123 +#elif defined(__clang__)
   1.124 +#define OVERRIDE override
   1.125 +#else
   1.126 +#define OVERRIDE
   1.127 +#endif
   1.128 +
   1.129 +// Annotate a virtual method indicating that subclasses must not override it,
   1.130 +// or annotate a class to indicate that it cannot be subclassed.
   1.131 +// Use like:
   1.132 +//   virtual void foo() FINAL;
   1.133 +//   class B FINAL : public A {};
   1.134 +#if defined(COMPILER_MSVC)
   1.135 +// TODO(jered): Change this to "final" when chromium no longer uses MSVC 2010.
   1.136 +#define FINAL sealed
   1.137 +#elif defined(__clang__)
   1.138 +#define FINAL final
   1.139 +#else
   1.140 +#define FINAL
   1.141 +#endif
   1.142 +
   1.143 +// Annotate a function indicating the caller must examine the return value.
   1.144 +// Use like:
   1.145 +//   int foo() WARN_UNUSED_RESULT;
   1.146 +// To explicitly ignore a result, see |ignore_result()| in <base/basictypes.h>.
   1.147 +#if defined(COMPILER_GCC)
   1.148 +#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
   1.149 +#else
   1.150 +#define WARN_UNUSED_RESULT
   1.151 +#endif
   1.152 +
   1.153 +// Tell the compiler a function is using a printf-style format string.
   1.154 +// |format_param| is the one-based index of the format string parameter;
   1.155 +// |dots_param| is the one-based index of the "..." parameter.
   1.156 +// For v*printf functions (which take a va_list), pass 0 for dots_param.
   1.157 +// (This is undocumented but matches what the system C headers do.)
   1.158 +#if defined(COMPILER_GCC)
   1.159 +#define PRINTF_FORMAT(format_param, dots_param) \
   1.160 +    __attribute__((format(printf, format_param, dots_param)))
   1.161 +#else
   1.162 +#define PRINTF_FORMAT(format_param, dots_param)
   1.163 +#endif
   1.164 +
   1.165 +// WPRINTF_FORMAT is the same, but for wide format strings.
   1.166 +// This doesn't appear to yet be implemented in any compiler.
   1.167 +// See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 .
   1.168 +#define WPRINTF_FORMAT(format_param, dots_param)
   1.169 +// If available, it would look like:
   1.170 +//   __attribute__((format(wprintf, format_param, dots_param)))
   1.171 +
   1.172 +
   1.173 +// MemorySanitizer annotations.
   1.174 +#ifdef MEMORY_SANITIZER
   1.175 +extern "C" {
   1.176 +void __msan_unpoison(const void *p, unsigned long s);
   1.177 +}  // extern "C"
   1.178 +
   1.179 +// Mark a memory region fully initialized.
   1.180 +// Use this to annotate code that deliberately reads uninitialized data, for
   1.181 +// example a GC scavenging root set pointers from the stack.
   1.182 +#define MSAN_UNPOISON(p, s)  __msan_unpoison(p, s)
   1.183 +#else  // MEMORY_SANITIZER
   1.184 +#define MSAN_UNPOISON(p, s)
   1.185 +#endif  // MEMORY_SANITIZER
   1.186 +
   1.187 +#endif  // BASE_COMPILER_SPECIFIC_H_

mercurial