[PATCH] D28310: Add virtual functions getter

Piotr Padlewski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 4 12:48:49 PST 2017


Prazek created this revision.
Prazek added a reviewer: rjmccall.
Prazek added a subscriber: cfe-commits.

Small refactor


https://reviews.llvm.org/D28310

Files:
  include/clang/AST/VTableBuilder.h
  lib/CodeGen/ItaniumCXXABI.cpp


Index: lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -367,19 +367,12 @@
 
  private:
    bool hasAnyVirtualInlineFunction(const CXXRecordDecl *RD) const {
-    const auto &VtableLayout =
-        CGM.getItaniumVTableContext().getVTableLayout(RD);
-
-    for (const auto &VtableComponent : VtableLayout.vtable_components()) {
-      // Skip empty slot.
-      if (!VtableComponent.isUsedFunctionPointerKind())
-        continue;
-
-      const CXXMethodDecl *Method = VtableComponent.getFunctionDecl();
-      if (Method->getCanonicalDecl()->isInlined())
-        return true;
-    }
-    return false;
+     const auto &VTableLayout =
+         CGM.getItaniumVTableContext().getVTableLayout(RD);
+     for (const auto *VFunction : VTableLayout.virtualFunctions())
+       if (VFunction->getCanonicalDecl()->isInlined())
+         return true;
+     return false;
   }
 
   bool isVTableHidden(const CXXRecordDecl *RD) const {
Index: include/clang/AST/VTableBuilder.h
===================================================================
--- include/clang/AST/VTableBuilder.h
+++ include/clang/AST/VTableBuilder.h
@@ -254,6 +254,17 @@
     return VTableThunks;
   }
 
+  llvm::SmallVector<const CXXMethodDecl *, 8> virtualFunctions() const {
+    llvm::SmallVector<const CXXMethodDecl *, 8> VFunctions;
+    for (const auto &VtableComponent : vtable_components()) {
+      // Skip everything except functions.
+      if (!VtableComponent.isUsedFunctionPointerKind())
+        continue;
+      VFunctions.push_back(VtableComponent.getFunctionDecl());
+    }
+    return VFunctions;
+  }
+
   AddressPointLocation getAddressPoint(BaseSubobject Base) const {
     assert(AddressPoints.count(Base) && "Did not find address point!");
     return AddressPoints.find(Base)->second;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28310.83109.patch
Type: text/x-patch
Size: 1895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170104/7ccb3299/attachment.bin>


More information about the cfe-commits mailing list