[PATCH] D117600: [CGCall] Annotate operator new with inaccessiblememonly if AssumeSaneOperatorNew is on
Bryce Wilson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 26 10:58:32 PST 2022
Bryce-MW updated this revision to Diff 403339.
Bryce-MW marked an inline comment as done.
Bryce-MW added a comment.
- Use proper attribute
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D117600/new/
https://reviews.llvm.org/D117600
Files:
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGCall.cpp
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2062,11 +2062,14 @@
AddAttributesFromFunctionProtoType(
getContext(), FuncAttrs, Fn->getType()->getAs<FunctionProtoType>());
if (AttrOnCallSite && Fn->isReplaceableGlobalAllocationFunction()) {
- // A sane operator new returns a non-aliasing pointer.
+ // A sane operator new returns a non-aliasing pointer and is
+ // inaccessiblememonly
auto Kind = Fn->getDeclName().getCXXOverloadedOperator();
if (getCodeGenOpts().AssumeSaneOperatorNew &&
- (Kind == OO_New || Kind == OO_Array_New))
+ (Kind == OO_New || Kind == OO_Array_New)) {
RetAttrs.addAttribute(llvm::Attribute::NoAlias);
+ FuncAttrs.addAttribute(llvm::Attribute::InacccessibleMemOnly);
+ }
}
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Fn);
const bool IsVirtualCall = MD && MD->isVirtual();
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2256,7 +2256,7 @@
def fno_asm : Flag<["-"], "fno-asm">, Group<f_Group>;
def fno_asynchronous_unwind_tables : Flag<["-"], "fno-asynchronous-unwind-tables">, Group<f_Group>;
def fno_assume_sane_operator_new : Flag<["-"], "fno-assume-sane-operator-new">, Group<f_Group>,
- HelpText<"Don't assume that C++'s global operator new can't alias any pointer">,
+ HelpText<"Don't assume that C++'s global operator new can't alias any pointer or access accessible memory">,
Flags<[CC1Option]>, MarshallingInfoNegativeFlag<CodeGenOpts<"AssumeSaneOperatorNew">>;
def fno_builtin : Flag<["-"], "fno-builtin">, Group<f_Group>, Flags<[CC1Option, CoreOption]>,
HelpText<"Disable implicit builtin knowledge of functions">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117600.403339.patch
Type: text/x-patch
Size: 1983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220126/a1f2fcf7/attachment.bin>
More information about the cfe-commits
mailing list