implement PR5654: add -fassume-sane-operator-new, which is enabled by default, and adds the malloc attribute to the global function new() and to the overloaded new operators.
feel free to chage the name to this lengthy argument
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91543 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7a27e11..bf5b350 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2799,6 +2799,11 @@
D.getIdentifierLoc(), Name, R, TInfo,
isStatic, isInline);
+ if ((Name.getCXXOverloadedOperator() == OO_New ||
+ Name.getCXXOverloadedOperator() == OO_Array_New) &&
+ getLangOptions().AssumeSaneOperatorNew)
+ NewFD->addAttr(::new (Context) MallocAttr());
+
isVirtualOkay = !isStatic;
} else {
// Determine whether the function was written with a