From bcdd41a1b919ea30131e03ecc9647b0cda9efb13 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Sun, 21 Jun 2015 16:33:50 +0000 Subject: [PATCH] [Codegen] Don't crash if destructor is not accessible. Testcase provided, in the PR, by Christian Shelton and reduced by David Majnemer. PR: 23584 Differential Revision: http://reviews.llvm.org/D10508 Reviewed by: rnk git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240242 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGClass.cpp | 4 ++++ test/CodeGenCXX/destructor-crash.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/CodeGenCXX/destructor-crash.cpp diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index 1d2b7875d8..4d6a4e288d 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -1297,6 +1297,10 @@ HasTrivialDestructorBody(ASTContext &Context, if (BaseClassDecl->hasTrivialDestructor()) return true; + // Give up if the destructor is not accessible. + if (!BaseClassDecl->getDestructor()) + return false; + if (!BaseClassDecl->getDestructor()->hasTrivialBody()) return false; diff --git a/test/CodeGenCXX/destructor-crash.cpp b/test/CodeGenCXX/destructor-crash.cpp new file mode 100644 index 0000000000..4329198651 --- /dev/null +++ b/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 {} -- 2.50.1