<div dir="ltr">Well, the whole approach here is still wrong (per the FIXME in CFGBuilder::addLocalScopeForVarDecl) but this at least makes it consistent. Let's take this for 3.9 to at least stem the bleeding.<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 9, 2016 at 11:57 AM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">For the record, this was for PR28666.<br>
<br>
Richard: what do you think about merging this to 3.9?<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Aug 2, 2016 at 2:07 PM, Devin Coughlin via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: dcoughlin<br>
> Date: Tue Aug 2 16:07:23 2016<br>
> New Revision: 277522<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=277522&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=277522&view=rev</a><br>
> Log:<br>
> [CFG] Fix crash finding destructor of lifetime-extended temporary.<br>
><br>
> Fix a crash under -Wthread-safety when finding the destructor for a<br>
> lifetime-extending reference.<br>
><br>
> A patch by Nandor Licker!<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D22419" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D22419</a><br>
><br>
> Modified:<br>
> cfe/trunk/lib/Analysis/CFG.cpp<br>
> cfe/trunk/test/SemaCXX/warn-<wbr>thread-safety-analysis.cpp<br>
><br>
> Modified: cfe/trunk/lib/Analysis/CFG.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=277522&r1=277521&r2=277522&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/<wbr>Analysis/CFG.cpp?rev=277522&<wbr>r1=277521&r2=277522&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Analysis/CFG.cpp (original)<br>
> +++ cfe/trunk/lib/Analysis/CFG.cpp Tue Aug 2 16:07:23 2016<br>
> @@ -3902,7 +3902,17 @@ CFGImplicitDtor::<wbr>getDestructorDecl(ASTCo<br>
> case CFGElement::<wbr>AutomaticObjectDtor: {<br>
> const VarDecl *var = castAs<CFGAutomaticObjDtor>().<wbr>getVarDecl();<br>
> QualType ty = var->getType();<br>
> - ty = ty.getNonReferenceType();<br>
> +<br>
> + // FIXME: See CFGBuilder::<wbr>addLocalScopeForVarDecl.<br>
> + //<br>
> + // Lifetime-extending constructs are handled here. This works for a single<br>
> + // temporary in an initializer expression.<br>
> + if (ty->isReferenceType()) {<br>
> + if (const Expr *Init = var->getInit()) {<br>
> + ty = getReferenceInitTemporaryType(<wbr>astContext, Init);<br>
> + }<br>
> + }<br>
> +<br>
> while (const ArrayType *arrayType = astContext.getAsArrayType(ty)) {<br>
> ty = arrayType->getElementType();<br>
> }<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/warn-<wbr>thread-safety-analysis.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=277522&r1=277521&r2=277522&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/warn-thread-safety-<wbr>analysis.cpp?rev=277522&r1=<wbr>277521&r2=277522&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/SemaCXX/warn-<wbr>thread-safety-analysis.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/warn-<wbr>thread-safety-analysis.cpp Tue Aug 2 16:07:23 2016<br>
> @@ -5160,6 +5160,21 @@ void test3() {<br>
> } // end namespace GlobalAcquiredBeforeAfterTest<br>
><br>
><br>
> +namespace LifetimeExtensionText {<br>
> +<br>
> +struct Holder {<br>
> + virtual ~Holder() throw() {}<br>
> + int i = 0;<br>
> +};<br>
> +<br>
> +void test() {<br>
> + // Should not crash.<br>
> + const auto &value = Holder().i;<br>
> +}<br>
> +<br>
> +} // end namespace LifetimeExtensionTest<br>
> +<br>
> +<br>
> namespace LockableUnions {<br>
><br>
> union LOCKABLE MutexUnion {<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>