public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [Bug default/26739] New: Handle qualified typedef array types
@ 2020-10-15 18:21 gprocida+abigail at google dot com
  2020-10-23 16:36 ` [Bug default/26739] " dodji at redhat dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gprocida+abigail at google dot com @ 2020-10-15 18:21 UTC (permalink / raw)
  To: libabigail

https://sourceware.org/bugzilla/show_bug.cgi?id=26739

            Bug ID: 26739
           Summary: Handle qualified typedef array types
           Product: libabigail
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: default
          Assignee: dodji at redhat dot com
          Reporter: gprocida+abigail at google dot com
                CC: libabigail at sourceware dot org
  Target Milestone: ---

The C language has a "feature" I believe also inherited by C++.

Array and function types cannot be CV-qualified. You can try with typedefs and
results are... non-obvious. Typedefs are *not* simply aliases.

If a typedef is qualified and it refers to a function type, then undefined
behaviour ensues. (WAT? Not legal, not illegal, not implementation-defined...
undefined.)

If a typedef is qualified and it refers to an array type, then the qualified
typedef resolves not necessarily to the original array type, but to a similar
one where the element types gain the qualifiers on the typedef. (WAT?!)

This means building C types requires a degree of evaluation rather than just
plain construction.

Unsurprisingly, this is confusing both to humans and to libabigail. The code
below has no ABI change, as member q is const int[7] in both versions. However,
abidiff reports things which may or may not be strictly true.

It's quite possible that the DWARF for these mutant typedefs is "interesting"
and I wouldn't be surprised if GCC and Clang have differences here. (GCC
already copies element type qualifiers to the array types, Clang does not).

==> mutant_typedef_arrays_c.0.c <==
typedef const int immutable[7];
typedef immutable monster;

struct A {
  monster q;
};

void fun(struct A * a) { (void) a; }

==> mutant_typedef_arrays_c.1.c <==
typedef int plain[7];
typedef const plain monster;

struct A {
  monster q;
};

void fun(struct A * a) {
  (void) a;
  // assignment to read-only location
  // a->q[0] = 0;
}

$ abidiff --no-show-locs mutant_typedef_arrays_c.?.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 fun(A*)' has some indirect sub-type changes:
    parameter 1 of type 'A*' has sub-type changes:
      in pointed to type 'struct A':
        type size hasn't changed
        1 data member change:
          type of 'const monster A::q' changed:
            in unqualified underlying type 'typedef monster':
              underlying type 'typedef immutable' changed:
                entity changed from 'typedef immutable' to compatible type
'int[7]'
                  array element type 'const int' changed:
                    entity changed from 'const int' to 'int'
                    type size hasn't changed
                  type name changed from 'const int[7]' to 'int[7]'
                  type size hasn't changed

$ echo $?
4

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-12-04 17:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15 18:21 [Bug default/26739] New: Handle qualified typedef array types gprocida+abigail at google dot com
2020-10-23 16:36 ` [Bug default/26739] " dodji at redhat dot com
2020-10-27 17:22 ` dodji at redhat dot com
2020-11-09 14:35 ` dodji at redhat dot com
2020-11-09 14:35 ` dodji at redhat dot com
2020-11-13 17:10 ` dodji at redhat dot com
2020-12-04 17:09 ` gprocida+abigail at google dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).