Watch
1
Fork
You've already forked gcc-TEST
0
forked from gcc/gcc
TEST repository for https://forge.sourceware.org/ experimenting.
  • C++ 31%
  • C 30.4%
  • Ada 14.9%
  • D 6.2%
  • Go 5.9%
  • Other 11.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
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 Daily bump. 2025-08-11 00:16:52 +00:00
contrib Daily bump. 2025-09-11 00:20:14 +00:00
fixincludes Daily bump. 2025-08-29 00:19:55 +00:00
gcc c: Implement C2y N3517 array subscripting without decay 2025-09-13 00:21:58 +00:00
gnattools Daily bump. 2025-06-23 00:16:33 +00:00
gotools
include Daily bump. 2025-08-17 00:19:17 +00:00
INSTALL
libada
libatomic Daily bump. 2025-08-01 00:20:20 +00:00
libbacktrace
libcc1 Daily bump. 2025-07-26 00:19:51 +00:00
libcody
libcpp Daily bump. 2025-09-02 00:19:26 +00:00
libdecnumber
libffi
libgcc Daily bump. 2025-08-31 00:18:58 +00:00
libgcobol Daily bump. 2025-09-06 00:20:34 +00:00
libgfortran Daily bump. 2025-09-03 00:20:18 +00:00
libgm2 Daily bump. 2025-07-24 00:20:56 +00:00
libgo runtime: avoid libc memmove and memclr 2025-07-08 15:49:16 -07:00
libgomp Daily bump. 2025-09-07 00:20:16 +00:00
libgrust Daily bump. 2025-08-06 00:21:26 +00:00
libiberty Daily bump. 2025-08-17 00:19:17 +00:00
libitm
libobjc
libphobos Daily bump. 2025-09-08 00:20:50 +00:00
libquadmath
libsanitizer [sanitizer_common] Remove reference to obsolete termio ioctls (#138822) 2025-07-30 23:29:52 +01:00
libssp
libstdc++-v3 Daily bump. 2025-09-13 00:19:19 +00:00
libvtv
lto-plugin
maintainer-scripts Daily bump. 2025-09-02 00:19:26 +00:00
zlib Daily bump. 2025-08-01 00:20:20 +00:00
.b4-config
.dir-locals.el
.gitattributes
.gitignore Rust: Move 'libformat_parser' build into the GCC build directory 2025-08-05 16:36:43 +02:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2025-09-05 00:19:51 +00:00
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 MAINTAINERS: Add myself as an aarch64 port reviewer 2025-09-04 14:35:30 +00:00
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.