[cfe-commits] r77663 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/Type.h lib/AST/ASTContext.cpp lib/AST/Type.cpp test/SemaTemplate/canonical-expr-type.cpp

Douglas Gregor dgregor at apple.com
Thu Jul 30 20:54:35 PDT 2009


Author: dgregor
Date: Thu Jul 30 22:54:25 2009
New Revision: 77663

URL: http://llvm.org/viewvc/llvm-project?rev=77663&view=rev
Log:
Canonicalize dependent extended vector types.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=77663&r1=77662&r2=77663&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Jul 30 22:54:25 2009
@@ -71,7 +71,7 @@
   llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
   std::vector<VariableArrayType*> VariableArrayTypes;
   llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
-  std::vector<DependentSizedExtVectorType*> DependentSizedExtVectorTypes;
+  llvm::FoldingSet<DependentSizedExtVectorType> DependentSizedExtVectorTypes;
   llvm::FoldingSet<VectorType> VectorTypes;
   llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
   llvm::FoldingSet<FunctionProtoType> FunctionProtoTypes;

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=77663&r1=77662&r2=77663&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Jul 30 22:54:25 2009
@@ -1235,21 +1235,23 @@
 ///   typedef T __attribute__((ext_vector_type(Size))) type;
 /// }
 /// @endcode
-class DependentSizedExtVectorType : public Type {
+class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
+  ASTContext &Context;
   Expr *SizeExpr;
   /// ElementType - The element type of the array.
   QualType ElementType;
   SourceLocation loc;
   
-  DependentSizedExtVectorType(QualType ElementType, QualType can, 
-                              Expr *SizeExpr, SourceLocation loc)
+  DependentSizedExtVectorType(ASTContext &Context, QualType ElementType, 
+                              QualType can, Expr *SizeExpr, SourceLocation loc)
     : Type (DependentSizedExtVector, can, true), 
-    SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {}
+      Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), 
+      loc(loc) {}
   friend class ASTContext;
   virtual void Destroy(ASTContext& C);
 
 public:
-  const Expr *getSizeExpr() const { return SizeExpr; }
+  Expr *getSizeExpr() const { return SizeExpr; }
   QualType getElementType() const { return ElementType; }
   SourceLocation getAttributeLoc() const { return loc; }
 
@@ -1260,6 +1262,13 @@
     return T->getTypeClass() == DependentSizedExtVector; 
   }
   static bool classof(const DependentSizedExtVectorType *) { return true; } 
+
+  void Profile(llvm::FoldingSetNodeID &ID) {
+    Profile(ID, Context, getElementType(), getSizeExpr());
+  }
+  
+  static void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
+                      QualType ElementType, Expr *SizeExpr);
 };
   
 

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

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Jul 30 22:54:25 2009
@@ -1515,11 +1515,35 @@
 QualType ASTContext::getDependentSizedExtVectorType(QualType vecType, 
                                                     Expr *SizeExpr,
                                                     SourceLocation AttrLoc) {
-  DependentSizedExtVectorType *New =
-      new (*this,8) DependentSizedExtVectorType(vecType, QualType(), 
-                                                SizeExpr, AttrLoc);
-
-  DependentSizedExtVectorTypes.push_back(New);
+  llvm::FoldingSetNodeID ID;
+  DependentSizedExtVectorType::Profile(ID, *this, getCanonicalType(vecType), 
+                                       SizeExpr);
+  
+  void *InsertPos = 0;
+  DependentSizedExtVectorType *Canon
+    = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
+  DependentSizedExtVectorType *New;
+  if (Canon) {
+    // We already have a canonical version of this array type; use it as
+    // the canonical type for a newly-built type.
+    New = new (*this,8) DependentSizedExtVectorType(*this, vecType,
+                                                    QualType(Canon, 0),
+                                                    SizeExpr, AttrLoc);
+  } else {
+    QualType CanonVecTy = getCanonicalType(vecType);
+    if (CanonVecTy == vecType) {
+      New = new (*this,8) DependentSizedExtVectorType(*this, vecType, 
+                                                      QualType(), SizeExpr, 
+                                                      AttrLoc);
+      DependentSizedExtVectorTypes.InsertNode(New, InsertPos);
+    } else {
+      QualType Canon = getDependentSizedExtVectorType(CanonVecTy, SizeExpr,
+                                                      SourceLocation());
+      New = new (*this,8) DependentSizedExtVectorType(*this, vecType, Canon,
+                                                      SizeExpr, AttrLoc);
+    }
+  }
+  
   Types.push_back(New);
   return QualType(New, 0);
 }

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

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Thu Jul 30 22:54:25 2009
@@ -76,6 +76,14 @@
   E->Profile(ID, Context, true);
 }
 
+void 
+DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, 
+                                     ASTContext &Context,
+                                     QualType ElementType, Expr *SizeExpr) {
+  ID.AddPointer(ElementType.getAsOpaquePtr());
+  SizeExpr->Profile(ID, Context, true);
+}
+
 void DependentSizedExtVectorType::Destroy(ASTContext& C) {
   // FIXME: Deallocate size expression, once we're cloning properly.
 //  if (SizeExpr)

Modified: cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp?rev=77663&r1=77662&r2=77663&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp (original)
+++ cfe/trunk/test/SemaTemplate/canonical-expr-type.cpp Thu Jul 30 22:54:25 2009
@@ -24,3 +24,15 @@
 
 template<typename T, int M, int N>
 void f1(T (&array)[M + N]) { } // expected-error{{redefinition}}
+
+// Test dependently-sized extended vector type canonicalization
+template<typename T, int N, int M>
+struct X2 {
+  typedef T __attribute__((ext_vector_type(N))) type1;
+  typedef T __attribute__((ext_vector_type(M))) type2;
+  typedef T __attribute__((ext_vector_type(N))) type3;
+  
+  void f0(type1); // expected-note{{previous}}
+  void f0(type2);
+  void f0(type3); // expected-error{{redeclared}}
+};





More information about the cfe-commits mailing list