Don't use a cookie if the global placement new function is used.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91251 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index c12ec14..150f11e 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -64,6 +64,19 @@
   if (!E->isArray())
     return 0;
 
+  // No cookie is required if the new operator being used is 
+  // ::operator new[](size_t, void*).
+  const FunctionDecl *OperatorNew = E->getOperatorNew();
+  if (OperatorNew->getDeclContext()->getLookupContext()->isFileContext()) {
+    if (OperatorNew->getNumParams() == 2) {
+      CanQualType ParamType = 
+        Ctx.getCanonicalType(OperatorNew->getParamDecl(1)->getType());
+      
+      if (ParamType == Ctx.VoidPtrTy)
+        return 0;
+    }
+  }
+      
   return CalculateCookiePadding(Ctx, E->getAllocatedType());
   QualType T = E->getAllocatedType();
 }
@@ -265,7 +278,6 @@
   return NewPtr;
 }
 
-
 static std::pair<llvm::Value *, llvm::Value *>
 GetAllocatedObjectPtrAndNumElements(CodeGenFunction &CGF,
                                     llvm::Value *Ptr, QualType DeleteTy) {