Bug 97088 - 17_intro/names.cc and experimental/names.cc fail with --disable-libstdcxx-pch
Summary: 17_intro/names.cc and experimental/names.cc fail with --disable-libstdcxx-pch
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 101211 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-09-17 15:07 UTC by Christophe Lyon
Modified: 2021-06-28 15:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-06-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christophe Lyon 2020-09-17 15:07:03 UTC
When configuring gcc with --disable-libstdcxx-pch, two libstdc++ fail on arm (linux and newlib targets) and aarch64 (with newlib).

For instance on arm-eabi (using newlib):
In file included from /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/thumb/v7ve+simd/hard/libstdc++-v3/include/cmath:45,
                 from /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/arm-none-eabi/thumb/v7ve+simd/hard/libstdc++-v3/include/arm-none-eabi/bits/stdc++.h:41,
                 from /libstdc++-v3/testsuite/17_intro/names.cc:203:
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-eabi/include/math.h:194: error: expected ')' before ';' token
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-eabi/include/math.h:195: error: expected ')' before ';' token
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-eabi/include/math.h:196: error: expected ')' before ';' token
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-eabi/include/math.h:197: error: expected ')' before ';' token
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-eabi/include/math.h:198: error: expected ')' before ';' token
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-eabi/include/math.h:199: error: expected ')' before ';' token
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-eabi/include/math.h:200: error: expected ')' before ';' token
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-eabi/include/math.h:201: error: expected ')' before ';' token

This happens because the testcase does
#define x (
and "x" is used as parameter names in several function prototypes in newlib's math.h


Similarly for arm-linux-gnueabi (with glibc), I can see:
In file included from /aci-gcc-fsf/builds/gcc-fsf-gccsrc/sysroot-arm-none-linux-gnueabi/usr/include/signal.h:306,
                 from /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/csignal:42,
                 from /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/include/arm-none-linux-gnueabi/bits/stdc++.h:43,
                 from /libstdc++-v3/testsuite/17_intro/names.cc:203:
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/sysroot-arm-none-linux-gnueabi/usr/include/sys/ucontext.h:89: error: expected unqualified-id before ':' token
/aci-gcc-fsf/builds/gcc-fsf-gccsrc/sysroot-arm-none-linux-gnueabi/usr/include/sys/ucontext.h:89: error: expected ')' before ':' token

When configured without --disable-libstdcxx-pch, the pch feature is auto-enabled, and the testcase is compiled with -include bits/stdc++.h which avoids the problem.

I think this is a problem with the test.
Comment 1 jsm-csl@polyomino.org.uk 2020-09-17 16:22:55 UTC
On Thu, 17 Sep 2020, clyon at gcc dot gnu.org wrote:

> This happens because the testcase does
> #define x (
> and "x" is used as parameter names in several function prototypes in newlib's
> math.h

That's a bug in newlib, which should be fixed there.
Comment 2 Christophe Lyon 2020-09-18 09:25:01 UTC
(In reply to joseph@codesourcery.com from comment #1)
> On Thu, 17 Sep 2020, clyon at gcc dot gnu.org wrote:
> 
> > This happens because the testcase does
> > #define x (
> > and "x" is used as parameter names in several function prototypes in newlib's
> > math.h
> 
> That's a bug in newlib, which should be fixed there.

OK, so you mean that prototypes like
extern int __isinff (float x);
should not name their parameters? I can certainly submit the simple patch to newlib.

Regarding the problem with glibc, the problem is in ucontext.h, where struct _libc_fpstate is declared as:
struct _libc_fpstate
{
  struct
  {
    unsigned int sign1:1;
    unsigned int unused:15;
    unsigned int sign2:1;
    unsigned int exponent:14;
    unsigned int j:1;
    unsigned int mantissa1:31;
    unsigned int mantissa0:32;
  } fpregs[8];
  unsigned int fpsr:32;
  unsigned int fpcr:32;
  unsigned char ftype[8];
  unsigned int init_flag;
};

The offending field is 'j', because libstdc++'s 17_intro/names.cc defines 'j' as '('. Do you mean that field should also be renamed? That sounds odd.
Comment 3 Jonathan Wakely 2020-09-20 20:06:42 UTC
(In reply to Christophe Lyon from comment #2)
> OK, so you mean that prototypes like
> extern int __isinff (float x);
> should not name their parameters? I can certainly submit the simple patch to
> newlib.

The parameter should use a reserved name, e.g. __x.

This is a valid C program which will presumably fail to compile with newlib:

#define x 1234
#include <math.h>
int main() { return 0; }

The point of the test is to ensure that libstdc++ headers don't use non-reserved names like 'x'. In this case it's found a newlib bug, not a libstdc++ one.

The glibc case is a bit more complicated. 'j' is not a reserved name, but (at least on x86) the __libc_fpstate types do use reserved names unless __USE_MISC is defined. In strict modes a reserved name like __j will be used intead. Maybe the test needs to account for that.
Comment 4 Jonathan Wakely 2020-09-21 13:09:34 UTC
<asm/types.h> also has this on ppc linux:

typedef struct { 
        __u32 u[4];
} __attribute__((aligned(16))) __vector128;
Comment 5 Jonathan Wakely 2021-06-25 17:09:16 UTC
*** Bug 101211 has been marked as a duplicate of this bug. ***
Comment 6 Jonathan Wakely 2021-06-25 17:10:21 UTC
This now happens even without --disable-libstdcxx-pch because in r12-1742 I added

{ dg-add-options no_pch }

which means the PCH headers aren't used for the test.
Comment 7 GCC Commits 2021-06-25 19:50:54 UTC
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:e83a5a6b6893e910dc0b6b1cd034e1a258406c93

commit r12-1814-ge83a5a6b6893e910dc0b6b1cd034e1a258406c93
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Jun 25 18:31:22 2021 +0100

    libstdc++: More workarounds in 17_intro/names.cc test [PR 97088]
    
    Conditionally #undef some more names that are used in system headers.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/97088
            * testsuite/17_intro/names.cc: Undef more names for newlib and
            also for arm-none-linux-gnueabi.
            * testsuite/experimental/names.cc: Disable PCH.
Comment 8 GCC Commits 2021-06-28 15:25:35 UTC
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:75f948f089ceb8888fd00913635264e20610d0f2

commit r12-1845-g75f948f089ceb8888fd00913635264e20610d0f2
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jun 28 15:13:34 2021 +0100

    libstdc++: Fix backwards logic in 17_intro/names.cc test [PR 97088]
    
    I meant to undef the names that clash with newlib headers for newlib,
    but I only undef'd them for non-newlib targets. This means they still
    cause errors for newlib, and aren't tested for other targets.
    
    This fixes the test to check those names for non-newlib targets, and to
    undef them to avoid errors for newlib.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/97088
            * testsuite/17_intro/names.cc: Fix #if condition for names used
            by newlib headers.