mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 22:24:07 +00:00
Teach MemoryBuiltins and InstructionSimplify that operator new never returns NULL.
This is safe per C++11 18.6.1.1p3: [operator new returns] a non-null pointer to suitably aligned storage (3.7.4), or else throw a bad_alloc exception. This requirement is binding on a replacement version of this function. Brings us a tiny bit closer to eliminating more vector push_backs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191310 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
#include "llvm/Analysis/ValueTracking.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/Analysis/InstructionSimplify.h"
|
||||
#include "llvm/Analysis/MemoryBuiltins.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
#include "llvm/IR/GlobalAlias.h"
|
||||
@ -2064,7 +2065,7 @@ bool llvm::isSafeToSpeculativelyExecute(const Value *V,
|
||||
|
||||
/// isKnownNonNull - Return true if we know that the specified value is never
|
||||
/// null.
|
||||
bool llvm::isKnownNonNull(const Value *V) {
|
||||
bool llvm::isKnownNonNull(const Value *V, const TargetLibraryInfo *TLI) {
|
||||
// Alloca never returns null, malloc might.
|
||||
if (isa<AllocaInst>(V)) return true;
|
||||
|
||||
@ -2075,5 +2076,10 @@ bool llvm::isKnownNonNull(const Value *V) {
|
||||
// Global values are not null unless extern weak.
|
||||
if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
|
||||
return !GV->hasExternalWeakLinkage();
|
||||
|
||||
// operator new never returns null.
|
||||
if (isOperatorNewLikeFn(V, TLI, /*LookThroughBitCast=*/true))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user