diff options
Diffstat (limited to 'test/Analysis/Inputs')
4 files changed, 331 insertions, 95 deletions
diff --git a/test/Analysis/Inputs/system-header-simulator-cxx-std-suppression.h b/test/Analysis/Inputs/system-header-simulator-cxx-std-suppression.h new file mode 100644 index 0000000000000..dc53af269c9c2 --- /dev/null +++ b/test/Analysis/Inputs/system-header-simulator-cxx-std-suppression.h @@ -0,0 +1,146 @@ +// This is a fake system header with divide-by-zero bugs introduced in +// c++ std library functions. We use these bugs to test hard-coded +// suppression of diagnostics within standard library functions that are known +// to produce false positives. + +#pragma clang system_header + +typedef unsigned char uint8_t; + +typedef __typeof__(sizeof(int)) size_t; +void *memmove(void *s1, const void *s2, size_t n); + +namespace std { + + template <class _Tp> + class allocator { + public: + void deallocate(void *p) { + ::delete p; + } + }; + + template <class _Alloc> + class allocator_traits { + public: + static void deallocate(void *p) { + _Alloc().deallocate(p); + } + }; + + template <class _Tp, class _Alloc> + class __list_imp + {}; + + template <class _Tp, class _Alloc = allocator<_Tp> > + class list + : private __list_imp<_Tp, _Alloc> + { + public: + void pop_front() { + // Fake use-after-free. + // No warning is expected as we are suppressing warning coming + // out of std::list. + int z = 0; + z = 5/z; + } + bool empty() const; + }; + + // basic_string + template<class _CharT, class _Alloc = allocator<_CharT> > + class __attribute__ ((__type_visibility__("default"))) basic_string { + bool isLong; + union { + _CharT localStorage[4]; + _CharT *externalStorage; + + void assignExternal(_CharT *newExternal) { + externalStorage = newExternal; + } + } storage; + + typedef allocator_traits<_Alloc> __alloc_traits; + + public: + basic_string(); + + void push_back(int c) { + // Fake error trigger. + // No warning is expected as we are suppressing warning coming + // out of std::basic_string. + int z = 0; + z = 5/z; + } + + _CharT *getBuffer() { + return isLong ? storage.externalStorage : storage.localStorage; + } + + basic_string &operator +=(int c) { + // Fake deallocate stack-based storage. + // No warning is expected as we are suppressing warnings within + // std::basic_string. + __alloc_traits::deallocate(getBuffer()); + } + + basic_string &operator =(const basic_string &other) { + // Fake deallocate stack-based storage, then use the variable in the + // same union. + // No warning is expected as we are suppressing warnings within + // std::basic_string. + __alloc_traits::deallocate(getBuffer()); + storage.assignExternal(new _CharT[4]); + } + }; + +template<class _Engine, class _UIntType> +class __independent_bits_engine { +public: + // constructors and seeding functions + __independent_bits_engine(_Engine& __e, size_t __w); +}; + +template<class _Engine, class _UIntType> +__independent_bits_engine<_Engine, _UIntType> + ::__independent_bits_engine(_Engine& __e, size_t __w) +{ + // Fake error trigger. + // No warning is expected as we are suppressing warning coming + // out of std::__independent_bits_engine. + int z = 0; + z = 5/z; +} + +#if __has_feature(cxx_decltype) +typedef decltype(nullptr) nullptr_t; + +template<class _Tp> +class shared_ptr +{ +public: + constexpr shared_ptr(nullptr_t); + explicit shared_ptr(_Tp* __p); + + shared_ptr(shared_ptr&& __r) { } + + ~shared_ptr(); + + shared_ptr& operator=(shared_ptr&& __r) { + // Fake error trigger. + // No warning is expected as we are suppressing warning coming + // out of std::shared_ptr. + int z = 0; + z = 5/z; + } +}; + +template<class _Tp> +inline +constexpr +shared_ptr<_Tp>::shared_ptr(nullptr_t) { +} + +#endif // __has_feature(cxx_decltype) +} + diff --git a/test/Analysis/Inputs/system-header-simulator-cxx.h b/test/Analysis/Inputs/system-header-simulator-cxx.h index f9049c3ae9e72..b32d200364b18 100644 --- a/test/Analysis/Inputs/system-header-simulator-cxx.h +++ b/test/Analysis/Inputs/system-header-simulator-cxx.h @@ -7,6 +7,9 @@ typedef unsigned char uint8_t; +typedef __typeof__(sizeof(int)) size_t; +void *memmove(void *s1, const void *s2, size_t n); + namespace std { template <class T1, class T2> struct pair { @@ -104,118 +107,127 @@ namespace std { const _E* end() const {return __begin_ + __size_;} }; - template<class InputIter, class OutputIter> - OutputIter copy(InputIter II, InputIter IE, OutputIter OI) { - while (II != IE) - *OI++ = *II++; - return OI; - } + template <bool, class _Tp = void> struct enable_if {}; + template <class _Tp> struct enable_if<true, _Tp> {typedef _Tp type;}; - struct input_iterator_tag { }; - struct output_iterator_tag { }; - struct forward_iterator_tag : public input_iterator_tag { }; - struct bidirectional_iterator_tag : public forward_iterator_tag { }; - struct random_access_iterator_tag : public bidirectional_iterator_tag { }; + template <class _Tp, _Tp __v> + struct integral_constant + { + static const _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant type; - template <class _Tp> - class allocator { - public: - void deallocate(void *p) { - ::delete p; - } - }; + operator value_type() const {return value;} - template <class _Alloc> - class allocator_traits { - public: - static void deallocate(void *p) { - _Alloc().deallocate(p); - } + value_type operator ()() const {return value;} }; - template <class _Tp, class _Alloc> - class __list_imp - {}; + template <class _Tp, _Tp __v> + const _Tp integral_constant<_Tp, __v>::value; - template <class _Tp, class _Alloc = allocator<_Tp> > - class list - : private __list_imp<_Tp, _Alloc> - { - public: - void pop_front() { - // Fake use-after-free. - // No warning is expected as we are suppressing warning coming - // out of std::list. - int z = 0; - z = 5/z; - } - bool empty() const; - }; + template <class _Tp, class _Arg> + struct is_trivially_assignable + : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)> + { + }; - // basic_string - template<class _CharT, class _Alloc = allocator<_CharT> > - class __attribute__ ((__type_visibility__("default"))) basic_string { - bool isLong; - union { - _CharT localStorage[4]; - _CharT *externalStorage; + typedef integral_constant<bool,true> true_type; + typedef integral_constant<bool,false> false_type; - void assignExternal(_CharT *newExternal) { - externalStorage = newExternal; - } - } storage; + template <class _Tp> struct is_const : public false_type {}; + template <class _Tp> struct is_const<_Tp const> : public true_type {}; - typedef allocator_traits<_Alloc> __alloc_traits; + template <class _Tp> struct is_reference : public false_type {}; + template <class _Tp> struct is_reference<_Tp&> : public true_type {}; - public: - basic_string(); - - void push_back(int c) { - // Fake error trigger. - // No warning is expected as we are suppressing warning coming - // out of std::basic_string. - int z = 0; - z = 5/z; - } + template <class _Tp, class _Up> struct is_same : public false_type {}; + template <class _Tp> struct is_same<_Tp, _Tp> : public true_type {}; + + template <class _Tp, bool = is_const<_Tp>::value || is_reference<_Tp>::value > + struct __add_const {typedef _Tp type;}; + + template <class _Tp> + struct __add_const<_Tp, false> {typedef const _Tp type;}; - _CharT *getBuffer() { - return isLong ? storage.externalStorage : storage.localStorage; + template <class _Tp> struct add_const {typedef typename __add_const<_Tp>::type type;}; + + template <class _Tp> struct remove_const {typedef _Tp type;}; + template <class _Tp> struct remove_const<const _Tp> {typedef _Tp type;}; + + template <class _Tp> struct add_lvalue_reference {typedef _Tp& type;}; + + template <class _Tp> struct is_trivially_copy_assignable + : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, + typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {}; + + template<class InputIter, class OutputIter> + OutputIter __copy(InputIter II, InputIter IE, OutputIter OI) { + while (II != IE) + *OI++ = *II++; + + return OI; } - basic_string &operator +=(int c) { - // Fake deallocate stack-based storage. - // No warning is expected as we are suppressing warnings within - // std::basic_string. - __alloc_traits::deallocate(getBuffer()); + template <class _Tp, class _Up> + inline + typename enable_if + < + is_same<typename remove_const<_Tp>::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* + >::type __copy(_Tp* __first, _Tp* __last, _Up* __result) { + size_t __n = __last - __first; + + if (__n > 0) + memmove(__result, __first, __n * sizeof(_Up)); + + return __result + __n; } - basic_string &operator =(const basic_string &other) { - // Fake deallocate stack-based storage, then use the variable in the - // same union. - // No warning is expected as we are suppressing warnings within - // std::basic_string. - __alloc_traits::deallocate(getBuffer()); - storage.assignExternal(new _CharT[4]); + template<class InputIter, class OutputIter> + OutputIter copy(InputIter II, InputIter IE, OutputIter OI) { + return __copy(II, IE, OI); + } + + template <class _BidirectionalIterator, class _OutputIterator> + inline + _OutputIterator + __copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, + _OutputIterator __result) + { + while (__first != __last) + *--__result = *--__last; + return __result; + } + + template <class _Tp, class _Up> + inline + typename enable_if + < + is_same<typename remove_const<_Tp>::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* + >::type __copy_backward(_Tp* __first, _Tp* __last, _Up* __result) { + size_t __n = __last - __first; + + if (__n > 0) + { + __result -= __n; + memmove(__result, __first, __n * sizeof(_Up)); } - }; + return __result; + } -template<class _Engine, class _UIntType> -class __independent_bits_engine { -public: - // constructors and seeding functions - __independent_bits_engine(_Engine& __e, size_t __w); -}; - -template<class _Engine, class _UIntType> -__independent_bits_engine<_Engine, _UIntType> - ::__independent_bits_engine(_Engine& __e, size_t __w) -{ - // Fake error trigger. - // No warning is expected as we are suppressing warning coming - // out of std::basic_string. - int z = 0; - z = 5/z; -} + template<class InputIter, class OutputIter> + OutputIter copy_backward(InputIter II, InputIter IE, OutputIter OI) { + return __copy_backward(II, IE, OI); + } + + struct input_iterator_tag { }; + struct output_iterator_tag { }; + struct forward_iterator_tag : public input_iterator_tag { }; + struct bidirectional_iterator_tag : public forward_iterator_tag { }; + struct random_access_iterator_tag : public bidirectional_iterator_tag { }; } diff --git a/test/Analysis/Inputs/system-header-simulator-for-nullability.h b/test/Analysis/Inputs/system-header-simulator-for-nullability.h new file mode 100644 index 0000000000000..8d49f323bc1d6 --- /dev/null +++ b/test/Analysis/Inputs/system-header-simulator-for-nullability.h @@ -0,0 +1,43 @@ +#pragma clang system_header + +#define nil 0 +#define BOOL int + +#define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin") +#define NS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end") + +NS_ASSUME_NONNULL_BEGIN + +typedef struct _NSZone NSZone; + +@protocol NSObject ++ (instancetype)alloc; +- (instancetype)init; +- (instancetype)autorelease; +@end + +@protocol NSCopying +- (id)copyWithZone:(nullable NSZone *)zone; +@end + +@protocol NSMutableCopying +- (id)mutableCopyWithZone:(nullable NSZone *)zone; +@end + +__attribute__((objc_root_class)) +@interface +NSObject<NSObject> +@end + +@interface NSString : NSObject<NSCopying> +- (BOOL)isEqualToString : (NSString *)aString; +- (NSString *)stringByAppendingString:(NSString *)aString; +@end + +void NSSystemFunctionTakingNonnull(NSString *s); + +@interface NSSystemClass : NSObject +- (void) takesNonnull:(NSString *)s; +@end + +NS_ASSUME_NONNULL_END diff --git a/test/Analysis/Inputs/system-header-simulator-for-objc-dealloc.h b/test/Analysis/Inputs/system-header-simulator-for-objc-dealloc.h new file mode 100644 index 0000000000000..231c0bf5640ec --- /dev/null +++ b/test/Analysis/Inputs/system-header-simulator-for-objc-dealloc.h @@ -0,0 +1,35 @@ +#pragma clang system_header + +#define nil ((id)0) + +typedef signed char BOOL; +@protocol NSObject +- (BOOL)isEqual:(id)object; +- (Class)class; +@end + +@interface NSObject <NSObject> {} ++ (instancetype)alloc; +- (void)dealloc; +- (id)init; +- (id)retain; +- (oneway void)release; +@end + +@interface NSRunLoop : NSObject ++ (NSRunLoop *)currentRunLoop; +- (void)cancelPerformSelectorsWithTarget:(id)target; +@end + +@interface NSNotificationCenter : NSObject ++ (NSNotificationCenter *)defaultCenter; +- (void)removeObserver:(id)observer; +@end + +typedef struct objc_selector *SEL; + +void _Block_release(const void *aBlock); +#define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) + +@interface CIFilter : NSObject +@end |