svf-lib 1.0.1308 → 1.0.1310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SVF-linux/Release-build/lib/libSvf.a +0 -0
- package/SVF-linux/include/SVF-LLVM/IRAnnotator.h +1 -0
- package/SVF-linux/include/Util/Casting.h +85 -29
- package/SVF-osx/Release-build/lib/libSvf.a +0 -0
- package/SVF-osx/include/SVF-LLVM/IRAnnotator.h +1 -0
- package/SVF-osx/include/Util/Casting.h +85 -29
- package/package.json +1 -1
|
Binary file
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
//
|
|
19
19
|
//===----------------------------------------------------------------------===//
|
|
20
20
|
//
|
|
21
|
-
// This file defines the
|
|
21
|
+
// This file defines the SVFUtil::isa<X>(), cast<X>(), dyn_cast<X>(), cast_or_null<X>(),
|
|
22
22
|
// and dyn_cast_or_null<X>() templates.
|
|
23
23
|
//
|
|
24
24
|
//===----------------------------------------------------------------------===//
|
|
@@ -26,7 +26,35 @@
|
|
|
26
26
|
#include <cassert>
|
|
27
27
|
#include <memory>
|
|
28
28
|
#include <type_traits>
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
//===-- Part of llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===//
|
|
31
|
+
|
|
32
|
+
// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in
|
|
33
|
+
// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.
|
|
34
|
+
#ifndef LLVM_HAS_CPP_ATTRIBUTE
|
|
35
|
+
#if defined(__cplusplus) && defined(__has_cpp_attribute)
|
|
36
|
+
# define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
|
|
37
|
+
#else
|
|
38
|
+
# define LLVM_HAS_CPP_ATTRIBUTE(x) 0
|
|
39
|
+
#endif
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
/// LLVM_NODISCARD - Warn if a type or return value is discarded.
|
|
43
|
+
|
|
44
|
+
// Use the 'nodiscard' attribute in C++17 or newer mode.
|
|
45
|
+
#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
|
|
46
|
+
#define LLVM_NODISCARD [[nodiscard]]
|
|
47
|
+
#elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)
|
|
48
|
+
#define LLVM_NODISCARD [[clang::warn_unused_result]]
|
|
49
|
+
// Clang in C++14 mode claims that it has the 'nodiscard' attribute, but also
|
|
50
|
+
// warns in the pedantic mode that 'nodiscard' is a C++17 extension (PR33518).
|
|
51
|
+
// Use the 'nodiscard' attribute in C++14 mode only with GCC.
|
|
52
|
+
// TODO: remove this workaround when PR33518 is resolved.
|
|
53
|
+
#elif defined(__GNUC__) && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
|
|
54
|
+
#define LLVM_NODISCARD [[nodiscard]]
|
|
55
|
+
#else
|
|
56
|
+
#define LLVM_NODISCARD
|
|
57
|
+
#endif
|
|
30
58
|
|
|
31
59
|
namespace SVF
|
|
32
60
|
{
|
|
@@ -34,8 +62,38 @@ namespace SVF
|
|
|
34
62
|
namespace SVFUtil
|
|
35
63
|
{
|
|
36
64
|
|
|
65
|
+
//===- Part of llvm/Support/type_traits.h - Simplfied type traits -------*- C++ -*-===//
|
|
66
|
+
|
|
67
|
+
/// If T is a pointer to X, return a pointer to const X. If it is not,
|
|
68
|
+
/// return const T.
|
|
69
|
+
template<typename T, typename Enable = void>
|
|
70
|
+
struct add_const_past_pointer
|
|
71
|
+
{
|
|
72
|
+
using type = const T;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
template <typename T>
|
|
76
|
+
struct add_const_past_pointer<T, std::enable_if_t<std::is_pointer<T>::value>>
|
|
77
|
+
{
|
|
78
|
+
using type = const std::remove_pointer_t<T> *;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/// If T is a pointer, just return it. If it is not, return T&.
|
|
82
|
+
template<typename T, typename Enable = void>
|
|
83
|
+
struct add_lvalue_reference_if_not_pointer
|
|
84
|
+
{
|
|
85
|
+
using type = T &;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
template <typename T>
|
|
89
|
+
struct add_lvalue_reference_if_not_pointer<
|
|
90
|
+
T, std::enable_if_t<std::is_pointer<T>::value>>
|
|
91
|
+
{
|
|
92
|
+
using type = T;
|
|
93
|
+
};
|
|
94
|
+
|
|
37
95
|
//===----------------------------------------------------------------------===//
|
|
38
|
-
//
|
|
96
|
+
// SVFUtil::isa<x> Support Templates
|
|
39
97
|
//===----------------------------------------------------------------------===//
|
|
40
98
|
|
|
41
99
|
// Define a template that can be specialized by smart pointers to reflect the
|
|
@@ -57,9 +115,9 @@ template<typename From> struct simplify_type<const From>
|
|
|
57
115
|
{
|
|
58
116
|
using NonConstSimpleType = typename simplify_type<From>::SimpleType;
|
|
59
117
|
using SimpleType =
|
|
60
|
-
typename
|
|
118
|
+
typename SVFUtil::add_const_past_pointer<NonConstSimpleType>::type;
|
|
61
119
|
using RetType =
|
|
62
|
-
typename
|
|
120
|
+
typename SVFUtil::add_lvalue_reference_if_not_pointer<SimpleType>::type;
|
|
63
121
|
|
|
64
122
|
static RetType getSimplifiedValue(const From& Val)
|
|
65
123
|
{
|
|
@@ -67,9 +125,9 @@ template<typename From> struct simplify_type<const From>
|
|
|
67
125
|
}
|
|
68
126
|
};
|
|
69
127
|
|
|
70
|
-
// The core of the implementation of
|
|
128
|
+
// The core of the implementation of SVFUtil::isa<X> is here; To and From should be
|
|
71
129
|
// the names of classes. This template can be specialized to customize the
|
|
72
|
-
// implementation of
|
|
130
|
+
// implementation of SVFUtil::isa<> without rewriting it from scratch.
|
|
73
131
|
template <typename To, typename From, typename Enabler = void>
|
|
74
132
|
struct isa_impl
|
|
75
133
|
{
|
|
@@ -81,8 +139,7 @@ struct isa_impl
|
|
|
81
139
|
|
|
82
140
|
/// \brief Always allow upcasts, and perform no dynamic check for them.
|
|
83
141
|
template <typename To, typename From>
|
|
84
|
-
struct isa_impl<
|
|
85
|
-
To, From, typename std::enable_if<std::is_base_of<To, From>::value>::type>
|
|
142
|
+
struct isa_impl<To, From, std::enable_if_t<std::is_base_of<To, From>::value>>
|
|
86
143
|
{
|
|
87
144
|
static inline bool doit(const From &)
|
|
88
145
|
{
|
|
@@ -111,7 +168,7 @@ struct isa_impl_cl<To, const std::unique_ptr<From>>
|
|
|
111
168
|
{
|
|
112
169
|
static inline bool doit(const std::unique_ptr<From> &Val)
|
|
113
170
|
{
|
|
114
|
-
assert(Val && "
|
|
171
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
115
172
|
return isa_impl_cl<To, From>::doit(*Val);
|
|
116
173
|
}
|
|
117
174
|
};
|
|
@@ -120,7 +177,7 @@ template <typename To, typename From> struct isa_impl_cl<To, From*>
|
|
|
120
177
|
{
|
|
121
178
|
static inline bool doit(const From *Val)
|
|
122
179
|
{
|
|
123
|
-
assert(Val && "
|
|
180
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
124
181
|
return isa_impl<To, From>::doit(*Val);
|
|
125
182
|
}
|
|
126
183
|
};
|
|
@@ -129,7 +186,7 @@ template <typename To, typename From> struct isa_impl_cl<To, From*const>
|
|
|
129
186
|
{
|
|
130
187
|
static inline bool doit(const From *Val)
|
|
131
188
|
{
|
|
132
|
-
assert(Val && "
|
|
189
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
133
190
|
return isa_impl<To, From>::doit(*Val);
|
|
134
191
|
}
|
|
135
192
|
};
|
|
@@ -138,7 +195,7 @@ template <typename To, typename From> struct isa_impl_cl<To, const From*>
|
|
|
138
195
|
{
|
|
139
196
|
static inline bool doit(const From *Val)
|
|
140
197
|
{
|
|
141
|
-
assert(Val && "
|
|
198
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
142
199
|
return isa_impl<To, From>::doit(*Val);
|
|
143
200
|
}
|
|
144
201
|
};
|
|
@@ -147,7 +204,7 @@ template <typename To, typename From> struct isa_impl_cl<To, const From*const>
|
|
|
147
204
|
{
|
|
148
205
|
static inline bool doit(const From *Val)
|
|
149
206
|
{
|
|
150
|
-
assert(Val && "
|
|
207
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
151
208
|
return isa_impl<To, From>::doit(*Val);
|
|
152
209
|
}
|
|
153
210
|
};
|
|
@@ -175,10 +232,10 @@ struct isa_impl_wrap<To, FromTy, FromTy>
|
|
|
175
232
|
}
|
|
176
233
|
};
|
|
177
234
|
|
|
178
|
-
//
|
|
235
|
+
// SVFUtil::isa<X> - Return true if the parameter to the template is an instance of the
|
|
179
236
|
// template type argument. Used like this:
|
|
180
237
|
//
|
|
181
|
-
// if (
|
|
238
|
+
// if (SVFUtil::isa<Type>(myVal)) { ... }
|
|
182
239
|
//
|
|
183
240
|
template <class X, class Y> LLVM_NODISCARD inline bool isa(const Y &Val)
|
|
184
241
|
{
|
|
@@ -291,11 +348,11 @@ template <class X> struct is_simple_type
|
|
|
291
348
|
// cast<Instruction>(myVal)->getParent()
|
|
292
349
|
//
|
|
293
350
|
template <class X, class Y>
|
|
294
|
-
inline
|
|
295
|
-
typename cast_retty<X, const Y>::ret_type
|
|
351
|
+
inline std::enable_if_t<!is_simple_type<Y>::value,
|
|
352
|
+
typename cast_retty<X, const Y>::ret_type>
|
|
296
353
|
cast(const Y &Val)
|
|
297
354
|
{
|
|
298
|
-
assert(
|
|
355
|
+
assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
|
|
299
356
|
return cast_convert_val<
|
|
300
357
|
X, const Y, typename simplify_type<const Y>::SimpleType>::doit(Val);
|
|
301
358
|
}
|
|
@@ -303,7 +360,7 @@ inline typename std::enable_if<!is_simple_type<Y>::value,
|
|
|
303
360
|
template <class X, class Y>
|
|
304
361
|
inline typename cast_retty<X, Y>::ret_type cast(Y &Val)
|
|
305
362
|
{
|
|
306
|
-
assert(
|
|
363
|
+
assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
|
|
307
364
|
return cast_convert_val<X, Y,
|
|
308
365
|
typename simplify_type<Y>::SimpleType>::doit(Val);
|
|
309
366
|
}
|
|
@@ -311,7 +368,7 @@ inline typename cast_retty<X, Y>::ret_type cast(Y &Val)
|
|
|
311
368
|
template <class X, class Y>
|
|
312
369
|
inline typename cast_retty<X, Y *>::ret_type cast(Y *Val)
|
|
313
370
|
{
|
|
314
|
-
assert(
|
|
371
|
+
assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
|
|
315
372
|
return cast_convert_val<X, Y*,
|
|
316
373
|
typename simplify_type<Y*>::SimpleType>::doit(Val);
|
|
317
374
|
}
|
|
@@ -320,7 +377,7 @@ template <class X, class Y>
|
|
|
320
377
|
inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
|
|
321
378
|
cast(std::unique_ptr<Y> &&Val)
|
|
322
379
|
{
|
|
323
|
-
assert(
|
|
380
|
+
assert(SVFUtil::isa<X>(Val.get()) && "cast<Ty>() argument of incompatible type!");
|
|
324
381
|
using ret_type = typename cast_retty<X, std::unique_ptr<Y>>::ret_type;
|
|
325
382
|
return ret_type(
|
|
326
383
|
cast_convert_val<X, Y *, typename simplify_type<Y *>::SimpleType>::doit(
|
|
@@ -336,24 +393,23 @@ inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
|
|
|
336
393
|
//
|
|
337
394
|
|
|
338
395
|
template <class X, class Y>
|
|
339
|
-
LLVM_NODISCARD inline
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
dyn_cast(const Y &Val)
|
|
396
|
+
LLVM_NODISCARD inline std::enable_if_t<
|
|
397
|
+
!is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>
|
|
398
|
+
dyn_cast(const Y &Val)
|
|
343
399
|
{
|
|
344
|
-
return
|
|
400
|
+
return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
|
|
345
401
|
}
|
|
346
402
|
|
|
347
403
|
template <class X, class Y>
|
|
348
404
|
LLVM_NODISCARD inline typename cast_retty<X, Y>::ret_type dyn_cast(Y &Val)
|
|
349
405
|
{
|
|
350
|
-
return
|
|
406
|
+
return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
|
|
351
407
|
}
|
|
352
408
|
|
|
353
409
|
template <class X, class Y>
|
|
354
410
|
LLVM_NODISCARD inline typename cast_retty<X, Y *>::ret_type dyn_cast(Y *Val)
|
|
355
411
|
{
|
|
356
|
-
return
|
|
412
|
+
return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
|
|
357
413
|
}
|
|
358
414
|
|
|
359
415
|
} // End namespace SVFUtil
|
|
Binary file
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
//
|
|
19
19
|
//===----------------------------------------------------------------------===//
|
|
20
20
|
//
|
|
21
|
-
// This file defines the
|
|
21
|
+
// This file defines the SVFUtil::isa<X>(), cast<X>(), dyn_cast<X>(), cast_or_null<X>(),
|
|
22
22
|
// and dyn_cast_or_null<X>() templates.
|
|
23
23
|
//
|
|
24
24
|
//===----------------------------------------------------------------------===//
|
|
@@ -26,7 +26,35 @@
|
|
|
26
26
|
#include <cassert>
|
|
27
27
|
#include <memory>
|
|
28
28
|
#include <type_traits>
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
//===-- Part of llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===//
|
|
31
|
+
|
|
32
|
+
// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in
|
|
33
|
+
// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.
|
|
34
|
+
#ifndef LLVM_HAS_CPP_ATTRIBUTE
|
|
35
|
+
#if defined(__cplusplus) && defined(__has_cpp_attribute)
|
|
36
|
+
# define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
|
|
37
|
+
#else
|
|
38
|
+
# define LLVM_HAS_CPP_ATTRIBUTE(x) 0
|
|
39
|
+
#endif
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
/// LLVM_NODISCARD - Warn if a type or return value is discarded.
|
|
43
|
+
|
|
44
|
+
// Use the 'nodiscard' attribute in C++17 or newer mode.
|
|
45
|
+
#if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
|
|
46
|
+
#define LLVM_NODISCARD [[nodiscard]]
|
|
47
|
+
#elif LLVM_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)
|
|
48
|
+
#define LLVM_NODISCARD [[clang::warn_unused_result]]
|
|
49
|
+
// Clang in C++14 mode claims that it has the 'nodiscard' attribute, but also
|
|
50
|
+
// warns in the pedantic mode that 'nodiscard' is a C++17 extension (PR33518).
|
|
51
|
+
// Use the 'nodiscard' attribute in C++14 mode only with GCC.
|
|
52
|
+
// TODO: remove this workaround when PR33518 is resolved.
|
|
53
|
+
#elif defined(__GNUC__) && LLVM_HAS_CPP_ATTRIBUTE(nodiscard)
|
|
54
|
+
#define LLVM_NODISCARD [[nodiscard]]
|
|
55
|
+
#else
|
|
56
|
+
#define LLVM_NODISCARD
|
|
57
|
+
#endif
|
|
30
58
|
|
|
31
59
|
namespace SVF
|
|
32
60
|
{
|
|
@@ -34,8 +62,38 @@ namespace SVF
|
|
|
34
62
|
namespace SVFUtil
|
|
35
63
|
{
|
|
36
64
|
|
|
65
|
+
//===- Part of llvm/Support/type_traits.h - Simplfied type traits -------*- C++ -*-===//
|
|
66
|
+
|
|
67
|
+
/// If T is a pointer to X, return a pointer to const X. If it is not,
|
|
68
|
+
/// return const T.
|
|
69
|
+
template<typename T, typename Enable = void>
|
|
70
|
+
struct add_const_past_pointer
|
|
71
|
+
{
|
|
72
|
+
using type = const T;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
template <typename T>
|
|
76
|
+
struct add_const_past_pointer<T, std::enable_if_t<std::is_pointer<T>::value>>
|
|
77
|
+
{
|
|
78
|
+
using type = const std::remove_pointer_t<T> *;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/// If T is a pointer, just return it. If it is not, return T&.
|
|
82
|
+
template<typename T, typename Enable = void>
|
|
83
|
+
struct add_lvalue_reference_if_not_pointer
|
|
84
|
+
{
|
|
85
|
+
using type = T &;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
template <typename T>
|
|
89
|
+
struct add_lvalue_reference_if_not_pointer<
|
|
90
|
+
T, std::enable_if_t<std::is_pointer<T>::value>>
|
|
91
|
+
{
|
|
92
|
+
using type = T;
|
|
93
|
+
};
|
|
94
|
+
|
|
37
95
|
//===----------------------------------------------------------------------===//
|
|
38
|
-
//
|
|
96
|
+
// SVFUtil::isa<x> Support Templates
|
|
39
97
|
//===----------------------------------------------------------------------===//
|
|
40
98
|
|
|
41
99
|
// Define a template that can be specialized by smart pointers to reflect the
|
|
@@ -57,9 +115,9 @@ template<typename From> struct simplify_type<const From>
|
|
|
57
115
|
{
|
|
58
116
|
using NonConstSimpleType = typename simplify_type<From>::SimpleType;
|
|
59
117
|
using SimpleType =
|
|
60
|
-
typename
|
|
118
|
+
typename SVFUtil::add_const_past_pointer<NonConstSimpleType>::type;
|
|
61
119
|
using RetType =
|
|
62
|
-
typename
|
|
120
|
+
typename SVFUtil::add_lvalue_reference_if_not_pointer<SimpleType>::type;
|
|
63
121
|
|
|
64
122
|
static RetType getSimplifiedValue(const From& Val)
|
|
65
123
|
{
|
|
@@ -67,9 +125,9 @@ template<typename From> struct simplify_type<const From>
|
|
|
67
125
|
}
|
|
68
126
|
};
|
|
69
127
|
|
|
70
|
-
// The core of the implementation of
|
|
128
|
+
// The core of the implementation of SVFUtil::isa<X> is here; To and From should be
|
|
71
129
|
// the names of classes. This template can be specialized to customize the
|
|
72
|
-
// implementation of
|
|
130
|
+
// implementation of SVFUtil::isa<> without rewriting it from scratch.
|
|
73
131
|
template <typename To, typename From, typename Enabler = void>
|
|
74
132
|
struct isa_impl
|
|
75
133
|
{
|
|
@@ -81,8 +139,7 @@ struct isa_impl
|
|
|
81
139
|
|
|
82
140
|
/// \brief Always allow upcasts, and perform no dynamic check for them.
|
|
83
141
|
template <typename To, typename From>
|
|
84
|
-
struct isa_impl<
|
|
85
|
-
To, From, typename std::enable_if<std::is_base_of<To, From>::value>::type>
|
|
142
|
+
struct isa_impl<To, From, std::enable_if_t<std::is_base_of<To, From>::value>>
|
|
86
143
|
{
|
|
87
144
|
static inline bool doit(const From &)
|
|
88
145
|
{
|
|
@@ -111,7 +168,7 @@ struct isa_impl_cl<To, const std::unique_ptr<From>>
|
|
|
111
168
|
{
|
|
112
169
|
static inline bool doit(const std::unique_ptr<From> &Val)
|
|
113
170
|
{
|
|
114
|
-
assert(Val && "
|
|
171
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
115
172
|
return isa_impl_cl<To, From>::doit(*Val);
|
|
116
173
|
}
|
|
117
174
|
};
|
|
@@ -120,7 +177,7 @@ template <typename To, typename From> struct isa_impl_cl<To, From*>
|
|
|
120
177
|
{
|
|
121
178
|
static inline bool doit(const From *Val)
|
|
122
179
|
{
|
|
123
|
-
assert(Val && "
|
|
180
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
124
181
|
return isa_impl<To, From>::doit(*Val);
|
|
125
182
|
}
|
|
126
183
|
};
|
|
@@ -129,7 +186,7 @@ template <typename To, typename From> struct isa_impl_cl<To, From*const>
|
|
|
129
186
|
{
|
|
130
187
|
static inline bool doit(const From *Val)
|
|
131
188
|
{
|
|
132
|
-
assert(Val && "
|
|
189
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
133
190
|
return isa_impl<To, From>::doit(*Val);
|
|
134
191
|
}
|
|
135
192
|
};
|
|
@@ -138,7 +195,7 @@ template <typename To, typename From> struct isa_impl_cl<To, const From*>
|
|
|
138
195
|
{
|
|
139
196
|
static inline bool doit(const From *Val)
|
|
140
197
|
{
|
|
141
|
-
assert(Val && "
|
|
198
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
142
199
|
return isa_impl<To, From>::doit(*Val);
|
|
143
200
|
}
|
|
144
201
|
};
|
|
@@ -147,7 +204,7 @@ template <typename To, typename From> struct isa_impl_cl<To, const From*const>
|
|
|
147
204
|
{
|
|
148
205
|
static inline bool doit(const From *Val)
|
|
149
206
|
{
|
|
150
|
-
assert(Val && "
|
|
207
|
+
assert(Val && "SVFUtil::isa<> used on a null pointer");
|
|
151
208
|
return isa_impl<To, From>::doit(*Val);
|
|
152
209
|
}
|
|
153
210
|
};
|
|
@@ -175,10 +232,10 @@ struct isa_impl_wrap<To, FromTy, FromTy>
|
|
|
175
232
|
}
|
|
176
233
|
};
|
|
177
234
|
|
|
178
|
-
//
|
|
235
|
+
// SVFUtil::isa<X> - Return true if the parameter to the template is an instance of the
|
|
179
236
|
// template type argument. Used like this:
|
|
180
237
|
//
|
|
181
|
-
// if (
|
|
238
|
+
// if (SVFUtil::isa<Type>(myVal)) { ... }
|
|
182
239
|
//
|
|
183
240
|
template <class X, class Y> LLVM_NODISCARD inline bool isa(const Y &Val)
|
|
184
241
|
{
|
|
@@ -291,11 +348,11 @@ template <class X> struct is_simple_type
|
|
|
291
348
|
// cast<Instruction>(myVal)->getParent()
|
|
292
349
|
//
|
|
293
350
|
template <class X, class Y>
|
|
294
|
-
inline
|
|
295
|
-
typename cast_retty<X, const Y>::ret_type
|
|
351
|
+
inline std::enable_if_t<!is_simple_type<Y>::value,
|
|
352
|
+
typename cast_retty<X, const Y>::ret_type>
|
|
296
353
|
cast(const Y &Val)
|
|
297
354
|
{
|
|
298
|
-
assert(
|
|
355
|
+
assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
|
|
299
356
|
return cast_convert_val<
|
|
300
357
|
X, const Y, typename simplify_type<const Y>::SimpleType>::doit(Val);
|
|
301
358
|
}
|
|
@@ -303,7 +360,7 @@ inline typename std::enable_if<!is_simple_type<Y>::value,
|
|
|
303
360
|
template <class X, class Y>
|
|
304
361
|
inline typename cast_retty<X, Y>::ret_type cast(Y &Val)
|
|
305
362
|
{
|
|
306
|
-
assert(
|
|
363
|
+
assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
|
|
307
364
|
return cast_convert_val<X, Y,
|
|
308
365
|
typename simplify_type<Y>::SimpleType>::doit(Val);
|
|
309
366
|
}
|
|
@@ -311,7 +368,7 @@ inline typename cast_retty<X, Y>::ret_type cast(Y &Val)
|
|
|
311
368
|
template <class X, class Y>
|
|
312
369
|
inline typename cast_retty<X, Y *>::ret_type cast(Y *Val)
|
|
313
370
|
{
|
|
314
|
-
assert(
|
|
371
|
+
assert(SVFUtil::isa<X>(Val) && "cast<Ty>() argument of incompatible type!");
|
|
315
372
|
return cast_convert_val<X, Y*,
|
|
316
373
|
typename simplify_type<Y*>::SimpleType>::doit(Val);
|
|
317
374
|
}
|
|
@@ -320,7 +377,7 @@ template <class X, class Y>
|
|
|
320
377
|
inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
|
|
321
378
|
cast(std::unique_ptr<Y> &&Val)
|
|
322
379
|
{
|
|
323
|
-
assert(
|
|
380
|
+
assert(SVFUtil::isa<X>(Val.get()) && "cast<Ty>() argument of incompatible type!");
|
|
324
381
|
using ret_type = typename cast_retty<X, std::unique_ptr<Y>>::ret_type;
|
|
325
382
|
return ret_type(
|
|
326
383
|
cast_convert_val<X, Y *, typename simplify_type<Y *>::SimpleType>::doit(
|
|
@@ -336,24 +393,23 @@ inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
|
|
|
336
393
|
//
|
|
337
394
|
|
|
338
395
|
template <class X, class Y>
|
|
339
|
-
LLVM_NODISCARD inline
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
dyn_cast(const Y &Val)
|
|
396
|
+
LLVM_NODISCARD inline std::enable_if_t<
|
|
397
|
+
!is_simple_type<Y>::value, typename cast_retty<X, const Y>::ret_type>
|
|
398
|
+
dyn_cast(const Y &Val)
|
|
343
399
|
{
|
|
344
|
-
return
|
|
400
|
+
return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
|
|
345
401
|
}
|
|
346
402
|
|
|
347
403
|
template <class X, class Y>
|
|
348
404
|
LLVM_NODISCARD inline typename cast_retty<X, Y>::ret_type dyn_cast(Y &Val)
|
|
349
405
|
{
|
|
350
|
-
return
|
|
406
|
+
return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
|
|
351
407
|
}
|
|
352
408
|
|
|
353
409
|
template <class X, class Y>
|
|
354
410
|
LLVM_NODISCARD inline typename cast_retty<X, Y *>::ret_type dyn_cast(Y *Val)
|
|
355
411
|
{
|
|
356
|
-
return
|
|
412
|
+
return SVFUtil::isa<X>(Val) ? SVFUtil::cast<X>(Val) : nullptr;
|
|
357
413
|
}
|
|
358
414
|
|
|
359
415
|
} // End namespace SVFUtil
|