[cfe-commits] r94744 - in /cfe/trunk: include/clang/AST/UnresolvedSet.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaOverload.cpp test/CXX/class.access/p4.cpp

John McCall rjmccall at apple.com
Wed Jan 27 23:38:47 PST 2010


Author: rjmccall
Date: Thu Jan 28 01:38:46 2010
New Revision: 94744

URL: http://llvm.org/viewvc/llvm-project?rev=94744&view=rev
Log:
Access control for surrogate function calls.  Required a moderately gross hack
to get the access bits set properly in conversion sets.


Modified:
    cfe/trunk/include/clang/AST/UnresolvedSet.h
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/CXX/class.access/p4.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/UnresolvedSet.h (original)
+++ cfe/trunk/include/clang/AST/UnresolvedSet.h Thu Jan 28 01:38:46 2010
@@ -147,6 +147,10 @@
     decls().pop_back();
   }
 
+  void setAccess(iterator I, AccessSpecifier AS) {
+    I.ir->setInt(AS);
+  }
+
   void clear() { decls().clear(); }
   void set_size(unsigned N) { decls().set_size(N); }
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jan 28 01:38:46 2010
@@ -2086,6 +2086,11 @@
   if (Record->isInvalidDecl())
     return;
 
+  // Set access bits correctly on the directly-declared conversions.
+  UnresolvedSetImpl *Convs = Record->getConversionFunctions();
+  for (UnresolvedSetIterator I = Convs->begin(), E = Convs->end(); I != E; ++I)
+    Convs->setAccess(I, (*I)->getAccess());
+
   if (!Record->isAbstract()) {
     // Collect all the pure virtual methods and see if this is an abstract
     // class after all.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Jan 28 01:38:46 2010
@@ -6231,7 +6231,7 @@
       = cast<CXXConversionDecl>(
                          Best->Conversions[0].UserDefined.ConversionFunction);
 
-    // FIXME: access control
+    CheckMemberOperatorAccess(LParenLoc, Object, Conv, Best->getAccess());
 
     // We selected one of the surrogate functions that converts the
     // object parameter to a function pointer. Perform the conversion
@@ -6246,8 +6246,8 @@
                          CommaLocs, RParenLoc).release();
   }
 
-  if (getLangOptions().AccessControl)
-    CheckAccess(R, Best->Function, Best->getAccess());
+  CheckMemberOperatorAccess(LParenLoc, Object,
+                            Best->Function, Best->getAccess());
 
   // We found an overloaded operator(). Build a CXXOperatorCallExpr
   // that calls this method, using Object for the implicit object

Modified: cfe/trunk/test/CXX/class.access/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/p4.cpp?rev=94744&r1=94743&r2=94744&view=diff

==============================================================================
--- cfe/trunk/test/CXX/class.access/p4.cpp (original)
+++ cfe/trunk/test/CXX/class.access/p4.cpp Thu Jan 28 01:38:46 2010
@@ -39,15 +39,21 @@
     void operator+(Public&);
     void operator[](Public&);
     void operator()(Public&);
+    typedef void (*PublicSurrogate)(Public&);
+    operator PublicSurrogate() const;
   protected:
     void operator+(Protected&); // expected-note {{declared protected here}}
     void operator[](Protected&); // expected-note {{declared protected here}}
     void operator()(Protected&); // expected-note {{declared protected here}}
+    typedef void (*ProtectedSurrogate)(Protected&);
+    operator ProtectedSurrogate() const; // expected-note {{declared protected here}}
   private:
     void operator+(Private&); // expected-note {{declared private here}}
     void operator[](Private&); // expected-note {{declared private here}}
     void operator()(Private&); // expected-note {{declared private here}}
     void operator-(); // expected-note {{declared private here}}
+    typedef void (*PrivateSurrogate)(Private&);
+    operator PrivateSurrogate() const; // expected-note {{declared private here}}
   };
   void operator+(const A &, Public&);
   void operator+(const A &, Protected&);
@@ -71,5 +77,9 @@
     ca + prot;
     ca + priv;
     -ca;
+    // These are all surrogate calls
+    ca(pub);
+    ca(prot); // expected-error {{access to protected member}}
+    ca(priv); // expected-error {{access to private member}}
   }
 }





More information about the cfe-commits mailing list