[cfe-dev] clang::MangleContext::shouldMangleDeclName

Vassil Vassilev vasil.georgiev.vasilev at cern.ch
Thu Oct 25 06:50:04 PDT 2012


On 10/25/2012 10:35 AM, John McCall wrote:
> On Oct 25, 2012, at 12:01 AM, Vassil Vassilev wrote:
>> On 10/24/12 11:07 PM, John McCall wrote:
>>> On Oct 24, 2012, at 2:03 PM, John McCall wrote:
>>>> On Oct 24, 2012, at 2:20 AM, Vassil Vassilev wrote:
>>>>> shouldMangleDeclName returns true for decls like EnumConstantDecl.
>>>>> Is that expected behaviour? Am I missing something?
>>>> It doesn't really return anything meaningful for declarations that
>>>> obviously aren't mangled.
>>> To clarify, that query is only meaningful for declarations that can be
>>> directly referenced as global symbols.  It's not meaningful for, say,
>>> enum constants or classes or using declarations.
>>>
>>> John.
>> Thanks for the answer, John!
>>
>> It's somehow contra-intuitive for shouldMangleDeclName to return true for decls that aren't/can't be mangled.
> The point of the function is to decide whether the linking symbol for the declaration should be mangled, as opposed to simply being the same as its identifier.  It does not make sense to ask whether to mangle the linking symbol of a declaration that does not have a linking symbol.  If you would like to prepare a patch to have this function assert when given an EnumConstantDecl, that would be acceptable;  but otherwise I see no reason to prefer any particular answer.
>
> John.
John,
   I see your point. You come from the fact that the uses of the 
function in clang are through GlobalDecl, which is translated to a 
global symbol.
   My use-case was to provide an interface (see below), where (that was 
I thought first) shouldMangleDeclName will help me avoid the asserts in 
mangleName.

   void mangleName(const clang::NamedDecl* D,
                                std::string& mangledName) const {
     if (!m_MangleCtx) {
m_MangleCtx.reset(getCI()->getASTContext().createMangleContext());
     }
     if (m_MangleCtx->shouldMangleDeclName(D)) {
       llvm::raw_string_ostream RawStr(mangledName);
       m_MangleCtx->mangleName(D, RawStr);
       RawStr.flush();
     } else {
       mangledName = D->getNameAsString();
     }
   }

Of course I can and will work that around on my side, but I thought is 
good to have.
Thanks for the explanation!
Vassil



More information about the cfe-dev mailing list