security/sandbox/chromium/base/compiler_specific.h

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #ifndef BASE_COMPILER_SPECIFIC_H_
michael@0 6 #define BASE_COMPILER_SPECIFIC_H_
michael@0 7
michael@0 8 #include "build/build_config.h"
michael@0 9
michael@0 10 #if defined(COMPILER_MSVC)
michael@0 11
michael@0 12 // Macros for suppressing and disabling warnings on MSVC.
michael@0 13 //
michael@0 14 // Warning numbers are enumerated at:
michael@0 15 // http://msdn.microsoft.com/en-us/library/8x5x43k7(VS.80).aspx
michael@0 16 //
michael@0 17 // The warning pragma:
michael@0 18 // http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx
michael@0 19 //
michael@0 20 // Using __pragma instead of #pragma inside macros:
michael@0 21 // http://msdn.microsoft.com/en-us/library/d9x1s805.aspx
michael@0 22
michael@0 23 // MSVC_SUPPRESS_WARNING disables warning |n| for the remainder of the line and
michael@0 24 // for the next line of the source file.
michael@0 25 #define MSVC_SUPPRESS_WARNING(n) __pragma(warning(suppress:n))
michael@0 26
michael@0 27 // MSVC_PUSH_DISABLE_WARNING pushes |n| onto a stack of warnings to be disabled.
michael@0 28 // The warning remains disabled until popped by MSVC_POP_WARNING.
michael@0 29 #define MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \
michael@0 30 __pragma(warning(disable:n))
michael@0 31
michael@0 32 // MSVC_PUSH_WARNING_LEVEL pushes |n| as the global warning level. The level
michael@0 33 // remains in effect until popped by MSVC_POP_WARNING(). Use 0 to disable all
michael@0 34 // warnings.
michael@0 35 #define MSVC_PUSH_WARNING_LEVEL(n) __pragma(warning(push, n))
michael@0 36
michael@0 37 // Pop effects of innermost MSVC_PUSH_* macro.
michael@0 38 #define MSVC_POP_WARNING() __pragma(warning(pop))
michael@0 39
michael@0 40 #define MSVC_DISABLE_OPTIMIZE() __pragma(optimize("", off))
michael@0 41 #define MSVC_ENABLE_OPTIMIZE() __pragma(optimize("", on))
michael@0 42
michael@0 43 // Allows exporting a class that inherits from a non-exported base class.
michael@0 44 // This uses suppress instead of push/pop because the delimiter after the
michael@0 45 // declaration (either "," or "{") has to be placed before the pop macro.
michael@0 46 //
michael@0 47 // Example usage:
michael@0 48 // class EXPORT_API Foo : NON_EXPORTED_BASE(public Bar) {
michael@0 49 //
michael@0 50 // MSVC Compiler warning C4275:
michael@0 51 // non dll-interface class 'Bar' used as base for dll-interface class 'Foo'.
michael@0 52 // Note that this is intended to be used only when no access to the base class'
michael@0 53 // static data is done through derived classes or inline methods. For more info,
michael@0 54 // see http://msdn.microsoft.com/en-us/library/3tdb471s(VS.80).aspx
michael@0 55 #define NON_EXPORTED_BASE(code) MSVC_SUPPRESS_WARNING(4275) \
michael@0 56 code
michael@0 57
michael@0 58 #else // Not MSVC
michael@0 59
michael@0 60 #define MSVC_SUPPRESS_WARNING(n)
michael@0 61 #define MSVC_PUSH_DISABLE_WARNING(n)
michael@0 62 #define MSVC_PUSH_WARNING_LEVEL(n)
michael@0 63 #define MSVC_POP_WARNING()
michael@0 64 #define MSVC_DISABLE_OPTIMIZE()
michael@0 65 #define MSVC_ENABLE_OPTIMIZE()
michael@0 66 #define NON_EXPORTED_BASE(code) code
michael@0 67
michael@0 68 #endif // COMPILER_MSVC
michael@0 69
michael@0 70
michael@0 71 // Annotate a variable indicating it's ok if the variable is not used.
michael@0 72 // (Typically used to silence a compiler warning when the assignment
michael@0 73 // is important for some other reason.)
michael@0 74 // Use like:
michael@0 75 // int x ALLOW_UNUSED = ...;
michael@0 76 #if defined(COMPILER_GCC)
michael@0 77 #define ALLOW_UNUSED __attribute__((unused))
michael@0 78 #else
michael@0 79 #define ALLOW_UNUSED
michael@0 80 #endif
michael@0 81
michael@0 82 // Annotate a function indicating it should not be inlined.
michael@0 83 // Use like:
michael@0 84 // NOINLINE void DoStuff() { ... }
michael@0 85 #if defined(COMPILER_GCC)
michael@0 86 #define NOINLINE __attribute__((noinline))
michael@0 87 #elif defined(COMPILER_MSVC)
michael@0 88 #define NOINLINE __declspec(noinline)
michael@0 89 #else
michael@0 90 #define NOINLINE
michael@0 91 #endif
michael@0 92
michael@0 93 // Specify memory alignment for structs, classes, etc.
michael@0 94 // Use like:
michael@0 95 // class ALIGNAS(16) MyClass { ... }
michael@0 96 // ALIGNAS(16) int array[4];
michael@0 97 #if defined(COMPILER_MSVC)
michael@0 98 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
michael@0 99 #elif defined(COMPILER_GCC)
michael@0 100 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
michael@0 101 #endif
michael@0 102
michael@0 103 // Return the byte alignment of the given type (available at compile time). Use
michael@0 104 // sizeof(type) prior to checking __alignof to workaround Visual C++ bug:
michael@0 105 // http://goo.gl/isH0C
michael@0 106 // Use like:
michael@0 107 // ALIGNOF(int32) // this would be 4
michael@0 108 #if defined(COMPILER_MSVC)
michael@0 109 #define ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
michael@0 110 #elif defined(COMPILER_GCC)
michael@0 111 #define ALIGNOF(type) __alignof__(type)
michael@0 112 #endif
michael@0 113
michael@0 114 // Annotate a virtual method indicating it must be overriding a virtual
michael@0 115 // method in the parent class.
michael@0 116 // Use like:
michael@0 117 // virtual void foo() OVERRIDE;
michael@0 118 #if defined(COMPILER_MSVC)
michael@0 119 #define OVERRIDE override
michael@0 120 #elif defined(__clang__)
michael@0 121 #define OVERRIDE override
michael@0 122 #else
michael@0 123 #define OVERRIDE
michael@0 124 #endif
michael@0 125
michael@0 126 // Annotate a virtual method indicating that subclasses must not override it,
michael@0 127 // or annotate a class to indicate that it cannot be subclassed.
michael@0 128 // Use like:
michael@0 129 // virtual void foo() FINAL;
michael@0 130 // class B FINAL : public A {};
michael@0 131 #if defined(COMPILER_MSVC)
michael@0 132 // TODO(jered): Change this to "final" when chromium no longer uses MSVC 2010.
michael@0 133 #define FINAL sealed
michael@0 134 #elif defined(__clang__)
michael@0 135 #define FINAL final
michael@0 136 #else
michael@0 137 #define FINAL
michael@0 138 #endif
michael@0 139
michael@0 140 // Annotate a function indicating the caller must examine the return value.
michael@0 141 // Use like:
michael@0 142 // int foo() WARN_UNUSED_RESULT;
michael@0 143 // To explicitly ignore a result, see |ignore_result()| in <base/basictypes.h>.
michael@0 144 #if defined(COMPILER_GCC)
michael@0 145 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
michael@0 146 #else
michael@0 147 #define WARN_UNUSED_RESULT
michael@0 148 #endif
michael@0 149
michael@0 150 // Tell the compiler a function is using a printf-style format string.
michael@0 151 // |format_param| is the one-based index of the format string parameter;
michael@0 152 // |dots_param| is the one-based index of the "..." parameter.
michael@0 153 // For v*printf functions (which take a va_list), pass 0 for dots_param.
michael@0 154 // (This is undocumented but matches what the system C headers do.)
michael@0 155 #if defined(COMPILER_GCC)
michael@0 156 #define PRINTF_FORMAT(format_param, dots_param) \
michael@0 157 __attribute__((format(printf, format_param, dots_param)))
michael@0 158 #else
michael@0 159 #define PRINTF_FORMAT(format_param, dots_param)
michael@0 160 #endif
michael@0 161
michael@0 162 // WPRINTF_FORMAT is the same, but for wide format strings.
michael@0 163 // This doesn't appear to yet be implemented in any compiler.
michael@0 164 // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 .
michael@0 165 #define WPRINTF_FORMAT(format_param, dots_param)
michael@0 166 // If available, it would look like:
michael@0 167 // __attribute__((format(wprintf, format_param, dots_param)))
michael@0 168
michael@0 169
michael@0 170 // MemorySanitizer annotations.
michael@0 171 #ifdef MEMORY_SANITIZER
michael@0 172 extern "C" {
michael@0 173 void __msan_unpoison(const void *p, unsigned long s);
michael@0 174 } // extern "C"
michael@0 175
michael@0 176 // Mark a memory region fully initialized.
michael@0 177 // Use this to annotate code that deliberately reads uninitialized data, for
michael@0 178 // example a GC scavenging root set pointers from the stack.
michael@0 179 #define MSAN_UNPOISON(p, s) __msan_unpoison(p, s)
michael@0 180 #else // MEMORY_SANITIZER
michael@0 181 #define MSAN_UNPOISON(p, s)
michael@0 182 #endif // MEMORY_SANITIZER
michael@0 183
michael@0 184 #endif // BASE_COMPILER_SPECIFIC_H_

mercurial