瀏覽代碼

gcc: heap_allocated: Manipulate cleanup handlers directly.

* gcc-plugin/src/starpu.c (handle_heap_allocated_attribute): Use
  `push_cleanup' instead of the `cleanup' attribute.  The previous code
  shouldn't have worked because it was passing a decl instead of an
  identifier as the `cleanup' parameter (which led to a segfault in
  `lookup_name' on i686).

* gcc-plugin/tests/mocks.h (_starpu_free_unref): Remove.
  (starpu_free): New function.
* include/starpu_data.h (_starpu_free_unref): Remove declaration.
* src/util/malloc.c (_starpu_free_unref): Remove.
Ludovic Courtès 13 年之前
父節點
當前提交
fb59c025b2
共有 4 個文件被更改,包括 14 次插入17 次删除
  1. 10 5
      gcc-plugin/src/starpu.c
  2. 4 3
      gcc-plugin/tests/mocks.h
  3. 0 2
      include/starpu_data.h
  4. 0 7
      src/util/malloc.c

+ 10 - 5
gcc-plugin/src/starpu.c

@@ -1026,12 +1026,17 @@ handle_heap_allocated_attribute (tree *node, tree name, tree args,
       TREE_SIDE_EFFECTS (alloc) = true;
       add_stmt (alloc);
 
-      /* Add a destructor for VAR.
+      /* Add a destructor for VAR.  Instead of consing the `cleanup'
+	 attribute for VAR, directly use `push_cleanup'.  This guarantees
+	 that CLEANUP_ID is looked up in the right context, and allows us to
+	 pass VAR directly to `starpu_free', instead of `&VAR'.
+
 	 TODO: Provide a way to disable this.  */
-      DECL_ATTRIBUTES (var) =
-	tree_cons (get_identifier ("cleanup"),
-		   lookup_name (get_identifier ("_starpu_free_unref")),
-		   DECL_ATTRIBUTES (var));
+
+      static tree cleanup_decl;
+      LOOKUP_STARPU_FUNCTION (cleanup_decl, "starpu_free");
+
+      push_cleanup (var, build_call_expr (cleanup_decl, 1, var), false);
     }
 
   return NULL_TREE;

+ 4 - 3
gcc-plugin/tests/mocks.h

@@ -292,11 +292,12 @@ starpu_malloc (void **ptr, size_t size)
   return 0;
 }
 
-void
-_starpu_free_unref (void *ptr)
+int
+starpu_free (void *ptr)
 {
-  assert (* (void **) ptr == expected_free_argument);
+  assert (ptr == expected_free_argument);
   free_calls++;
+  return 0;
 }
 
 

+ 0 - 2
include/starpu_data.h

@@ -78,8 +78,6 @@ void starpu_data_release(starpu_data_handle_t handle);
 int starpu_malloc(void **A, size_t dim);
 int starpu_free(void *A);
 
-void _starpu_free_unref(void *p);
-
 /* XXX These macros are provided to avoid breaking old codes. But consider
  * these function names as deprecated. */
 #define starpu_data_malloc_pinned_if_possible	starpu_malloc

+ 0 - 7
src/util/malloc.c

@@ -238,10 +238,3 @@ int starpu_free(void *A)
 
 	return 0;
 }
-
-/* Internal convenience function, used by code generated by the GCC
- * plug-in.  */
-void _starpu_free_unref(void *p)
-{
-	(void)starpu_free(* (void **)p);
-}