Assertion failure when mangling complex decltype

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Assertion failure when mangling complex decltype

David Blaikie via cfe-dev
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: [hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Assertion failure when mangling complex decltype

David Blaikie via cfe-dev
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: [hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Fwd: Assertion failure when mangling complex decltype

David Blaikie via cfe-dev
Reproducible on TOT. Confirmed!

Thanks!

On Fri, Jan 25, 2019 at 10:10 AM Ding Fei <[hidden email]> 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 <[hidden email]> 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 [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 <[hidden email]> 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: [hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



--
Best Regards
 
Ding Fei
E-mail: [hidden email]


--
Best Regards
 
Ding Fei
E-mail: [hidden email]


--
Best Regards
 
Ding Fei
E-mail: [hidden email]


--
Best Regards
 
Ding Fei
E-mail: [hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Assertion failure when mangling complex decltype

David Blaikie via cfe-dev
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, <[hidden email]> wrote:
Reproducible on TOT. Confirmed!

Thanks!

On Fri, Jan 25, 2019 at 10:10 AM Ding Fei <[hidden email]> 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 <[hidden email]> 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 [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 <[hidden email]> 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: [hidden email]

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



--
Best Regards
 
Ding Fei
E-mail: [hidden email]


--
Best Regards
 
Ding Fei
E-mail: [hidden email]


--
Best Regards
 
Ding Fei
E-mail: [hidden email]


--
Best Regards
 
Ding Fei
E-mail: [hidden email]
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev