From: Ted Kremenek Date: Wed, 18 Jul 2012 04:57:57 +0000 (+0000) Subject: Teach CFG construction about destructors resulting from references to array types... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88237bf587581026dcfc8386abf055cb201aa487;p=clang Teach CFG construction about destructors resulting from references to array types. Fixes crash in . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160424 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index e3cd74b1e4..e141ed9a44 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -776,13 +776,12 @@ void CFGBuilder::addAutomaticObjDtors(LocalScope::const_iterator B, // If this destructor is marked as a no-return destructor, we need to // create a new block for the destructor which does not have as a successor // anything built thus far: control won't flow out of this block. - QualType Ty; - if ((*I)->getType()->isReferenceType()) { + QualType Ty = (*I)->getType(); + if (Ty->isReferenceType()) { Ty = getReferenceInitTemporaryType(*Context, (*I)->getInit()); - } else { - Ty = Context->getBaseElementType((*I)->getType()); } - + Ty = Context->getBaseElementType(Ty); + const CXXDestructorDecl *Dtor = Ty->getAsCXXRecordDecl()->getDestructor(); if (cast(Dtor->getType())->getNoReturnAttr()) Block = createNoReturnBlock(); diff --git a/test/Analysis/cxx-for-range-cfg.cpp b/test/Analysis/cxx-for-range-cfg.cpp new file mode 100644 index 0000000000..e258c7a1e2 --- /dev/null +++ b/test/Analysis/cxx-for-range-cfg.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -Wall -fsyntax-only %s -std=c++11 -verify + +// The rdar11671507_vector[]> would previously crash CFG construction +// because of the temporary array of vectors. +template +class rdar11671507_vector { +public: + rdar11671507_vector(); + ~rdar11671507_vector(); + T *Base; + T *End; +}; + +void rdar11671507(rdar11671507_vector v, rdar11671507_vector w) { + for (auto &vec : (rdar11671507_vector[]){ v, w }) {} // expected-warning {{unused}} +}