public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Preventing ISO C errors when using macros for builtin types
@ 2019-06-05 13:26 Jozef Lawrynowicz
  2019-06-05 16:49 ` Segher Boessenkool
  2019-06-06  8:09 ` Richard Biener
  0 siblings, 2 replies; 13+ messages in thread
From: Jozef Lawrynowicz @ 2019-06-05 13:26 UTC (permalink / raw)
  To: gcc

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

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

end of thread, other threads:[~2019-06-12 16:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 13:26 Preventing ISO C errors when using macros for builtin types Jozef Lawrynowicz
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

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).