Index: lib/IR/User.cpp =================================================================== --- lib/IR/User.cpp +++ lib/IR/User.cpp @@ -121,21 +121,23 @@ assert(DescBytesToAllocate % sizeof(void *) == 0 && "We need this to satisfy alignment constraints for Uses"); + User *Obj = nullptr; uint8_t *Storage = static_cast( - ::operator new(Size + sizeof(Use) * Us + DescBytesToAllocate)); - Use *Start = reinterpret_cast(Storage + DescBytesToAllocate); - Use *End = Start + Us; - User *Obj = reinterpret_cast(End); - Obj->NumUserOperands = Us; - Obj->HasHungOffUses = false; - Obj->HasDescriptor = DescBytes != 0; - Use::initTags(Start, End); - - if (DescBytes != 0) { - auto *DescInfo = reinterpret_cast(Storage + DescBytes); - DescInfo->SizeInBytes = DescBytes; + ::operator new(Size + sizeof(Use) * Us + DescBytesToAllocate, std::nothrow)); + if (Storage != nullptr) { + Use *Start = reinterpret_cast(Storage + DescBytesToAllocate); + Use *End = Start + Us; + Obj = reinterpret_cast(End); + Obj->NumUserOperands = Us; + Obj->HasHungOffUses = false; + Obj->HasDescriptor = DescBytes != 0; + Use::initTags(Start, End); + + if (DescBytes != 0) { + auto *DI = reinterpret_cast(Storage + DescBytes); + DI->SizeInBytes = DescBytes; + } } - return Obj; } @@ -149,13 +151,16 @@ void *User::operator new(size_t Size) { // Allocate space for a single Use* - void *Storage = ::operator new(Size + sizeof(Use *)); - Use **HungOffOperandList = static_cast(Storage); - User *Obj = reinterpret_cast(HungOffOperandList + 1); - Obj->NumUserOperands = 0; - Obj->HasHungOffUses = true; - Obj->HasDescriptor = false; - *HungOffOperandList = nullptr; + User *Obj = nullptr; + void *Storage = ::operator new(Size + sizeof(Use *), std::nothrow); + if (Storage != nullptr) { + Use **HungOffOperandList = static_cast(Storage); + Obj = reinterpret_cast(HungOffOperandList + 1); + Obj->NumUserOperands = 0; + Obj->HasHungOffUses = true; + Obj->HasDescriptor = false; + *HungOffOperandList = nullptr; + } return Obj; }