public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: "gprocida at google dot com" <sourceware-bugzilla@sourceware.org>
To: libabigail@sourceware.org
Subject: [Bug default/30048] incorrect qualifiers within compound types
Date: Wed, 08 Feb 2023 13:08:33 +0000	[thread overview]
Message-ID: <bug-30048-9487-6QSCBzRhIm@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30048-9487@http.sourceware.org/bugzilla/>

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

--- Comment #7 from gprocida at google dot com ---
Hi Dodji.

I don't feel qualified to review the code change and I haven't had the chance
to patch and test it (but I'm sure you have!).

However, I can offer some test case suggestions.

Firstly, printing out C types is a hard problem! I worked on an implementation
that seems to have mostly survived over a year or so of use:

https://android.googlesource.com/platform/external/stg/+/refs/heads/master/naming.h
https://android.googlesource.com/platform/external/stg/+/refs/heads/master/naming.cc

The important code here is Name, which consolidates precedence handling, and
the Describe function object, which works recursively on the type graph. I
documented the original design approach here:

https://android.googlesource.com/platform/external/stg/+/refs/heads/master/doc/NAMES.md

I think the main takeaway is that qualifiers can be "tacked on" without
disturbing the rest of the code too much but some contextual awareness is
needed to make sure the qualifiers end up on the correct side with appropriate
whitespace. It would have been significantly easier if the world (or C itself)
just had "int const" and not "const int".

In terms of testing... this is my torture test for naming and diffs. The
comments are (or at least were at one point) valid input for cdecl(1).

Please feel free to use or adapt this for libabigail. If you need copyright /
licence attribution it's: Google Inc. 2020, LLVM licence (Apache + LLVM
exception), same as libabigail.

struct amusement {
  // declare A as array 7 of int
  int A[7];
  // declare B as pointer to int
  int *B;
  // declare C as pointer to function (void) returning int
  int (*C)(void );
  // declare D as array 7 of array 7 of int
  int D[7][7];
  // declare E as array 7 of pointer to int
  int *E[7];
  // declare F as array 7 of pointer to function (void) returning int
  int (*F[7])(void );
  // declare G as pointer to array 7 of int
  int (*G)[7];
  // declare H as pointer to pointer to int
  int **H;
  // declare I as pointer to function (void) returning int
  int (*I)(void );
  // declare J as pointer to function (void) returning pointer to array 7 of
int
  int (*(*J)(void ))[7];
  // declare K as pointer to function (void) returning pointer to int
  int *(*K)(void );
  // declare L as pointer to function (void) returning pointer to function
(void) returning int
  int (*(*L)(void ))(void );

  // declare a as array 7 of volatile int
  volatile int a[7];
  // declare b as const pointer to volatile int
  volatile int * const b;
  // declare c as const pointer to function (void) returning int
  int (* const c)(void );
  // declare d as array 7 of array 7 of volatile int
  volatile int d[7][7];
  // declare e as array 7 of const pointer to volatile int
  volatile int * const e[7];
  // declare f as array 7 of const pointer to function (void) returning int
  int (* const f[7])(void );
  // declare g as const pointer to array 7 of volatile int
  volatile int (* const g)[7];
  // declare h as const pointer to const pointer to volatile int
  volatile int * const * const h;
  // declare i as const pointer to function (void) returning int
  int (* const i)(void );
  // declare j as const pointer to function (void) returning pointer to array 7
of volatile int
  volatile int (*(* const j)(void ))[7];
  // declare k as const pointer to function (void) returning pointer to
volatile int
  volatile int *(* const k)(void );
  // declare l as const pointer to function (void) returning pointer to
function (void) returning int
  int (*(* const l)(void ))(void );
};

struct amusement * fun(void) { return 0; }

// declare M as function (void) returning int
int M(void ) { return 0; }
// declare N as function (void) returning pointer to array 7 of int
int (*N(void ))[7] { return 0; }
// declare O as function (void) returning pointer to int
int *O(void ) { return 0; }
// declare P as function (void) returning pointer to function (void) returning
int
int (*P(void ))(void ) { return 0; }

// declare m as function (void) returning int
int m(void ) { return 0; }
// declare n as function (void) returning pointer to array 7 of volatile int
volatile int (*n(void ))[7] { return 0; }
// declare o as function (void) returning pointer to volatile int
volatile int *o(void ) { return 0; }
// declare p as function (void) returning pointer to function (void) returning
int
int (*p(void ))(void ) { return 0; }

This can be abidiff'd against:

struct amusement {
  int A;
  int B;
  int C;
  int D;
  int E;
  int F;
  int G;
  int H;
  int I;
  int J;
  int K;
  int L;

  int a;
  int b;
  int c;
  int d;
  int e;
  int f;
  int g;
  int h;
  int i;
  int j;
  int k;
  int l;
};

struct amusement * fun() { return 0; }

int M() { return 0; }
int N() { return 0; }
int O() { return 0; }
int P() { return 0; }

int m() { return 0; }
int n() { return 0; }
int o() { return 0; }
int p() { return 0; }

Regards,
Giuliano.

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

  parent reply	other threads:[~2023-02-08 13:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25  9:40 [Bug default/30048] New: " gprocida at google dot com
2023-01-25  9:57 ` [Bug default/30048] " gprocida at google dot com
2023-01-27  1:10 ` woodard at redhat dot com
2023-01-27 10:05 ` gprocida at google dot com
2023-01-27 10:10 ` gprocida at google dot com
2023-02-03  0:11 ` dodji at redhat dot com
2023-02-07 17:37 ` dodji at redhat dot com
2023-02-08 13:08 ` gprocida at google dot com [this message]
2023-02-10 12:50   ` Dodji Seketeli
2023-02-10 12:50 ` dodji at seketeli dot org
2023-02-10 12:50 ` dodji at redhat 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-30048-9487-6QSCBzRhIm@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).