[applied] Bug 27598 - abidiff mishandles union member functions

Message ID 87blazusqj.fsf@redhat.com
State Committed
Headers
Series [applied] Bug 27598 - abidiff mishandles union member functions |

Commit Message

Dodji Seketeli March 31, 2021, 5:40 p.m. UTC
  Hello,

abidiff segfaults when a union member function is involved in the
comparison.  This patch fixes that.

	* src/abg-default-reporter.cc (default_reporter::report): Assume
	the parent type of the method can be either a class or a union.
	* tests/data/test-diff-filter/test-PR27598-report-0.txt: New
	reference output for the test.
	* tests/data/test-diff-filter/test-PR27598-v{0,1}.cc: New source
	code for the input binaries below.
	* tests/data/test-diff-filter/test-PR27598-v{0,1}.o: New input
	test binaries.
	* tests/data/Makefile.am: Add the new test material to source
	distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the test inputs
	above to this test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>

Applied to master.

---
 src/abg-default-reporter.cc                   |  23 ++++++++++++------
 tests/data/Makefile.am                        |   5 ++++
 .../test-PR27598-report-0.txt                 |   0
 .../data/test-diff-filter/test-PR27598-v0.cc  |  14 +++++++++++
 tests/data/test-diff-filter/test-PR27598-v0.o | Bin 0 -> 3992 bytes
 .../data/test-diff-filter/test-PR27598-v1.cc  |  12 +++++++++
 tests/data/test-diff-filter/test-PR27598-v1.o | Bin 0 -> 3912 bytes
 tests/test-diff-filter.cc                     |   7 ++++++
 8 files changed, 53 insertions(+), 8 deletions(-)
 create mode 100644 tests/data/test-diff-filter/test-PR27598-report-0.txt
 create mode 100644 tests/data/test-diff-filter/test-PR27598-v0.cc
 create mode 100644 tests/data/test-diff-filter/test-PR27598-v0.o
 create mode 100644 tests/data/test-diff-filter/test-PR27598-v1.cc
 create mode 100644 tests/data/test-diff-filter/test-PR27598-v1.o
  

Patch

diff --git a/src/abg-default-reporter.cc b/src/abg-default-reporter.cc
index 9940fc07..a5cebef4 100644
--- a/src/abg-default-reporter.cc
+++ b/src/abg-default-reporter.cc
@@ -1575,19 +1575,26 @@  default_reporter::report(const function_decl_diff& d, ostream& out,
 	      << " to " << sf_vtable_offset << "\n";
 	}
 
-      // the classes of the two member functions.
-      class_decl_sptr fc =
-	is_class_type(is_method_type(ff->get_type())->get_class_type());
-      class_decl_sptr sc =
-	is_class_type(is_method_type(sf->get_type())->get_class_type());
+      // the parent types (classe or union) of the two member
+      // functions.
+      class_or_union_sptr f =
+	is_class_or_union_type(is_method_type(ff->get_type())->get_class_type());
+      class_or_union_sptr s =
+	is_class_or_union_type(is_method_type(sf->get_type())->get_class_type());
+
+      class_decl_sptr fc = is_class_type(f);
+      class_decl_sptr sc = is_class_type(s);
 
       // Detect if the virtual member function changes above
       // introduced a vtable change or not.
       bool vtable_added = false, vtable_removed = false;
-      if (!fc->get_is_declaration_only() && !sc->get_is_declaration_only())
+      if (!f->get_is_declaration_only() && !s->get_is_declaration_only())
 	{
-	  vtable_added = !fc->has_vtable() && sc->has_vtable();
-	  vtable_removed = fc->has_vtable() && !sc->has_vtable();
+	  if (fc && sc)
+	    {
+	      vtable_added = !fc->has_vtable() && sc->has_vtable();
+	      vtable_removed = fc->has_vtable() && !sc->has_vtable();
+	    }
 	}
       bool vtable_changed = ((ff_is_virtual != sf_is_virtual)
 			     || (ff_vtable_offset != sf_vtable_offset));
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index 0b406f3b..ab3d2490 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -927,6 +927,11 @@  test-diff-filter/test-PR27331-report-0.txt   \
 test-diff-filter/test-PR27569-v0.abi	     \
 test-diff-filter/test-PR27569-v1.abi         \
 test-diff-filter/test-PR27569-report-0.txt   \
+test-diff-filter/test-PR27598-v0.cc          \
+test-diff-filter/test-PR27598-v0.o           \
+test-diff-filter/test-PR27598-v1.cc          \
+test-diff-filter/test-PR27598-v1.o           \
+test-diff-filter/test-PR27598-report-0.txt   \
 \
 test-diff-suppr/test0-type-suppr-v0.cc	\
 test-diff-suppr/test0-type-suppr-v1.cc	\
diff --git a/tests/data/test-diff-filter/test-PR27598-report-0.txt b/tests/data/test-diff-filter/test-PR27598-report-0.txt
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/data/test-diff-filter/test-PR27598-v0.cc b/tests/data/test-diff-filter/test-PR27598-v0.cc
new file mode 100644
index 00000000..b31dee45
--- /dev/null
+++ b/tests/data/test-diff-filter/test-PR27598-v0.cc
@@ -0,0 +1,14 @@ 
+union S
+{
+  void bar() const
+  {
+  }
+
+  int needed;
+};
+
+void
+fun(S s)
+{
+  s.bar();
+}
diff --git a/tests/data/test-diff-filter/test-PR27598-v0.o b/tests/data/test-diff-filter/test-PR27598-v0.o
new file mode 100644
index 0000000000000000000000000000000000000000..146c539a484970ee6b8d541cba121b15f97cfe77
GIT binary patch
literal 3992
zcmbtWO=w(I6h3!erZeeFrb$z5(khu2EvYs0lm7oY64OpmYE1}~qJ%dyuQQ|bQ)XUj
ztSwzALO`M2xu_txaiM#EK#?x2AgCMHZbTO@)RkbNp6|^)$(@^5kb2<Wd(L<M?mhSC
zy&H4SpN=U-LW)k&x+Eykg~4^c5V8fDpz+Xl6U&Rm)nAHl{ywsL{a*3ixqHRcZ+?T-
z&2R67n$_!n-+cMbT}I-hlF-D^?Lrqt&H@c6m3WDD10}CR$_bs$vit(KxCbZXC6!1t
z!tqJ&6G?a|Xp;l+dMlv8OUo@%Zr_r2z@ACn{*e34UDhYy9lO;a_aHN0auaejqizp@
zt8$Cos<HDPIy=VvsCptb<~ox*Cl|Mms*&wP&UT)y>mGBDyGLEcHUk;;^n{b_0j<=D
ziOLw@c$^~~nBa8`lauOc5i+rbTo+98ab`}rSo&aph*7mQQ5e5AfiRonB(cwq#m0%;
zj5;$`8SB|x<@iHvkwPkH=>%55jpK*CbW#<OW#J;r_!u*B?VAvA#~SBSSsS3FN~wQR
z!x*pw+?bgRHzTGdV_SOj2!q6vG`J>ii#u<{95#+C19e;#Pks_tUxccqi|3xpFYM>j
zF?WT|oLfxK?%S6?oX+PnxlArSlbgxs^80h?sd>MWE_#7hOy~Bdr<=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+DE|+%f7W!?wt&R{Yl8<a^u2u{wL<*F?k8q|+4t%P?SDZG^(gfd_(x`<>R-@?
zQdiU;|GeTa?@v^2#GXP>rn`E=_@3hZwEgk#5w+Am^ha(t>rJxPkC;*Zmvy3FO=sq9
G|9=5D*dH4J

literal 0
HcmV?d00001

diff --git a/tests/data/test-diff-filter/test-PR27598-v1.cc b/tests/data/test-diff-filter/test-PR27598-v1.cc
new file mode 100644
index 00000000..67bb3ee2
--- /dev/null
+++ b/tests/data/test-diff-filter/test-PR27598-v1.cc
@@ -0,0 +1,12 @@ 
+union S
+{
+  void bar() const
+  {
+  }
+};
+
+void
+fun(S s)
+{
+  s.bar();
+}
diff --git a/tests/data/test-diff-filter/test-PR27598-v1.o b/tests/data/test-diff-filter/test-PR27598-v1.o
new file mode 100644
index 0000000000000000000000000000000000000000..7015d7a8d0904b47f9edbe4ebc63e575c82a0f9e
GIT binary patch
literal 3912
zcmbtWO=w(I6h3!er!(oaY0?za7&Wf}OKZ*iB>n%<k(g$RrD#G>3KHMUyv~eGX3ES<
zjiutEDikWTh~T2G?Y0Y{ATFc}b?L@+H=+xLx+|!}^SyV^<j&0tNImfGJ?A?=_uO;u
zJu@H9oI8_Hii8xsMC+2EMCrbDz8JDa8lgR*?N*i-N;iHfUH^Tc^y$o6>BjfJ!Q|GD
z4<h`=2aj*P{oo!$Nm6O35*YSkh$Cm7lv1g4tlLud+N7M&X@=$G8=-@Gfv2r$SSTQ=
ziz`i1eLa~Ehn8$`=O%OM4(n5JOWbZz-(hCH(gv6^npbzWfqRp`#O*pe@1wIr%nz#P
z`-d{l*yz~8@Sqyt*v>GgmC2mQoXi~0D7M*>RWFY?=?G}{pBkw$m`t+&p%G4YCuK4S
zmFhJcRJ&5eJ=aDMA)O@gKRcAzL)4d5vqROP$mS|X*~S+A2na2mLYDloXE@3rI~Q3t
zC$h}XGLzK4DFKJOT!t#z0A=G7`Kx~iCRCX}X2!yTC)8MCXOu@6B$=kZuDCnte3Wq5
zIH?TO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Z>*IV7Q}Sdsq>uIbbpiA&>&twX
z@i_lKv_I-&lK9DdpOta`RsEoHrn9yMB>vwSJaD1U><6h8;wN@LGXu<ee)NU*e@hJY
zEcFxkCuZX6|0w4C@!wYbrT@gOjo6R$`akG|(Ff5#ZGZe<h}-IY{eH(;Z<4)##EkQI
N^+Laz&dl5X{{r;)6*m9?

literal 0
HcmV?d00001

diff --git a/tests/test-diff-filter.cc b/tests/test-diff-filter.cc
index 0b6b6588..acf2d62f 100644
--- a/tests/test-diff-filter.cc
+++ b/tests/test-diff-filter.cc
@@ -793,6 +793,13 @@  InOutSpec in_out_specs[] =
    "--no-default-suppression",
    "data/test-diff-filter/test-PR27569-report-0.txt",
    "output/test-diff-filter/test-PR27569-report-0.txt",
+  },
+    {
+   "data/test-diff-filter/test-PR27598-v0.o",
+   "data/test-diff-filter/test-PR27598-v0.o",
+   "--no-default-suppression",
+   "data/test-diff-filter/test-PR27598-report-0.txt",
+   "output/test-diff-filter/test-PR27598-report-0.txt",
   },
   // This should be the last entry
   {NULL, NULL, NULL, NULL, NULL}