[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] canonical type for C++11 auto
From:       Richard Smith <richard () metafoo ! co ! uk>
Date:       2015-07-30 21:38:06
Message-ID: CAOfiQqniQg3=-aBTMXRLNjKbrFDu6ZMUbnuM=NHCDvd1DmYkqA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Thu, Jul 30, 2015 at 1:48 PM, Milian Wolff <mail@milianw.de> wrote:

> Ping?
>
>
>
> Could anyone help me out? In what direction should I look? How can I
> resolve the "auto" QualType (as returned by e.g. T.getAsString())" to the
> underlying type - in my test code below "int"?
>
>
>
> Any help would be greatly appreciated.
>

The problem is that libclang is looking at the TypeSourceInfo for the
variable declaration (VD->getTypeSourceInfo()), which contains just an
undeduced AutoType (that is, it contains the type as written). The deduced
type is present in the variable's type (VD->getType()) but not in the type
source information.

As I noted in the referenced thread, we could change this so that VarDecls'
TypeSourceInfo would include the deduced type. However, the same problem
exists for FunctionDecls (where the return type can involve an AutoType),
but we can't use the same approach there because we use the TypeSourceInfo
to track the declared type (which must match across redeclarations). It
would be preferable to have a solution that works for both cases, if
possible, and using the TypeSourceInfo to represent the declared type and
the declaration's type to represent the resolved type seems like the most
consistent approach.

Bye
>
>
>
> On Sunday, July 26, 2015 03:31:14 PM Milian Wolff wrote:
>
> > Hey all,
>
> >
>
> > I want to scratch my own itch by fixing the issue that
>
> > clang_getCanonicalType does not deduce the type for variables such as
> `auto
>
> > i = 1;`. See for context:
>
> >
>
> > https://llvm.org/bugs/show_bug.cgi?id=18669
>
> >
> http://clang-developers.42468.n3.nabble.com/API-for-auto-type-deduction-in-l
>
> > ibclang-td4037350.html
>
> >
>
> > I added a simple unit test as the first step:
>
> >
>
> > $ cat test/Index/cxx11-print-type.cpp
>
> > auto a = 1;
>
> >
>
> > // RUN: c-index-test -test-print-type -std=c++11 %s | FileCheck %s
>
> > // CHECK: VarDecl=a:1:6 [type=auto] [typeKind=Unexposed]
>
> > [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
>
> >
>
> > Running the first half manually I get:
>
> >
>
> > VarDecl=a:1:6 (Definition) [type=auto] [typekind=Unexposed] [isPOD=0]
>
> >
>
> > Sadly, I'm a bit lost as to where I'd have to fix this. Looking at
>
> > CXType.cpp's clang_getCanonicalType implementation, I tried something
> like
>
> > this:
>
> >
>
> > fprintf(stderr, "--------------> undeduced?: %d\n",
>
> > T->isUndeducedType()); if (T->isUndeducedType()) {
>
> > auto d = T->getContainedAutoType()->getDeducedType();
>
> > fprintf(stderr, "--------------> deduced valid? %d\n", !d.isNull());
>
> > if (!d.isNull()) {
>
> > T = d;
>
> > }
>
> > }
>
> >
>
> > This shows me that for the above input (i.e. `auto i = 1;`), the type is
>
> > undeduced, but I also cannot force deduction by getDeducedType (probably
> me
>
> > abusing/misinterpreting the API). So what can be done here - how could
> it be
>
> > fixed? Where would it be fixed?
>
> >
>
> > Thanks
>
>
>
> --
>
> Milian Wolff
>
> mail@milianw.de
>
> http://milianw.de
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>

[Attachment #5 (text/html)]

<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jul 30, 2015 \
at 1:48 PM, Milian Wolff <span dir="ltr">&lt;<a href="mailto:mail@milianw.de" \
target="_blank">mail@milianw.de</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><u></u> <div style="font-family:&#39;DejaVu Sans \
Mono&#39;;font-size:11pt;font-weight:400;font-style:normal"> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Ping?</p>
 <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Could \
anyone help me out? In what direction should I look? How can I resolve the \
&quot;auto&quot; QualType (as returned by e.g. T.getAsString())&quot; to the \
underlying type - in my test code below &quot;int&quot;?</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Any \
help would be greatly appreciated.</p></div></blockquote><div><br></div><div>The \
problem is that libclang is looking at the TypeSourceInfo for the variable \
declaration (VD-&gt;getTypeSourceInfo()), which contains just an undeduced AutoType \
(that is, it contains the type as written). The deduced type is present in the \
variable&#39;s type (VD-&gt;getType()) but not in the type source \
information.</div><div><br></div><div>As I noted in the referenced thread, we could \
change this so that VarDecls&#39; TypeSourceInfo would include the deduced type. \
However, the same problem exists for FunctionDecls (where the return type can involve \
an AutoType), but we can&#39;t use the same approach there because we use the \
TypeSourceInfo to track the declared type (which must match across redeclarations). \
It would be preferable to have a solution that works for both cases, if possible, and \
using the TypeSourceInfo to represent the declared type and the declaration&#39;s \
type to represent the resolved type seems like the most consistent \
approach.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:&#39;DejaVu \
Sans Mono&#39;;font-size:11pt;font-weight:400;font-style:normal"> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Bye</p><div><div \
class="h5"> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">On \
Sunday, July 26, 2015 03:31:14 PM Milian Wolff wrote:</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
Hey all,</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
I want to scratch my own itch by fixing the issue that</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
clang_getCanonicalType does not deduce the type for variables such as `auto</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
i = 1;`. See for context:</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug \
.cgi-3Fid-3D18669&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6 \
GUNn7_wosSM&m=WOzdlRnQ9czRxcKywKVYKsgtJ2R0vKVLNsm80In7fJw&s=f9itYkoqEOH14LUI6-y20iJ28vaFR54878SjQKlXW-Q&e=" \
target="_blank">https://llvm.org/bugs/show_bug.cgi?id=18669</a></p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__clang-2Ddevelopers.42468. \
n3.nabble.com_API-2Dfor-2Dauto-2Dtype-2Ddeduction-2Din-2Dl&d=AwMFaQ&c=8hUWFZcy2Z-Za5rB \
PlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=WOzdlRnQ9czRxcKywKVYKsgtJ2R0vKVLNsm80In7fJw&s=dS8-85fXEc7rdUzi1_bjeBhKmtu8huV7RgkgvD87mG8&e=" \
target="_blank">http://clang-developers.42468.n3.nabble.com/API-for-auto-type-deduction-in-l</a></p>
 <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
ibclang-td4037350.html</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
I added a simple unit test as the first step:</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
$ cat test/Index/cxx11-print-type.cpp</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
auto a = 1;</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
// RUN: c-index-test -test-print-type -std=c++11 %s | FileCheck %s</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
// CHECK: VarDecl=a:1:6 [type=auto] [typeKind=Unexposed]</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
[canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
Running the first half manually I get:</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
VarDecl=a:1:6 (Definition) [type=auto] [typekind=Unexposed] [isPOD=0]</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
Sadly, I&#39;m a bit lost as to where I&#39;d have to fix this. Looking at</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
CXType.cpp&#39;s clang_getCanonicalType implementation, I tried something like</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
this:</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
fprintf(stderr, &quot;--------------&gt; undeduced?: %d\n&quot;,</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
T-&gt;isUndeducedType()); if (T-&gt;isUndeducedType()) {</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
auto d = T-&gt;getContainedAutoType()-&gt;getDeducedType();</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
fprintf(stderr, &quot;--------------&gt; deduced valid? %d\n&quot;, !d.isNull());</p> \
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
if (!d.isNull()) {</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
T = d;</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
}</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
}</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
This shows me that for the above input (i.e. `auto i = 1;`), the type is</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
undeduced, but I also cannot force deduction by getDeducedType (probably me</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
abusing/misinterpreting the API). So what can be done here - how could it be</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
fixed? Where would it be fixed?</p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">&gt; \
Thanks</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">-- \
</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Milian \
Wolff</p> <p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><a \
href="mailto:mail@milianw.de" target="_blank">mail@milianw.de</a></p> <p \
style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><a \
href="https://urldefense.proofpoint.com/v2/url?u=http-3A__milianw.de&d=AwMFaQ&c=8hUWFZ \
cy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=WOzdlRnQ9czRxcKywKVYKsgtJ2R0vKVLNsm80In7fJw&s=GJQNwsNNm4bL_fPu0udMzF3zOQxFZQ0ZCsuLWCO0hZE&e=" \
target="_blank">http://milianw.de</a></p></div></div></div><br>_______________________________________________<br>
 cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" rel="noreferrer" \
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br> \
<br></blockquote></div><br></div></div>



_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic