r213016 - AST: Fix __uuidof for template specializations

David Majnemer david.majnemer at gmail.com
Mon Jul 14 21:42:38 PDT 2014


On Mon, Jul 14, 2014 at 6:18 PM, Richard Smith <richard at metafoo.co.uk>
wrote:

> On Mon, Jul 14, 2014 at 4:40 PM, David Majnemer <david.majnemer at gmail.com>
> wrote:
>
>> Author: majnemer
>> Date: Mon Jul 14 18:40:24 2014
>> New Revision: 213016
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=213016&view=rev
>> Log:
>> AST: Fix __uuidof for template specializations
>>
>> While we previously supported __uuidof applied to a template
>> specialization, we would only find the uuid attribute if it was applied
>> to the template argument.  We would erroneously ignore the uuid
>> attribute on the specialization itself.
>>
>> This is required to parse Windows Runtime C++ Template Library headers.
>>
>> Added:
>>     cfe/trunk/test/CodeGenCXX/microsoft-templ-uuidof.cpp
>> Modified:
>>     cfe/trunk/lib/AST/ExprCXX.cpp
>>
>> Modified: cfe/trunk/lib/AST/ExprCXX.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=213016&r1=213015&r2=213016&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/AST/ExprCXX.cpp (original)
>> +++ cfe/trunk/lib/AST/ExprCXX.cpp Mon Jul 14 18:40:24 2014
>> @@ -68,6 +68,11 @@ const UuidAttr *CXXUuidofExpr::GetUuidAt
>>    if (!RD)
>>      return nullptr;
>>
>> +  // Loop over all record redeclarations looking for a uuid attribute.
>> +  for (const TagDecl *I : RD->redecls())
>> +    if (const UuidAttr *Uuid = I->getAttr<UuidAttr>())
>> +      return Uuid;
>>
>
> Given that this is an inherited attribute, do you really need to walk over
> the redeclarations looking for it?
>

I believe the code was trying to handle the case where the attribute might
not be on the definition but on some later declaration.

However, there shouldn't be any need to walk every redeclaration; it should
be on the most recent declaration.  Good call, r213044.


>
>
>> +
>>    // __uuidof can grab UUIDs from template arguments.
>>    if (ClassTemplateSpecializationDecl *CTSD =
>>            dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
>> @@ -106,11 +111,6 @@ const UuidAttr *CXXUuidofExpr::GetUuidAt
>>      return UuidForRD;
>>    }
>>
>> -  // Loop over all record redeclarations looking for a uuid attribute.
>> -  for (const TagDecl *I : RD->redecls())
>> -    if (const UuidAttr *Uuid = I->getAttr<UuidAttr>())
>> -      return Uuid;
>> -
>>    return nullptr;
>>  }
>>
>>
>> Added: cfe/trunk/test/CodeGenCXX/microsoft-templ-uuidof.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-templ-uuidof.cpp?rev=213016&view=auto
>>
>> ==============================================================================
>> --- cfe/trunk/test/CodeGenCXX/microsoft-templ-uuidof.cpp (added)
>> +++ cfe/trunk/test/CodeGenCXX/microsoft-templ-uuidof.cpp Mon Jul 14
>> 18:40:24 2014
>> @@ -0,0 +1,37 @@
>> +// RUN: %clang_cc1 -emit-llvm %s -o - -DDEFINE_GUID
>> -triple=i386-pc-win32 -fms-extensions | FileCheck %s --check-prefix=CHECK
>> +
>> +struct _GUID;
>> +
>> +template <typename>
>> +struct X {
>> +};
>> +
>> +struct __declspec(uuid("{AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA}")) A {};
>> +
>> +struct B {};
>> +
>> +template <>
>> +struct __declspec(uuid("{BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB}")) X<B>
>> {};
>> +
>> +struct __declspec(uuid("{CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC}")) C {};
>> +
>> +const _GUID &xa = __uuidof(X<A>);
>> +// CHECK-DAG:  @"\01?xa@@3ABU_GUID@@B" = {{.*}}
>> @_GUID_aaaaaaaa_aaaa_aaaa_aaaa_aaaaaaaaaaaa
>> +
>> +const _GUID &xb = __uuidof(X<B>);
>> +// CHECK-DAG:  @"\01?xb@@3ABU_GUID@@B" = {{.*}}
>> @_GUID_bbbbbbbb_bbbb_bbbb_bbbb_bbbbbbbbbbbb
>> +const _GUID &xc = __uuidof(X<C>);
>> +// CHECK-DAG:  @"\01?xc@@3ABU_GUID@@B" = {{.*}}
>> @_GUID_cccccccc_cccc_cccc_cccc_cccccccccccc
>> +
>> +template <>
>> +struct __declspec(uuid("{DDDDDDDD-DDDD-DDDD-DDDD-DDDDDDDDDDDD}")) X<C>
>> {};
>> +
>> +template <typename>
>> +struct __declspec(uuid("{EEEEEEEE-EEEE-EEEE-EEEE-EEEEEEEEEEEE}")) Y {
>> +};
>> +
>> +const _GUID &xd = __uuidof(X<C>);
>> +// CHECK-DAG:  @"\01?xd@@3ABU_GUID@@B" = {{.*}}
>> @_GUID_dddddddd_dddd_dddd_dddd_dddddddddddd
>> +
>> +const _GUID &yd = __uuidof(Y<X<C> >);
>> +// CHECK-DAG:  @"\01?yd@@3ABU_GUID@@B" = {{.*}}
>> @_GUID_dddddddd_dddd_dddd_dddd_dddddddddddd
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140714/53bb43f8/attachment.html>


More information about the cfe-commits mailing list