pcwang-thead created this revision. Herald added subscribers: lxfind, dang. pcwang-thead requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Since C++14 has been released for about seven years and most standard libraries have implemented sized deallocation functions, it's time to make this feature default again. For tests assumed that sized deallocation is disabled, just force them to disable this feature by adding -fno-sized-deallocation. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D112921 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp clang/test/AST/ast-dump-expr.cpp clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp clang/test/CodeGenCXX/delete-two-arg.cpp clang/test/CodeGenCXX/delete.cpp clang/test/CodeGenCXX/new.cpp clang/test/CodeGenCoroutines/coro-alloc.cpp clang/test/CodeGenCoroutines/coro-cleanup.cpp clang/test/CodeGenCoroutines/coro-gro.cpp clang/test/SemaCXX/builtin-operator-new-delete.cpp clang/test/SemaCXX/unavailable_aligned_allocation.cpp clang/unittests/StaticAnalyzer/CallEventTest.cpp clang/www/cxx_status.html
Index: clang/www/cxx_status.html =================================================================== --- clang/www/cxx_status.html +++ clang/www/cxx_status.html @@ -578,12 +578,11 @@ </table> <p> -<span id="n3778">(7): In Clang 3.7 and later, sized deallocation is only enabled -if the user passes the <code>-fsized-deallocation</code> flag. The user must -supply definitions of the sized deallocation functions, either by providing them -explicitly or by using a C++ standard library that does. <code>libstdc++</code> -added these functions in version 5.0, and <code>libc++</code> added them in -version 3.7. +<span id="n3778">(7): The user must supply definitions of the sized deallocation +functions, either by providing them explicitly or by using a C++ standard library +that does. <code>libstdc++</code> added these functions in version 5.0, and +<code>libc++</code> added them in version 3.7. The user can also use the +<code>-fno-sized-deallocation</code> option to disable sized deallocation. </span> </p> </details> Index: clang/unittests/StaticAnalyzer/CallEventTest.cpp =================================================================== --- clang/unittests/StaticAnalyzer/CallEventTest.cpp +++ clang/unittests/StaticAnalyzer/CallEventTest.cpp @@ -81,7 +81,7 @@ } )", Diags)); - EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n"); + EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n"); } } // namespace Index: clang/test/SemaCXX/unavailable_aligned_allocation.cpp =================================================================== --- clang/test/SemaCXX/unavailable_aligned_allocation.cpp +++ clang/test/SemaCXX/unavailable_aligned_allocation.cpp @@ -1,15 +1,15 @@ -// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DMACOS %s -// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s -// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DMACOS %s -// RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DIOS %s -// RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s -// RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DTVOS %s -// RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s -// RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DWATCHOS %s -// RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s -// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DZOS %s -// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -std=c++1z -verify -DNO_ERRORS %s -// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DZOS %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fno-sized-deallocation -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DMACOS %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fno-sized-deallocation -fexceptions -std=c++1z -verify -DNO_ERRORS %s +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fno-sized-deallocation -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DMACOS %s +// RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fno-sized-deallocation -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DIOS %s +// RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fno-sized-deallocation -fexceptions -std=c++1z -verify -DNO_ERRORS %s +// RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fno-sized-deallocation -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DTVOS %s +// RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fno-sized-deallocation -fexceptions -std=c++1z -verify -DNO_ERRORS %s +// RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fno-sized-deallocation -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DWATCHOS %s +// RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fno-sized-deallocation -fexceptions -std=c++1z -verify -DNO_ERRORS %s +// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -fno-sized-deallocation -faligned-alloc-unavailable -std=c++1z -verify -DZOS %s +// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -fno-sized-deallocation -std=c++1z -verify -DNO_ERRORS %s +// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -fno-sized-deallocation -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DZOS %s namespace std { typedef decltype(sizeof(0)) size_t; Index: clang/test/SemaCXX/builtin-operator-new-delete.cpp =================================================================== --- clang/test/SemaCXX/builtin-operator-new-delete.cpp +++ clang/test/SemaCXX/builtin-operator-new-delete.cpp @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s -// RUN: %clang_cc1 -std=c++03 -fsyntax-only -verify %s -// RUN: %clang_cc1 -std=c++03 -faligned-allocation -fsyntax-only -verify %s -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fsized-deallocation %s +// RUN: %clang_cc1 -std=c++1z -fno-sized-deallocation -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++03 -fno-sized-deallocation -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++03 -fno-sized-deallocation -faligned-allocation -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++11 -fno-sized-deallocation -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++11 -fno-sized-deallocation -fsyntax-only -verify -fsized-deallocation %s #if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete) #error builtins should always be available Index: clang/test/CodeGenCoroutines/coro-gro.cpp =================================================================== --- clang/test/CodeGenCoroutines/coro-gro.cpp +++ clang/test/CodeGenCoroutines/coro-gro.cpp @@ -1,6 +1,6 @@ // Verifies lifetime of __gro local variable // Verify that coroutine promise and allocated memory are freed up on exception. -// RUN: %clang_cc1 -std=c++1z -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -disable-llvm-passes | FileCheck %s +// RUN: %clang_cc1 -std=c++1z -fno-sized-deallocation -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -disable-llvm-passes | FileCheck %s namespace std::experimental { template <typename... T> struct coroutine_traits; Index: clang/test/CodeGenCoroutines/coro-cleanup.cpp =================================================================== --- clang/test/CodeGenCoroutines/coro-cleanup.cpp +++ clang/test/CodeGenCoroutines/coro-cleanup.cpp @@ -1,5 +1,5 @@ // Verify that coroutine promise and allocated memory are freed up on exception. -// RUN: %clang_cc1 -std=c++1z -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s +// RUN: %clang_cc1 -std=c++1z -fno-sized-deallocation -fcoroutines-ts -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -fexceptions -fcxx-exceptions -disable-llvm-passes | FileCheck %s namespace std::experimental { template <typename... T> struct coroutine_traits; Index: clang/test/CodeGenCoroutines/coro-alloc.cpp =================================================================== --- clang/test/CodeGenCoroutines/coro-alloc.cpp +++ clang/test/CodeGenCoroutines/coro-alloc.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 \ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -fno-sized-deallocation \ // RUN: -Wno-coroutine-missing-unhandled-exception -emit-llvm %s -o - -disable-llvm-passes \ // RUN: | FileCheck %s Index: clang/test/CodeGenCXX/new.cpp =================================================================== --- clang/test/CodeGenCXX/new.cpp +++ clang/test/CodeGenCXX/new.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -std=c++14 -fno-sized-deallocation -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s typedef __typeof__(sizeof(0)) size_t; Index: clang/test/CodeGenCXX/delete.cpp =================================================================== --- clang/test/CodeGenCXX/delete.cpp +++ clang/test/CodeGenCXX/delete.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOSIZE -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 %s -emit-llvm -o - -Oz -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-SIZE +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fno-sized-deallocation %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOSIZE +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fno-sized-deallocation %s -emit-llvm -o - -Oz -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-SIZE void t1(int *a) { delete a; Index: clang/test/CodeGenCXX/delete-two-arg.cpp =================================================================== --- clang/test/CodeGenCXX/delete-two-arg.cpp +++ clang/test/CodeGenCXX/delete-two-arg.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i686-pc-linux-gnu %s -o - -emit-llvm -verify | FileCheck %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fno-sized-deallocation %s -o - -emit-llvm -verify | FileCheck %s // expected-no-diagnostics typedef __typeof(sizeof(int)) size_t; Index: clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp =================================================================== --- clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp +++ clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp @@ -1,11 +1,11 @@ -// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm %s -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefixes=CHECK,CHECK-ITANIUM,CHECK-64BIT -// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm %s -triple x86_64-windows -o - | FileCheck %s --check-prefixes=CHECK,CHECK-MSABI,CHECK-MSABI64,CHECK-64BIT -// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm %s -triple i386-windows -o - | FileCheck %s --check-prefixes=CHECK,CHECK-MSABI,CHECK-MSABI32,CHECK-32BIT +// RUN: %clang_cc1 -std=c++2a -fno-sized-deallocation -fexceptions -emit-llvm %s -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefixes=CHECK,CHECK-ITANIUM,CHECK-64BIT +// RUN: %clang_cc1 -std=c++2a -fno-sized-deallocation -fexceptions -emit-llvm %s -triple x86_64-windows -o - | FileCheck %s --check-prefixes=CHECK,CHECK-MSABI,CHECK-MSABI64,CHECK-64BIT +// RUN: %clang_cc1 -std=c++2a -fno-sized-deallocation -fexceptions -emit-llvm %s -triple i386-windows -o - | FileCheck %s --check-prefixes=CHECK,CHECK-MSABI,CHECK-MSABI32,CHECK-32BIT // PR46908: ensure the IR passes the verifier with optimizations enabled. -// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm-only %s -triple x86_64-linux-gnu -O2 -// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm-only %s -triple x86_64-windows -O2 -// RUN: %clang_cc1 -std=c++2a -fexceptions -emit-llvm-only %s -triple i386-windows -O2 +// RUN: %clang_cc1 -std=c++2a -fno-sized-deallocation -fexceptions -emit-llvm-only %s -triple x86_64-linux-gnu -O2 +// RUN: %clang_cc1 -std=c++2a -fno-sized-deallocation -fexceptions -emit-llvm-only %s -triple x86_64-windows -O2 +// RUN: %clang_cc1 -std=c++2a -fno-sized-deallocation -fexceptions -emit-llvm-only %s -triple i386-windows -O2 namespace std { using size_t = decltype(sizeof(0)); Index: clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp =================================================================== --- clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp +++ clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp @@ -5,8 +5,8 @@ // Check that we don't used sized deallocation without -fsized-deallocation and // C++14. -// RUN: %clang_cc1 -std=c++11 %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-UNSIZED -// RUN: %clang_cc1 -std=c++14 %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-UNSIZED +// RUN: %clang_cc1 -std=c++11 -fno-sized-deallocation %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-UNSIZED +// RUN: %clang_cc1 -std=c++14 -fno-sized-deallocation %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-UNSIZED // CHECK-UNSIZED-NOT: _ZdlPvm // CHECK-UNSIZED-NOT: _ZdaPvm Index: clang/test/AST/ast-dump-expr.cpp =================================================================== --- clang/test/AST/ast-dump-expr.cpp +++ clang/test/AST/ast-dump-expr.cpp @@ -1,10 +1,10 @@ // Test without serialization: -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -fcxx-exceptions -std=gnu++17 -ast-dump %s \ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fno-sized-deallocation -Wno-unused-value -fcxx-exceptions -std=gnu++17 -ast-dump %s \ // RUN: | FileCheck --strict-whitespace %s // // Test with serialization: -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -fcxx-exceptions -std=gnu++17 -emit-pch -o %t %s -// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value -fcxx-exceptions -std=gnu++17 \ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fno-sized-deallocation -Wno-unused-value -fcxx-exceptions -std=gnu++17 -emit-pch -o %t %s +// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -fno-sized-deallocation -Wno-unused-value -fcxx-exceptions -std=gnu++17 \ // RUN: -include-pch %t -ast-dump-all /dev/null \ // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \ // RUN: | FileCheck --strict-whitespace %s Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6400,11 +6400,15 @@ CmdArgs.push_back("-fno-relaxed-template-template-args"); } - // -fsized-deallocation is off by default, as it is an ABI-breaking change for - // most platforms. - if (Args.hasFlag(options::OPT_fsized_deallocation, - options::OPT_fno_sized_deallocation, false)) - CmdArgs.push_back("-fsized-deallocation"); + // -fsized-deallocation is on by default in C++14 onwards and otherwise off + // by default. + if (Arg *A = Args.getLastArg(options::OPT_fsized_deallocation, + options::OPT_fno_sized_deallocation)) { + if (A->getOption().matches(options::OPT_fsized_deallocation)) + CmdArgs.push_back("-fsized-deallocation"); + else + CmdArgs.push_back("-fno-sized-deallocation"); + } // -faligned-allocation is on by default in C++17 onwards and otherwise off // by default. Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -476,6 +476,7 @@ // Key paths that are constant during parsing of options with the same key path prefix. defvar cplusplus = LangOpts<"CPlusPlus">; defvar cpp11 = LangOpts<"CPlusPlus11">; +defvar cpp14 = LangOpts<"CPlusPlus14">; defvar cpp17 = LangOpts<"CPlusPlus17">; defvar cpp20 = LangOpts<"CPlusPlus20">; defvar c99 = LangOpts<"C99">; @@ -2339,9 +2340,9 @@ PosFlag<SetTrue>, NegFlag<SetFalse, [CC1Option], "Disable C++17 relaxed template template argument matching">>; defm sized_deallocation : BoolFOption<"sized-deallocation", - LangOpts<"SizedDeallocation">, DefaultFalse, - PosFlag<SetTrue, [CC1Option], "Enable C++14 sized global deallocation functions">, - NegFlag<SetFalse>>; + LangOpts<"SizedDeallocation">, Default<cpp14.KeyPath>, + PosFlag<SetTrue, [], "Enable C++14 sized global deallocation functions">, + NegFlag<SetFalse>, BothFlags<[CC1Option]>>; defm aligned_allocation : BoolFOption<"aligned-allocation", LangOpts<"AlignedAllocation">, Default<cpp17.KeyPath>, PosFlag<SetTrue, [], "Enable C++17 aligned allocation functions">,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits