From e4820f9e332a88ac306017ad327a40eaa059867b Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Thu, 17 Apr 2014 11:18:21 +0200 Subject: [PATCH] File static data member changes in STATIC_DATA_MEMBER_CHANGE_CATEGORY * include/abg-comparison.h (diff_category::STATIC_DATA_MEMBER_CHANGE_CATEGORY): New category. (diff_category::EVERYTHING_CATEGORY): Update * src/abg-comp-filter.cc (static_data_member_type_size_changed) (static_data_member_added_or_removed): Define new static functions. (harmless_filter::visit): Categorize changes to static data members as STATIC_DATA_MEMBER_CHANGE_CATEGORY. * tools/bidiff.cc (set_diff_context_from_opts): STATIC_DATA_MEMBER_CHANGE_CATEGORY is falls into the harmless group. * tests/data/test-diff-filter/test12-report.txt: New test input. * tests/data/test-diff-filter/test12-v0.cc: Likewise. * tests/data/test-diff-filter/test12-v0.o: Likewise. * tests/data/test-diff-filter/test12-v1.cc: Likewise. * tests/data/test-diff-filter/test12-v1.o: Likewise. * tools/bidiff.cc: Run this test with the additional input data above. * tests/Makefile.am: Adjust. Signed-off-by: Dodji Seketeli --- include/abg-comparison.h | 8 +- src/abg-comp-filter.cc | 71 ++++++++++++++++++ tests/Makefile.am | 7 +- tests/data/test-diff-filter/test12-report.txt | 7 ++ tests/data/test-diff-filter/test12-v0.cc | 10 +++ tests/data/test-diff-filter/test12-v0.o | Bin 0 -> 2904 bytes tests/data/test-diff-filter/test12-v1.cc | 12 +++ tests/data/test-diff-filter/test12-v1.o | Bin 0 -> 3072 bytes tests/test-diff-filter.cc | 7 ++ tools/bidiff.cc | 3 +- 10 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 tests/data/test-diff-filter/test12-report.txt create mode 100644 tests/data/test-diff-filter/test12-v0.cc create mode 100644 tests/data/test-diff-filter/test12-v0.o create mode 100644 tests/data/test-diff-filter/test12-v1.cc create mode 100644 tests/data/test-diff-filter/test12-v1.o diff --git a/include/abg-comparison.h b/include/abg-comparison.h index d28a70ea..48818577 100644 --- a/include/abg-comparison.h +++ b/include/abg-comparison.h @@ -245,15 +245,18 @@ enum diff_category /// or removal of a non-virtual member function. NON_VIRT_MEM_FUN_CHANGE_CATEGORY = 1 << 3, + /// This means that a diff node in the sub-tree carries an addition + /// or removal of a static data member. + STATIC_DATA_MEMBER_CHANGE_CATEGORY = 1 << 4, /// This means the diff node (or at least one of its descendant /// nodes) carries a change that modifies the size of a type or an /// offset of a type member. - SIZE_OR_OFFSET_CHANGE_CATEGORY = 1 << 4, + SIZE_OR_OFFSET_CHANGE_CATEGORY = 1 << 5, /// This means that a diff node in the sub-tree carries a change to /// a vtable. - VIRTUAL_MEMBER_CHANGE_CATEGORY = 1 << 5, + VIRTUAL_MEMBER_CHANGE_CATEGORY = 1 << 6, /// A special enumerator that is the logical 'or' all the /// enumerators above. @@ -265,6 +268,7 @@ enum diff_category | COMPATIBLE_TYPE_CHANGE_CATEGORY | DECL_NAME_CHANGE_CATEGORY | NON_VIRT_MEM_FUN_CHANGE_CATEGORY + | STATIC_DATA_MEMBER_CHANGE_CATEGORY | SIZE_OR_OFFSET_CHANGE_CATEGORY | VIRTUAL_MEMBER_CHANGE_CATEGORY }; diff --git a/src/abg-comp-filter.cc b/src/abg-comp-filter.cc index 48f8f45e..707d1224 100644 --- a/src/abg-comp-filter.cc +++ b/src/abg-comp-filter.cc @@ -200,6 +200,30 @@ non_static_data_member_type_size_changed(decl_base_sptr f, decl_base_sptr s) return type_size_changed(fv->get_type(), sv->get_type()); } +/// Test if the size of a non-static data member changed accross two +/// versions. +/// +/// @param f the first version of the non-static data member. +/// +/// @param s the second version of the non-static data member. +static bool +static_data_member_type_size_changed(decl_base_sptr f, decl_base_sptr s) +{ + if (!is_member_decl(f) + || !is_member_decl(s)) + return false; + + var_decl_sptr fv = dynamic_pointer_cast(f), + sv = dynamic_pointer_cast(s); + if (!fv + || !sv + || !get_member_is_static(fv) + || !get_member_is_static(sv)) + return false; + + return type_size_changed(fv->get_type(), sv->get_type()); +} + /// Test if two types are different but compatible. /// /// @param d1 the declaration of the first type to consider. @@ -279,6 +303,49 @@ non_static_data_member_added_or_removed(const diff* diff) (dynamic_cast(diff)); } +/// Test if a class_diff node has static members added or removed. +/// +/// @param diff the diff node to consider. +/// +/// @return true iff the class_diff node has static members added +/// or removed. +static bool +static_data_member_added_or_removed(const class_diff* diff) +{ + if (diff && !diff_involves_decl_only_class(diff)) + { + for (string_decl_base_sptr_map::const_iterator i = + diff->inserted_data_members().begin(); + i != diff->inserted_data_members().end(); + ++i) + if (get_member_is_static(i->second)) + return true; + + for (string_decl_base_sptr_map::const_iterator i = + diff->deleted_data_members().begin(); + i != diff->deleted_data_members().end(); + ++i) + if (get_member_is_static(i->second)) + return true; + } + + return false; +} + +/// Test if a class_diff node has static members added or +/// removed. +/// +/// @param diff the diff node to consider. +/// +/// @return true iff the class_diff node has static members added +/// or removed. +static bool +static_data_member_added_or_removed(const diff* diff) +{ + return static_data_member_added_or_removed + (dynamic_cast(diff)); +} + /// Test if the class_diff node has a change involving virtual member /// functions. /// @@ -448,6 +515,10 @@ harmless_filter::visit(diff* d, bool pre) if (has_non_virtual_mem_fn_change(d)) category |= NON_VIRT_MEM_FUN_CHANGE_CATEGORY; + if (static_data_member_added_or_removed(d) + || static_data_member_type_size_changed(f, s)) + category |= STATIC_DATA_MEMBER_CHANGE_CATEGORY; + if (category) d->add_to_category(category); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 36873927..f8a1003c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -219,7 +219,12 @@ data/test-diff-filter/test11-v0.cc \ data/test-diff-filter/test11-v1.cc \ data/test-diff-filter/test11-v0.o \ data/test-diff-filter/test11-v1.o \ -data/test-diff-filter/test11-report.txt +data/test-diff-filter/test11-report.txt \ +data/test-diff-filter/test12-v0.cc \ +data/test-diff-filter/test12-v1.cc \ +data/test-diff-filter/test12-v0.o \ +data/test-diff-filter/test12-v1.o \ +data/test-diff-filter/test12-report.txt clean-local: clean-local-check .PHONY: clean-local-check diff --git a/tests/data/test-diff-filter/test12-report.txt b/tests/data/test-diff-filter/test12-report.txt new file mode 100644 index 00000000..60c617f6 --- /dev/null +++ b/tests/data/test-diff-filter/test12-report.txt @@ -0,0 +1,7 @@ +Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added function +Variables changes summary: 0 Removed, 0 Changed, 1 Added variable + + +1 Added variable: + 'static char S::m0 + diff --git a/tests/data/test-diff-filter/test12-v0.cc b/tests/data/test-diff-filter/test12-v0.cc new file mode 100644 index 00000000..ee328955 --- /dev/null +++ b/tests/data/test-diff-filter/test12-v0.cc @@ -0,0 +1,10 @@ +struct S +{ + static int m1; +}; + +int S::m1; + +void +foo(S&) +{} diff --git a/tests/data/test-diff-filter/test12-v0.o b/tests/data/test-diff-filter/test12-v0.o new file mode 100644 index 0000000000000000000000000000000000000000..314e25c2bdbb60f0c2840a9ac988ecca485795e1 GIT binary patch literal 2904 zcmbtWPj4GV6o0cDCpOzyPTYz{;jjft6Scd}ny3veY28L4iCR@vLN8URwYJChf_IJV zZ4^ML5<-Y_fFh6(5}bN~Bj14!z_mBH@Bz40>Y=>1J7bT>i#YU2v-95X{hc>|><8O7 z-Z2;hNenK-Sdu8fm*$wSC2S4KP=edL5C7hM`03O4eh2sl@tH)IPeP=80!)9517M6@ zLxmZ7z)a#`W+oRzG346)KCr^H69D^Zi0~|ZjBmRzcZ5tn@8Gv^ffP8PFs_v?u+zn| zWfqr<3v7{HikoR2fXLIE#A1_sRvQJkGh2S8;t=!oKX7%KkD#FmtGKY>4GW1 zZT7>E<8gMQe#~85tTT-L<_97W@7CJ`Kjc*8i_a@cN0<@8&7ABmeQ$ zNgZzpe|^&Z&!7SI`@j5kdtLU>m-6c*^M9u)bX&SMa1TD==o_+v-1BY?$4{JS4q#W>QtWWX5gRaDkga|bH}KTtd$U+ zRUzS7ohMv>4b#kKa)V?QsA4TK&V250|E(z5FC&=aY9IdIC0^^k-q^6saI}D9Ljt4JZE-d#DOQ-^Sy80uX*FK z{r1lFmkc3*MZje^)|dtO)jY0b^Y*!Yzhm!t zamrWMSL|vS-;Ml@o*((6ppB|GYWFt|*Uwkaui4ce)cV8FuXToNAbo!h{Lj2 zJ~dPP2>bLn@^q0TUEV5{-!r!7r+3hRNN4H8O8o#3=Y)^PHQ{{XXFn& zr{lNo_L@P|9pYSqy;f`F-c1 ztWUaU>u35C1bO{?kkdc>=w$wCU-h#?v296yO^PD=T1nSyC-e8^M!h2)7Ll9BOW!}* z)4cped4A}8siNms=TuB~1^Dx!$}u)`cZ}-DTM6-b6%wDYwctw-I>GaAqJuSlMBem04E zS>dUk@1*W&JjdnFsh&5K_RMqMPqjEwg)bC)Ixj5WNWgvIINwU1;;XyQy(POTX+uL< TVy=g$`2DH#wltt#s{Q;2Z^O+H literal 0 HcmV?d00001 diff --git a/tests/test-diff-filter.cc b/tests/test-diff-filter.cc index 23167dd0..0a3d4866 100644 --- a/tests/test-diff-filter.cc +++ b/tests/test-diff-filter.cc @@ -145,6 +145,13 @@ InOutSpec in_out_specs[] = "data/test-diff-filter/test11-report.txt", "output/test-diff-filter/test11-report.txt", }, + { + "data/test-diff-filter/test12-v0.o", + "data/test-diff-filter/test12-v1.o", + "--no-harmless", + "data/test-diff-filter/test12-report.txt", + "output/test-diff-filter/test12-report.txt", + }, // This should be the last entry {NULL, NULL, NULL, NULL, NULL} }; diff --git a/tools/bidiff.cc b/tools/bidiff.cc index 0e96cd3a..3d9ff57e 100644 --- a/tools/bidiff.cc +++ b/tools/bidiff.cc @@ -297,7 +297,8 @@ set_diff_context_from_opts(diff_context_sptr ctxt, (abigail::comparison::ACCESS_CHANGE_CATEGORY | abigail::comparison::COMPATIBLE_TYPE_CHANGE_CATEGORY | abigail::comparison::DECL_NAME_CHANGE_CATEGORY - | abigail::comparison::NON_VIRT_MEM_FUN_CHANGE_CATEGORY); + | abigail::comparison::NON_VIRT_MEM_FUN_CHANGE_CATEGORY + | abigail::comparison::STATIC_DATA_MEMBER_CHANGE_CATEGORY); if (!opts.show_harmful_changes) ctxt->switch_categories_off (abigail::comparison::SIZE_OR_OFFSET_CHANGE_CATEGORY