[cfe-commits] r111363 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/new.cpp

Douglas Gregor dgregor at apple.com
Wed Aug 18 08:06:25 PDT 2010


Author: dgregor
Date: Wed Aug 18 10:06:25 2010
New Revision: 111363

URL: http://llvm.org/viewvc/llvm-project?rev=111363&view=rev
Log:
Make sure to add MallocAttr to explicitly-declared operator new/new[]
when -fassume-sane-operator-new. Patch by Tom Jablin!

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/new.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=111363&r1=111362&r2=111363&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Aug 18 10:06:25 2010
@@ -1257,8 +1257,11 @@
           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;
+        }
       }
     }
   }

Modified: cfe/trunk/test/CodeGenCXX/new.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new.cpp?rev=111363&r1=111362&r2=111363&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/new.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/new.cpp Wed Aug 18 10:06:25 2010
@@ -73,6 +73,10 @@
   new U[n];
 }
 
+// noalias
+// CHECK: declare noalias i8* @_Znam
+void *operator new[](size_t);
+
 void t9() {
   bool b;
 





More information about the cfe-commits mailing list