[cfe-commits] Fix PR13434 - mangling of templates with function pointers as arguments

Timur Iskhodzhanov timurrrr at google.com
Tue Jul 31 04:32:13 PDT 2012


On Tue, Jul 31, 2012 at 4:56 AM, John McCall <rjmccall at apple.com> wrote:
> On Jul 27, 2012, at 7:30 AM, Timur Iskhodzhanov wrote:
>> Attached is an updated patch which has slightly uglier code (due to
>> code duplication) but better mangling.
>> The "eta" mangling remains the same, "_E$$A6" has been replaced with
>> "_E" everywhere.
>
> +  QualType pointee = T->getPointeeType();
> +  assert(isa<FunctionProtoType>(pointee));
> +  mangleType(static_cast<const FunctionProtoType*>(pointee.getTypePtr()), NULL, false, false);
>
> The easier way to do an assert-and-cast is like this:
>   cast<FunctionProtoType>(pointee)
>
> However, you can't actually do a cast here, because there could be a typedef in the way.  Test case:
>   typedef void fn();
>   void foo(fn^ block) { block(); }
>
> So instead you need to do this:
>   pointee->castAs<FunctionProtoType>()
> This is like getAs<>, but asserting.
Thanks for the tip!
See the updated patch.

FTR, the idea of using static_cast came to me after looking at
MicrosoftMangle:972.
Probably, static_cast should be replaced with getAs/castAs there too ?

> John.
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug_13434_4.patch
Type: application/octet-stream
Size: 3896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120731/bf6df3bc/attachment.obj>


More information about the cfe-commits mailing list