Make sure to add MallocAttr to explicitly-declared operator new/new[]

when -fassume-sane-operator-new. Patch by Tom Jablin!

llvm-svn: 111363
This commit is contained in:
Douglas Gregor 2010-08-18 15:06:25 +00:00
parent b13f5d99af
commit c1a42fdd53
2 changed files with 8 additions and 1 deletions

View File

@ -1257,8 +1257,11 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
Context.getCanonicalType(
Func->getParamDecl(0)->getType().getUnqualifiedType());
// FIXME: Do we need to check for default arguments here?
if (Func->getNumParams() == 1 && InitialParamType == Argument)
if (Func->getNumParams() == 1 && InitialParamType == Argument) {
if(AddMallocAttr && !Func->hasAttr<MallocAttr>())
Func->addAttr(::new (Context) MallocAttr());
return;
}
}
}
}

View File

@ -73,6 +73,10 @@ void t8(int n) {
new U[n];
}
// noalias
// CHECK: declare noalias i8* @_Znam
void *operator new[](size_t);
void t9() {
bool b;