libitm: Fix recent changes to allocations log.
authorTorvald Riegel <triegel@redhat.com>
Sun, 22 Nov 2015 20:56:20 +0000 (20:56 +0000)
committerTorvald Riegel <torvald@gcc.gnu.org>
Sun, 22 Nov 2015 20:56:20 +0000 (20:56 +0000)
libitm/
* libitm_i.h (gtm_alloc_action): Remove union.
* testsuite/libitm.c/alloc-1.c: New.

From-SVN: r230727

libitm/ChangeLog
libitm/libitm_i.h
libitm/testsuite/libitm.c/alloc-1.c [new file with mode: 0644]

index 4be05613c6c51a8cbbce815fa4316f6f74ac78ca..a986e6766f1fc1379152e676b66e0d6f09c29643 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-22  Torvald Riegel  <triegel@redhat.com>
+
+       * libitm_i.h (gtm_alloc_action): Remove union.
+       * testsuite/libitm.c/alloc-1.c: New.
+
 2015-11-19  Torvald Riegel  <triegel@redhat.com>
 
        * testsuite/libitm.c++/eh-5.C: New.
index f01a1ab54e40f71baf92ab8e67a014b636f67880..4b72348da59076ca83108137e40f9f8f86a7d0e9 100644 (file)
@@ -106,12 +106,10 @@ namespace GTM HIDDEN {
 // the template used inside gtm_thread can instantiate.
 struct gtm_alloc_action
 {
-  // Iff free_fn_sz is nonzero, it must be used instead of free_fn.
-  union
-  {
-    void (*free_fn)(void *);
-    void (*free_fn_sz)(void *, size_t);
-  };
+  // Iff free_fn_sz is nonzero, it must be used instead of free_fn, and vice
+  // versa.
+  void (*free_fn)(void *);
+  void (*free_fn_sz)(void *, size_t);
   size_t sz;
   // If true, this is an allocation; we discard the log entry on outermost
   // commit, and deallocate on abort.  If false, this is a deallocation and
diff --git a/libitm/testsuite/libitm.c/alloc-1.c b/libitm/testsuite/libitm.c/alloc-1.c
new file mode 100644 (file)
index 0000000..49faab5
--- /dev/null
@@ -0,0 +1,17 @@
+// Test that rolling back allocations works.
+#include <stdlib.h>
+
+void __attribute((transaction_pure,noinline)) dont_optimize(void* p)
+{
+  *(volatile char *) p;
+}
+
+int main()
+{
+  __transaction_atomic {
+    void *p = malloc (23);
+    dont_optimize (p);
+    __transaction_cancel;
+  }
+  return 0;
+}