]> git.ipfire.org Git - thirdparty/gcc.git/commit
d: Fix accesses of immutable arrays using constant index still bounds checked
authorIain Buclaw <ibuclaw@gdcproject.org>
Sat, 1 Jul 2023 21:32:53 +0000 (23:32 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Sat, 1 Jul 2023 23:10:31 +0000 (01:10 +0200)
commit61b1c562f8c703bff045e91257120e42b7fae523
tree9262cb6550adba86a8ec45f4408a042b4776809c
parentfca6d9c12f5bf06469cf9f7db8c42f66ef792fd2
d: Fix accesses of immutable arrays using constant index still bounds checked

Starts setting TREE_READONLY against specific kinds of VAR_DECLs, so
that the middle-end/optimization passes can more aggressively constant
fold D code that makes use of `immutable' or `const'.

PR d/110514

gcc/d/ChangeLog:

* decl.cc (get_symbol_decl): Set TREE_READONLY on certain kinds of
const and immutable variables.
* expr.cc (ExprVisitor::visit (ArrayLiteralExp *)): Set TREE_READONLY
on immutable dynamic array literals.

gcc/testsuite/ChangeLog:

* gdc.dg/pr110514a.d: New test.
* gdc.dg/pr110514b.d: New test.
* gdc.dg/pr110514c.d: New test.
* gdc.dg/pr110514d.d: New test.
gcc/d/decl.cc
gcc/d/expr.cc
gcc/testsuite/gdc.dg/pr110514a.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr110514b.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr110514c.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr110514d.d [new file with mode: 0644]