[PATCH] D26074: [ELF] Add getOffset to ELFSectionRef and enable LLVM casting for it

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 13:09:43 PDT 2016


On Fri, Oct 28, 2016 at 12:13 PM, Eugene Leviant <evgeny.leviant at gmail.com>
wrote:

> > If you add classof to one derived class, you want to define classof for
> all derived classes, otherwise it won't work.
>
> AFAIK, this just means that you can't use LLVM casting for other
> classes in the hierarchy. But let's use static_cast for now.


That's true for this case, but that's a violation of the contract of
classof. If class A is a derived class of B, isa<A>(X) == true implies that
isa<B>(X) == true.

2016-10-28 21:52 GMT+03:00 Rui Ueyama <ruiu at google.com>:
> > On Fri, Oct 28, 2016 at 11:44 AM, Eugene Leviant <
> evgeny.leviant at gmail.com>
> > wrote:
> >>
> >> evgeny777 added a comment.
> >>
> >> I have Sectio
> >>
> >>
> >>
> >> ================
> >> Comment at: include/llvm/Object/ELFObjectFile.h:99-101
> >> +  static inline bool classof(const SectionRef *v) {
> >> +    return v->getObject()->isELF();
> >> +  }
> >> ----------------
> >> ruiu wrote:
> >> > Why do you want this?
> >> I have SectionRef object and I want to get section offset, which is ELF
> >> section property.
> >> With this I can write:
> >>
> >> ```
> >> cast<ELFSectionRef>(S)->getOffset();
> >> ```
> >> Without it I have to use this one:
> >> ```
> >>
> >> cast<ELFObjectFileBase>(S->getObject())->getSectionOffset(S->
> getRawDataRefImpl());
> >> ```
> >
> >
> > If you add classof to one derived class, you want to define classof for
> all
> > derived classes, otherwise it won't work. If you already know the type
> of an
> > object, you can just do static_cast<>, can't you?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161028/eb1e486d/attachment.html>


More information about the llvm-commits mailing list