Skip to content

Commit 2e5035a

Browse files
authored
Revert "[clang] Enable sized deallocation by default in C++14 onwards (#83774)" (#90299)
https://lab.llvm.org/buildbot/#/builders/168/builds/20063 (should be fixed with #90292) More details in #83774 This reverts commit cf5a8b4.
1 parent 3ec858b commit 2e5035a

File tree

42 files changed

+113
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+113
-555
lines changed

clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,7 @@ TEST_F(TargetDeclTest, OverloadExpr) {
839839
[[delete]] x;
840840
}
841841
)cpp";
842-
// Sized deallocation is enabled by default in C++14 onwards.
843-
EXPECT_DECLS("CXXDeleteExpr",
844-
"void operator delete(void *, unsigned long) noexcept");
842+
EXPECT_DECLS("CXXDeleteExpr", "void operator delete(void *) noexcept");
845843
}
846844

847845
TEST_F(TargetDeclTest, DependentExprs) {

clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ struct S {
1212
// CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope
1313
void *operator new(size_t size) noexcept(false);
1414

15+
struct T {
16+
// Sized deallocations are not enabled by default, and so this new/delete pair
17+
// does not match. However, we expect only one warning, for the new, because
18+
// the operator delete is a placement delete and we do not warn on mismatching
19+
// placement operations.
20+
// CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope
21+
void *operator new(size_t size) noexcept;
22+
void operator delete(void *ptr, size_t) noexcept; // ok only if sized deallocation is enabled
23+
};
24+
1525
struct U {
1626
void *operator new(size_t size) noexcept;
1727
void operator delete(void *ptr) noexcept;

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ C++ Language Changes
9090
--------------------
9191
- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang extension with ``unsigned`` modifiers also allowed. (#GH85223).
9292

93-
C++14 Feature Support
94-
^^^^^^^^^^^^^^^^^^^^^
95-
- Sized deallocation is enabled by default in C++14 onwards. The user may specify
96-
``-fno-sized-deallocation`` to disable it if there are some regressions.
97-
9893
C++17 Feature Support
9994
^^^^^^^^^^^^^^^^^^^^^
10095
- Clang now exposes ``__GCC_DESTRUCTIVE_SIZE`` and ``__GCC_CONSTRUCTIVE_SIZE``

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ class MarshallingInfoVisibility<KeyPathAndMacro kpm, code default>
603603
// Key paths that are constant during parsing of options with the same key path prefix.
604604
defvar cplusplus = LangOpts<"CPlusPlus">;
605605
defvar cpp11 = LangOpts<"CPlusPlus11">;
606-
defvar cpp14 = LangOpts<"CPlusPlus14">;
607606
defvar cpp17 = LangOpts<"CPlusPlus17">;
608607
defvar cpp20 = LangOpts<"CPlusPlus20">;
609608
defvar c99 = LangOpts<"C99">;
@@ -3371,9 +3370,10 @@ defm relaxed_template_template_args : BoolFOption<"relaxed-template-template-arg
33713370
"Enable C++17 relaxed template template argument matching">,
33723371
NegFlag<SetFalse>>;
33733372
defm sized_deallocation : BoolFOption<"sized-deallocation",
3374-
LangOpts<"SizedDeallocation">, Default<cpp14.KeyPath>,
3375-
PosFlag<SetTrue, [], [], "Enable C++14 sized global deallocation functions">,
3376-
NegFlag<SetFalse>, BothFlags<[], [ClangOption, CC1Option]>>;
3373+
LangOpts<"SizedDeallocation">, DefaultFalse,
3374+
PosFlag<SetTrue, [], [ClangOption, CC1Option],
3375+
"Enable C++14 sized global deallocation functions">,
3376+
NegFlag<SetFalse>>;
33773377
defm aligned_allocation : BoolFOption<"aligned-allocation",
33783378
LangOpts<"AlignedAllocation">, Default<cpp17.KeyPath>,
33793379
PosFlag<SetTrue, [], [ClangOption], "Enable C++17 aligned allocation functions">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7262,15 +7262,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
72627262
Args.addOptInFlag(CmdArgs, options::OPT_frelaxed_template_template_args,
72637263
options::OPT_fno_relaxed_template_template_args);
72647264

7265-
// -fsized-deallocation is on by default in C++14 onwards and otherwise off
7266-
// by default.
7267-
if (Arg *A = Args.getLastArg(options::OPT_fsized_deallocation,
7268-
options::OPT_fno_sized_deallocation)) {
7269-
if (A->getOption().matches(options::OPT_fno_sized_deallocation))
7270-
CmdArgs.push_back("-fno-sized-deallocation");
7271-
else
7272-
CmdArgs.push_back("-fsized-deallocation");
7273-
}
7265+
// -fsized-deallocation is off by default, as it is an ABI-breaking change for
7266+
// most platforms.
7267+
Args.addOptInFlag(CmdArgs, options::OPT_fsized_deallocation,
7268+
options::OPT_fno_sized_deallocation);
72747269

72757270
// -faligned-allocation is on by default in C++17 onwards and otherwise off
72767271
// by default.

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,68 +2912,16 @@ static bool sdkSupportsBuiltinModules(const Darwin::DarwinPlatformKind &TargetPl
29122912
}
29132913
}
29142914

2915-
static inline llvm::VersionTuple
2916-
sizedDeallocMinVersion(llvm::Triple::OSType OS) {
2917-
switch (OS) {
2918-
default:
2919-
break;
2920-
case llvm::Triple::Darwin:
2921-
case llvm::Triple::MacOSX: // Earliest supporting version is 10.12.
2922-
return llvm::VersionTuple(10U, 12U);
2923-
case llvm::Triple::IOS:
2924-
case llvm::Triple::TvOS: // Earliest supporting version is 10.0.0.
2925-
return llvm::VersionTuple(10U);
2926-
case llvm::Triple::WatchOS: // Earliest supporting version is 3.0.0.
2927-
return llvm::VersionTuple(3U);
2928-
}
2929-
2930-
llvm_unreachable("Unexpected OS");
2931-
}
2932-
2933-
bool Darwin::isSizedDeallocationUnavailable() const {
2934-
llvm::Triple::OSType OS;
2935-
2936-
if (isTargetMacCatalyst())
2937-
return TargetVersion < sizedDeallocMinVersion(llvm::Triple::MacOSX);
2938-
switch (TargetPlatform) {
2939-
case MacOS: // Earlier than 10.12.
2940-
OS = llvm::Triple::MacOSX;
2941-
break;
2942-
case IPhoneOS:
2943-
OS = llvm::Triple::IOS;
2944-
break;
2945-
case TvOS: // Earlier than 10.0.
2946-
OS = llvm::Triple::TvOS;
2947-
break;
2948-
case WatchOS: // Earlier than 3.0.
2949-
OS = llvm::Triple::WatchOS;
2950-
break;
2951-
case DriverKit:
2952-
case XROS:
2953-
// Always available.
2954-
return false;
2955-
}
2956-
2957-
return TargetVersion < sizedDeallocMinVersion(OS);
2958-
}
2959-
2960-
void Darwin::addClangTargetOptions(
2961-
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
2962-
Action::OffloadKind DeviceOffloadKind) const {
2915+
void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
2916+
llvm::opt::ArgStringList &CC1Args,
2917+
Action::OffloadKind DeviceOffloadKind) const {
29632918
// Pass "-faligned-alloc-unavailable" only when the user hasn't manually
29642919
// enabled or disabled aligned allocations.
29652920
if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
29662921
options::OPT_fno_aligned_allocation) &&
29672922
isAlignedAllocationUnavailable())
29682923
CC1Args.push_back("-faligned-alloc-unavailable");
29692924

2970-
// Pass "-fno-sized-deallocation" only when the user hasn't manually enabled
2971-
// or disabled sized deallocations.
2972-
if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
2973-
options::OPT_fno_sized_deallocation) &&
2974-
isSizedDeallocationUnavailable())
2975-
CC1Args.push_back("-fno-sized-deallocation");
2976-
29772925
addClangCC1ASTargetOptions(DriverArgs, CC1Args);
29782926

29792927
// Enable compatibility mode for NSItemProviderCompletionHandler in

clang/lib/Driver/ToolChains/Darwin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,6 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
511511
/// targeting.
512512
bool isAlignedAllocationUnavailable() const;
513513

514-
/// Return true if c++14 sized deallocation functions are not implemented in
515-
/// the c++ standard library of the deployment target we are targeting.
516-
bool isSizedDeallocationUnavailable() const;
517-
518514
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
519515
llvm::opt::ArgStringList &CC1Args,
520516
Action::OffloadKind DeviceOffloadKind) const override;

clang/lib/Driver/ToolChains/ZOS.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@ void ZOS::addClangTargetOptions(const ArgList &DriverArgs,
3636
if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
3737
options::OPT_fno_aligned_allocation))
3838
CC1Args.push_back("-faligned-alloc-unavailable");
39-
40-
// Pass "-fno-sized-deallocation" only when the user hasn't manually enabled
41-
// or disabled sized deallocations.
42-
if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
43-
options::OPT_fno_sized_deallocation))
44-
CC1Args.push_back("-fno-sized-deallocation");
4539
}
4640

4741
void zos::Assembler::ConstructJob(Compilation &C, const JobAction &JA,

clang/test/AST/ast-dump-expr-json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ void TestNonADLCall3() {
23332333
// CHECK-NEXT: "kind": "FunctionDecl",
23342334
// CHECK-NEXT: "name": "operator delete",
23352335
// CHECK-NEXT: "type": {
2336-
// CHECK-NEXT: "qualType": "void (void *, unsigned long) noexcept"
2336+
// CHECK-NEXT: "qualType": "void (void *) noexcept"
23372337
// CHECK-NEXT: }
23382338
// CHECK-NEXT: },
23392339
// CHECK-NEXT: "inner": [

clang/test/AST/ast-dump-expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void UnaryExpressions(int *p) {
164164
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:8> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
165165

166166
::delete p;
167-
// CHECK: CXXDeleteExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:12> 'void' global Function 0x{{[^ ]*}} 'operator delete' 'void (void *, unsigned long) noexcept'
167+
// CHECK: CXXDeleteExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:12> 'void' global Function 0x{{[^ ]*}} 'operator delete' 'void (void *) noexcept'
168168
// CHECK-NEXT: ImplicitCastExpr
169169
// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:12> 'int *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'int *'
170170

0 commit comments

Comments
 (0)