r213016 - AST: Fix __uuidof for template specializations

David Majnemer david.majnemer at gmail.com
Mon Jul 14 16:40:24 PDT 2014


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;
+
   // __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





More information about the cfe-commits mailing list