[cfe-commits] r126503 - in /cfe/trunk: include/clang/Sema/Overload.h lib/Sema/SemaExprCXX.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaOverload.cpp

Chandler Carruth chandlerc at gmail.com
Fri Feb 25 11:41:06 PST 2011


Author: chandlerc
Date: Fri Feb 25 13:41:05 2011
New Revision: 126503

URL: http://llvm.org/viewvc/llvm-project?rev=126503&view=rev
Log:
Remove the FIXME I introduced last night, and pull the logic for
marking selected overloads into the callers. This allows a few callers
to skip it altogether (they would have anyways because they weren't
interested in successful overloads) or defer until after further checks
take place much like the check required for PR9323 to avoid marking
unused copy constructors.

Modified:
    cfe/trunk/include/clang/Sema/Overload.h
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=126503&r1=126502&r2=126503&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Fri Feb 25 13:41:05 2011
@@ -653,8 +653,7 @@
     /// Find the best viable function on this overload set, if it exists.
     OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc,
                                          OverloadCandidateSet::iterator& Best,
-                                         bool UserDefinedConversion = false,
-                                         bool IsExtraneousCopy = false);
+                                         bool UserDefinedConversion = false);
 
     void NoteCandidates(Sema &S,
                         OverloadCandidateDisplayKind OCD,

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=126503&r1=126502&r2=126503&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Feb 25 13:41:05 2011
@@ -1349,6 +1349,7 @@
   case OR_Success: {
     // Got one!
     FunctionDecl *FnDecl = Best->Function;
+    MarkDeclarationReferenced(StartLoc, FnDecl);
     // The first argument is size_t, and the first parameter must be size_t,
     // too. This is checked on declaration and can be assumed. (It can't be
     // asserted on, though, since invalid decls are left in there.)
@@ -2922,6 +2923,8 @@
           Self.PerformImplicitConversion(RHS, Best->BuiltinTypes.ParamTypes[1],
                                          Best->Conversions[1], Sema::AA_Converting))
         break;
+      if (Best->Function)
+        Self.MarkDeclarationReferenced(QuestionLoc, Best->Function);
       return false;
 
     case OR_No_Viable_Function:

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=126503&r1=126502&r2=126503&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Feb 25 13:41:05 2011
@@ -2441,6 +2441,10 @@
 
   FunctionDecl *Function = Best->Function;
 
+  // This is the overload that will actually be used for the initialization, so
+  // mark it as used.
+  S.MarkDeclarationReferenced(DeclLoc, Function);
+
   // Compute the returned type of the conversion.
   if (isa<CXXConversionDecl>(Function))
     T2 = Function->getResultType();
@@ -3045,6 +3049,7 @@
   }
 
   FunctionDecl *Function = Best->Function;
+  S.MarkDeclarationReferenced(DeclLoc, Function);
 
   if (isa<CXXConstructorDecl>(Function)) {
     // Add the user-defined conversion step. Any cv-qualification conversion is
@@ -3478,9 +3483,7 @@
   }
 
   OverloadCandidateSet::iterator Best;
-  switch (CandidateSet.BestViableFunction(S, Loc, Best,
-                                          /*UserDefinedConversion=*/ false,
-                                          IsExtraneousCopy)) {
+  switch (CandidateSet.BestViableFunction(S, Loc, Best)) {
   case OR_Success:
     break;
 
@@ -3544,6 +3547,8 @@
     return S.Owned(CurInitExpr);
   }
 
+  S.MarkDeclarationReferenced(Loc, Constructor);
+
   // Determine the arguments required to actually perform the
   // constructor call (we might have derived-to-base conversions, or
   // the copy constructor may have default arguments).

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=126503&r1=126502&r2=126503&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Feb 25 13:41:05 2011
@@ -2261,6 +2261,8 @@
     // Record the standard conversion we used and the conversion function.
     if (CXXConstructorDecl *Constructor
           = dyn_cast<CXXConstructorDecl>(Best->Function)) {
+      S.MarkDeclarationReferenced(From->getLocStart(), Constructor);
+
       // C++ [over.ics.user]p1:
       //   If the user-defined conversion is specified by a
       //   constructor (12.3.1), the initial standard conversion
@@ -2282,6 +2284,8 @@
       return OR_Success;
     } else if (CXXConversionDecl *Conversion
                  = dyn_cast<CXXConversionDecl>(Best->Function)) {
+      S.MarkDeclarationReferenced(From->getLocStart(), Conversion);
+
       // C++ [over.ics.user]p1:
       //
       //   [...] If the user-defined conversion is specified by a
@@ -3068,6 +3072,8 @@
     if (!Best->FinalConversion.DirectBinding)
       return false;
 
+    if (Best->Function)
+      S.MarkDeclarationReferenced(DeclLoc, Best->Function);
     ICS.setUserDefined();
     ICS.UserDefined.Before = Best->Conversions[0].Standard;
     ICS.UserDefined.After = Best->FinalConversion;
@@ -6248,8 +6254,7 @@
 OverloadingResult
 OverloadCandidateSet::BestViableFunction(Sema &S, SourceLocation Loc,
                                          iterator &Best,
-                                         bool UserDefinedConversion,
-                                         bool IsExtraneousCopy) {
+                                         bool UserDefinedConversion) {
   // Find the best viable function.
   Best = end();
   for (iterator Cand = begin(); Cand != end(); ++Cand) {
@@ -6281,21 +6286,6 @@
        Best->Function->getAttr<UnavailableAttr>()))
     return OR_Deleted;
 
-  // C++ [basic.def.odr]p2:
-  //   An overloaded function is used if it is selected by overload resolution
-  //   when referred to from a potentially-evaluated expression. [Note: this
-  //   covers calls to named functions (5.2.2), operator overloading
-  //   (clause 13), user-defined conversions (12.3.2), allocation function for
-  //   placement new (5.3.4), as well as non-default initialization (8.5).
-  //
-  // As a special exception, we don't mark functions selected for extraneous
-  // copy constructor calls as used; the nature of extraneous copy constructor
-  // calls is that they are never in fact called.
-  // FIXME: This doesn't seem like the right approach. Should we be doing
-  // overload resolution at all for extraneous copies?
-  if (Best->Function && !IsExtraneousCopy)
-    S.MarkDeclarationReferenced(Loc, Best->Function);
-
   return OR_Success;
 }
 
@@ -7687,6 +7677,7 @@
   switch (CandidateSet.BestViableFunction(*this, Fn->getLocStart(), Best)) {
   case OR_Success: {
     FunctionDecl *FDecl = Best->Function;
+    MarkDeclarationReferenced(Fn->getExprLoc(), FDecl);
     CheckUnresolvedLookupAccess(ULE, Best->FoundDecl);
     DiagnoseUseOfDecl(FDecl? FDecl : Best->FoundDecl.getDecl(),
                       ULE->getNameLoc());
@@ -7833,6 +7824,8 @@
       // We matched an overloaded operator. Build a call to that
       // operator.
 
+      MarkDeclarationReferenced(OpLoc, FnDecl);
+
       // Convert the arguments.
       if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FnDecl)) {
         CheckMemberOperatorAccess(OpLoc, Args[0], 0, Best->FoundDecl);
@@ -8056,6 +8049,8 @@
         // We matched an overloaded operator. Build a call to that
         // operator.
 
+        MarkDeclarationReferenced(OpLoc, FnDecl);
+
         // Convert the arguments.
         if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FnDecl)) {
           // Best->Access is only meaningful for class members.
@@ -8237,6 +8232,8 @@
         // We matched an overloaded operator. Build a call to that
         // operator.
 
+        MarkDeclarationReferenced(LLoc, FnDecl);
+
         CheckMemberOperatorAccess(LLoc, Args[0], Args[1], Best->FoundDecl);
         DiagnoseUseOfDecl(Best->FoundDecl, LLoc);
 
@@ -8408,6 +8405,7 @@
                                             Best)) {
     case OR_Success:
       Method = cast<CXXMethodDecl>(Best->Function);
+      MarkDeclarationReferenced(UnresExpr->getMemberLoc(), Method);
       FoundDecl = Best->FoundDecl;
       CheckUnresolvedMemberAccess(UnresExpr, Best->FoundDecl);
       DiagnoseUseOfDecl(Best->FoundDecl, UnresExpr->getNameLoc());
@@ -8635,6 +8633,7 @@
                          RParenLoc);
   }
 
+  MarkDeclarationReferenced(LParenLoc, Best->Function);
   CheckMemberOperatorAccess(LParenLoc, Object, 0, Best->FoundDecl);
   DiagnoseUseOfDecl(Best->FoundDecl, LParenLoc);
 
@@ -8813,6 +8812,7 @@
     return ExprError();
   }
 
+  MarkDeclarationReferenced(OpLoc, Best->Function);
   CheckMemberOperatorAccess(OpLoc, Base, 0, Best->FoundDecl);
   DiagnoseUseOfDecl(Best->FoundDecl, OpLoc);
 





More information about the cfe-commits mailing list