tree-core.h (tree_index): Add TI_POINTER_BOUNDS_TYPE.
authorIlya Enkovich <ilya.enkovich@intel.com>
Wed, 30 Oct 2013 09:09:44 +0000 (09:09 +0000)
committerKirill Yukhin <kyukhin@gcc.gnu.org>
Wed, 30 Oct 2013 09:09:44 +0000 (09:09 +0000)
        * tree-core.h (tree_index): Add TI_POINTER_BOUNDS_TYPE.
        * tree.h (POINTER_BOUNDS_P): New.
        (BOUNDED_TYPE_P): New.
        (BOUNDED_P): New.
        (pointer_bounds_type_node): New.
        * tree.c (build_common_tree_nodes): Initialize
        pointer_bounds_type_node.
        * gimple.h (gimple_call_get_nobnd_arg_index): New.
        (gimple_call_num_nobnd_args): New.
        (gimple_call_nobnd_arg): New.
        (gimple_return_retbnd): New.
        (gimple_return_set_retbnd): New
        * gimple.c (gimple_build_return): Increase number of ops
        for return statement.
        (gimple_call_get_nobnd_arg_index): New.
        * gimple-pretty-print.c (dump_gimple_return): Print second op.

From-SVN: r204199

gcc/ChangeLog
gcc/chkp-builtins.def [new file with mode: 0644]
gcc/gimple-pretty-print.c
gcc/gimple.c
gcc/gimple.h
gcc/tree-core.h
gcc/tree.c
gcc/tree.h

index e391718c74878985ef5da0473cfb9eb29802ac2e..e733a50d580b42460788b63afa91d7dc5cea2f1c 100644 (file)
@@ -1,3 +1,22 @@
+2013-10-30  Ilya Enkovich  <ilya.enkovich@intel.com>
+
+       * tree-core.h (tree_index): Add TI_POINTER_BOUNDS_TYPE.
+       * tree.h (POINTER_BOUNDS_P): New.
+       (BOUNDED_TYPE_P): New.
+       (BOUNDED_P): New.
+       (pointer_bounds_type_node): New.
+       * tree.c (build_common_tree_nodes): Initialize
+       pointer_bounds_type_node.
+       * gimple.h (gimple_call_get_nobnd_arg_index): New.
+       (gimple_call_num_nobnd_args): New.
+       (gimple_call_nobnd_arg): New.
+       (gimple_return_retbnd): New.
+       (gimple_return_set_retbnd): New
+       * gimple.c (gimple_build_return): Increase number of ops
+       for return statement.
+       (gimple_call_get_nobnd_arg_index): New.
+       * gimple-pretty-print.c (dump_gimple_return): Print second op.
+
 2013-10-30  Ilya Enkovich  <ilya.enkovich@intel.com>
 
        * ipa.c (cgraph_build_static_cdtor_1): Support contructors
diff --git a/gcc/chkp-builtins.def b/gcc/chkp-builtins.def
new file mode 100644 (file)
index 0000000..d19b541
--- /dev/null
@@ -0,0 +1,73 @@
+/* This file contains the definitions and documentation for the
+   builtins used in the GNU compiler.
+   Copyright (C) 2013 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+/* Before including this file, you should define macros:
+
+      DEF_BUILTIN_STUB(ENUM, NAME)
+      DEF_CHKP_BUILTIN(ENUM, NAME, TYPE, ATTRS)
+
+   See builtins.def for details.  */
+
+/* Following builtins are used by compiler for Pointer Bounds Checker
+   instrumentation.  Currently these generic builtins are not
+   implemented and target has to provide his own version.  See
+   builtin_chkp_function target hook documentation for more details.  */
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDMK, "__chkp_bndmk")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDSTX, "__chkp_bndstx")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDCL, "__chkp_bndcl")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDCU, "__chkp_bndcu")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDLDX, "__chkp_bndldx")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_BNDRET, "__chkp_bndret")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_INTERSECT, "__chkp_intersect")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_ARG_BND, "__chkp_arg_bnd")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_SIZEOF, "__chkp_sizeof")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_EXTRACT_LOWER, "__chkp_extract_lower")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_EXTRACT_UPPER, "__chkp_extract_upper")
+DEF_BUILTIN_STUB (BUILT_IN_CHKP_NARROW, "__chkp_narrow")
+
+/* Pointer Bounds Checker builtins for users.  Only
+   BUILT_IN_CHKP_SET_PTR_BOUNDS may be redefined
+   by target.  Other builtins calls are expanded
+   in the Pointer Bounds Checker pass.  */
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_SET_PTR_BOUNDS, "__bnd_set_ptr_bounds", BT_FN_PTR_CONST_PTR_SIZE, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_INIT_PTR_BOUNDS, "__bnd_init_ptr_bounds", BT_FN_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_NULL_PTR_BOUNDS, "__bnd_null_ptr_bounds", BT_FN_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_COPY_PTR_BOUNDS, "__bnd_copy_ptr_bounds", BT_FN_PTR_CONST_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_NARROW_PTR_BOUNDS, "__bnd_narrow_ptr_bounds", BT_FN_PTR_CONST_PTR_CONST_PTR_SIZE, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_STORE_PTR_BOUNDS, "__bnd_store_ptr_bounds", BT_FN_VOID_PTRPTR_CONST_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_CHECK_PTR_LBOUNDS, "__bnd_chk_ptr_lbounds", BT_FN_VOID_CONST_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_CHECK_PTR_UBOUNDS, "__bnd_chk_ptr_ubounds", BT_FN_VOID_CONST_PTR, ATTR_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_CHECK_PTR_BOUNDS, "__bnd_chk_ptr_bounds", BT_FN_VOID_CONST_PTR_SIZE, ATTR_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_GET_PTR_LBOUND, "__bnd_get_ptr_lbound", BT_FN_CONST_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_GET_PTR_UBOUND, "__bnd_get_ptr_ubound", BT_FN_CONST_PTR_CONST_PTR, ATTR_CONST_NOTHROW_LEAF_LIST)
+
+/* Pointer Bounds Checker specific versions of string functions.  */
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMCPY_NOBND, "chkp_memcpy_nobnd", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMCPY_NOCHK, "chkp_memcpy_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMCPY_NOBND_NOCHK, "chkp_memcpy_nobnd_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMMOVE_NOBND, "chkp_memmove_nobnd", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMMOVE_NOCHK, "chkp_memmove_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMMOVE_NOBND_NOCHK, "chkp_memmove_nobnd_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMPCPY_NOBND, "chkp_mempcpy_nobnd", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMPCPY_NOCHK, "chkp_mempcpy_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMPCPY_NOBND_NOCHK, "chkp_mempcpy_nobnd_nochk", BT_FN_PTR_PTR_CONST_PTR_SIZE, ATTR_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMSET_NOBND, "chkp_memset_nobnd", BT_FN_PTR_PTR_INT_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMSET_NOCHK, "chkp_memset_nochk", BT_FN_PTR_PTR_INT_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
+DEF_CHKP_BUILTIN (BUILT_IN_CHKP_MEMSET_NOBND_NOCHK, "chkp_memset_nobnd_nochk", BT_FN_PTR_PTR_INT_SIZE, ATTR_RET1_NOTHROW_NONNULL_LEAF)
index e4b0f81481d299000491879fa4486707f3257770..248dfea01af449b5aeb4b672eb3c259df476760f 100644 (file)
@@ -539,11 +539,12 @@ dump_gimple_assign (pretty_printer *buffer, gimple gs, int spc, int flags)
 static void
 dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
 {
-  tree t;
+  tree t, t2;
 
   t = gimple_return_retval (gs);
+  t2 = gimple_return_retbnd (gs);
   if (flags & TDF_RAW)
-    dump_gimple_fmt (buffer, spc, flags, "%G <%T>", gs, t);
+    dump_gimple_fmt (buffer, spc, flags, "%G <%T %T>", gs, t, t2);
   else
     {
       pp_string (buffer, "return");
@@ -552,6 +553,11 @@ dump_gimple_return (pretty_printer *buffer, gimple gs, int spc, int flags)
          pp_space (buffer);
          dump_generic_node (buffer, t, spc, flags, false);
        }
+      if (t2)
+       {
+         pp_string (buffer, ", ");
+         dump_generic_node (buffer, t2, spc, flags, false);
+       }
       pp_semicolon (buffer);
     }
 }
index 3ddceb95cf32a438297615689c2ab0fe359dd67c..20f6010a1130bdbd47d00f8f2820ace6a1b8ee05 100644 (file)
@@ -174,7 +174,7 @@ gimple_build_with_ops_stat (enum gimple_code code, unsigned subcode,
 gimple
 gimple_build_return (tree retval)
 {
-  gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 1);
+  gimple s = gimple_build_with_ops (GIMPLE_RETURN, ERROR_MARK, 2);
   if (retval)
     gimple_return_set_retval (s, retval);
   return s;
@@ -366,6 +366,26 @@ gimple_build_call_from_tree (tree t)
 }
 
 
+/* Return index of INDEX's non bound argument of the call.  */
+
+unsigned
+gimple_call_get_nobnd_arg_index (const_gimple gs, unsigned index)
+{
+  unsigned num_args = gimple_call_num_args (gs);
+  for (unsigned n = 0; n < num_args; n++)
+    {
+      if (POINTER_BOUNDS_P (gimple_call_arg (gs, n)))
+       continue;
+      else if (index)
+       index--;
+      else
+       return n;
+    }
+
+  gcc_unreachable ();
+}
+
+
 /* Extract the operands and code for expression EXPR into *SUBCODE_P,
    *OP1_P, *OP2_P and *OP3_P respectively.  */
 
index b0fb861079f22fb4bfdd992071069c264d7383ec..b34424c18d3560aa2a410fb57e44953255c3d7fc 100644 (file)
@@ -918,6 +918,7 @@ extern tree get_initialized_tmp_var (tree, gimple_seq *, gimple_seq *);
 extern tree get_formal_tmp_var (tree, gimple_seq *);
 extern void declare_vars (tree, gimple, bool);
 extern void annotate_all_with_location (gimple_seq, location_t);
+extern unsigned gimple_call_get_nobnd_arg_index (const_gimple, unsigned);
 
 /* Validation of GIMPLE expressions.  Note that these predicates only check
    the basic form of the expression, they don't recurse to make sure that
@@ -2413,6 +2414,32 @@ gimple_call_arg (const_gimple gs, unsigned index)
 }
 
 
+/* Return the number of arguments used by call statement GS
+   ignoring bound ones.  */
+
+static inline unsigned
+gimple_call_num_nobnd_args (const_gimple gs)
+{
+  unsigned num_args = gimple_call_num_args (gs);
+  unsigned res = num_args;
+  for (unsigned n = 0; n < num_args; n++)
+    if (POINTER_BOUNDS_P (gimple_call_arg (gs, n)))
+      res--;
+  return res;
+}
+
+
+/* Return INDEX's call argument ignoring bound ones.  */
+static inline tree
+gimple_call_nobnd_arg (const_gimple gs, unsigned index)
+{
+  /* No bound args may exist if pointers checker is off.  */
+  if (!flag_check_pointer_bounds)
+    return gimple_call_arg (gs, index);
+  return gimple_call_arg (gs, gimple_call_get_nobnd_arg_index (gs, index));
+}
+
+
 /* Return a pointer to the argument at position INDEX for call
    statement GS.  */
 
@@ -5219,6 +5246,26 @@ gimple_return_set_retval (gimple gs, tree retval)
 }
 
 
+/* Return the return bounds for GIMPLE_RETURN GS.  */
+
+static inline tree
+gimple_return_retbnd (const_gimple gs)
+{
+  GIMPLE_CHECK (gs, GIMPLE_RETURN);
+  return gimple_op (gs, 1);
+}
+
+
+/* Set RETVAL to be the return bounds for GIMPLE_RETURN GS.  */
+
+static inline void
+gimple_return_set_retbnd (gimple gs, tree retval)
+{
+  GIMPLE_CHECK (gs, GIMPLE_RETURN);
+  gimple_set_op (gs, 1, retval);
+}
+
+
 /* Returns true when the gimple statement STMT is any of the OpenMP types.  */
 
 #define CASE_GIMPLE_OMP                                \
index ea110bc09e374efe1d9c53f4538eb339b6dc2ec9..638b3ab3f68c88164981edf9e709fa8013a39a15 100644 (file)
@@ -448,6 +448,8 @@ enum tree_index {
   TI_FILEPTR_TYPE,
   TI_POINTER_SIZED_TYPE,
 
+  TI_POINTER_BOUNDS_TYPE,
+
   TI_DFLOAT32_TYPE,
   TI_DFLOAT64_TYPE,
   TI_DFLOAT128_TYPE,
index ecefee1f8b8f99594875b4b91a4fe0b7d89c97e2..094459a384bdf364e254fd634d0815a787ae512e 100644 (file)
@@ -9765,6 +9765,8 @@ build_common_tree_nodes (bool signed_char, bool short_double)
   void_type_node = make_node (VOID_TYPE);
   layout_type (void_type_node);
 
+  pointer_bounds_type_node = targetm.chkp_bound_type ();
+
   /* We are not going to have real types in C with less than byte alignment,
      so we might as well not have any types that claim to have it.  */
   TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
index cbe8272f646108cc2996dc4fd1284ff1ca2352e3..33aea7fff12e978de9adba8d94d9703a3e563e2d 100644 (file)
@@ -546,6 +546,17 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
 #define POINTER_BOUNDS_TYPE_P(NODE) \
   (TREE_CODE (NODE) == POINTER_BOUNDS_TYPE)
 
+/* Nonzero if this node has a pointer bounds type.  */
+#define POINTER_BOUNDS_P(NODE) \
+  (POINTER_BOUNDS_TYPE_P (TREE_TYPE (NODE)))
+
+/* Nonzero if this type supposes bounds existence.  */
+#define BOUNDED_TYPE_P(type) (POINTER_TYPE_P (type))
+
+/* Nonzero for objects with bounded type.  */
+#define BOUNDED_P(node) \
+  BOUNDED_TYPE_P (TREE_TYPE (node))
+
 /* Nonzero if this type is the (possibly qualified) void type.  */
 #define VOID_TYPE_P(NODE) (TREE_CODE (NODE) == VOID_TYPE)
 
@@ -3200,6 +3211,8 @@ tree_operand_check_code (const_tree __t, enum tree_code __code, int __i,
 #define complex_double_type_node       global_trees[TI_COMPLEX_DOUBLE_TYPE]
 #define complex_long_double_type_node  global_trees[TI_COMPLEX_LONG_DOUBLE_TYPE]
 
+#define pointer_bounds_type_node        global_trees[TI_POINTER_BOUNDS_TYPE]
+
 #define void_type_node                 global_trees[TI_VOID_TYPE]
 /* The C type `void *'.  */
 #define ptr_type_node                  global_trees[TI_PTR_TYPE]