diff options
Diffstat (limited to 'test/Analysis/Inputs')
5 files changed, 99 insertions, 1 deletions
diff --git a/test/Analysis/Inputs/system-header-simulator-cxx.h b/test/Analysis/Inputs/system-header-simulator-cxx.h index e762d0a..eee0e31 100644 --- a/test/Analysis/Inputs/system-header-simulator-cxx.h +++ b/test/Analysis/Inputs/system-header-simulator-cxx.h @@ -1,3 +1,8 @@ +// Like the compiler, the static analyzer treats some functions differently if +// they come from a system header -- for example, it is assumed that system +// functions do not arbitrarily free() their parameters, and that some bugs +// found in system headers cannot be fixed by the user and should be +// suppressed. #pragma clang system_header namespace std { @@ -54,4 +59,35 @@ namespace std { return 0; } }; + + class bad_alloc : public exception { + public: + bad_alloc() throw(); + bad_alloc(const bad_alloc&) throw(); + bad_alloc& operator=(const bad_alloc&) throw(); + virtual const char* what() const throw() { + return 0; + } + }; + + struct nothrow_t {}; + + extern const nothrow_t nothrow; + + template<class InputIter, class OutputIter> + OutputIter copy(InputIter II, InputIter IE, OutputIter OI) { + while (II != IE) + *OI++ = *II++; + return OI; + } } + +void* operator new(std::size_t, const std::nothrow_t&) throw(); +void* operator new[](std::size_t, const std::nothrow_t&) throw(); +void operator delete(void*, const std::nothrow_t&) throw(); +void operator delete[](void*, const std::nothrow_t&) throw(); + +void* operator new (std::size_t size, void* ptr) throw() { return ptr; }; +void* operator new[] (std::size_t size, void* ptr) throw() { return ptr; }; +void operator delete (void* ptr, void*) throw() {}; +void operator delete[] (void* ptr, void*) throw() {}; diff --git a/test/Analysis/Inputs/system-header-simulator-for-malloc.h b/test/Analysis/Inputs/system-header-simulator-for-malloc.h new file mode 100644 index 0000000..e764556 --- /dev/null +++ b/test/Analysis/Inputs/system-header-simulator-for-malloc.h @@ -0,0 +1,34 @@ +// Like the compiler, the static analyzer treats some functions differently if +// they come from a system header -- for example, it is assumed that system +// functions do not arbitrarily free() their parameters, and that some bugs +// found in system headers cannot be fixed by the user and should be +// suppressed. +#pragma clang system_header + +typedef __typeof(sizeof(int)) size_t; +void *malloc(size_t); +void *calloc(size_t, size_t); +void free(void *); + + +#if __OBJC__ + +#import "system-header-simulator-objc.h" + +@interface Wrapper : NSData +- (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)len; +@end + +@implementation Wrapper +- (id)initWithBytesNoCopy:(void *)bytes length:(NSUInteger)len { + return [self initWithBytesNoCopy:bytes length:len freeWhenDone:1]; // no-warning +} +@end + +@interface CustomData : NSData ++ (id)somethingNoCopy:(char *)bytes; ++ (id)somethingNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)freeBuffer; ++ (id)something:(char *)bytes freeWhenDone:(BOOL)freeBuffer; +@end + +#endif diff --git a/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h b/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h index 99986f4..b65b7a6 100644 --- a/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h +++ b/test/Analysis/Inputs/system-header-simulator-for-simple-stream.h @@ -1,4 +1,8 @@ - +// Like the compiler, the static analyzer treats some functions differently if +// they come from a system header -- for example, it is assumed that system +// functions do not arbitrarily free() their parameters, and that some bugs +// found in system headers cannot be fixed by the user and should be +// suppressed. #pragma clang system_header typedef struct __sFILE { @@ -9,3 +13,9 @@ int fputc(int, FILE *); int fputs(const char * restrict, FILE * restrict) __asm("_" "fputs" ); int fclose(FILE *); void exit(int); + +// The following is a fake system header function +typedef struct __FileStruct { + FILE * p; +} FileStruct; +void fakeSystemHeaderCall(FileStruct *); diff --git a/test/Analysis/Inputs/system-header-simulator-objc.h b/test/Analysis/Inputs/system-header-simulator-objc.h index a647b37..ecc99e1 100644 --- a/test/Analysis/Inputs/system-header-simulator-objc.h +++ b/test/Analysis/Inputs/system-header-simulator-objc.h @@ -1,3 +1,8 @@ +// Like the compiler, the static analyzer treats some functions differently if +// they come from a system header -- for example, it is assumed that system +// functions do not arbitrarily free() their parameters, and that some bugs +// found in system headers cannot be fixed by the user and should be +// suppressed. #pragma clang system_header typedef unsigned int UInt32; diff --git a/test/Analysis/Inputs/system-header-simulator.h b/test/Analysis/Inputs/system-header-simulator.h index e28b890..04688c78 100644 --- a/test/Analysis/Inputs/system-header-simulator.h +++ b/test/Analysis/Inputs/system-header-simulator.h @@ -1,3 +1,8 @@ +// Like the compiler, the static analyzer treats some functions differently if +// they come from a system header -- for example, it is assumed that system +// functions do not arbitrarily free() their parameters, and that some bugs +// found in system headers cannot be fixed by the user and should be +// suppressed. #pragma clang system_header typedef struct _FILE FILE; @@ -62,3 +67,11 @@ typedef void (*xpc_finalizer_t)(void *value); void xpc_connection_set_context(xpc_connection_t connection, void *context); void xpc_connection_set_finalizer_f(xpc_connection_t connection, xpc_finalizer_t finalizer); void xpc_connection_resume(xpc_connection_t connection); + +//The following is a fake system header function +void fakeSystemHeaderCallInt(int *); + +typedef struct __SomeStruct { + char * p; +} SomeStruct; +void fakeSystemHeaderCall(SomeStruct *); |