public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: "gprocida+abigail at google dot com" <sourceware-bugzilla@sourceware.org>
To: libabigail@sourceware.org
Subject: [Bug default/26739] New: Handle qualified typedef array types
Date: Thu, 15 Oct 2020 18:21:37 +0000	[thread overview]
Message-ID: <bug-26739-9487@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2020-10-15 18:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-15 18:21 gprocida+abigail at google dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-26739-9487@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).