]> granicus.if.org Git - clang/commitdiff
Make sure to add MallocAttr to explicitly-declared operator new/new[]
authorDouglas Gregor <dgregor@apple.com>
Wed, 18 Aug 2010 15:06:25 +0000 (15:06 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 18 Aug 2010 15:06:25 +0000 (15:06 +0000)
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

lib/Sema/SemaExprCXX.cpp
test/CodeGenCXX/new.cpp

index 5e46090c0588f7274d1b6113ed325c808078378f..8599a146c69b9e3882077ebdea54f2acda5c0c4b 100644 (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;
+        }
       }
     }
   }
index 3f22e89f2a536a8f5f25131d31a9f189b17e1dab..61a5a153ca52bbf6c9997668aee398ad27199f35 100644 (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;