This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Preventing ISO C errors when using macros for builtin types

On Mon, 10 Jun 2019 13:32:42 -0500
Segher Boessenkool <> wrote:

> On Mon, Jun 10, 2019 at 05:20:31PM +0100, Jozef Lawrynowicz wrote:
> > On Thu, 6 Jun 2019 10:09:32 +0200
> > Richard Biener <> wrote:
> >   
> > > On Wed, Jun 5, 2019 at 3:26 PM Jozef Lawrynowicz <> wrote:  
> > > >
> > > > 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    
> > > 
> > > I think that would be OK - note you could also modify your target board.  
> > 
> > I'm now realising that the most straightforward way to fix this issue will be
> > to just modify the configuration of the DejaGNU target board, so that
> > DEFAULT_CFLAGS is set there and declarations of DEFAULT_CFLAGS in the testsuite
> > that would set -pedantic-errors are never used.  
> That is not a fix, that is sweeping the problem under the rug.
> As a somewhat dirty hack I added
> #if __MSP430X_LARGE__
> #undef __SIZE_TYPE__
> __extension__ typedef unsigned __int20 __SIZE_TYPE__;
> #endif
> to the start of the installed stddef.h, and that fixes the problem fine,
> for correct programs that do not forget to include <stddef.h> (directly
> or indirectly), anyway.
> Segher

But we have some 850 generic tests in gcc/testsuite that use __SIZE_TYPE__
without including stddef.h. They just rely on the preprocessor to expand this
using the builtin macro definition.

I assumed it was standard (and preferred, for the sake of compilation time at
least) for them to omit including stddef.h, which is why I was
considering pursuing some way of modifying how the builtin macro is expanded.

I could add something like your above code snippet to the tests that trigger
the ISO C error, but this is what I was originally trying to avoid.

At least, it seems like a good number of tests have the following:
  typedef __SIZE_TYPE__ size_t;
For these the fixup is simple as we can just add __extension__ before the

For others (e.g. gcc.dg/c99-const-expr-10.c), either we 
- add something like your snippet above and redefine __SIZE_TYPE__, or
- replace uses of __SIZE_TYPE__ with size_t and add the typedef i.e.
    __extension__ typedef __SIZE_TYPE__ size_t;
Do you have any opinion on which of these would be preferred?

For modifying the individual tests, I would assume it would be to add the
required typedefs at the top of the file, as this is what some tests already
do. It also avoids having the target specific caveats in the test file and may
help other targets with non-ISO types.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]