• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GCC with patches for OS216


Commit MetaInfo

Revisionf267a3109884c6b623b72f20cbc208561efaf5ff (tree)
Time2020-06-17 06:35:34
AuthorIain Buclaw <ibuclaw@gdcp...>
CommiterIain Buclaw

Log Message

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.

Change Summary

Incremental Difference

--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -1712,6 +1712,26 @@ void_okay_p (tree t)
17121712 return t;
17131713 }
17141714
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+
17151735 /* Builds a bounds condition checking that INDEX is between 0 and LEN.
17161736 The condition returns the INDEX if true, or throws a RangeError.
17171737 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)
17311751 tree condition = fold_build2 (inclusive ? GT_EXPR : GE_EXPR,
17321752 d_bool_type, index, len);
17331753 /* 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);
17371755
17381756 return build_condition (TREE_TYPE (index), condition, boundserr, index);
17391757 }
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -285,6 +285,7 @@ d_init_options (unsigned int, cl_decoded_option *decoded_options)
285285 global.params.useOut = CHECKENABLEdefault;
286286 global.params.useArrayBounds = CHECKENABLEdefault;
287287 global.params.useSwitchError = CHECKENABLEdefault;
288+ global.params.checkAction = CHECKACTION_D;
288289 global.params.useModuleInfo = true;
289290 global.params.useTypeInfo = true;
290291 global.params.useExceptions = true;
@@ -775,7 +776,7 @@ d_post_options (const char ** fn)
775776 if (!global_options_set.x_flag_exceptions)
776777 global.params.useExceptions = false;
777778
778- global.params.checkAction = CHECKACTION_halt;
779+ global.params.checkAction = CHECKACTION_C;
779780 }
780781
781782 /* Keep in sync with existing -fbounds-check flag. */
--- a/gcc/d/d-tree.h
+++ b/gcc/d/d-tree.h
@@ -560,6 +560,7 @@ extern tree build_memref (tree, tree, tree);
560560 extern tree build_array_set (tree, tree, tree);
561561 extern tree build_array_from_val (Type *, tree);
562562 extern tree void_okay_p (tree);
563+extern tree build_array_bounds_call (const Loc &);
563564 extern tree build_bounds_condition (const Loc &, tree, tree, bool);
564565 extern bool array_bounds_check (void);
565566 extern tree bind_expr (tree, tree);
--- a/gcc/d/expr.cc
+++ b/gcc/d/expr.cc
@@ -1218,9 +1218,7 @@ public:
12181218
12191219 if (!e->indexIsInBounds && array_bounds_check ())
12201220 {
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);
12241222
12251223 result = d_save_expr (result);
12261224 result = build_condition (TREE_TYPE (result),