public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jozef Lawrynowicz <jozefl.gcc@gmail.com>
To: gcc@gcc.gnu.org
Subject: Preventing ISO C errors when using macros for builtin types
Date: Wed, 05 Jun 2019 13:26:00 -0000	[thread overview]
Message-ID: <20190605142559.05791323@jozef-kubuntu> (raw)

The MSP430 target in the large memory model uses the (non-ISO) __int20 type for
SIZE_TYPE and PTRDIFF_TYPE.
The preprocessor therefore expands a builtin such as __SIZE_TYPE__ to
"__int20 unsigned" in user code.
When compiling with the "-pedantic-errors" flag, the use of any of these
builtin macros results in an error of the form:

> tester.c:4:9: error: ISO C does not support '__int20' types [-Wpedantic]

The GCC documentation does instruct users *not* to use these types directly
(cpp.texi):
> You should not use these macros directly; instead, include the
> appropriate headers and use the typedefs.
When using the typedefs (e.g. size_t) in a program compiled with
-pedantic-errors, there is no ISO C error.

However, in the testsuite there is an ever-growing list of tests which use
the macros to avoid having to include any header files required for the
typedefs.
Since -pendantic-errors is often passed as a default flag in the testsuite,
there are many false failures when testing with -mlarge, caused by this ISO C
error.

I would like to try to find a way to address this issue within GCC itself, so
that constant updates to the testsuite are not required to filter these types
of failures out.

I tried one approach suggested here
https://gcc.gnu.org/ml/gcc-patches/2018-11/msg02219.html
which was to add "__extension__" to the definition of SIZE_TYPE/PTRDIFF_TYPE in
msp430.h, however it became clear that that will not work, since the following
is not valid:
> typedef __extension__ __int20 ptrdiff_t;

> error: expected identifier or '(' before '__extension__'

__extension__ must be placed at the beginning of the declaration.

I'm assuming it would not be valid to modify the behaviour of __extension__
so it can be placed within a declaration, and not just at the
beginning. However, there is minimal documentation on this keyword (it does not
state that it can be used in declarations, even though it can), so I wonder
what the "rules" are.

I would appreciate if anyone can help me decide if:
- It would be OK for the use of builtin macros such as __SIZE_TYPE__ to somehow
  not trigger the "pedantic errors", and what a valid approach might look like
  * would finding a way to sandwich __extension__ into the expansion of these
    macros be acceptable?
  or,
- These types of failures should be continued to be fixed in the tests
  themselves, for example by adding __extension__ before their usage.

Thanks,
Jozef

             reply	other threads:[~2019-06-05 13:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-05 13:26 Jozef Lawrynowicz [this message]
2019-06-05 16:49 ` Segher Boessenkool
2019-06-05 19:49   ` Jozef Lawrynowicz
2019-06-05 22:12     ` Segher Boessenkool
2019-06-10 15:57       ` Jozef Lawrynowicz
2019-06-06  8:09 ` Richard Biener
2019-06-10 16:20   ` Jozef Lawrynowicz
2019-06-10 18:32     ` Segher Boessenkool
2019-06-10 19:58       ` Jozef Lawrynowicz
2019-06-10 22:09         ` Segher Boessenkool
2019-06-11 20:44           ` Jozef Lawrynowicz
2019-06-11 23:01             ` Segher Boessenkool
2019-06-12 16:40               ` Jozef Lawrynowicz

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=20190605142559.05791323@jozef-kubuntu \
    --to=jozefl.gcc@gmail.com \
    --cc=gcc@gcc.gnu.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).