[PATCH] [Clang/CodeGen] Prevent crash if destructor class is not accessible

Reid Kleckner rnk at google.com
Sat Jun 20 20:15:43 PDT 2015


Lgtm

Sent from phone
On Jun 19, 2015 5:14 PM, "Davide Italiano" <dccitaliano at gmail.com> wrote:

> Reordered checks as suggested.
> Anders Carlsson LGTM'd the change. Reid, do you think we can go forward
> and check this in?
>
>
> http://reviews.llvm.org/D10508
>
> Files:
>   lib/CodeGen/CGClass.cpp
>   test/CodeGenCXX/destructor-crash.cpp
>
> Index: lib/CodeGen/CGClass.cpp
> ===================================================================
> --- lib/CodeGen/CGClass.cpp
> +++ lib/CodeGen/CGClass.cpp
> @@ -1297,6 +1297,10 @@
>    if (BaseClassDecl->hasTrivialDestructor())
>      return true;
>
> +  // Give up if the destructor is not accessible.
> +  if (!BaseClassDecl->getDestructor())
> +    return false;
> +
>    if (!BaseClassDecl->getDestructor()->hasTrivialBody())
>      return false;
>
> Index: test/CodeGenCXX/destructor-crash.cpp
> ===================================================================
> --- test/CodeGenCXX/destructor-crash.cpp
> +++ test/CodeGenCXX/destructor-crash.cpp
> @@ -0,0 +1,19 @@
> +// RUN: %clang_cc1 %s -emit-llvm -std=c++11 -o %t
> +
> +struct A {
> +  ~A();
> +};
> +
> +struct B {
> +  A a;
> +};
> +
> +struct C {
> +  union {
> +    B b;
> +  };
> +
> +  ~C() noexcept;
> +};
> +
> +C::~C() noexcept {}
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150620/157dc6b6/attachment.html>


More information about the cfe-commits mailing list