From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 81A3C385840C; Mon, 27 Sep 2021 18:35:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81A3C385840C From: "i at maskray dot me" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/102502] New: C11: _Static_assert disallows const int operand in -O0 while allows it in higher -O Date: Mon, 27 Sep 2021 18:35:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: i at maskray dot me X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Sep 2021 18:35:53 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102502 Bug ID: 102502 Summary: C11: _Static_assert disallows const int operand in -O0 while allows it in higher -O Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: i at maskray dot me Target Milestone: --- Under some circumstances, const size_t allocation_size =3D 32768; _Static_assert (allocation_size >=3D sizeof (struct dirent64), "allocatio= n_size < sizeof (struct dirent64)"); -O0 and non -O0 have different behaviors whether the `const int` operand ca= n be used in a constant expression (-O0: `error: expression in static assertion = is not constant`). This is different from a bug "fixed for GCC 8 by r8-4755". git clone https://sourceware.org/git/glibc.git cd glibc mkdir -p out/gcc; cd out/gcc ../../configure --prefix=3D/tmp/glibc/gcc --disable-werror make -j 20 # you can SIGINT after some needed files used below are genera= ted Comment out some lines to allow -O0 compiles: --- i/include/libc-symbols.h +++ w/include/libc-symbols.h @@ -71,9 +71,9 @@ #define _LIBC 1 /* Some files must be compiled with optimization on. */ -#if !defined __ASSEMBLER__ && !defined __OPTIMIZE__ -# error "glibc cannot be compiled without optimization" -#endif +//#if !defined __ASSEMBLER__ && !defined __OPTIMIZE__ +//# error "glibc cannot be compiled without optimization" +//#endif /* -ffast-math cannot be applied to the C library, as it alters the ABI. Some test components that use -ffast-math are currently not part of # My source dir is at $HOME/Dev/glibc . You may need to adjust. a=3D(../sysdeps/unix/sysv/linux/dl-opendir.c -std=3Dgnu11 -fgnu89-inline -g= -Wall -Wwrite-strings -Wundef -fmerge-all-constants -frounding-math -fno-stack-protector -fno-common -Wstrict-prototypes -Wold-style-definition -fmath-errno -fPIC -fno-stack-protector -DSTACK_PROTECTOR_LEVEL=3D0 -mno-mmx -ftls-model=3Dinitial-exec -I../include -I$HOME/Dev/glibc/out/gcc/elf -I$HOME/Dev/glibc/out/gcc -I../sysdeps/unix/sysv/linux/x86_64/64 -I../sysdeps/unix/sysv/linux/x86_64 -I../sysdeps/unix/sysv/linux/x86/include -I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/x86/nptl -I../sysdeps/unix/sysv/linux/wordsize-64 -I../sysdeps/x86_64/nptl -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux -I../sysdeps/nptl -I../sysdeps/pthread -I../sysdeps/gnu -I../sysdeps/unix/i= net -I../sysdeps/unix/sysv -I../sysdeps/unix/x86_64 -I../sysdeps/unix -I../sysdeps/posix -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../sysdeps/x86_64 -I../sysdeps/x86/include -I../sysdeps/x86 -I../sysdeps/ieee754/float128 -I../sysdeps/ieee754/ldbl-96/include -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/wordsize-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I.. -I../libio -I. -D_LIBC_REENTRANT -include $HOME/Dev/glibc/out/gcc/libc-modules.h -include ../include/libc-symbols.h -= DPIC -DSHARED -DTOP_NAMESPACE=3Dglibc -fsyntax-only) cd $HOME/Dev/glibc/elf % gcc-11 $=3Da -O2 # no diagnostic % gcc-11 $=3Da -O1 # no diagnostic % gcc-11 $=3Da -O0 In file included from ../include/features.h:488, from ../posix/sys/types.h:25, from ../include/sys/types.h:1, from ../sysdeps/unix/sysv/linux/dirstream.h:21, from ../include/dirent.h:3, from ../sysdeps/unix/sysv/linux/opendir.c:18, from ../sysdeps/unix/sysv/linux/dl-opendir.c:1: ../sysdeps/unix/sysv/linux/opendir.c: In function =E2=80=98__alloc_dir=E2= =80=99: ../sysdeps/unix/sysv/linux/opendir.c:107:35: error: expression in static assertion is not constant 107 | _Static_assert (allocation_size >=3D sizeof (struct dirent64), | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ ../include/sys/cdefs.h:7:59: note: in definition of macro =E2=80=98_Static_= assert=E2=80=99 7 | # define _Static_assert(expr, diagnostic) _Static_assert (expr, diagnostic) | ^~~~ gcc-8, gcc-9, and gcc-10 from Debian testing have the same behavior.=