[PATCH] Use dereferencable attribute in Clang for C++ references

Richard Smith richard at metafoo.co.uk
Thu Jul 10 14:27:27 PDT 2014


On 10 Jul 2014 14:24, "Aaron Ballman" <aaron at aaronballman.com> wrote:
>
> On Thu, Jul 10, 2014 at 5:15 PM, hfinkel at anl.gov <hfinkel at anl.gov> wrote:
> > Updated for changes in the LLVM patch (in response to Nick's review).
> >
> > There also need to be a lot of regression-test updates (not yet
included here).
> >
> > http://reviews.llvm.org/D4450
> >
> > Files:
> >   lib/CodeGen/CGCall.cpp
> >
> > Index: lib/CodeGen/CGCall.cpp
> > ===================================================================
> > --- lib/CodeGen/CGCall.cpp
> > +++ lib/CodeGen/CGCall.cpp
> > @@ -1200,8 +1200,16 @@
> >      llvm_unreachable("Invalid ABI kind for return argument");
> >    }
> >
> > -  if (RetTy->isReferenceType())
> > +  if (RetTy->isReferenceType()) {
> > +    QualType PTy = RetTy->getAs<ReferenceType>()->getPointeeType();
> > +    if (PTy->isConstantSizeType()) {
> > +      unsigned Bytes =
> > +        std::min(4095u, (unsigned) getContext().getTypeSize(PTy)/8);
>
> What about getTypeSizeInChars instead of getTypeSize / 8?
>
> Where does the 4095 constant come from? Since it's used in two places,
> I would feel slightly more comfortable if it was named (or at least
> commented).

I believe this is the maximum value the attribute happens to support.
Please provide this as a constant in an LLVM header rather than hardcoding
it here.

> > +      RetAttrs.addDereferencableAttr(Bytes);
> > +    }
> > +
> >      RetAttrs.addAttribute(llvm::Attribute::NonNull);
> > +  }
> >
> >    if (RetAttrs.hasAttributes())
> >      PAL.push_back(llvm::
> > @@ -1291,8 +1299,16 @@
> >      }
> >      }
> >
> > -    if (ParamType->isReferenceType())
> > +    if (ParamType->isReferenceType()) {
> > +      QualType PTy =
ParamType->getAs<ReferenceType>()->getPointeeType();
> > +      if (PTy->isConstantSizeType()) {
> > +        unsigned Bytes =
> > +          std::min(4095u, (unsigned) getContext().getTypeSize(PTy)/8);
> > +        Attrs.addDereferencableAttr(Bytes);
> > +      }
> > +
> >        Attrs.addAttribute(llvm::Attribute::NonNull);
> > +    }
> >
> >      if (Attrs.hasAttributes())
> >        PAL.push_back(llvm::AttributeSet::get(getLLVMContext(), Index,
Attrs));
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
>
> ~Aaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140710/240c2b5f/attachment.html>


More information about the cfe-commits mailing list