r230160 - Relax the requirement on sized deallocation a bit: Default on unsized delete if sized delete is not provided in global scope, and -fdefine-sized-deallocation option is disabled.

Richard Smith richard at metafoo.co.uk
Mon Feb 23 13:24:22 PST 2015


On Sat, Feb 21, 2015 at 10:36 PM, Larisse Voufo <lvoufo at google.com> wrote:

> Author: lvoufo
> Date: Sun Feb 22 00:36:53 2015
> New Revision: 230160
>
> URL: http://llvm.org/viewvc/llvm-project?rev=230160&view=rev
> Log:
> Relax the requirement on sized deallocation a bit: Default on unsized
> delete if sized delete is not provided in global scope, and
> -fdefine-sized-deallocation option is disabled.
>

This makes our default C++14 mode non-conforming, and is a breaking change
compared to previous Clang versions. We could provide this mechanism under
an option, but this is not appropriate as our default C++14 behavior.
Please put this behind a -cc1 option or revert.

It also makes DefineSizedDeallocation pretty much useless: we now only
implicitly define sized deallocation if the library declares it, in which
case it's reasonable to assume the library provides a definition and we
have no need to define our own.

Modified:
>     cfe/trunk/lib/Sema/SemaExprCXX.cpp
>     cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
>     cfe/trunk/test/CodeGenCXX/implicit-allocation-functions.cpp
>     cfe/trunk/test/SemaCXX/cxx1y-sized-deallocation.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=230160&r1=230159&r2=230160&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sun Feb 22 00:36:53 2015
> @@ -2089,6 +2089,15 @@ void Sema::DeclareGlobalAllocationFuncti
>        }
>      }
>    }
> +
> +  // If the function is sized operator delete and has not already been
> +  // declared, and weak definitions have been disabled, do not declare
> +  // it implicitly. Instead, let deallocation function lookup pick up
> +  // unsized delete.
> +  // FIXME: We should remove this guard once backward compatibility is
> +  // no longer an issue
> +  if (NumParams == 2 && !getLangOpts().DefineSizedDeallocation)
> +    return;
>
>    FunctionProtoType::ExtProtoInfo EPI;
>
>
> Modified: cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp?rev=230160&r1=230159&r2=230160&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/cxx1y-sized-deallocation.cpp Sun Feb 22
> 00:36:53 2015
> @@ -1,6 +1,8 @@
> -// RUN: %clang_cc1 -std=c++1y %s -emit-llvm -triple x86_64-linux-gnu -o -
> | FileCheck %s --check-prefix=CHECK --check-prefix=CHECKUND
> +// RUN: %clang_cc1 -std=c++1y %s -emit-llvm -triple x86_64-linux-gnu -o -
> | FileCheck %s --check-prefix=CHECK-UNSIZED
> +// RUN: %clang_cc1 -std=c++1y %s -emit-llvm -triple x86_64-linux-gnu -o -
> -DINLIB | FileCheck %s --check-prefix=CHECK --check-prefix=CHECKUND
>  // RUN: %clang_cc1 -std=c++1y %s -emit-llvm -triple x86_64-linux-gnu
> -fdefine-sized-deallocation -o - | FileCheck %s --check-prefix=CHECK
> --check-prefix=CHECKDEF
> -// RUN: %clang_cc1 -std=c++11 -fsized-deallocation %s -emit-llvm -triple
> x86_64-linux-gnu -o - | FileCheck %s --check-prefix=CHECK
> --check-prefix=CHECKUND
> +// RUN: %clang_cc1 -std=c++11 -fsized-deallocation %s -emit-llvm -triple
> x86_64-linux-gnu -o - | FileCheck %s --check-prefix=CHECK-UNSIZED
> +// RUN: %clang_cc1 -std=c++11 -fsized-deallocation %s -emit-llvm -triple
> x86_64-linux-gnu -o - -DINLIB | FileCheck %s --check-prefix=CHECK
> --check-prefix=CHECKUND
>  // RUN: %clang_cc1 -std=c++11 -fsized-deallocation
> -fdefine-sized-deallocation %s -emit-llvm -triple x86_64-linux-gnu -o - |
> FileCheck %s --check-prefix=CHECK --check-prefix=CHECKDEF
>  // 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++1y %s -emit-llvm -triple x86_64-linux-gnu
> -fno-sized-deallocation -o - | FileCheck %s --check-prefix=CHECK-UNSIZED
> @@ -10,6 +12,11 @@
>
>  typedef decltype(sizeof(0)) size_t;
>
> +#ifdef INLIB
> +void operator delete(void *, size_t) noexcept;
> +void operator delete[](void *, size_t) noexcept;
> +#endif
> +
>  typedef int A;
>  struct B { int n; };
>  struct C { ~C() {} };
>
> Modified: cfe/trunk/test/CodeGenCXX/implicit-allocation-functions.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/implicit-allocation-functions.cpp?rev=230160&r1=230159&r2=230160&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/implicit-allocation-functions.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/implicit-allocation-functions.cpp Sun Feb 22
> 00:36:53 2015
> @@ -1,15 +1,20 @@
>  // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++11 %s 2>&1 | FileCheck %s -check-prefix=CHECKDEF
> -check-prefix=CHECK11
>  // RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++11 -fvisibility hidden %s 2>&1 | FileCheck %s
> -check-prefix=CHECKHID -check-prefix=CHECK11
> -// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -fno-sized-deallocation %s 2>&1 | FileCheck %s
> -check-prefix=CHECKDEF -check-prefix=CHECK11
> -// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 %s 2>&1 | FileCheck %s -check-prefix=CHECKDEF
> -check-prefix=CHECK14 -check-prefix=CHECK14UND
> -// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -fvisibility hidden %s 2>&1 | FileCheck %s
> -check-prefix=CHECKHID -check-prefix=CHECK14 -check-prefix=CHECK14UND
> -// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -fdefine-sized-deallocation %s 2>&1 | FileCheck %s
> -check-prefix=CHECKDEF -check-prefix=CHECK14 -check-prefix=CHECK14DEFCOMDAT
> -// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -fdefine-sized-deallocation -fvisibility hidden %s 2>&1 |
> FileCheck %s -check-prefix=CHECKHID -check-prefix=CHECK14
> -check-prefix=CHECK14DEFCOMDAT
> -// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-macosx -o - -std=c++14
> -fdefine-sized-deallocation %s | FileCheck %s -check-prefix=CHECKDEF
> -check-prefix=CHECK14 -check-prefix=CHECK14DEFNOCOMDAT
> +// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -DINLIB -fno-sized-deallocation %s 2>&1 | FileCheck %s
> -check-prefix=CHECKDEF -check-prefix=CHECK11
> +// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -DINLIB %s 2>&1 | FileCheck %s -check-prefix=CHECKDEF
> -check-prefix=CHECK14 -check-prefix=CHECK14UND
> +// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -DINLIB -fvisibility hidden %s 2>&1 | FileCheck %s
> -check-prefix=CHECKHID -check-prefix=CHECK14 -check-prefix=CHECK14UND
> +// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -DINLIB -fdefine-sized-deallocation %s 2>&1 | FileCheck %s
> -check-prefix=CHECKDEF -check-prefix=CHECK14 -check-prefix=CHECK14DEFCOMDAT
> +// RUN: %clang_cc1 -emit-llvm -triple x86_64-unknown-unknown -o -
> -std=c++14 -DINLIB -fdefine-sized-deallocation -fvisibility hidden %s 2>&1
> | FileCheck %s -check-prefix=CHECKHID -check-prefix=CHECK14
> -check-prefix=CHECK14DEFCOMDAT
> +// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-macosx -o - -std=c++14
> -DINLIB -fdefine-sized-deallocation %s | FileCheck %s
> -check-prefix=CHECKDEF -check-prefix=CHECK14
> -check-prefix=CHECK14DEFNOCOMDAT
>
>  // PR22419: Implicit sized deallocation functions always have default
> visibility.
>  //   Generalized to all implicit allocation functions.
>
> +#ifdef INLIB
> +typedef decltype(sizeof(0)) size_t;
> +void operator delete(void *, size_t) noexcept;
> +void operator delete[](void *, size_t) noexcept;
> +#endif
>
>  // CHECK14-DAG: %struct.A = type { i8 }
>  struct A { };
>
> Modified: cfe/trunk/test/SemaCXX/cxx1y-sized-deallocation.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1y-sized-deallocation.cpp?rev=230160&r1=230159&r2=230160&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/cxx1y-sized-deallocation.cpp (original)
> +++ cfe/trunk/test/SemaCXX/cxx1y-sized-deallocation.cpp Sun Feb 22
> 00:36:53 2015
> @@ -1,6 +1,8 @@
>  // RUN: %clang_cc1 -std=c++1y -verify %s -fsized-deallocation
> -fexceptions -fcxx-exceptions
>
>  using size_t = decltype(sizeof(0));
> +void operator delete(void *, size_t) noexcept;   // expected-note
> {{'operator delete' declared here}}
> +void operator delete[](void *, size_t) noexcept;
>
>  void f(void *p, void *q) {
>    // OK, implicitly declared.
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150223/19639375/attachment.html>


More information about the cfe-commits mailing list