public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "i at maskray dot me" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-102502-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102502

            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 = 32768;
  _Static_assert (allocation_size >= sizeof (struct dirent64), "allocation_size
< sizeof (struct dirent64)");

-O0 and non -O0 have different behaviors whether the `const int` operand can 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=/tmp/glibc/gcc --disable-werror
make -j 20   # you can SIGINT after some needed files used below are generated

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=(../sysdeps/unix/sysv/linux/dl-opendir.c -std=gnu11 -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=0 -mno-mmx
-ftls-model=initial-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/inet
-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=glibc -fsyntax-only)

cd $HOME/Dev/glibc/elf


% gcc-11 $=a -O2  # no diagnostic
% gcc-11 $=a -O1  # no diagnostic
% gcc-11 $=a -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 ‘__alloc_dir’:
../sysdeps/unix/sysv/linux/opendir.c:107:35: error: expression in static
assertion is not constant
  107 |   _Static_assert (allocation_size >= sizeof (struct dirent64),
      |                   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/sys/cdefs.h:7:59: note: in definition of macro ‘_Static_assert’
    7 | # define _Static_assert(expr, diagnostic) _Static_assert (expr,
diagnostic)
      |                                                           ^~~~


gcc-8, gcc-9, and gcc-10 from Debian testing have the same behavior.

             reply	other threads:[~2021-09-27 18:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 18:35 i at maskray dot me [this message]
2021-09-27 18:41 ` [Bug c/102502] " pinskia at gcc dot gnu.org
2021-09-27 18:55 ` jakub at gcc dot gnu.org
2021-09-27 19:53 ` i at maskray dot me
2021-09-27 20:54 ` pinskia at gcc dot gnu.org
2021-09-27 21:05 ` jakub at gcc dot gnu.org

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=bug-102502-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).