summaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 161fe8c7b3b..71fbf09caa7 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -66,6 +66,11 @@ along with GCC; see the file COPYING3. If not see
#include "asan.h"
#include "ubsan.h"
#include "cilk.h"
+#include "ipa-ref.h"
+#include "lto-streamer.h"
+#include "cgraph.h"
+#include "tree-chkp.h"
+#include "rtl-chkp.h"
static tree do_mpc_arg1 (tree, tree, int (*)(mpc_ptr, mpc_srcptr, mpc_rnd_t));
@@ -4324,6 +4329,13 @@ std_expand_builtin_va_start (tree valist, rtx nextarg)
{
rtx va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE);
convert_move (va_r, nextarg, 0);
+
+ /* We do not have any valid bounds for the pointer, so
+ just store zero bounds for it. */
+ if (chkp_function_instrumented_p (current_function_decl))
+ chkp_expand_bounds_reset_for_mem (valist,
+ make_tree (TREE_TYPE (valist),
+ nextarg));
}
/* Expand EXP, a call to __builtin_va_start. */
@@ -5791,7 +5803,19 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
&& fcode != BUILT_IN_EXECVE
&& fcode != BUILT_IN_ALLOCA
&& fcode != BUILT_IN_ALLOCA_WITH_ALIGN
- && fcode != BUILT_IN_FREE)
+ && fcode != BUILT_IN_FREE
+ && fcode != BUILT_IN_CHKP_SET_PTR_BOUNDS
+ && fcode != BUILT_IN_CHKP_INIT_PTR_BOUNDS
+ && fcode != BUILT_IN_CHKP_NULL_PTR_BOUNDS
+ && fcode != BUILT_IN_CHKP_COPY_PTR_BOUNDS
+ && fcode != BUILT_IN_CHKP_NARROW_PTR_BOUNDS
+ && fcode != BUILT_IN_CHKP_STORE_PTR_BOUNDS
+ && fcode != BUILT_IN_CHKP_CHECK_PTR_LBOUNDS
+ && fcode != BUILT_IN_CHKP_CHECK_PTR_UBOUNDS
+ && fcode != BUILT_IN_CHKP_CHECK_PTR_BOUNDS
+ && fcode != BUILT_IN_CHKP_GET_PTR_LBOUND
+ && fcode != BUILT_IN_CHKP_GET_PTR_UBOUND
+ && fcode != BUILT_IN_CHKP_BNDRET)
return expand_call (exp, target, ignore);
/* The built-in function expanders test for target == const0_rtx
@@ -5825,6 +5849,8 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
}
}
+ gcc_assert (!CALL_WITH_BOUNDS_P (exp));
+
switch (fcode)
{
CASE_FLT_FN (BUILT_IN_FABS):
@@ -6829,6 +6855,51 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
expand_builtin_cilk_pop_frame (exp);
return const0_rtx;
+ case BUILT_IN_CHKP_INIT_PTR_BOUNDS:
+ case BUILT_IN_CHKP_NULL_PTR_BOUNDS:
+ case BUILT_IN_CHKP_COPY_PTR_BOUNDS:
+ case BUILT_IN_CHKP_CHECK_PTR_LBOUNDS:
+ case BUILT_IN_CHKP_CHECK_PTR_UBOUNDS:
+ case BUILT_IN_CHKP_CHECK_PTR_BOUNDS:
+ case BUILT_IN_CHKP_SET_PTR_BOUNDS:
+ case BUILT_IN_CHKP_NARROW_PTR_BOUNDS:
+ case BUILT_IN_CHKP_STORE_PTR_BOUNDS:
+ case BUILT_IN_CHKP_GET_PTR_LBOUND:
+ case BUILT_IN_CHKP_GET_PTR_UBOUND:
+ /* We allow user CHKP builtins if Pointer Bounds
+ Checker is off. */
+ if (!chkp_function_instrumented_p (current_function_decl))
+ {
+ if (fcode == BUILT_IN_CHKP_SET_PTR_BOUNDS
+ || fcode == BUILT_IN_CHKP_NARROW_PTR_BOUNDS
+ || fcode == BUILT_IN_CHKP_INIT_PTR_BOUNDS
+ || fcode == BUILT_IN_CHKP_NULL_PTR_BOUNDS
+ || fcode == BUILT_IN_CHKP_COPY_PTR_BOUNDS)
+ return expand_normal (CALL_EXPR_ARG (exp, 0));
+ else if (fcode == BUILT_IN_CHKP_GET_PTR_LBOUND)
+ return expand_normal (size_zero_node);
+ else if (fcode == BUILT_IN_CHKP_GET_PTR_UBOUND)
+ return expand_normal (size_int (-1));
+ else
+ return const0_rtx;
+ }
+ /* FALLTHROUGH */
+
+ case BUILT_IN_CHKP_BNDMK:
+ case BUILT_IN_CHKP_BNDSTX:
+ case BUILT_IN_CHKP_BNDCL:
+ case BUILT_IN_CHKP_BNDCU:
+ case BUILT_IN_CHKP_BNDLDX:
+ case BUILT_IN_CHKP_BNDRET:
+ case BUILT_IN_CHKP_INTERSECT:
+ case BUILT_IN_CHKP_NARROW:
+ case BUILT_IN_CHKP_EXTRACT_LOWER:
+ case BUILT_IN_CHKP_EXTRACT_UPPER:
+ /* Software implementation of Pointer Bounds Checker is NYI.
+ Target support is required. */
+ error ("Your target platform does not support -fcheck-pointer-bounds");
+ break;
+
default: /* just do library call, if unknown builtin */
break;
}