Index: llvm/trunk/include/llvm/Support/Allocator.h =================================================================== --- llvm/trunk/include/llvm/Support/Allocator.h +++ llvm/trunk/include/llvm/Support/Allocator.h @@ -90,7 +90,10 @@ public: void Reset() {} - void *Allocate(size_t Size, size_t /*Alignment*/) { return malloc(Size); } + LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, + size_t /*Alignment*/) { + return malloc(Size); + } // Pull in base class overloads. using AllocatorBase::Allocate; @@ -200,7 +203,7 @@ } /// \brief Allocate space at the specified alignment. - void *Allocate(size_t Size, size_t Alignment) { + LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, size_t Alignment) { assert(Alignment > 0 && "0-byte alignnment is not allowed. Use 1 instead."); // Keep track of how many bytes we've allocated. Index: llvm/trunk/include/llvm/Support/Compiler.h =================================================================== --- llvm/trunk/include/llvm/Support/Compiler.h +++ llvm/trunk/include/llvm/Support/Compiler.h @@ -236,6 +236,12 @@ #define LLVM_ATTRIBUTE_NORETURN #endif +#if __has_attribute(returns_nonnull) || __GNUC_PREREQ(4, 9) +#define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) +#else +#define LLVM_ATTRIBUTE_RETURNS_NONNULL +#endif + /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress /// pedantic diagnostics. #ifdef __GNUC__