Umesh Kalappa via llvm-dev
2016-Dec-21 13:01 UTC
[llvm-dev] DeclarationName and the StringRef.
To context was , Basic requirement was to append extra string to the decl name and update all his references to the updated name. , So we are constructing the DeclarationName instance as stated below code snap. and from DeclarationName instance ,we are constructing the DeclarationNameInfo and same info used to create decl spec with FunctionDecl::Create () . Question is , How do ,someone instantiate the DeclarationName instance using StringRef ,because in the current trunk code snap ,we see that the DeclarationName can be constructed using the IdentifierInfo or Objc Selector or CXXOperatorId etc as argument in the constructor . The code i.e void appendExtern(StringRef Sr) { char *ExternChar = const_cast<char *> (Sr.data()); *Ptr =reinterpret_cast<void *>(ExternChar); this->ExternName = DeclarationName::getFromOpaquePtr(Ptr); } the above is kind of hack ,may result in dangling memory references ,Any thoughts on this ? we thought to change the DeclarationName class ,with adding new DeclarationName constructor ,that construct the DeclarationName instance by StringRef as argument. i.e DeclarationName(StringRef Sr) ; Before doing this ,we thought to check with community for better alternative / suggestions . Thank you ~Umesh On Wed, Dec 21, 2016 at 4:34 PM, Umesh Kalappa <umesh.kalappa0 at gmail.com> wrote:> Hi Guys , > > We have the function that accepts StringRef and construct > the DeclarationName instance . > > Currenlty we are achieving the same as ,the code snap > > void appendExtern(StringRef Sr) > { > char *ExternChar = const_cast<char *> (Sr.data()); > *Ptr =reinterpret_cast<void *>(ExternChar); > > this->ExternName = DeclarationName::getFromOpaquePtr(Ptr); > > } > > There is, any better way of achieving this ,because the above code is > crashing intermittently ? > > Thank you and any help here appreciated. > ~Umesh > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161221/f9e2a65a/attachment.html>
Friedman, Eli via llvm-dev
2016-Dec-21 18:04 UTC
[llvm-dev] DeclarationName and the StringRef.
On 12/21/2016 5:01 AM, Umesh Kalappa via llvm-dev wrote:> To context was , > > Basic requirement was to append extra string to the decl name and > update all his references to the updated name. , > > So we are constructing the DeclarationName instance as stated below > code snap. > and from DeclarationName instance ,we are constructing the > DeclarationNameInfo and same info used to create decl spec > with FunctionDecl::Create () . > > Question is , > > How do ,someone instantiate the DeclarationName instance using > StringRef ,because in the current trunk code snap ,we see that > the DeclarationName can be constructed using the IdentifierInfo or > Objc Selector or CXXOperatorId etc as argument in the constructor . > > The code i.e > void appendExtern(StringRef Sr) > { > char *ExternChar = const_cast<char *> (Sr.data()); > *Ptr =reinterpret_cast<void *>(ExternChar); > this->ExternName = DeclarationName::getFromOpaquePtr(Ptr); > > } > > the above is kind of hack ,may result in dangling memory references > ,Any thoughts on this ? > > we thought to change the DeclarationName class ,with adding > new DeclarationName constructor ,that construct the DeclarationName > instance by StringRef as argument. i.e DeclarationName(StringRef Sr) ; > > Before doing this ,we thought to check with community for better > alternative / suggestions . >Usually it's better to send questions about the clang frontend to just cfe-dev, rather than llvm-dev. You can use IdentifierTable::get to get an IdentifierInfo for an arbitrary string, then make a DeclarationName from that. -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161221/4536114d/attachment.html>
Umesh Kalappa via llvm-dev
2016-Dec-22 04:07 UTC
[llvm-dev] DeclarationName and the StringRef.
Thank you eli, my bad will take care that next time. On Dec 21, 2016 11:34 PM, "Friedman, Eli" <efriedma at codeaurora.org> wrote:> On 12/21/2016 5:01 AM, Umesh Kalappa via llvm-dev wrote: > > To context was , > > Basic requirement was to append extra string to the decl name and update > all his references to the updated name. , > > So we are constructing the DeclarationName instance as stated below code > snap. > and from DeclarationName instance ,we are constructing the > DeclarationNameInfo and same info used to create decl spec > with FunctionDecl::Create () . > > Question is , > > How do ,someone instantiate the DeclarationName instance using StringRef > ,because in the current trunk code snap ,we see that the DeclarationName > can be constructed using the IdentifierInfo or Objc Selector or > CXXOperatorId etc as argument in the constructor . > > The code i.e > > void appendExtern(StringRef Sr) > { > char *ExternChar = const_cast<char *> (Sr.data()); > *Ptr =reinterpret_cast<void *>(ExternChar); > > this->ExternName = DeclarationName::getFromOpaquePtr(Ptr); > > } > > the above is kind of hack ,may result in dangling memory references ,Any > thoughts on this ? > > we thought to change the DeclarationName class ,with adding > new DeclarationName constructor ,that construct the DeclarationName > instance by StringRef as argument. i.e DeclarationName(StringRef Sr) ; > > Before doing this ,we thought to check with community for better > alternative / suggestions . > > > Usually it's better to send questions about the clang frontend to just > cfe-dev, rather than llvm-dev. > > You can use IdentifierTable::get to get an IdentifierInfo for an arbitrary > string, then make a DeclarationName from that. > > -Eli > > -- > Employee of Qualcomm Innovation Center, Inc. > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161222/441c4e50/attachment.html>