https://github.com/nikic created https://github.com/llvm/llvm-project/pull/200349
Reverts llvm/llvm-project#197199. This had some unexpected optimization impact. >From 0a5d3ddeee1faf6c6f232bdcde62c5266ba8f8d4 Mon Sep 17 00:00:00 2001 From: Nikita Popov <[email protected]> Date: Fri, 29 May 2026 10:36:47 +0200 Subject: [PATCH] Revert "[Clang] Mark new as inaccessiblememonly if sane (#197199)" This reverts commit 01c93f511b4b5f734ac420709266036497610014. --- clang/lib/CodeGen/CGCall.cpp | 12 +++--------- clang/test/CodeGenCXX/new_hot_cold.cpp | 8 ++++---- clang/test/CodeGenCXX/operator-new.cpp | 6 ++---- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index f4c6f3a6e96f4..2468394929360 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -2615,17 +2615,11 @@ void CodeGenModule::ConstructAttributeList(StringRef Name, AddAttributesFromFunctionProtoType( getContext(), FuncAttrs, Fn->getType()->getAs<FunctionProtoType>()); if (AttrOnCallSite && Fn->isReplaceableGlobalAllocationFunction()) { - // A sane operator new returns a non-aliasing pointer and does not - // read or write accessible memory. + // A sane operator new returns a non-aliasing pointer. + auto Kind = Fn->getDeclName().getCXXOverloadedOperator(); if (getCodeGenOpts().AssumeSaneOperatorNew && - Fn->getDeclName().isAnyOperatorNew()) { + (Kind == OO_New || Kind == OO_Array_New)) RetAttrs.addAttribute(llvm::Attribute::NoAlias); - // FIXME: inaccessiblemem could cause issues if LTO makes the - // previously inaccessible memory accessible after linking. - FuncAttrs.addMemoryAttr( - llvm::MemoryEffects::inaccessibleOrErrnoMemOnly( - llvm::ModRefInfo::ModRef, llvm::ModRefInfo::Mod)); - } } const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Fn); const bool IsVirtualCall = MD && MD->isVirtual(); diff --git a/clang/test/CodeGenCXX/new_hot_cold.cpp b/clang/test/CodeGenCXX/new_hot_cold.cpp index 439166ddea566..014e815201485 100644 --- a/clang/test/CodeGenCXX/new_hot_cold.cpp +++ b/clang/test/CodeGenCXX/new_hot_cold.cpp @@ -124,7 +124,7 @@ void hot_cold_new_align_nothrow_array() { // CHECK-DAG: attributes [[ATTR_NOBUILTIN]] = { nobuiltin allocsize(0) {{.*}} } // CHECK-DAG: attributes [[ATTR_NOBUILTIN_NOTHROW]] = { nobuiltin nounwind allocsize(0) {{.*}} } -// CHECK-DAG: attributes [[ATTR_NO_BUILTIN_CALL]] = { allocsize(0) memory(inaccessiblemem: readwrite, errnomem: write) } -// CHECK-DAG: attributes [[ATTR_BUILTIN_CALL]] = { builtin allocsize(0) memory(inaccessiblemem: readwrite, errnomem: write) } -// CHECK-DAG: attributes [[ATTR_NO_BUILTIN_NOTHROW_CALL]] = { nounwind allocsize(0) memory(inaccessiblemem: readwrite, errnomem: write) } -// CHECK-DAG: attributes [[ATTR_BUILTIN_NOTHROW_CALL]] = { builtin nounwind allocsize(0) memory(inaccessiblemem: readwrite, errnomem: write) } +// CHECK-DAG: attributes [[ATTR_NO_BUILTIN_CALL]] = { allocsize(0) } +// CHECK-DAG: attributes [[ATTR_BUILTIN_CALL]] = { builtin allocsize(0) } +// CHECK-DAG: attributes [[ATTR_NO_BUILTIN_NOTHROW_CALL]] = { nounwind allocsize(0) } +// CHECK-DAG: attributes [[ATTR_BUILTIN_NOTHROW_CALL]] = { builtin nounwind allocsize(0) } diff --git a/clang/test/CodeGenCXX/operator-new.cpp b/clang/test/CodeGenCXX/operator-new.cpp index e741d85fe4cd2..1d7887146705e 100644 --- a/clang/test/CodeGenCXX/operator-new.cpp +++ b/clang/test/CodeGenCXX/operator-new.cpp @@ -22,10 +22,8 @@ void *f2(long N) { // ALL-NEXT: [[OVER:%.*]] = extractvalue {{.*}} [[UWO]], 1 // ALL-NEXT: [[SUM:%.*]] = extractvalue {{.*}} [[UWO]], 0 // ALL-NEXT: [[RESULT:%.*]] = select i1 [[OVER]], i32 -1, i32 [[SUM]] - // SANE-NEXT: call noalias noundef nonnull ptr @_Znaj(i32 noundef [[RESULT]]) [[ATTR:#[0-9]+]] - // SANENOT-NEXT: call noundef nonnull ptr @_Znaj(i32 noundef [[RESULT]]) [[ATTR:#[0-9]+]] + // SANE-NEXT: call noalias noundef nonnull ptr @_Znaj(i32 noundef [[RESULT]]) + // SANENOT-NEXT: call noundef nonnull ptr @_Znaj(i32 noundef [[RESULT]]) } // ALL: declare noundef nonnull ptr @_Znaj( -// SANE: attributes [[ATTR]] = { builtin allocsize(0) memory(inaccessiblemem: readwrite, errnomem: write) } -// SANENOT: attributes [[ATTR]] = { builtin allocsize(0) } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
