Source code

Revision control

Other Tools

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef MemMoveAnnotation_h__
6
#define MemMoveAnnotation_h__
7
8
#include "CustomMatchers.h"
9
#include "CustomTypeAnnotation.h"
10
#include "Utils.h"
11
12
#include <unordered_set>
13
14
class MemMoveAnnotation final : public CustomTypeAnnotation {
15
public:
16
MemMoveAnnotation()
17
: CustomTypeAnnotation(moz_non_memmovable, "non-memmove()able") {}
18
19
virtual ~MemMoveAnnotation() {}
20
21
protected:
22
std::string getImplicitReason(const TagDecl *D) const override {
23
// Annotate everything in ::std, with a few exceptions; see bug
24
// 1201314 for discussion.
25
if (getDeclarationNamespace(D) == "std") {
26
// This doesn't check that it's really ::std::pair and not
27
// ::std::something_else::pair, but should be good enough.
28
StringRef Name = getNameChecked(D);
29
if (isNameExcepted(Name.data())) {
30
return "";
31
}
32
return "it is an stl-provided type not guaranteed to be memmove-able";
33
}
34
return "";
35
}
36
37
private:
38
bool isNameExcepted(const char *Name) const {
39
static std::unordered_set<std::string> NamesSet = {
40
{"pair"},
41
{"atomic"},
42
// libstdc++ specific names
43
{"__atomic_base"},
44
{"atomic_bool"},
45
{"__cxx_atomic_impl"},
46
{"__cxx_atomic_base_impl"},
47
{"__pair_base"},
48
// MSVCRT specific names
49
{"_Atomic_impl"},
50
{"_Atomic_base"},
51
{"_Atomic_bool"},
52
{"_Atomic_char"},
53
{"_Atomic_schar"},
54
{"_Atomic_uchar"},
55
{"_Atomic_char16_t"},
56
{"_Atomic_char32_t"},
57
{"_Atomic_wchar_t"},
58
{"_Atomic_short"},
59
{"_Atomic_ushort"},
60
{"_Atomic_int"},
61
{"_Atomic_uint"},
62
{"_Atomic_long"},
63
{"_Atomic_ulong"},
64
{"_Atomic_llong"},
65
{"_Atomic_ullong"},
66
{"_Atomic_address"},
67
// MSVCRT 2019
68
{"_Atomic_integral"},
69
{"_Atomic_integral_facade"},
70
{"_Atomic_padded"},
71
{"_Atomic_pointer"},
72
{"_Atomic_storage"}};
73
74
return NamesSet.find(Name) != NamesSet.end();
75
}
76
};
77
78
extern MemMoveAnnotation NonMemMovable;
79
80
#endif