[llvm-commits] [PATCH] Casting.h: Don't cast away const with static_cast<>
Rafael EspĂndola
rafael.espindola at gmail.com
Fri Mar 22 15:20:11 PDT 2013
On 20 March 2013 15:21, Sean Silva <silvas at purdue.edu> wrote:
> This patch was mostly a "peephole" change that I saw when I was in the area.
> I'm not familiar enough with this code (or at least it's not in cache for me
> ATM) to be able to meaningfully comment on your patch.
>
> Judging by the look of some of the fixups you did for this patch, you might
> want to doublecheck if there is anything on the clang side that needs to be
> fixed up.
Thanks for the reminder. And thanks for finding this in the first place!
I took another look on what simplify_type was trying to do. What I found was:
As the description says, it extracts the underlying type from a "smart
pointer" (also includes things like llvm::Use). There are 3 basic
kinds of pointers to consider:
* const correct: A 'const MyPtr<int> &' produces a 'const int*'. A
'MyPtr<int> &' produces a 'int *'.
* always const: Even a 'MyPtr<int> &' produces a 'const int*'.
* no const: Even a 'const MyPtr<int> &' produces a 'int*'.
The existing code had a broken forwarding system. It looks like it was
trying to implement const correct smart pointer by default, but since
it was broken, every specialization had both const and non const
versions.
Another problem with the existing implementation is that it was
dropping the 'const' in some areas, forcing some specializations to
use const_cast (::clang::CFGTerminator).
The attached patches
* Remove the unused specializations. Since they are unused, it is hard
to know which variant should be implemented.
* Make sure we don't drop const.
* Fix the default forwarding so that const correct pointer only need
one specialization.
* Simplifies the existing specializations.
The LLVM/Clang specific logic is fairly simple. It is the template
meta programming that makes the patches a bit complex. Michael, are
you OK reviewing these patches?
> -- Sean Silva
Thanks,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm.patch
Type: application/octet-stream
Size: 14115 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130322/3aff0008/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang.patch
Type: application/octet-stream
Size: 4656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130322/3aff0008/attachment-0001.obj>
More information about the llvm-commits
mailing list