[cfe-commits] r96695 - /cfe/trunk/lib/CodeGen/CGVtable.cpp

Anders Carlsson andersca at mac.com
Fri Feb 19 12:08:13 PST 2010


Author: andersca
Date: Fri Feb 19 14:08:13 2010
New Revision: 96695

URL: http://llvm.org/viewvc/llvm-project?rev=96695&view=rev
Log:
Add the CK_UnusedFunctionPointer component kind for unused function pointers.

Modified:
    cfe/trunk/lib/CodeGen/CGVtable.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Fri Feb 19 14:08:13 2010
@@ -668,7 +668,12 @@
     CK_CompleteDtorPointer,
     
     /// CK_DeletingDtorPointer - A pointer to the deleting destructor.
-    CK_DeletingDtorPointer
+    CK_DeletingDtorPointer,
+    
+    /// CK_UnusedFunctionPointer - In some cases, a vtable function pointer
+    /// will end up never being called. Such vtable function pointers are
+    /// represented as a CK_UnusedFunctionPointer. 
+    CK_UnusedFunctionPointer
   };
 
   static VtableComponent MakeVCallOffset(int64_t Offset) {
@@ -705,6 +710,13 @@
                            reinterpret_cast<uintptr_t>(DD));
   }
 
+  static VtableComponent MakeUnusedFunction(const CXXMethodDecl *MD) {
+    assert(!isa<CXXDestructorDecl>(MD) && 
+           "Don't use MakeUnusedFunction with destructors!");
+    return VtableComponent(CK_UnusedFunctionPointer,
+                           reinterpret_cast<uintptr_t>(MD));                           
+  }
+
   /// getKind - Get the kind of this vtable component.
   Kind getKind() const {
     return (Kind)(Value & 0x7);
@@ -747,6 +759,12 @@
     return reinterpret_cast<CXXDestructorDecl *>(getPointer());
   }
 
+  const CXXMethodDecl *getUnusedFunctionDecl() const {
+    assert(getKind() == CK_UnusedFunctionPointer);
+    
+    return reinterpret_cast<CXXMethodDecl *>(getPointer());
+  }
+  
 private:
   VtableComponent(Kind ComponentKind, int64_t Offset) {
     assert((ComponentKind == CK_VCallOffset || 
@@ -761,7 +779,8 @@
     assert((ComponentKind == CK_RTTI || 
             ComponentKind == CK_FunctionPointer ||
             ComponentKind == CK_CompleteDtorPointer ||
-            ComponentKind == CK_DeletingDtorPointer) &&
+            ComponentKind == CK_DeletingDtorPointer ||
+            ComponentKind == CK_UnusedFunctionPointer) &&
             "Invalid component kind!");
     
     assert((Ptr & 7) == 0 && "Pointer not sufficiently aligned!");
@@ -780,7 +799,8 @@
     assert((getKind() == CK_RTTI || 
             getKind() == CK_FunctionPointer ||
             getKind() == CK_CompleteDtorPointer ||
-            getKind() == CK_DeletingDtorPointer) &&
+            getKind() == CK_DeletingDtorPointer ||
+            getKind() == CK_UnusedFunctionPointer) &&
            "Invalid component kind!");
     
     return static_cast<uintptr_t>(Value & ~7ULL);
@@ -1589,6 +1609,17 @@
       break;
     }
 
+    case VtableComponent::CK_UnusedFunctionPointer: {
+      const CXXMethodDecl *MD = Component.getUnusedFunctionDecl();
+
+      std::string Str = 
+        PredefinedExpr::ComputeName(PredefinedExpr::PrettyFunctionNoVirtual, 
+                                    MD);
+      Out << "[unused] " << Str;
+      if (MD->isPure())
+        Out << " [pure]";
+    }
+
     }
 
     Out << '\n';





More information about the cfe-commits mailing list