File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 25
25
#include " swift/AST/PrintOptions.h"
26
26
#include " swift/AST/TypeAlignments.h"
27
27
#include " swift/Basic/OptionSet.h"
28
+ #include " swift/Basic/Compiler.h"
28
29
#include < functional>
29
30
#include < string>
30
31
@@ -536,7 +537,9 @@ template <class X> inline CanTypeWrapper<X> cast_or_null(CanType type) {
536
537
return CanTypeWrapper<X>(cast_or_null<X>(type.getPointer ()));
537
538
}
538
539
template <class X > inline CanTypeWrapper<X> dyn_cast (CanType type) {
539
- return CanTypeWrapper<X>(dyn_cast<X>(type.getPointer ()));
540
+ auto Ty = type.getPointer ();
541
+ SWIFT_ASSUME (Ty != nullptr );
542
+ return CanTypeWrapper<X>(dyn_cast<X>(Ty));
540
543
}
541
544
template <class X > inline CanTypeWrapper<X> dyn_cast_or_null (CanType type) {
542
545
return CanTypeWrapper<X>(dyn_cast_or_null<X>(type.getPointer ()));
@@ -554,7 +557,9 @@ inline CanTypeWrapper<X> cast(CanTypeWrapper<P> type) {
554
557
}
555
558
template <class X , class P >
556
559
inline CanTypeWrapper<X> dyn_cast (CanTypeWrapper<P> type) {
557
- return CanTypeWrapper<X>(dyn_cast<X>(type.getPointer ()));
560
+ auto Ty = type.getPointer ();
561
+ SWIFT_ASSUME (Ty != nullptr );
562
+ return CanTypeWrapper<X>(dyn_cast<X>(Ty));
558
563
}
559
564
template <class X , class P >
560
565
inline CanTypeWrapper<X> dyn_cast_or_null (CanTypeWrapper<P> type) {
Original file line number Diff line number Diff line change @@ -446,7 +446,9 @@ class alignas(1 << TypeAlignInBits) TypeBase {
446
446
template <typename T>
447
447
T *getAs () {
448
448
static_assert (!isSugaredType<T>(), " getAs desugars types" );
449
- return dyn_cast<T>(getDesugaredType ());
449
+ auto Ty = getDesugaredType ();
450
+ SWIFT_ASSUME (Ty != nullptr );
451
+ return dyn_cast<T>(Ty);
450
452
}
451
453
452
454
template <typename T>
Original file line number Diff line number Diff line change 19
19
#define SWIFT_COMPILER_IS_MSVC 0
20
20
#endif
21
21
22
+ // Workaround non-clang compilers
23
+ #ifndef __has_builtin
24
+ #define __has_builtin (x ) 0
25
+ #endif
26
+
22
27
#if SWIFT_COMPILER_IS_MSVC && _MSC_VER < 1910
23
28
// Work around MSVC bug: attempting to reference a deleted function
24
29
// https://connect.microsoft.com/VisualStudio/feedback/details/3116505
28
33
#define SWIFT_DELETE_OPERATOR_DELETED = delete ;
29
34
#endif
30
35
36
+ // __builtin_assume() is an optimization hint.
37
+ #if __has_builtin(__builtin_assume)
38
+ #define SWIFT_ASSUME (x ) __builtin_assume(x)
39
+ #else
40
+ #define SWIFT_ASSUME (x )
41
+ #endif
42
+
31
43
#endif // SWIFT_BASIC_COMPILER_H
You can’t perform that action at this time.
0 commit comments