mirrored from git://gcc.gnu.org/git/gcc.git
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// { dg-do "compile" } | ||
// { dg-options "-O -fdump-tree-optimized" } | ||
immutable uint[] imm_arr = [1,2,3]; | ||
int test_imm(immutable uint[] ptr) | ||
{ | ||
return imm_arr[2] == 3 ? 123 : 456; | ||
} | ||
// { dg-final { scan-assembler-not "_d_arraybounds_indexp" } } | ||
// { dg-final { scan-tree-dump "return 123;" optimized } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// { dg-do "compile" } | ||
// { dg-options "-O" } | ||
immutable uint[] imm_ctor_arr; | ||
int test_imm_ctor(immutable uint[] ptr) | ||
{ | ||
return imm_ctor_arr[2] == 3; | ||
} | ||
// { dg-final { scan-assembler "_d_arraybounds_indexp" } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// { dg-do "compile" } | ||
// { dg-options "-O" } | ||
const uint[] cst_arr = [1,2,3]; | ||
int test_cst(const uint[] ptr) | ||
{ | ||
return cst_arr[2] == 3; | ||
} | ||
// { dg-final { scan-assembler "_d_arraybounds_indexp" } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// { dg-do "compile" } | ||
// { dg-options "-O" } | ||
const uint[] cst_ctor_arr; | ||
int test_cst_ctor(const uint[] ptr) | ||
{ | ||
return cst_ctor_arr[2] == 3; | ||
} | ||
// { dg-final { scan-assembler "_d_arraybounds_indexp" } } |