1
Fork 0
forked from gcc/gcc-TEST
TEST repository for https://forge.sourceware.org/ experimenting.
Find a file
Joseph Myers 908edc1309 c: Implement C2y N3517 array subscripting without decay
N3517 (array subscripting without decay) has been added to C2y (via a
remote vote in May, not at a meeting).  Implement this in GCC.

The conceptual change, that the array subscripting operator [] no
longer involves an array operand decaying to a pointer, is something
GCC has done for a very long time.  The main effect in terms of what
is made possible in the language, subscripting a register array
(undefined behavior in C23 and before), was available as a GNU
extension, but only with constant indices.  There is also a new
constraint that array indices must not be negative when they are
integer constant expressions and the array operand has array type
(negative indices are fine with pointers) - an access out of bounds of
an array (even when contained within a larger object) has undefined
behavior at runtime when not a constraint violation.

Thus, the previous GCC extension is adapted to allow the cases of
register arrays not previously allowed, clearing DECL_REGISTER on them
as needed (similar to what is done with register declarations of
structures with volatile members) and restricting the pedwarn to
pedwarn_c23.  That pedwarn_c23 is also extended to cover the C23 case
of register compound literals (although not strictly needed since it
was undefined behavior rather than a constraint violation in C23).
The new error is added (only for flag_isoc2y) for negative array
indices with an operand of array type.

N3517 has some specific wording about the type of the result of
non-lvalue array element access.  It's unclear what's actually desired
there in the case where the array element is itself of array type; see
C23 issue 1001 regarding types of qualified members of rvalue
structures and unions more generally.  Rather than implementing the
specific wording about this in N3517, that is deferred until there's
an accepted resolution to issue 1001 and can be dealt with as part of
implementing such a resolution.

Nothing specific is done about the obsolescence in that paper of
writing index[array] or index[pointer] as opposed to array[index] or
pointer[index], although that seems like a reasonable enough thing to
warn about.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c/
	* c-typeck.cc (c_mark_addressable): New parameter
	override_register.
	(build_array_ref): Update calls to c_mark_addressable.  Give error
	in C2Y mode for negative array indices when array expression is an
	array not a pointer.  Use pedwarn_c23 for subscripting register
	array; diagnose that also for register compound literal.
	* c-tree.h (c_mark_addressable): Update prototype.

gcc/testsuite/
	* gcc.dg/c23-array-negative-1.c, gcc.dg/c23-register-array-1.c,
	gcc.dg/c23-register-array-2.c, gcc.dg/c23-register-array-3.c,
	gcc.dg/c23-register-array-4.c, gcc.dg/c2y-array-negative-1.c,
	gcc.dg/c2y-register-array-2.c, gcc.dg/c2y-register-array-3.c: New
	tests.
2025-09-13 00:21:58 +00:00
.forgejo
.github
c++tools
config
contrib Daily bump. 2025-09-11 00:20:14 +00:00
fixincludes
gcc c: Implement C2y N3517 array subscripting without decay 2025-09-13 00:21:58 +00:00
gnattools
gotools
include
INSTALL
libada
libatomic
libbacktrace
libcc1
libcody
libcpp
libdecnumber
libffi
libgcc
libgcobol
libgfortran
libgm2
libgo
libgomp Daily bump. 2025-09-07 00:20:16 +00:00
libgrust
libiberty
libitm
libobjc
libphobos Daily bump. 2025-09-08 00:20:50 +00:00
libquadmath
libsanitizer
libssp
libstdc++-v3 Daily bump. 2025-09-13 00:19:19 +00:00
libvtv
lto-plugin
maintainer-scripts
zlib
.b4-config
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ar-lib
ChangeLog
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS
Makefile.def
Makefile.in
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
SECURITY.txt
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.