[PATCH] D108481: Avoid nullptr dereferencing of 'Constraint'

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 26 09:53:13 PDT 2021


aaron.ballman added inline comments.


================
Comment at: clang/lib/Sema/SemaConcept.cpp:1065-1068
   assert(TC &&
          "TPL must have a template type parameter with a type constraint");
   auto *Constraint =
+      cast<ConceptSpecializationExpr>(TC->getImmediatelyDeclaredConstraint());
----------------
erichkeane wrote:
> aaron.ballman wrote:
> > mlychkov wrote:
> > > aaron.ballman wrote:
> > > > If we're going to be touching this code, there's more suspect code here that needs to be cleaned up a bit. Directly above this is:
> > > > ```
> > > >   const TypeConstraint *TC =
> > > >       cast<TemplateTypeParmDecl>(TPL->getParam(0))->getTypeConstraint();
> > > >   assert(TC &&
> > > >          "TPL must have a template type parameter with a type constraint");
> > > > ```
> > > > That assertion can be removed entirely -- if the `cast<>` fails, it doesn't return null, it asserts.
> > > Actually, cast return nonnull value, but
> > >    TC = "cast_result"->getTypeConstraint();
> > > and TC may become nullptr, I suppose.
> > Good catch! I think we should add the assertion on `TC` being nonnull back. I'll take care of that.
> Ooh, good catch!  I definitely missed that when suggesting removing the assert.  @aaron.ballman  can you re-add the assert on 1065?
I've put the assert back in 0cf4f81082e9fa052e60450b8cbb10007e59931c, thanks for letting us know @mlychkov!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D108481/new/

https://reviews.llvm.org/D108481



More information about the cfe-commits mailing list