]> sourceware.org Git - libabigail.git/commitdiff
Bug 21228 - Handle cloning union member functions
authorDodji Seketeli <dodji@redhat.com>
Tue, 7 Mar 2017 10:14:52 +0000 (11:14 +0100)
committerDodji Seketeli <dodji@redhat.com>
Tue, 7 Mar 2017 10:50:56 +0000 (11:50 +0100)
It turns out we allow member function cloning only for functions that
are members of classes, not for functions that are member of unions.

This patch fixes that by turning the method
class_decl::add_member_function into the
class_or_union::add_member_function.  Note that there was already an
overload of class_or_union::add_member_function; now, all the member
functions add_member_function are members of the class_or_union type.

The patch then modifies function_decl::clone to make that code avoid
assuming that only member functions of classes can be cloned.

* include/abg-ir.h (class_or_union::add_member_function): Move the
class_decl::add_member_function overload declaration into the
class class_or_union class.
(class class_decl): Make the class class_or_union be a friend of
class_decl.
* src/abg-ir.cc (class_decl::add_member_function): Transform the
definition of this overload into ...
(class_or_union::add_member_function): ... this one.  Make sure
that when setting the virtual-ness attributes of the member
function, we are effectively looking at the a function that is a
member of a class.
(function_decl::clone): Do not assert that a member function is
necessarily a member of a class_decl.  It can also a member of a
union_decl!.  So, rather, assert that the scope of the member
function is of type class_or_union.
* tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64.rpm:
New test input RPM.
* tests/data/test-diff-pkg/tbb-2017-9.20170118.fc27.x86_64.rpm:
* tests/data/test-diff-pkg/tbb-debuginfo-2017-8.20161128.fc26.x86_64.rpm:
Likewise.
* tests/data/test-diff-pkg/tbb-debuginfo-2017-9.20170118.fc27.x86_64.rpm:
Likewise.
* tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64--tbb-2017-9.20170118.fc27.x86_64.txt:
New reference test output.
* tests/data/Makefile.am: Add the new test input RPMs to the
source distribution.
* tests/test-diff-pkg.cc (in_out_specs): Take the new input tests
above into account.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
include/abg-ir.h
src/abg-ir.cc
tests/data/Makefile.am
tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64--tbb-2017-9.20170118.fc27.x86_64.txt [new file with mode: 0644]
tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64.rpm [new file with mode: 0644]
tests/data/test-diff-pkg/tbb-2017-9.20170118.fc27.x86_64.rpm [new file with mode: 0644]
tests/data/test-diff-pkg/tbb-debuginfo-2017-8.20161128.fc26.x86_64.rpm [new file with mode: 0644]
tests/data/test-diff-pkg/tbb-debuginfo-2017-9.20170118.fc27.x86_64.rpm [new file with mode: 0644]
tests/test-diff-pkg.cc

index be795c5dcc733489b86b6d2fc1f70e597d4fb0de..d107d151e9de06e923a98c0073fea9084a85ebbb 100644 (file)
@@ -3302,6 +3302,14 @@ public:
                      bool is_static, bool is_ctor,
                      bool is_dtor, bool is_const);
 
+  void
+  add_member_function(method_decl_sptr f,
+                     access_specifier a,
+                     bool is_virtual,
+                     size_t vtable_offset,
+                     bool is_static, bool is_ctor,
+                     bool is_dtor, bool is_const);
+
   const member_functions&
   get_member_functions() const;
 
@@ -3466,14 +3474,6 @@ public:
   class_decl_sptr
   find_base_class(const string&) const;
 
-  void
-  add_member_function(method_decl_sptr f,
-                     access_specifier a,
-                     bool is_virtual,
-                     size_t vtable_offset,
-                     bool is_static, bool is_ctor,
-                     bool is_dtor, bool is_const);
-
   const member_functions&
   get_virtual_mem_fns() const;
 
@@ -3525,6 +3525,7 @@ public:
   equals(const class_decl&, const class_decl&, change_kind*);
 
   friend class method_decl;
+  friend class class_or_union;
 };// end class class_decl
 
 bool
index a5ce2eae78c63ff894640dc71a4c436d416fcf8c..94937d7c754d6155836ab373d700fa85e85b676d 100644 (file)
@@ -13630,7 +13630,7 @@ function_decl::clone() const
                                      get_linkage_name(),
                                      get_visibility(),
                                      get_binding()));
-      class_decl* scope = dynamic_cast<class_decl*>(get_scope());
+      class_or_union* scope = is_class_or_union_type(get_scope());
       assert(scope);
       scope->add_member_function(m, get_member_access_specifier(*this),
                                 get_member_function_is_virtual(*this),
@@ -16377,16 +16377,20 @@ sort_virtual_member_functions(class_decl::member_functions& mem_fns)
   std::sort(mem_fns.begin(), mem_fns.end(), lt);
 }
 
-/// Add a member function to the current instance of class_decl.
+/// Add a member function to the current instance of @ref class_or_union.
 ///
 /// @param f a method_decl to add to the current class.  This function
 /// should not have been already added to a scope.
 ///
 /// @param access the access specifier for the member function to add.
 ///
+/// @param is_virtual if this is true then it means the function @p f
+/// is a virtual function.  That also means that the current instance
+/// of @ref class_or_union is actually an instance of @ref class_decl.
+///
 /// @param vtable_offset the offset of the member function in the
-/// virtual table.  If the member function is not virtual, this offset
-/// must be 0 (zero).
+/// virtual table.  This parameter is taken into account only if @p
+/// is_virtual is true.
 ///
 /// @param is_static whether the member function is static.
 ///
@@ -16396,20 +16400,25 @@ sort_virtual_member_functions(class_decl::member_functions& mem_fns)
 ///
 /// @param is_const whether the member function is const.
 void
-class_decl::add_member_function(method_decl_sptr f,
-                               access_specifier a,
-                               bool is_virtual,
-                               size_t vtable_offset,
-                               bool is_static, bool is_ctor,
-                               bool is_dtor, bool is_const)
-{
-  class_or_union::add_member_function(f, a, is_static, is_ctor,
-                                     is_dtor, is_const);
-  set_member_function_vtable_offset(f, vtable_offset);
-  set_member_function_is_virtual(f, is_virtual);
-
-  if (is_virtual)
-    sort_virtual_member_functions(priv_->virtual_mem_fns_);
+class_or_union::add_member_function(method_decl_sptr f,
+                                   access_specifier a,
+                                   bool is_virtual,
+                                   size_t vtable_offset,
+                                   bool is_static, bool is_ctor,
+                                   bool is_dtor, bool is_const)
+{
+  add_member_function(f, a, is_static, is_ctor,
+                     is_dtor, is_const);
+
+  if (class_decl* klass = is_class_type(this))
+    {
+      set_member_function_is_virtual(f, is_virtual);
+      if (is_virtual)
+       {
+         set_member_function_vtable_offset(f, vtable_offset);
+         sort_virtual_member_functions(klass->priv_->virtual_mem_fns_);
+       }
+    }
 }
 
 /// When a virtual member function has seen its virtualness set by
index 072db544cf5db1cf096d081f833019b4b72fc600..9fd822a4ed7f747594d997c0d76d11e2ca343dcc 100644 (file)
@@ -1247,6 +1247,11 @@ test-diff-pkg/tbb-devel-4.1-9.20130314.fc22.x86_64.rpm \
 test-diff-pkg/tbb-devel-4.3-3.20141204.fc23.x86_64.rpm \
 test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-0.txt \
 test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt \
+test-diff-pkg/tbb-2017-9.20170118.fc27.x86_64.rpm \
+test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64.rpm \
+test-diff-pkg/tbb-debuginfo-2017-8.20161128.fc26.x86_64.rpm \
+test-diff-pkg/tbb-debuginfo-2017-9.20170118.fc27.x86_64.rpm \
+test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64--tbb-2017-9.20170118.fc27.x86_64.txt \
 test-diff-pkg/libICE-debuginfo-1.0.6-1.el6.x86_64.rpm \
 test-diff-pkg/libICE-debuginfo-1.0.9-2.el7.x86_64.rpm \
 test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm \
diff --git a/tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64--tbb-2017-9.20170118.fc27.x86_64.txt b/tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64--tbb-2017-9.20170118.fc27.x86_64.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64.rpm b/tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64.rpm
new file mode 100644 (file)
index 0000000..8dc48da
Binary files /dev/null and b/tests/data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64.rpm differ
diff --git a/tests/data/test-diff-pkg/tbb-2017-9.20170118.fc27.x86_64.rpm b/tests/data/test-diff-pkg/tbb-2017-9.20170118.fc27.x86_64.rpm
new file mode 100644 (file)
index 0000000..59382fd
Binary files /dev/null and b/tests/data/test-diff-pkg/tbb-2017-9.20170118.fc27.x86_64.rpm differ
diff --git a/tests/data/test-diff-pkg/tbb-debuginfo-2017-8.20161128.fc26.x86_64.rpm b/tests/data/test-diff-pkg/tbb-debuginfo-2017-8.20161128.fc26.x86_64.rpm
new file mode 100644 (file)
index 0000000..795d81b
Binary files /dev/null and b/tests/data/test-diff-pkg/tbb-debuginfo-2017-8.20161128.fc26.x86_64.rpm differ
diff --git a/tests/data/test-diff-pkg/tbb-debuginfo-2017-9.20170118.fc27.x86_64.rpm b/tests/data/test-diff-pkg/tbb-debuginfo-2017-9.20170118.fc27.x86_64.rpm
new file mode 100644 (file)
index 0000000..d67b062
Binary files /dev/null and b/tests/data/test-diff-pkg/tbb-debuginfo-2017-9.20170118.fc27.x86_64.rpm differ
index 6e81be197eaaa52a8b23d8271b552e7c32c2b100..06ce41f75cf7f3f68e1ed76ee0453b9e329239d1 100644 (file)
@@ -1,6 +1,6 @@
 // -*- Mode: C++ -*-
 //
-// Copyright (C) 2013-2016 Red Hat, Inc.
+// Copyright (C) 2013-2017 Red Hat, Inc.
 //
 // This file is part of the GNU Application Binary Interface Generic
 // Analysis and Instrumentation Library (libabigail).  This library is
@@ -378,6 +378,18 @@ static InOutSpec in_out_specs[] =
     "data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt",
     "output/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt"
   },
+  {
+    "data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64.rpm",
+    "data/test-diff-pkg/tbb-2017-9.20170118.fc27.x86_64.rpm",
+    "--no-default-suppression",
+    "",
+    "data/test-diff-pkg/tbb-debuginfo-2017-8.20161128.fc26.x86_64.rpm",
+    "data/test-diff-pkg/tbb-debuginfo-2017-9.20170118.fc27.x86_64.rpm",
+    "",
+    "",
+    "data/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64--tbb-2017-9.20170118.fc27.x86_64.txt",
+    "output/test-diff-pkg/tbb-2017-8.20161128.fc26.x86_64--tbb-2017-9.20170118.fc27.x86_64.txt"
+  },
   {
     "data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm",
     "data/test-diff-pkg/libICE-1.0.9-2.el7.x86_64.rpm",
This page took 0.064785 seconds and 5 git commands to generate.