diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-18 15:06:25 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-18 15:06:25 +0000 |
commit | 7b86862ff555a9d848ac7abf6042d192b6d5a04d (patch) | |
tree | c7caceba87703434f13383a3d6a08e92795b392c | |
parent | 783c56f47745f719590b17afd7ed937bf2407b53 (diff) |
Make sure to add MallocAttr to explicitly-declared operator new/new[]
when -fassume-sane-operator-new. Patch by Tom Jablin!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111363 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 5 | ||||
-rw-r--r-- | test/CodeGenCXX/new.cpp | 4 |
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 5e46090c05..8599a146c6 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -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; + } } } } diff --git a/test/CodeGenCXX/new.cpp b/test/CodeGenCXX/new.cpp index 3f22e89f2a..61a5a153ca 100644 --- a/test/CodeGenCXX/new.cpp +++ b/test/CodeGenCXX/new.cpp @@ -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; |