diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-06-16 10:11:07 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-06-16 23:35:34 +0200 |
commit | f267a3109884c6b623b72f20cbc208561efaf5ff (patch) | |
tree | 855ddae45ab983915bafb49f5d4a5183a2f7c1c0 /gcc/d/d-codegen.cc | |
parent | e40b11a91cb345db1324c3cb8f75b01e28056693 (diff) | |
download | gcc-f267a3109884c6b623b72f20cbc208561efaf5ff.zip gcc-f267a3109884c6b623b72f20cbc208561efaf5ff.tar.gz gcc-f267a3109884c6b623b72f20cbc208561efaf5ff.tar.bz2 |
d: Move generation of array bounds error to own function.
gcc/d/ChangeLog:
* d-codegen.cc (build_array_bounds_call): New function.
(build_bounds_condition): Use build_array_bounds_call.
* d-lang.cc (d_init_options): Explicitly set default check action to
CHECKACTION_D.
(d_post_options): Set check action to CHECKACTION_C if the flag
-fno-druntime was seen.
* d-tree.h (build_array_bounds_call): Declare.
* expr.cc (ExprVisitor::visit (AssertExp *)): Use
build_array_bounds_call.
Diffstat (limited to 'gcc/d/d-codegen.cc')
-rw-r--r-- | gcc/d/d-codegen.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index d31638e..9d13e12 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -1712,6 +1712,26 @@ void_okay_p (tree t) return t; } +/* Builds a CALL_EXPR at location LOC in the source file to execute when an + array bounds check fails. */ + +tree +build_array_bounds_call (const Loc &loc) +{ + switch (global.params.checkAction) + { + case CHECKACTION_D: + return d_assert_call (loc, LIBCALL_ARRAY_BOUNDS); + + case CHECKACTION_C: + case CHECKACTION_halt: + return build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0); + + default: + gcc_unreachable (); + } +} + /* Builds a bounds condition checking that INDEX is between 0 and LEN. The condition returns the INDEX if true, or throws a RangeError. If INCLUSIVE, we allow INDEX == LEN to return true also. */ @@ -1731,9 +1751,7 @@ build_bounds_condition (const Loc& loc, tree index, tree len, bool inclusive) tree condition = fold_build2 (inclusive ? GT_EXPR : GE_EXPR, d_bool_type, index, len); /* Terminate the program with a trap if no D runtime present. */ - tree boundserr = (global.params.checkAction == CHECKACTION_D) - ? d_assert_call (loc, LIBCALL_ARRAY_BOUNDS) - : build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0); + tree boundserr = build_array_bounds_call (loc); return build_condition (TREE_TYPE (index), condition, boundserr, index); } |