<div dir="ltr">On Fri, Mar 22, 2013 at 3:20 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">On 20 March 2013 15:21, Sean Silva <<a href="mailto:silvas@purdue.edu">silvas@purdue.edu</a>> wrote:<br>

> This patch was mostly a "peephole" change that I saw when I was in the area.<br>
> I'm not familiar enough with this code (or at least it's not in cache for me<br>
> ATM) to be able to meaningfully comment on your patch.<br>
><br>
> Judging by the look of some of the fixups you did for this patch, you might<br>
> want to doublecheck if there is anything on the clang side that needs to be<br>
> fixed up.<br>
<br>
</div></div>Thanks for the reminder. And thanks for finding this in the first place!<br>
<br>
I took another look on what simplify_type was trying to do. What I found was:<br>
<br>
As the description says, it extracts the underlying type from a "smart<br>
pointer" (also includes things like llvm::Use). There are 3 basic<br>
kinds of pointers to consider:<br>
<br>
* const correct: A 'const MyPtr<int> &' produces a 'const int*'. A<br>
'MyPtr<int> &' produces a 'int *'.<br>
* always const: Even a 'MyPtr<int> &' produces a 'const int*'.<br>
* no const: Even a 'const MyPtr<int> &' produces a 'int*'.<br>
<br>
The existing code had a broken forwarding system. It looks like it was<br>
trying to implement const correct smart pointer by default, but since<br>
it was broken, every specialization had both const and non const<br>
versions.<br>
<br>
Another problem with the existing implementation is that it was<br>
dropping the 'const' in some areas, forcing some specializations to<br>
use const_cast (::clang::CFGTerminator).<br>
<br>
The attached patches<br>
<br>
* Remove the unused specializations. Since they are unused, it is hard<br>
to know which variant should be implemented.<br>
* Make sure we don't drop const.<br>
* Fix the default forwarding so that const correct pointer only need<br>
one specialization.<br>
* Simplifies the existing specializations.<br>
<br>
The LLVM/Clang specific logic is fairly simple. It is the template<br>
meta programming that makes the patches a bit complex. Michael, are<br>
you OK reviewing these patches?<br>
<br>
> -- Sean Silva<br>
<br>
Thanks,<br>
Rafael<br>
</blockquote></div><br></div><div class="gmail_extra" style>The LLVM part LGTM with the following change:</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>put</div><div class="gmail_extra" style>
<br></div><div class="gmail_extra" style><div class="gmail_extra">+template<typename T, typename Enable = void></div><div class="gmail_extra">+struct add_lvalue_reference_if_not_pointer {</div><div class="gmail_extra">
+  typedef T &type;</div><div class="gmail_extra">+};</div><div class="gmail_extra">+</div><div class="gmail_extra">+template<typename T></div><div class="gmail_extra">+struct add_lvalue_reference_if_not_pointer<T,</div>
<div class="gmail_extra">+                                     typename enable_if<is_pointer<T> >::type> {</div><div class="gmail_extra">+  typedef T type;</div><div class="gmail_extra">+};</div><div class="gmail_extra">
+</div><div class="gmail_extra">+template<typename T, typename Enable = void></div><div class="gmail_extra">+struct add_const_past_pointer {</div><div class="gmail_extra">+  typedef const T type;</div><div class="gmail_extra">
+};</div><div class="gmail_extra">+</div><div class="gmail_extra">+template<typename T></div><div class="gmail_extra">+struct add_const_past_pointer<T, typename enable_if<is_pointer<T> >::type> {</div>
<div class="gmail_extra">+  typedef const typename remove_pointer<T>::type *type;</div><div class="gmail_extra">+};</div><div class="gmail_extra">+</div><div class="gmail_extra"><br></div><div class="gmail_extra" style>
in type_traits.h and comment them.</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>- Michael Spencer</div></div><div class="gmail_extra"><br></div></div>