GCC with patches for OS216
Revision | f267a3109884c6b623b72f20cbc208561efaf5ff (tree) |
---|---|
Time | 2020-06-17 06:35:34 |
Author | Iain Buclaw <ibuclaw@gdcp...> |
Commiter | Iain Buclaw |
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.
@@ -1712,6 +1712,26 @@ void_okay_p (tree t) | ||
1712 | 1712 | return t; |
1713 | 1713 | } |
1714 | 1714 | |
1715 | +/* Builds a CALL_EXPR at location LOC in the source file to execute when an | |
1716 | + array bounds check fails. */ | |
1717 | + | |
1718 | +tree | |
1719 | +build_array_bounds_call (const Loc &loc) | |
1720 | +{ | |
1721 | + switch (global.params.checkAction) | |
1722 | + { | |
1723 | + case CHECKACTION_D: | |
1724 | + return d_assert_call (loc, LIBCALL_ARRAY_BOUNDS); | |
1725 | + | |
1726 | + case CHECKACTION_C: | |
1727 | + case CHECKACTION_halt: | |
1728 | + return build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0); | |
1729 | + | |
1730 | + default: | |
1731 | + gcc_unreachable (); | |
1732 | + } | |
1733 | +} | |
1734 | + | |
1715 | 1735 | /* Builds a bounds condition checking that INDEX is between 0 and LEN. |
1716 | 1736 | The condition returns the INDEX if true, or throws a RangeError. |
1717 | 1737 | 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) | ||
1731 | 1751 | tree condition = fold_build2 (inclusive ? GT_EXPR : GE_EXPR, |
1732 | 1752 | d_bool_type, index, len); |
1733 | 1753 | /* Terminate the program with a trap if no D runtime present. */ |
1734 | - tree boundserr = (global.params.checkAction == CHECKACTION_D) | |
1735 | - ? d_assert_call (loc, LIBCALL_ARRAY_BOUNDS) | |
1736 | - : build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0); | |
1754 | + tree boundserr = build_array_bounds_call (loc); | |
1737 | 1755 | |
1738 | 1756 | return build_condition (TREE_TYPE (index), condition, boundserr, index); |
1739 | 1757 | } |
@@ -285,6 +285,7 @@ d_init_options (unsigned int, cl_decoded_option *decoded_options) | ||
285 | 285 | global.params.useOut = CHECKENABLEdefault; |
286 | 286 | global.params.useArrayBounds = CHECKENABLEdefault; |
287 | 287 | global.params.useSwitchError = CHECKENABLEdefault; |
288 | + global.params.checkAction = CHECKACTION_D; | |
288 | 289 | global.params.useModuleInfo = true; |
289 | 290 | global.params.useTypeInfo = true; |
290 | 291 | global.params.useExceptions = true; |
@@ -775,7 +776,7 @@ d_post_options (const char ** fn) | ||
775 | 776 | if (!global_options_set.x_flag_exceptions) |
776 | 777 | global.params.useExceptions = false; |
777 | 778 | |
778 | - global.params.checkAction = CHECKACTION_halt; | |
779 | + global.params.checkAction = CHECKACTION_C; | |
779 | 780 | } |
780 | 781 | |
781 | 782 | /* Keep in sync with existing -fbounds-check flag. */ |
@@ -560,6 +560,7 @@ extern tree build_memref (tree, tree, tree); | ||
560 | 560 | extern tree build_array_set (tree, tree, tree); |
561 | 561 | extern tree build_array_from_val (Type *, tree); |
562 | 562 | extern tree void_okay_p (tree); |
563 | +extern tree build_array_bounds_call (const Loc &); | |
563 | 564 | extern tree build_bounds_condition (const Loc &, tree, tree, bool); |
564 | 565 | extern bool array_bounds_check (void); |
565 | 566 | extern tree bind_expr (tree, tree); |
@@ -1218,9 +1218,7 @@ public: | ||
1218 | 1218 | |
1219 | 1219 | if (!e->indexIsInBounds && array_bounds_check ()) |
1220 | 1220 | { |
1221 | - tree tassert = (global.params.checkAction == CHECKACTION_D) | |
1222 | - ? d_assert_call (e->loc, LIBCALL_ARRAY_BOUNDS) | |
1223 | - : build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0); | |
1221 | + tree tassert = build_array_bounds_call (e->loc); | |
1224 | 1222 | |
1225 | 1223 | result = d_save_expr (result); |
1226 | 1224 | result = build_condition (TREE_TYPE (result), |