/work/obj-fuzz/dist/include/gtest/BlackBox.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2015 Google Inc. All rights reserved. |
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 | | |
15 | | #ifndef GTEST_BLACKBOX_H |
16 | | #define GTEST_BLACKBOX_H |
17 | | |
18 | | #include "mozilla/Attributes.h" |
19 | | #if defined(_MSC_VER) |
20 | | #include <intrin.h> |
21 | | #endif // _MSC_VER |
22 | | |
23 | | namespace mozilla { |
24 | | |
25 | | #if defined(_MSC_VER) |
26 | | |
27 | | char volatile* UseCharPointer(char volatile*); |
28 | | |
29 | | MOZ_ALWAYS_INLINE_EVEN_DEBUG void* BlackBoxVoidPtr(void* aPtr) { |
30 | | aPtr = const_cast<char*>(UseCharPointer(reinterpret_cast<char*>(aPtr))); |
31 | | _ReadWriteBarrier(); |
32 | | return aPtr; |
33 | | } |
34 | | |
35 | | #else |
36 | | |
37 | | // See: https://youtu.be/nXaxk27zwlk?t=2441 |
38 | 0 | MOZ_ALWAYS_INLINE_EVEN_DEBUG void* BlackBoxVoidPtr(void* aPtr) { |
39 | 0 | // "g" is what we want here, but the comment in the Google |
40 | 0 | // benchmark code suggests that GCC likes "i,r,m" better. |
41 | 0 | // However, on Mozilla try server i,r,m breaks GCC but g |
42 | 0 | // works in GCC, so using g for both clang and GCC. |
43 | 0 | // godbolt.org indicates that g works already in GCC 4.9, |
44 | 0 | // which is the oldest GCC we support at the time of this |
45 | 0 | // code landing. godbolt.org suggests that this clearly |
46 | 0 | // works is LLVM 5, but it's unclear if this inhibits |
47 | 0 | // all relevant optimizations properly on earlier LLVM. |
48 | 0 | asm volatile("" : "+g"(aPtr) : "g"(aPtr) : "memory"); |
49 | 0 | return aPtr; |
50 | 0 | } |
51 | | |
52 | | #endif // _MSC_VER |
53 | | |
54 | | template<class T> |
55 | 0 | MOZ_ALWAYS_INLINE_EVEN_DEBUG T* BlackBox(T* aPtr) { |
56 | 0 | return static_cast<T*>(BlackBoxVoidPtr(aPtr)); |
57 | 0 | } Unexecuted instantiation: nsTString<char>* mozilla::BlackBox<nsTString<char> >(nsTString<char>*) Unexecuted instantiation: bool* mozilla::BlackBox<bool>(bool*) Unexecuted instantiation: nsTString<char16_t>* mozilla::BlackBox<nsTString<char16_t> >(nsTString<char16_t>*) Unexecuted instantiation: nsTAutoStringN<char, 64ul>* mozilla::BlackBox<nsTAutoStringN<char, 64ul> >(nsTAutoStringN<char, 64ul>*) Unexecuted instantiation: nsTAutoStringN<char16_t, 64ul>* mozilla::BlackBox<nsTAutoStringN<char16_t, 64ul> >(nsTAutoStringN<char16_t, 64ul>*) |
58 | | |
59 | | } // namespace mozilla |
60 | | |
61 | | #endif // GTEST_BLACKBOX_H |