aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/expr.cc
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2023-07-01 23:32:53 +0200
committerIain Buclaw <ibuclaw@gdcproject.org>2023-07-02 01:10:31 +0200
commit61b1c562f8c703bff045e91257120e42b7fae523 (patch)
tree9262cb6550adba86a8ec45f4408a042b4776809c /gcc/d/expr.cc
parentfca6d9c12f5bf06469cf9f7db8c42f66ef792fd2 (diff)
downloadgcc-61b1c562f8c703bff045e91257120e42b7fae523.zip
gcc-61b1c562f8c703bff045e91257120e42b7fae523.tar.gz
gcc-61b1c562f8c703bff045e91257120e42b7fae523.tar.bz2
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.
Diffstat (limited to 'gcc/d/expr.cc')
-rw-r--r--gcc/d/expr.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc
index c6245ff..aeafe43 100644
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -2701,6 +2701,10 @@ public:
if (tb->ty == TY::Tarray)
ctor = d_array_value (type, size_int (e->elements->length), ctor);
+ /* Immutable literals can be placed in rodata. */
+ if (tb->isImmutable ())
+ TREE_READONLY (decl) = 1;
+
d_pushdecl (decl);
rest_of_decl_compilation (decl, 1, 0);
}