r277522 - [CFG] Fix crash finding destructor of lifetime-extended temporary.

Hans Wennborg via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 11:24:49 PDT 2016


Merged in r278376.

Thanks,
Hans

On Thu, Aug 11, 2016 at 11:13 AM, Richard Smith <richard at metafoo.co.uk> wrote:
> 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.
>
>
> On Tue, Aug 9, 2016 at 11:57 AM, Hans Wennborg <hans at chromium.org> wrote:
>>
>> For the record, this was for PR28666.
>>
>> Richard: what do you think about merging this to 3.9?
>>
>> On Tue, Aug 2, 2016 at 2:07 PM, Devin Coughlin via cfe-commits
>> <cfe-commits at lists.llvm.org> wrote:
>> > Author: dcoughlin
>> > Date: Tue Aug  2 16:07:23 2016
>> > New Revision: 277522
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=277522&view=rev
>> > Log:
>> > [CFG] Fix crash finding destructor of lifetime-extended temporary.
>> >
>> > Fix a crash under -Wthread-safety when finding the destructor for a
>> > lifetime-extending reference.
>> >
>> > A patch by Nandor Licker!
>> >
>> > Differential Revision: https://reviews.llvm.org/D22419
>> >
>> > Modified:
>> >     cfe/trunk/lib/Analysis/CFG.cpp
>> >     cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
>> >
>> > Modified: cfe/trunk/lib/Analysis/CFG.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=277522&r1=277521&r2=277522&view=diff
>> >
>> > ==============================================================================
>> > --- cfe/trunk/lib/Analysis/CFG.cpp (original)
>> > +++ cfe/trunk/lib/Analysis/CFG.cpp Tue Aug  2 16:07:23 2016
>> > @@ -3902,7 +3902,17 @@ CFGImplicitDtor::getDestructorDecl(ASTCo
>> >      case CFGElement::AutomaticObjectDtor: {
>> >        const VarDecl *var = castAs<CFGAutomaticObjDtor>().getVarDecl();
>> >        QualType ty = var->getType();
>> > -      ty = ty.getNonReferenceType();
>> > +
>> > +      // FIXME: See CFGBuilder::addLocalScopeForVarDecl.
>> > +      //
>> > +      // Lifetime-extending constructs are handled here. This works for
>> > a single
>> > +      // temporary in an initializer expression.
>> > +      if (ty->isReferenceType()) {
>> > +        if (const Expr *Init = var->getInit()) {
>> > +          ty = getReferenceInitTemporaryType(astContext, Init);
>> > +        }
>> > +      }
>> > +
>> >        while (const ArrayType *arrayType =
>> > astContext.getAsArrayType(ty)) {
>> >          ty = arrayType->getElementType();
>> >        }
>> >
>> > Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=277522&r1=277521&r2=277522&view=diff
>> >
>> > ==============================================================================
>> > --- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
>> > +++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Tue Aug  2
>> > 16:07:23 2016
>> > @@ -5160,6 +5160,21 @@ void test3() {
>> >  }  // end namespace  GlobalAcquiredBeforeAfterTest
>> >
>> >
>> > +namespace LifetimeExtensionText {
>> > +
>> > +struct Holder {
>> > +  virtual ~Holder() throw() {}
>> > +  int i = 0;
>> > +};
>> > +
>> > +void test() {
>> > +  // Should not crash.
>> > +  const auto &value = Holder().i;
>> > +}
>> > +
>> > +} // end namespace LifetimeExtensionTest
>> > +
>> > +
>> >  namespace LockableUnions {
>> >
>> >  union LOCKABLE MutexUnion {
>> >
>> >
>> > _______________________________________________
>> > cfe-commits mailing list
>> > cfe-commits at lists.llvm.org
>> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>


More information about the cfe-commits mailing list