Patchwork [ubsan] Add libcall arguments

login
register
mail settings
Submitter Marek Polacek
Date July 22, 2013, 8:50 a.m.
Message ID <20130722085024.GD14359@redhat.com>
Download mbox | patch
Permalink /patch/260610/
State New
Headers show

Comments

Marek Polacek - July 22, 2013, 8:50 a.m.
On Sun, Jul 21, 2013 at 10:41:15PM -0400, Jason Merrill wrote:
> On 07/21/2013 02:26 PM, Marek Polacek wrote:
> >	(pointer_sized_type_node): Define.
> 
> Let's call it pointer_sized_int_node.

Sure.  Here it is.

2013-07-21  Marek Polacek  <polacek@redhat.com>

	* tree.h (enum tree_index): Add TI_POINTER_SIZED_TYPE. 
	(pointer_sized_int_node): Define.
	* tree.c (build_common_tree_nodes): Initialize
	pointer_sized_int_node.
	* ubsan.c (ubsan_encode_value): Use pointer_sized_int_node instead
	calling uptr_type.
	(uptr_type): Remove function.
	* asan.c (asan_global_struct): Use pointer_sized_int_node instead
	calling build_nonstandard_integer_type.
	(initialize_sanitizer_builtins): Likewise.
	(asan_finish_file): Likewise.


	Marek

Patch

--- gcc/tree.c.mp	2013-07-21 19:54:35.416986756 +0200
+++ gcc/tree.c	2013-07-21 19:56:58.347562787 +0200
@@ -9638,6 +9638,8 @@  build_common_tree_nodes (bool signed_cha
     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
   fileptr_type_node = ptr_type_node;
 
+  pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);
+
   float_type_node = make_node (REAL_TYPE);
   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
   layout_type (float_type_node);
--- gcc/ubsan.c.mp	2013-07-21 20:04:59.469653493 +0200
+++ gcc/ubsan.c	2013-07-21 20:07:00.227178083 +0200
@@ -123,14 +123,6 @@  ubsan_typedesc_new (tree type, tree decl
   return desc;
 }
 
-/* Build the ubsan uptr type.  */
-
-static tree
-uptr_type (void)
-{
-  return build_nonstandard_integer_type (POINTER_SIZE, 1);
-}
-
 /* Helper routine, which encodes a value in the uptr type.
    Arguments with precision <= POINTER_SIZE are passed directly,
    the rest is passed by reference.  T is a value we are to encode.  */
@@ -143,7 +135,7 @@  ubsan_encode_value (tree t)
     {
     case INTEGER_TYPE:
       if (TYPE_PRECISION (type) <= POINTER_SIZE)
-	return fold_build1 (NOP_EXPR, uptr_type (), t);
+	return fold_build1 (NOP_EXPR, pointer_sized_int_node, t);
       else
 	return build_fold_addr_expr (t);
     case REAL_TYPE:
@@ -153,7 +145,7 @@  ubsan_encode_value (tree t)
 	  {
 	    tree itype = build_nonstandard_integer_type (bitsize, true);
 	    t = fold_build1 (VIEW_CONVERT_EXPR, itype, t);
-	    return fold_convert (uptr_type (), t);
+	    return fold_convert (pointer_sized_int_node, t);
 	  }
 	else
 	  {
--- gcc/tree.h.mp	2013-07-21 19:54:35.441986868 +0200
+++ gcc/tree.h	2013-07-21 19:56:05.128353854 +0200
@@ -4227,6 +4227,7 @@  enum tree_index
   TI_VA_LIST_FPR_COUNTER_FIELD,
   TI_BOOLEAN_TYPE,
   TI_FILEPTR_TYPE,
+  TI_POINTER_SIZED_TYPE,
 
   TI_DFLOAT32_TYPE,
   TI_DFLOAT64_TYPE,
@@ -4383,6 +4384,7 @@  extern GTY(()) tree global_trees[TI_MAX]
 #define va_list_fpr_counter_field	global_trees[TI_VA_LIST_FPR_COUNTER_FIELD]
 /* The C type `FILE *'.  */
 #define fileptr_type_node		global_trees[TI_FILEPTR_TYPE]
+#define pointer_sized_int_node		global_trees[TI_POINTER_SIZED_TYPE]
 
 #define boolean_type_node		global_trees[TI_BOOLEAN_TYPE]
 #define boolean_false_node		global_trees[TI_BOOLEAN_FALSE]
--- gcc/asan.c.mp	2013-07-21 20:07:15.013237456 +0200
+++ gcc/asan.c	2013-07-21 20:16:10.929376734 +0200
@@ -1954,7 +1954,7 @@  asan_global_struct (void)
 	= build_decl (UNKNOWN_LOCATION, FIELD_DECL,
 		      get_identifier (field_names[i]),
 		      (i == 0 || i == 3) ? const_ptr_type_node
-		      : build_nonstandard_integer_type (POINTER_SIZE, 1));
+		      : pointer_sized_int_node);
       DECL_CONTEXT (fields[i]) = ret;
       if (i)
 	DECL_CHAIN (fields[i - 1]) = fields[i];
@@ -2039,8 +2039,7 @@  initialize_sanitizer_builtins (void)
 				ptr_type_node, ptr_type_node, NULL_TREE);
   tree BT_FN_VOID_PTR_PTRMODE
     = build_function_type_list (void_type_node, ptr_type_node,
-				build_nonstandard_integer_type (POINTER_SIZE,
-								1), NULL_TREE);
+				pointer_sized_int_node, NULL_TREE);
   tree BT_FN_VOID_INT
     = build_function_type_list (void_type_node, integer_type_node, NULL_TREE);
   tree BT_FN_BOOL_VPTR_PTR_IX_INT_INT[5];
@@ -2197,7 +2196,6 @@  asan_finish_file (void)
   if (gcount)
     {
       tree type = asan_global_struct (), var, ctor;
-      tree uptr = build_nonstandard_integer_type (POINTER_SIZE, 1);
       tree dtor_statements = NULL_TREE;
       vec<constructor_elt, va_gc> *v;
       char buf[20];
@@ -2226,15 +2224,16 @@  asan_finish_file (void)
       varpool_assemble_decl (varpool_node_for_decl (var));
 
       fn = builtin_decl_implicit (BUILT_IN_ASAN_REGISTER_GLOBALS);
+      tree gcount_tree = build_int_cst (pointer_sized_int_node, gcount);
       append_to_statement_list (build_call_expr (fn, 2,
 						 build_fold_addr_expr (var),
-						 build_int_cst (uptr, gcount)),
+						 gcount_tree),
 				&asan_ctor_statements);
 
       fn = builtin_decl_implicit (BUILT_IN_ASAN_UNREGISTER_GLOBALS);
       append_to_statement_list (build_call_expr (fn, 2,
 						 build_fold_addr_expr (var),
-						 build_int_cst (uptr, gcount)),
+						 gcount_tree),
 				&dtor_statements);
       cgraph_build_static_cdtor ('D', dtor_statements,
 				 MAX_RESERVED_INIT_PRIORITY - 1);