<div dir="ltr">So what should be a proper solution to this problem? :<div><br></div><div>1) Make type printer output to be equivalent to <cxxabi.h> demangler?</div><div>2) Implement AST Matcher for mangled names?</div><div>Or there is some other way I'm missing?</div><div><br></div><div>Thanks,</div><div>Roman</div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-03-01 11:12 GMT-08:00 Roman Popov <span dir="ltr"><<a href="mailto:ripopov@gmail.com" target="_blank">ripopov@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Well, it turned out there are more problems in this direction. <div><br></div><div>Consider this code sample:</div><div><br></div><div><div><b>template < auto &ref , auto *ptr, auto v></b></div><div><b>struct foo {};</b></div><div><b>static int x;</b></div><div><b>foo <x, &x, nullptr> f;</b></div></div><div><br></div><div>Standard demangler from <cxxabi.h> demangles f type like this:</div><div><br></div><div><b>foo<x, &x, (decltype(nullptr))0><br></b></div><div> </div><div>But clang Type printer used by ASTMatcher prints it like this:</div><div><br></div><div><div><b>struct foo<&x, &x, nullptr> &&</b></div></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Roman</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2018-02-28 20:02 GMT-08:00 Roman Popov <span dir="ltr"><<a href="mailto:ripopov@gmail.com" target="_blank">ripopov@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok, simply adding suffixes based on BuiltinType Kind solves the problem for me. I will update to Clang trunk tomorrow and check if it will work there.</div><div class="m_-4263391817552882914HOEnZb"><div class="m_-4263391817552882914h5"><div class="gmail_extra"><br><div class="gmail_quote">2018-02-28 18:54 GMT-08:00 Roman Popov <span dir="ltr"><<a href="mailto:ripopov@gmail.com" target="_blank">ripopov@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Well, from what I'm seeing non-type argument printer is actually untyped. <div>It uses APInt, which looks like "generic" arbitrary precision integer, that knows nothing about C++ type system.<br><br></div><div>So solution is to print APInt value without type postfix, and then generate type postfix based on template parameter type.</div><div><br></div><div>I'm not really familiar with Clang yet, so it will take a time to fix this. But I will try.</div><div><br></div><div>Another option would be using mangled type names in AST Matcher. This way it will be even better: you wan't need to demangle names from LLVM IR.</div><div><br></div><div><br></div></div><div class="m_-4263391817552882914m_-3147294398158431935HOEnZb"><div class="m_-4263391817552882914m_-3147294398158431935h5"><div class="gmail_extra"><br><div class="gmail_quote">2018-02-28 18:07 GMT-08:00 Roman Popov <span dir="ltr"><<a href="mailto:ripopov@gmail.com" target="_blank">ripopov@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ok, let me run the code in debugger to understand how it makes decision when to print U. </div><div class="m_-4263391817552882914m_-3147294398158431935m_-7234493148276088155HOEnZb"><div class="m_-4263391817552882914m_-3147294398158431935m_-7234493148276088155h5"><div class="gmail_extra"><br><div class="gmail_quote">2018-02-28 18:05 GMT-08:00 Artem Dergachev <span dir="ltr"><<a href="mailto:noqnoqneo@gmail.com" target="_blank">noqnoqneo@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Huh, nice one. It means that the problem is somewhere in QualType::getQualifiedNameAsSt<wbr>ring(). No, it doesn't seem to be fixed in trunk. This might be an easy and welcomed patch.<span><br>
<br>
On 28/02/2018 5:56 PM, Roman Popov wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>
Btw, I'm using Clang 5.0, probably it is already fixed in trunk?<br>
<br></span>
2018-02-28 17:54 GMT-08:00 Roman Popov <<a href="mailto:ripopov@gmail.com" target="_blank">ripopov@gmail.com</a> <mailto:<a href="mailto:ripopov@gmail.com" target="_blank">ripopov@gmail.com</a>>>:<span><br>
<br>
Yes, it matches indeed vs my_nm::my_type<int, 10>.<br>
<br></span>
I think this is a bug in*asString() *matcher: Here is reproducer:<span><br>
<br>
*namespace my_nm {*<br>
*template<typename T, unsigned U>*<br>
*struct my_type { };*<br>
*}*<br>
*<br>
*<br></span>
*my_nm::my_type<int, 10> m1;*<br>
*my_nm::my_type<int, 11u> m2;*<span><br>
<br>
LLVM IR generator correctly generates both types with unsigned<br>
second parameter. But AST Matcher thinks that m1 has signed<br>
parameter, and m2 has unsigned:<br>
<br></span>
m1 matches vs *my_nm::my_type<int, 10>*<br>
m2 matches vs *my_nm::my_type<int, 11U> *(notice capital U)<br>
<br>
In LLVM IR types are *my_nm::my_type<int, 10u> and<br>
*my_nm::my_type<int, 11u> **<span><br>
<br>
<br>
Thanks, Roman<br>
<br>
<br>
<br>
2018-02-28 17:37 GMT-08:00 Artem Dergachev <<a href="mailto:noqnoqneo@gmail.com" target="_blank">noqnoqneo@gmail.com</a><br></span>
<mailto:<a href="mailto:noqnoqneo@gmail.com" target="_blank">noqnoqneo@gmail.com</a>>>:<div><div class="m_-4263391817552882914m_-3147294398158431935m_-7234493148276088155m_-1189905136270545452h5"><br>
<br>
Sorry i don't have a quick way of trying this at the moment;<br>
Does it work with "struct my_nm::my_type<int, 10>"? - because<br>
that's what i see in clang's -ast-dump. Does<br>
varDecl(hasType(asString(...))<wbr>) work? If you match qualType()<br>
and dump .getAsString() on all results, what do you see?<br>
<br>
Cause i think it should ultimately work.<br>
<br>
On 28/02/2018 2:12 PM, Roman Popov wrote:<br>
<br>
Thanks Artem. This is what I've tried before writing<br>
original mail. However it does not work, I got zero matches.<br>
<br>
Here is reproducer:<br>
<br>
*namespace my_nm {*<br>
*template<typename T, unsigned U>*<br>
*struct my_type { };*<br>
*}*<br>
*<br>
*<br>
*my_nm::my_type<int, 10> m;<br>
*<br>
<br>
<br>
I got types from LLVM IR analysis, and then want to find<br>
them in Clang AST.<br>
<br>
From LLVM I got mangled name:<br>
*N5my_nm7my_typeIiLj10EEE*<br>
<br>
Demangled to:<br>
*my_nm::my_type<int, 10u>*<br>
<br>
However I can't find it by any matcher:<br>
<br>
auto matches =<br>
match(qualType(asString("*my_n<wbr>m::my_type<int,<br>
10u>*")).bind("types"), astCtx); // Zero matches<br>
<br>
auto matches =<br>
match(qualType(asString("*N5my<wbr>_nm7my_typeIiLj10EEE*")).bind(<wbr>"types"),<br>
astCtx); // Zero matches<br>
<br>
Probably there is some other way to go back from LLVM IR<br>
to Clang AST?<br>
<br>
<br>
Thanks,<br>
Roman<br>
<br>
<br>
2018-02-28 12:36 GMT-08:00 Artem Dergachev<br>
<<a href="mailto:noqnoqneo@gmail.com" target="_blank">noqnoqneo@gmail.com</a> <mailto:<a href="mailto:noqnoqneo@gmail.com" target="_blank">noqnoqneo@gmail.com</a>><br></div></div>
<mailto:<a href="mailto:noqnoqneo@gmail.com" target="_blank">noqnoqneo@gmail.com</a> <mailto:<a href="mailto:noqnoqneo@gmail.com" target="_blank">noqnoqneo@gmail.com</a>>>><wbr>:<span><br>
<br>
I don't think it's possible via straightforward lookup<br>
- you might<br>
need to scan the AST to do this.<br>
<br>
Eg. using ASTMatchers:<br>
<br>
qualType(asString("my_nm::my_t<wbr>ype<int, 10u>"))<br>
<br>
Or, if you're not using ASTMatchers (likely), you can<br>
do the same<br>
with a RecursiveASTVisitor. Or manually.<br>
<br>
<br>
On 27/02/2018 10:56 AM, Roman Popov via cfe-dev wrote:<br>
<br>
Hello,<br>
<br>
Is it possible to find type in AST by it's<br>
qualified type?<br>
<br>
For example I have string "my_nm::my_type<int,<br>
10u>", how can<br>
I get clang::QualType if type is present in<br>
translation unit?<br>
<br>
Thanks,<br>
Roman<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a> <mailto:<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><wbr>><br></span>
<mailto:<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><span><br>
<mailto:<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><wbr>>><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin<wbr>/mailman/listinfo/cfe-dev</a>><br>
<br></span>
<<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin<wbr>/mailman/listinfo/cfe-dev</a><br>
<<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin<wbr>/mailman/listinfo/cfe-dev</a>>><br>
<br>
<br>
<br>
<br>
<br>
<br>
</blockquote>
<br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>