[cfe-commits] r88960 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/SemaCXX/composite-pointer-type.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Mon Nov 16 13:03:45 PST 2009


Author: cornedbee
Date: Mon Nov 16 15:03:45 2009
New Revision: 88960

URL: http://llvm.org/viewvc/llvm-project?rev=88960&view=rev
Log:
Repair broken FindCompositePointerType. Correct early termination condition. Get CVR qualifiers from canonical types. Traverse collected qualifiers in reverse order on rebuilding the pointer, so that we don't swap inner and outer qualifiers. That last one fixes PR5509.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaCXX/composite-pointer-type.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Nov 16 15:03:45 2009
@@ -1884,8 +1884,6 @@
       !T2->isPointerType() && !T2->isMemberPointerType())
    return QualType();
 
-  // FIXME: Do we need to work on the canonical types?
-
   // C++0x 5.9p2
   //   Pointer conversions and qualification conversions are performed on
   //   pointer operands to bring them to their composite pointer type. If
@@ -1907,8 +1905,8 @@
   }
 
   // Now both have to be pointers or member pointers.
-  if (!T1->isPointerType() && !T1->isMemberPointerType() &&
-      !T2->isPointerType() && !T2->isMemberPointerType())
+  if ((!T1->isPointerType() && !T1->isMemberPointerType()) ||
+      (!T2->isPointerType() && !T2->isMemberPointerType()))
     return QualType();
 
   //   Otherwise, of one of the operands has type "pointer to cv1 void," then
@@ -1922,9 +1920,13 @@
   // conversions in both directions. If only one works, or if the two composite
   // types are the same, we have succeeded.
   // FIXME: extended qualifiers?
-  llvm::SmallVector<unsigned, 4> QualifierUnion;
-  llvm::SmallVector<std::pair<const Type *, const Type *>, 4> MemberOfClass;
-  QualType Composite1 = T1, Composite2 = T2;
+  typedef llvm::SmallVector<unsigned, 4> QualifierVector;
+  QualifierVector QualifierUnion;
+  typedef llvm::SmallVector<std::pair<const Type *, const Type *>, 4>
+      ContainingClassVector;
+  ContainingClassVector MemberOfClass;
+  QualType Composite1 = Context.getCanonicalType(T1),
+           Composite2 = Context.getCanonicalType(T2);
   do {
     const PointerType *Ptr1, *Ptr2;
     if ((Ptr1 = Composite1->getAs<PointerType>()) &&
@@ -1956,11 +1958,11 @@
   } while (true);
 
   // Rewrap the composites as pointers or member pointers with the union CVRs.
-  llvm::SmallVector<std::pair<const Type *, const Type *>, 4>::iterator MOC
-    = MemberOfClass.begin();
-  for (llvm::SmallVector<unsigned, 4>::iterator
-         I = QualifierUnion.begin(),
-         E = QualifierUnion.end();
+  ContainingClassVector::reverse_iterator MOC
+    = MemberOfClass.rbegin();
+  for (QualifierVector::reverse_iterator
+         I = QualifierUnion.rbegin(),
+         E = QualifierUnion.rend();
        I != E; (void)++I, ++MOC) {
     Qualifiers Quals = Qualifiers::fromCVRMask(*I);
     if (MOC->first && MOC->second) {

Modified: cfe/trunk/test/SemaCXX/composite-pointer-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/composite-pointer-type.cpp?rev=88960&r1=88959&r2=88960&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/composite-pointer-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/composite-pointer-type.cpp Mon Nov 16 15:03:45 2009
@@ -33,3 +33,13 @@
 int ptrcmp2(long *a, int *b) {
   return a < b; // expected-error{{distinct}}
 }
+
+// PR5509 - Multi-level pointers
+int f2() {
+  typedef int *IntPtr;
+  typedef IntPtr *IntPtrPtr;
+  typedef IntPtr const *IntPtrConstPtr;
+  IntPtrConstPtr i = 0;
+  IntPtrPtr j = 0;
+  return i != j;
+}





More information about the cfe-commits mailing list