mirror of
git://sourceware.org/git/libabigail.git
synced 2025-02-21 08:17:00 +00:00
18252 - Added parameters are not properly sorted
In the changed functions/variables section of the abidiff report, when function parameters were added or removed, they were not properly sorted. This patch fixes that. * src/abg-comparison.cc (sort_string_parm_map): Define new static function. (struct parm_comp): Define new type. (function_type_diff::priv::{sorted_deleted_parms_, sorted_added_parms_}): New data members that hold sorted deleted/added parameters. (function_type_diff::ensure_lookup_tables_populated): Initialize the two new data members above. (function_type_diff::report): For the report of parameters that got added/removed, use the sorted set of added/removed parameters above. * tests/data/test-diff-dwarf/test24-added-fn-parms-report-0.txt: New test input. * tests/data/test-diff-dwarf/libtest24-added-fn-parms-v{0,1}.so: Likewise. * tests/data/test-diff-dwarf/test25-removed-fn-parms-report-0.txt: Likewise. * tests/data/test-diff-dwarf/libtest25-removed-fn-parms-v{0,1}.so: Likewise. * tests/data/test-diff-dwarf/test24-added-fn-parms-v{0,1}.c: Likewise. * tests/data/test-diff-dwarf/test25-removed-fn-parms-v{0,1}.c: Likewise. * tests/data/Makefile.am: Add the new test material above to the source distribution. Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
parent
21adfb066f
commit
6baecca506
@ -282,6 +282,10 @@ static void
|
||||
sort_string_fn_parm_diff_sptr_map(const string_fn_parm_diff_sptr_map& map,
|
||||
vector<fn_parm_diff_sptr>& sorted);
|
||||
|
||||
static void
|
||||
sort_string_parm_map(const string_parm_map& map,
|
||||
vector<function_decl::parameter_sptr>& sorted);
|
||||
|
||||
static type_base_sptr
|
||||
get_leaf_type(qualified_type_def_sptr t);
|
||||
|
||||
@ -9081,7 +9085,9 @@ struct function_type_diff::priv
|
||||
|
||||
// useful lookup tables.
|
||||
string_parm_map deleted_parms_;
|
||||
vector<function_decl::parameter_sptr> sorted_deleted_parms_;
|
||||
string_parm_map added_parms_;
|
||||
vector<function_decl::parameter_sptr> sorted_added_parms_;
|
||||
// This map contains parameters sub-type changes that don't change
|
||||
// the name of the type of the parameter.
|
||||
string_fn_parm_diff_sptr_map subtype_changed_parms_;
|
||||
@ -9168,6 +9174,12 @@ function_type_diff::ensure_lookup_tables_populated()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort_string_parm_map(priv_->deleted_parms_,
|
||||
priv_->sorted_deleted_parms_);
|
||||
|
||||
sort_string_parm_map(priv_->added_parms_,
|
||||
priv_->sorted_added_parms_);
|
||||
}
|
||||
|
||||
/// In the vector of deleted parameters, get the one that is at a given
|
||||
@ -9396,12 +9408,13 @@ function_type_diff::report(ostream& out, const string& indent) const
|
||||
|
||||
// Report about the parameters that got removed.
|
||||
bool emitted = false;
|
||||
for (string_parm_map::const_iterator i = priv_->deleted_parms_.begin();
|
||||
i != priv_->deleted_parms_.end();
|
||||
for (vector<function_decl::parameter_sptr>::const_iterator i =
|
||||
priv_->sorted_deleted_parms_.begin();
|
||||
i != priv_->sorted_deleted_parms_.end();
|
||||
++i)
|
||||
{
|
||||
out << indent << "parameter " << i->second->get_index()
|
||||
<< " of type '" << i->second->get_type_pretty_representation()
|
||||
out << indent << "parameter " << (*i)->get_index()
|
||||
<< " of type '" << (*i)->get_type_pretty_representation()
|
||||
<< "' was removed\n";
|
||||
emitted = true;
|
||||
}
|
||||
@ -9410,12 +9423,13 @@ function_type_diff::report(ostream& out, const string& indent) const
|
||||
|
||||
// Report about the parameters that got added
|
||||
emitted = false;
|
||||
for (string_parm_map::const_iterator i = priv_->added_parms_.begin();
|
||||
i != priv_->added_parms_.end();
|
||||
for (vector<function_decl::parameter_sptr>::const_iterator i =
|
||||
priv_->sorted_added_parms_.begin();
|
||||
i != priv_->sorted_added_parms_.end();
|
||||
++i)
|
||||
{
|
||||
out << indent << "parameter " << i->second->get_index()
|
||||
<< " of type '" << i->second->get_type_pretty_representation()
|
||||
out << indent << "parameter " << (*i)->get_index()
|
||||
<< " of type '" << (*i)->get_type_pretty_representation()
|
||||
<< "' was added\n";
|
||||
emitted = true;
|
||||
}
|
||||
@ -9645,6 +9659,59 @@ sort_string_fn_parm_diff_sptr_map(const string_fn_parm_diff_sptr_map& map,
|
||||
std::sort(sorted.begin(), sorted.end(), comp);
|
||||
}
|
||||
|
||||
/// Functor that compares two function parameters for the purpose of
|
||||
/// sorting them.
|
||||
struct parm_comp
|
||||
{
|
||||
/// Returns true iff the index of the first parameter is smaller
|
||||
/// than the of the second parameter.
|
||||
///
|
||||
/// @param l the first parameter to compare.
|
||||
///
|
||||
/// @param r the second parameter to compare.
|
||||
///
|
||||
/// @return true iff the index of the first parameter is smaller
|
||||
/// than the of the second parameter.
|
||||
bool
|
||||
operator()(const function_decl::parameter& l,
|
||||
const function_decl::parameter& r)
|
||||
{return l.get_index() < r.get_index();}
|
||||
|
||||
/// Returns true iff the index of the first parameter is smaller
|
||||
/// than the of the second parameter.
|
||||
///
|
||||
/// @param l the first parameter to compare.
|
||||
///
|
||||
/// @param r the second parameter to compare.
|
||||
///
|
||||
/// @return true iff the index of the first parameter is smaller
|
||||
/// than the of the second parameter.
|
||||
bool
|
||||
operator()(const function_decl::parameter_sptr& l,
|
||||
const function_decl::parameter_sptr& r)
|
||||
{return operator()(*l, *r);}
|
||||
}; // end struct parm_comp
|
||||
|
||||
/// Sort a map of string -> function parameters.
|
||||
///
|
||||
/// @param map the map to sort.
|
||||
///
|
||||
/// @param sorted the resulting sorted vector of
|
||||
/// @ref vector<function_decl::parameter_sptr>
|
||||
static void
|
||||
sort_string_parm_map(const string_parm_map& map,
|
||||
vector<function_decl::parameter_sptr>& sorted)
|
||||
{
|
||||
for (string_parm_map::const_iterator i = map.begin();
|
||||
i != map.end();
|
||||
++i)
|
||||
sorted.push_back(i->second);
|
||||
|
||||
// TODO: finish this.
|
||||
parm_comp comp;
|
||||
std::sort(sorted.begin(), sorted.end(), comp);
|
||||
}
|
||||
|
||||
/// Serialize a report of the changes encapsulated in the current
|
||||
/// instance of function_decl_diff over to an output stream.
|
||||
///
|
||||
|
@ -192,6 +192,16 @@ test-diff-dwarf/libtest-23-diff-arch-v0-32.so \
|
||||
test-diff-dwarf/libtest-23-diff-arch-v0-64.so \
|
||||
test-diff-dwarf/test-23-diff-arch-report-0.txt \
|
||||
test-diff-dwarf/test-23-diff-arch-v0.cc \
|
||||
test-diff-dwarf/libtest24-added-fn-parms-v0.so \
|
||||
test-diff-dwarf/libtest24-added-fn-parms-v1.so \
|
||||
test-diff-dwarf/test24-added-fn-parms-report-0.txt \
|
||||
test-diff-dwarf/test24-added-fn-parms-v0.c \
|
||||
test-diff-dwarf/test24-added-fn-parms-v1.c \
|
||||
test-diff-dwarf/libtest25-removed-fn-parms-v0.so \
|
||||
test-diff-dwarf/libtest25-removed-fn-parms-v1.so \
|
||||
test-diff-dwarf/test25-removed-fn-parms-report-0.txt \
|
||||
test-diff-dwarf/test25-removed-fn-parms-v0.c \
|
||||
test-diff-dwarf/test25-removed-fn-parms-v1.c \
|
||||
\
|
||||
test-read-dwarf/test0 \
|
||||
test-read-dwarf/test0.abi \
|
||||
|
BIN
tests/data/test-diff-dwarf/libtest24-added-fn-parms-v0.so
Executable file
BIN
tests/data/test-diff-dwarf/libtest24-added-fn-parms-v0.so
Executable file
Binary file not shown.
BIN
tests/data/test-diff-dwarf/libtest24-added-fn-parms-v1.so
Executable file
BIN
tests/data/test-diff-dwarf/libtest24-added-fn-parms-v1.so
Executable file
Binary file not shown.
BIN
tests/data/test-diff-dwarf/libtest25-removed-fn-parms-v0.so
Executable file
BIN
tests/data/test-diff-dwarf/libtest25-removed-fn-parms-v0.so
Executable file
Binary file not shown.
BIN
tests/data/test-diff-dwarf/libtest25-removed-fn-parms-v1.so
Executable file
BIN
tests/data/test-diff-dwarf/libtest25-removed-fn-parms-v1.so
Executable file
Binary file not shown.
@ -0,0 +1,12 @@
|
||||
Functions changes summary: 0 Removed, 1 Changed, 0 Added function
|
||||
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
|
||||
|
||||
1 function with some indirect sub-type change:
|
||||
|
||||
[C]'function void fun()' has some indirect sub-type changes:
|
||||
parameter 0 of type 'unsigned int' was added
|
||||
parameter 1 of type 'char' was added
|
||||
parameter 2 of type 'int' was added
|
||||
|
||||
|
||||
|
6
tests/data/test-diff-dwarf/test24-added-fn-parms-v0.c
Normal file
6
tests/data/test-diff-dwarf/test24-added-fn-parms-v0.c
Normal file
@ -0,0 +1,6 @@
|
||||
// To compile this type:
|
||||
// gcc -g -Wall -shared -o libtest24-added-fn-parms-v0.so test24-added-fn-parms-v0.c
|
||||
void
|
||||
fun()
|
||||
{
|
||||
}
|
13
tests/data/test-diff-dwarf/test24-added-fn-parms-v1.c
Normal file
13
tests/data/test-diff-dwarf/test24-added-fn-parms-v1.c
Normal file
@ -0,0 +1,13 @@
|
||||
// To compile this type:
|
||||
// gcc -g -Wall -shared -o libtest24-added-fn-parms-v1.so test24-added-fn-parms-v1.c
|
||||
void
|
||||
fun()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
fun(__attribute__((unused))unsigned arg0,
|
||||
__attribute__((unused)) char arg1,
|
||||
__attribute__((unused)) int arg2)
|
||||
{
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
Functions changes summary: 0 Removed, 1 Changed, 0 Added function
|
||||
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
|
||||
|
||||
1 function with some indirect sub-type change:
|
||||
|
||||
[C]'function void fun(unsigned int, char, int)' has some indirect sub-type changes:
|
||||
parameter 0 of type 'unsigned int' was removed
|
||||
parameter 1 of type 'char' was removed
|
||||
parameter 2 of type 'int' was removed
|
||||
|
||||
|
||||
|
8
tests/data/test-diff-dwarf/test25-removed-fn-parms-v0.c
Normal file
8
tests/data/test-diff-dwarf/test25-removed-fn-parms-v0.c
Normal file
@ -0,0 +1,8 @@
|
||||
// To compile this type:
|
||||
// gcc -g -Wall -shared -o libtest25-added-fn-parms-v0.so test25-added-fn-parms-v0.c
|
||||
void
|
||||
fun(__attribute__((unused))unsigned arg0,
|
||||
__attribute__((unused)) char arg1,
|
||||
__attribute__((unused)) int arg2)
|
||||
{
|
||||
}
|
6
tests/data/test-diff-dwarf/test25-removed-fn-parms-v1.c
Normal file
6
tests/data/test-diff-dwarf/test25-removed-fn-parms-v1.c
Normal file
@ -0,0 +1,6 @@
|
||||
// To compile this type:
|
||||
// gcc -g -Wall -shared -o libtest25-added-fn-parms-v1.so test25-added-fn-parms-v1.c
|
||||
void
|
||||
fun()
|
||||
{
|
||||
}
|
@ -205,6 +205,18 @@ InOutSpec in_out_specs[] =
|
||||
"data/test-diff-dwarf/libtest-23-diff-arch-v0-64.so",
|
||||
"data/test-diff-dwarf/test-23-diff-arch-report-0.txt",
|
||||
"output/test-diff-dwarf/test-23-diff-arch-report-0.txt"
|
||||
},
|
||||
{
|
||||
"data/test-diff-dwarf/libtest24-added-fn-parms-v0.so",
|
||||
"data/test-diff-dwarf/libtest24-added-fn-parms-v1.so",
|
||||
"data/test-diff-dwarf/test24-added-fn-parms-report-0.txt",
|
||||
"output/test-diff-dwarf/test24-added-fn-parms-report-0.txt"
|
||||
},
|
||||
{
|
||||
"data/test-diff-dwarf/libtest25-removed-fn-parms-v0.so",
|
||||
"data/test-diff-dwarf/libtest25-removed-fn-parms-v1.so",
|
||||
"data/test-diff-dwarf/test25-removed-fn-parms-report-0.txt",
|
||||
"output/test-diff-dwarf/test25-removed-fn-parms-report-0.txt"
|
||||
},
|
||||
// This should be the last entry
|
||||
{NULL, NULL, NULL, NULL}
|
||||
|
Loading…
Reference in New Issue
Block a user