[cfe-dev] Fwd: Assertion failure when mangling complex decltype

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Mon Jan 28 09:26:08 PST 2019


The mangler is only designed to produce mangled names for declarations that
have symbols. You cannot expect to be able to pass other declarations to it
and get a meaningful result back (or even for it to not crash).

If you want a unique identifier for an arbitrary declaration for some
reason, USRs may be a better fit.


On Mon, 28 Jan 2019, 05:28 Ding Fei via cfe-dev, <cfe-dev at lists.llvm.org>
wrote:

> Reproducible on TOT. Confirmed!
>
> Thanks!
>
> On Fri, Jan 25, 2019 at 10:10 AM Ding Fei <danix800 at gmail.com> wrote:
>
>> Also found crashes on the snippet from
>> llvm/tools/yaml2obj/yaml2coff.cpp:305-314, simplified as:
>>
>> *template <typename value_type>*
>> *struct binary_le_impl {*
>> *  value_type Value;*
>> *};*
>>
>> *template <typename value_type>*
>> *void op_left_shift(const binary_le_impl<value_type> &BLE) {*
>> *  char Buffer[sizeof(BLE.Value)];*
>> *}*
>>
>>
>> when mangling local *Buffer*.
>>
>> Thanks!
>>
>> On Fri, Jan 25, 2019 at 9:39 AM Ding Fei <danix800 at gmail.com> wrote:
>>
>>> Sorry I didn't make it clear enough.
>>>
>>> We are developing set of clang-tidy rules for code checking, one of
>>> which tries to mangle
>>> every var declared and dump mangled names out for further analysis.
>>>
>>> Usually this is not required for entities within function definition but
>>> they are well defined
>>> according Itanium C++ ABI
>>> <http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling> *[5.1.7]
>>> Scope Encoding*. So we mangled every local vars too
>>> the check matcher sees.
>>>
>>> Our code is based on release_70 [llvm + clang + clang-tools-extra]
>>>
>>> The possible check prototype might look like:
>>>
>>> *void Check_XXX::registerMatchers(ast_matchers::MatchFinder *Finder) {*
>>> *  using namespace ast_matchers;*
>>> *  Finder->addMatcher(varDecl(unless(parmVarDecl())).bind("V"), this);*
>>> *}*
>>>
>>> *void Check_XXX::check(const ast_matchers::MatchFinder::MatchResult
>>> &Result) {*
>>> *  auto &MangleCtx = getMangleCtx(); // an ItaniumMangleContext*
>>> *  auto *V = Result.Nodes.getNodeAs<VarDecl>("V");*
>>>
>>> *  if (!V || !MangleCtx.shouldMangleCXXName(V)) {*
>>>
>>> *    return;*
>>>
>>> *  }*
>>>
>>> *  SmallString<64> Buffer;*
>>> *  llvm::raw_svector_ostream Stream(Buffer);*
>>> *  MangleCtx.MangleCXXName(V, Stream);*
>>> *  llvm::outs() << "Mangled var: " << Buffer.str() << "\n";*
>>> *}*
>>>
>>>
>>> The example code that triggers the assertion (sampled from
>>> *llvm/lib/Analysis/LazyCallGraph.cpp:1557-1564*):
>>>
>>> *#include <type_traits>*
>>>
>>> *class Node {};*
>>>
>>> *template<typename GetBeginT>*
>>> *void buildGenericSCCs(GetBeginT &&GetBegin) {*
>>> *  decltype(GetBegin(std::declval<Node &>())) DFSStack;*
>>> *}*
>>>
>>>
>>> The assertion triggered is
>>>
>>> *tools/clang/lib/AST/ItaniumMangle.cpp:4317: void (anonymous
>>> namespace)::*
>>> *CXXNameMangler::**mangleFunctionParam(const clang::ParmVarDecl *):*
>>> *Assertion `parmDepth < FunctionTypeDepth.getDepth()' failed.*
>>>
>>>
>>> Hope those info is enough for you, thanks!
>>>
>>> On Fri, Jan 25, 2019 at 2:07 AM Erik Pilkington <
>>> erik.pilkington at gmail.com> wrote:
>>>
>>>> Wait, why are we trying to mangle the local var decl here? Doesn't seem
>>>> to repro on TOT for me, can you provide a backtrace/preprocessed source/a
>>>> clang invocation for this?
>>>>
>>>> Erik
>>>>
>>>> On 1/24/19 3:22 AM, Ding Fei via cfe-dev wrote:
>>>>
>>>> Hi all,
>>>>
>>>> On release_70, for the example code:
>>>>
>>>> *#include <type_traits>*
>>>> *class Node {};*
>>>>
>>>> *template<typename GetBeginT> *
>>>> *void buildGenericSCCs(GetBeginT &&GetBegin) { *
>>>> *  decltype(GetBegin(std::declval<Node &>())) DFSStack; *
>>>> *} *
>>>>
>>>> In Mangle.h when calling mangleCXXName() on VarDecl of DFSStack,
>>>> assertion triggered:
>>>>
>>>> *tools/clang/lib/AST/ItaniumMangle.cpp:4317: void (anonymous
>>>> namespace)::CXXNameMangler::mangleFunctionParam(const clang::ParmVarDecl
>>>> *): Assertion `parmDepth < FunctionTypeDepth.getDepth()' failed.*
>>>>
>>>> Do anyone have any ideas on the cause of it? Thanks
>>>> --
>>>> Best Regards
>>>>
>>>> Ding Fei
>>>> E-mail: danix800 at gmail.com
>>>>
>>>> _______________________________________________
>>>> cfe-dev mailing listcfe-dev at lists.llvm.orghttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>>
>>>>
>>>>
>>>
>>> --
>>> Best Regards
>>>
>>> Ding Fei
>>> E-mail: danix800 at gmail.com
>>>
>>
>>
>> --
>> Best Regards
>>
>> Ding Fei
>> E-mail: danix800 at gmail.com
>>
>
>
> --
> Best Regards
>
> Ding Fei
> E-mail: danix800 at gmail.com
>
>
> --
> Best Regards
>
> Ding Fei
> E-mail: danix800 at gmail.com
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190128/6e01e34a/attachment.html>


More information about the cfe-dev mailing list