From 2f8e1db0e7a163eda943001703d9fa0ecfad2806 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Wed, 31 Mar 2021 14:56:52 +0200 Subject: [PATCH] Bug 27598 - abidiff mishandles union member functions 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 --- 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 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|^)$(@^5kb2mGBDyGLEcHUk;;^n{b_0j<=D ziOLw@c$^~~nBa8`lauOc5i+rbTo+98ab`}rSo&aph*7mQQ5e5AfiRonB(cwq#m0%; zj5;$`8SB|x<@iHvkwPkH=>%55jpK*CbW#ii#u<{95#+C19e;#Pks_tUxccqi|3xpFYM>j zF?WT|oLfxK?%S6?oX+PnxlArSlbgxs^80h?sd>MWE_#7hOy~Bdr<=iY%RgE5TYjfr zX3^`EYbRHZ9GX6KAU$2BrHlLd)Z`Z^sMWjF^8Jcmp=_<)^s|+A<&}E2S`V^~ddVx* zt6sg4JwHEl_~6ka*~^{4?*?5$KYb;aDVHD8%LqVcW@nG3r+9sP|HIOVwuQyyI$xb9 zwKAf14keN|x!{j7js^;M_LP7aI)^=?$l-GpMNaRgZ%{e3cIx_c4jGS?p>b%lA+56xg;#qW(40f54Hy82Mjn8V zJ^<%y8bQw5ZuKi2+S(6ji7&(k95df-)JJYDUwe+ScA ztGai;NAhN%l4kXXSq1^e97L9t0LNVSaRWWl8$x@t`tl0F9=j;IJ%&AWLMJsNc?Caj z;WaJ4Vc{3Gd_#|@@OssVJ~nXkbbh6A$%{u16n>L<1TH*qIWczpG?Yxh&G=G3+n&EK zA=&o3HIBTf*&!`IW#OKd^A_IF@^L-d@n1A>vp#8!12gAeFmThJGTqmkfmh-&==8># za2>zlWdeUCpiIRJJj#^1T?&Cr-%-tkh84fGTwSWSF16V_>Kr(6m(3vhqyLsT;rjayACcsjcT#d%W`sXYdrq)z zYKQOiD1&YLEGwewm(%r2YX{U1@2FkBMaJxy4AD^yeg?rH+qT9!8-w{@8Z1CC$hO6M z7B&C#`q3|HU(6qGjy?ZtjM*{aGNTK<3xYwm?Q5)y%Kx6upVPj`Kg7+>e~U3YCR`SD z{wf56Y}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%3KHMUyv~eGX3ES< zjiutEDikWTh~T2G?Y0Y{ATFc}b?L@+H=+xLx+|!}^SyV^BjfJ!Q|GD z4GgmC2mQoXi~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=~Kz{^`!bHR4rbZ;`1xa)8d8muNCH}_{?Xn(CqmIclzML!cn(S$mX+ocQQX& z$QP#a?*2Ky>Xy7fD<<*>+==C2rRkrp`AxswsIcg@EA`W>$Bs-KIpj{%D5y6&l&iOv z{am$GeYcUTHG9T2 z`*}YH{=-(n64LHyB6W3+)arm5-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