[0/3] Handle data member replacement by anonymous data member

Message ID 86mu65a2i2.fsf@seketeli.org
State Committed
Headers

Commit Message

Dodji Seketeli May 18, 2020, 11:47 a.m. UTC
  Hello,

This patchset is to address the enhancement request at
https://sourceware.org/bugzilla/show_bug.cgi?id=25661, which aims at
recognizing replacements of data members by anonymous members.

In the case where such a replacement does not lead to a harmful change
to the bit layout of the class/struct, the patchset makes libabigail
(through abidiff) avoid flagging the change as (potentially)
problematic and just filters it out.  However, calling abidiff with
--harmless describes the change (hopefully) appropriately.

To make a long story short, let's look at a screenshot of what the
patch makes abidiff report on the kind of changes we are interested in:

$ diff -u test-v0.c test-v1.c
$ abidiff test-v0.o test-v1.o
Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added function
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable


$ abidiff -l test-v0.o test-v1.o
Leaf changes summary: 0 artifact changed (1 filtered out)
Changed leaf types summary: 0 (1 filtered out) 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


$ abidiff --harmless test-v0.o test-v1.o
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 foo(S*)' at test-v1.c:11:1 has some indirect sub-type changes:
    parameter 1 of type 'S*' has sub-type changes:
      in pointed to type 'struct S' at test-v1.c:1:1:
        type size hasn't changed
        data member 'S::a' was replaced by anonymous data member:
          'union {int a; char added;}'


$ abidiff --harmless -l test-v0.o test-v1.o
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 S at test-v0.c:1:1' changed:
  type size hasn't changed
  data member 'S::a' was replaced by anonymous data member:
    'union {int a; char added;}'

$ 

The last patch is where the real work about this task is happening.
The first two patches are fixes that are required for the last one.

The set has been applied to master.

Thanks.
  

Patch

--- test-v0.c	2020-05-18 11:45:49.640328955 +0200
+++ test-v1.c	2020-05-18 11:45:44.079261669 +0200
@@ -1,6 +1,10 @@ 
 struct S
 {
-  int a;
+  union
+  {
+    int  a;
+    char added;
+  };
 };
 
 void