[cfe-commits] r86030 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/CodeGen/CGCXX.cpp lib/Sema/SemaType.cpp test/CodeGenCXX/ptr-to-datamember.cpp

Douglas Gregor dgregor at apple.com
Wed Nov 4 08:49:01 PST 2009


Author: dgregor
Date: Wed Nov  4 10:49:01 2009
New Revision: 86030

URL: http://llvm.org/viewvc/llvm-project?rev=86030&view=rev
Log:
Store the unresolved class type in MemberPointerType's Class field,
from Peter Collingbourne!


Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=86030&r1=86029&r2=86030&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Nov  4 10:49:01 2009
@@ -1374,7 +1374,7 @@
   // If the pointee or class type isn't canonical, this won't be a canonical
   // type either, so fill in the canonical type field.
   QualType Canonical;
-  if (!T.isCanonical()) {
+  if (!T.isCanonical() || !Cls->isCanonicalUnqualified()) {
     Canonical = getMemberPointerType(getCanonicalType(T),getCanonicalType(Cls));
 
     // Get the new insert position for the node we care about.

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=86030&r1=86029&r2=86030&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Nov  4 10:49:01 2009
@@ -291,7 +291,7 @@
   const FunctionProtoType *FPT = 
     MPT->getPointeeType()->getAs<FunctionProtoType>();
   const CXXRecordDecl *RD = 
-    cast<CXXRecordDecl>(cast<RecordType>(MPT->getClass())->getDecl());
+    cast<CXXRecordDecl>(MPT->getClass()->getAs<RecordType>()->getDecl());
 
   const llvm::FunctionType *FTy = 
     CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(RD, FPT),

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=86030&r1=86029&r2=86030&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Nov  4 10:49:01 2009
@@ -22,6 +22,7 @@
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Parse/DeclSpec.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Support/ErrorHandling.h"
 using namespace clang;
 
 /// \brief Perform adjustment on the parameter type of a function.
@@ -1162,15 +1163,29 @@
       }
       // The scope spec must refer to a class, or be dependent.
       QualType ClsType;
-      if (isDependentScopeSpecifier(DeclType.Mem.Scope())) {
+      if (isDependentScopeSpecifier(DeclType.Mem.Scope())
+            || dyn_cast_or_null<CXXRecordDecl>(
+                                   computeDeclContext(DeclType.Mem.Scope()))) {
         NestedNameSpecifier *NNS
           = (NestedNameSpecifier *)DeclType.Mem.Scope().getScopeRep();
-        assert(NNS->getAsType() && "Nested-name-specifier must name a type");
-        ClsType = QualType(NNS->getAsType(), 0);
-      } else if (CXXRecordDecl *RD
-                   = dyn_cast_or_null<CXXRecordDecl>(
-                                    computeDeclContext(DeclType.Mem.Scope()))) {
-        ClsType = Context.getTagDeclType(RD);
+        NestedNameSpecifier *NNSPrefix = NNS->getPrefix();
+        switch (NNS->getKind()) {
+        case NestedNameSpecifier::Identifier:
+          ClsType = Context.getTypenameType(NNSPrefix, NNS->getAsIdentifier());
+          break;
+
+        case NestedNameSpecifier::Namespace:
+        case NestedNameSpecifier::Global:
+          llvm::llvm_unreachable("Nested-name-specifier must name a type");
+          break;
+            
+        case NestedNameSpecifier::TypeSpec:
+        case NestedNameSpecifier::TypeSpecWithTemplate:
+          ClsType = QualType(NNS->getAsType(), 0);
+          if (NNSPrefix)
+            ClsType = Context.getQualifiedNameType(NNSPrefix, ClsType);
+          break;
+        }
       } else {
         Diag(DeclType.Mem.Scope().getBeginLoc(),
              diag::err_illegal_decl_mempointer_in_nonclass)

Modified: cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp?rev=86030&r1=86029&r2=86030&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ptr-to-datamember.cpp Wed Nov  4 10:49:01 2009
@@ -32,6 +32,15 @@
   F Af;
 }; 
 
+template <typename T> struct TT {
+  int T::t::*pti;
+};
+
+struct I {
+  typedef I t;
+  int x;
+};
+
 void pr(const F& b) {
   printf(" %d %f\n", b.iF, b.fF);
 }
@@ -69,9 +78,12 @@
 int main() 
 {
   A a1;
+  TT<I> tt;
+  I i;
   int A::* pa = &A::Ai;
   float A::* pf = &A::f;
   double A::* pd = &A::d;
+  tt.pti = &I::x;
   printf("%d %d %d\n", &A::Ai, &A::f, &A::d);
   printf("%d\n", &A::B::iB);
   printf("%d\n", &A::B1::iB1);
@@ -81,6 +93,7 @@
   printf("%d\n", &A::B::V::iV);
   printf("%d\n", &A::B1::V::iV);
   printf("%d, %f, %f  \n", a1.*pa, a1.*pf, a1.*pd);
+  printf("%d\n", i.*tt.pti);
   test_aggr_pdata(a1);
   test_aggr_pdata_1(&a1);
 }





More information about the cfe-commits mailing list