Treat function type changes as local.
authorGiuliano Procida <gprocida@google.com>
Thu, 12 Mar 2020 06:30:36 +0000 (06:30 +0000)
committerDodji Seketeli <dodji@redhat.com>
Tue, 17 Mar 2020 12:33:26 +0000 (13:33 +0100)
In leaf-changes-only mode, if the type of a struct's function pointer
member changes it currently gets categorised as a non-local change and
so is not reported. The change to any function passing such a struct
is considered non-local and also not reported.

This patch broadens the definition of local changes to include these
cases and so have them be reported in leaf-changes-only mode. It may
be the first of a sequence of such patches,

* src/abg-ir.cc (types_have_similar_structure): Always compare
function types (instead of just returning true) regardless of
        whether they are components of pointer-to-function or
        reference-to-function types.
* tests/data/Makefile.am: Add new test case files.
* tests/data/test-abidiff-exit/test-leaf2-report.txt: New test
case.
* tests/data/test-abidiff-exit/test-leaf2-v0.cc: Ditto.
* tests/data/test-abidiff-exit/test-leaf2-v0.o: Ditto.
* tests/data/test-abidiff-exit/test-leaf2-v1.cc: Ditto.
* tests/data/test-abidiff-exit/test-leaf2-v1.o: Ditto.
* tests/test-abidiff-exit.cc: Run new test case.

Signed-off-by: Giuliano Procida <gprocida@google.com>
src/abg-ir.cc
tests/data/Makefile.am
tests/data/test-abidiff-exit/test-leaf2-report.txt [new file with mode: 0644]
tests/data/test-abidiff-exit/test-leaf2-v0.cc [new file with mode: 0644]
tests/data/test-abidiff-exit/test-leaf2-v0.o [new file with mode: 0644]
tests/data/test-abidiff-exit/test-leaf2-v1.cc [new file with mode: 0644]
tests/data/test-abidiff-exit/test-leaf2-v1.o [new file with mode: 0644]
tests/test-abidiff-exit.cc

index 3b1577a81e1833b8dcf02b1ebb8c7a2409996902..2cb76ffc89d81e97fe00958cfd84af1cfbe36ca2 100644 (file)
@@ -22745,25 +22745,25 @@ types_have_similar_structure(const type_base* first, const type_base* second)
   if (const function_type* ty1 = is_function_type(first))
     {
       const function_type* ty2 = is_function_type(second);
-      if (!was_indirect_type)
-       {
-         if (!types_have_similar_structure(ty1->get_return_type(),
-                                           ty2->get_return_type()))
-           return false;
+      if (!ty2)
+       return false;
 
-         if (ty1->get_parameters().size() != ty2->get_parameters().size())
-           return false;
+      if (!types_have_similar_structure(ty1->get_return_type(),
+                                       ty2->get_return_type()))
+       return false;
 
-         for (function_type::parameters::const_iterator
-                i = ty1->get_parameters().begin(),
-                j = ty2->get_parameters().begin();
-              (i != ty1->get_parameters().end()
-               && j != ty2->get_parameters().end());
-              ++i, ++j)
-           if (!types_have_similar_structure((*i)->get_type(),
-                                             (*j)->get_type()))
-             return false;
-       }
+      if (ty1->get_parameters().size() != ty2->get_parameters().size())
+       return false;
+
+      for (function_type::parameters::const_iterator
+            i = ty1->get_parameters().begin(),
+            j = ty2->get_parameters().begin();
+          (i != ty1->get_parameters().end()
+           && j != ty2->get_parameters().end());
+          ++i, ++j)
+       if (!types_have_similar_structure((*i)->get_type(),
+                                         (*j)->get_type()))
+         return false;
 
       return true;
     }
index bf76ca2e617b5d7292153e1aabdd17cb897e291e..3b4b614b0cfd0805e3e1a0f9e5d2b8fd226b9b83 100644 (file)
@@ -120,6 +120,11 @@ test-abidiff-exit/test-leaf1-v0.o \
 test-abidiff-exit/test-leaf1-v1.cc \
 test-abidiff-exit/test-leaf1-v1.o \
 test-abidiff-exit/test-leaf1-report.txt \
+test-abidiff-exit/test-leaf2-v0.cc \
+test-abidiff-exit/test-leaf2-v0.o \
+test-abidiff-exit/test-leaf2-v1.cc \
+test-abidiff-exit/test-leaf2-v1.o \
+test-abidiff-exit/test-leaf2-report.txt \
 test-abidiff-exit/test-leaf3-v0.c \
 test-abidiff-exit/test-leaf3-v0.o \
 test-abidiff-exit/test-leaf3-v1.c \
diff --git a/tests/data/test-abidiff-exit/test-leaf2-report.txt b/tests/data/test-abidiff-exit/test-leaf2-report.txt
new file mode 100644 (file)
index 0000000..2765b46
--- /dev/null
@@ -0,0 +1,12 @@
+Leaf changes summary: 1 artifact changed
+Changed leaf types summary: 1 leaf type changed
+Removed/Changed/Added functions summary: 0 Removed, 0 Changed, 0 Added function
+Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable
+
+'struct ops' changed:
+  type size hasn't changed
+  there are data member changes:
+    type 'void (int)*' of 'ops::munge' changed:
+      pointer type changed from: 'void (int)*' to: 'char (long int, bool)*'
+
+
diff --git a/tests/data/test-abidiff-exit/test-leaf2-v0.cc b/tests/data/test-abidiff-exit/test-leaf2-v0.cc
new file mode 100644 (file)
index 0000000..b75dd84
--- /dev/null
@@ -0,0 +1,6 @@
+struct ops {
+  void (*munge)(int x);
+};
+
+void register_ops(const ops&) {
+}
diff --git a/tests/data/test-abidiff-exit/test-leaf2-v0.o b/tests/data/test-abidiff-exit/test-leaf2-v0.o
new file mode 100644 (file)
index 0000000..211a338
Binary files /dev/null and b/tests/data/test-abidiff-exit/test-leaf2-v0.o differ
diff --git a/tests/data/test-abidiff-exit/test-leaf2-v1.cc b/tests/data/test-abidiff-exit/test-leaf2-v1.cc
new file mode 100644 (file)
index 0000000..f308a34
--- /dev/null
@@ -0,0 +1,6 @@
+struct ops {
+  char (*munge)(long x, bool gunk);
+};
+
+void register_ops(const ops&) {
+}
diff --git a/tests/data/test-abidiff-exit/test-leaf2-v1.o b/tests/data/test-abidiff-exit/test-leaf2-v1.o
new file mode 100644 (file)
index 0000000..9db3ed5
Binary files /dev/null and b/tests/data/test-abidiff-exit/test-leaf2-v1.o differ
index 5967863dc405efafb642de7e83835746cf999813..6ecbfd249ecd918fa4033d004c04312689fbe894 100644 (file)
@@ -140,6 +140,15 @@ InOutSpec in_out_specs[] =
     "data/test-abidiff-exit/test-leaf1-report.txt",
     "output/test-abidiff-exit/test-leaf1-report.txt"
   },
+  {
+    "data/test-abidiff-exit/test-leaf2-v0.o",
+    "data/test-abidiff-exit/test-leaf2-v1.o",
+    "",
+    "--no-show-locs --leaf-changes-only",
+    abigail::tools_utils::ABIDIFF_ABI_CHANGE,
+    "data/test-abidiff-exit/test-leaf2-report.txt",
+    "output/test-abidiff-exit/test-leaf2-report.txt"
+  },
   {
     "data/test-abidiff-exit/test-leaf3-v0.o",
     "data/test-abidiff-exit/test-leaf3-v1.o",