summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorhainque <hainque@138bc75d-0d04-0410-961f-82ee72b054a4>2008-07-19 17:49:18 +0000
committerhainque <hainque@138bc75d-0d04-0410-961f-82ee72b054a4>2008-07-19 17:49:18 +0000
commit65c05dfdcfbd74e48f5432af9d7561bd4cba5ce9 (patch)
tree795260e8dc7f7962b579f40cd7ab751d17f86412 /gcc
parentbf3431bdaba9ed43e0de9dac4a29e18b0f7b280d (diff)
downloadgcc-65c05dfdcfbd74e48f5432af9d7561bd4cba5ce9.tar.gz
* doc/tm.texi (MALLOC_ABI_ALIGNMENT): New macro. Alignment, in bits,
a C conformant malloc implementation has to provide. * defaults.h (MALLOC_ABI_ALIGNMENT): Default to BITS_PER_WORD. ada/ * targtyps.c (get_target_default_allocator_alignment): Use it. testsuite/ * gcc.dg/mallign.c: New test. * gnat.dg/allocator_maxalign1.adb: New test. * gnat.dg/test_allocator_maxalign2.adb: Main caller for ... * gnat.dg/allocator_maxalign2.ad[bs]: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@137984 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/ada/ChangeLog5
-rw-r--r--gcc/ada/targtyps.c6
-rw-r--r--gcc/defaults.h6
-rw-r--r--gcc/doc/tm.texi5
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/mallign.c15
-rw-r--r--gcc/testsuite/gnat.dg/allocator_maxalign1.adb42
-rw-r--r--gcc/testsuite/gnat.dg/allocator_maxalign2.adb33
-rw-r--r--gcc/testsuite/gnat.dg/allocator_maxalign2.ads12
-rw-r--r--gcc/testsuite/gnat.dg/test_allocator_maxalign2.adb8
11 files changed, 140 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4464f1190e7..392ba5876c9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2008-07-19 Olivier Hainque <hainque@adacore.com>
+
+ * doc/tm.texi (MALLOC_ABI_ALIGNMENT): New macro. Alignment, in
+ bits, a C conformant malloc implementation has to provide.
+ * defaults.h (MALLOC_ABI_ALIGNMENT): Default to BITS_PER_WORD.
+
2008-07-19 Joseph Myers <joseph@codesourcery.com>
PR target/36780
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 7b0873a86a4..f08dc9f72d7 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,8 @@
+2008-07-19 Olivier Hainque <hainque@adacore.com>
+
+ * targtyps.c (get_target_default_allocator_alignment): Use
+ MALLOC_ABI_ALIGNMENT.
+
2008-07-17 Olivier Hainque <hainque@adacore.com>
* adaint.c (__MINGW32__ section): Include ctype.h and define
diff --git a/gcc/ada/targtyps.c b/gcc/ada/targtyps.c
index 79dafcaf2fe..c4e3299667d 100644
--- a/gcc/ada/targtyps.c
+++ b/gcc/ada/targtyps.c
@@ -164,17 +164,13 @@ get_target_maximum_default_alignment (void)
Stricter alignment requests trigger gigi's aligning_type circuitry for
objects allocated by the default allocator. */
-#ifndef MALLOC_ALIGNMENT
-#define MALLOC_ALIGNMENT BIGGEST_ALIGNMENT
-#endif
-
Pos
get_target_default_allocator_alignment (void)
{
/* ??? Need a way to get info about __gnat_malloc from here (whether
it is handy and what alignment it honors). */
- return MALLOC_ALIGNMENT / BITS_PER_UNIT;
+ return MALLOC_ABI_ALIGNMENT / BITS_PER_UNIT;
}
/* Standard'Maximum_Allowed_Alignment. Maximum alignment that we may
diff --git a/gcc/defaults.h b/gcc/defaults.h
index 3eecd8db81a..80294305850 100644
--- a/gcc/defaults.h
+++ b/gcc/defaults.h
@@ -551,6 +551,12 @@ along with GCC; see the file COPYING3. If not see
#define PUSH_ARGS_REVERSED 0
#endif
+/* Default value for the alignment (in bits) a C conformant malloc has to
+ provide. This default is intended to be safe and always correct. */
+#ifndef MALLOC_ABI_ALIGNMENT
+#define MALLOC_ABI_ALIGNMENT BITS_PER_WORD
+#endif
+
/* If PREFERRED_STACK_BOUNDARY is not defined, set it to STACK_BOUNDARY.
STACK_BOUNDARY is required. */
#ifndef PREFERRED_STACK_BOUNDARY
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 58600186940..e238797ed77 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -1095,6 +1095,11 @@ bits. Note that this is not the biggest alignment that is supported,
just the biggest alignment that, when violated, may cause a fault.
@end defmac
+@defmac MALLOC_ABI_ALIGNMENT
+Alignment, in bits, a C conformant malloc implementation has to
+provide. If not defined, the default value is @code{BITS_PER_WORD}.
+@end defmac
+
@defmac MINIMUM_ATOMIC_ALIGNMENT
If defined, the smallest alignment, in bits, that can be given to an
object that can be referenced in one operation, without disturbing any
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 105edc4ccf4..a487a3e74c9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2008-07-19 Olivier Hainque <hainque@adacore.com>
+
+ * gcc.dg/mallign.c: New test.
+ * gnat.dg/allocator_maxalign1.adb: New test.
+ * gnat.dg/test_allocator_maxalign2.adb: Main caller for ...
+ * gnat.dg/allocator_maxalign2.ad[bs]: New test.
+
2008-07-19 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/intrinsic_argument_conformance_2.f90: New.
diff --git a/gcc/testsuite/gcc.dg/mallign.c b/gcc/testsuite/gcc.dg/mallign.c
new file mode 100644
index 00000000000..4a64dbbcc3b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/mallign.c
@@ -0,0 +1,15 @@
+/* Check that malloc's alignment honors what we trust it
+ minimally should. */
+
+/* { dg-do run } */
+/* { dg-options "-fno-builtin-malloc" } */
+
+#include <stdlib.h>
+typedef int word __attribute__((mode(word)));
+
+int main()
+{
+ if ((long)malloc (1) & (sizeof(word)-1))
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gnat.dg/allocator_maxalign1.adb b/gcc/testsuite/gnat.dg/allocator_maxalign1.adb
new file mode 100644
index 00000000000..062c39bbf87
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/allocator_maxalign1.adb
@@ -0,0 +1,42 @@
+-- { dg-do run }
+
+with System.Storage_Elements; use System.Storage_Elements;
+with Ada.Unchecked_Deallocation;
+
+procedure Allocator_Maxalign1 is
+
+ Max_Alignment : constant := Standard'Maximum_Alignment;
+
+ type Block is record
+ X : Integer;
+ end record;
+ for Block'Alignment use Standard'Maximum_Alignment;
+
+ type Block_Access is access all Block;
+ procedure Free is new Ada.Unchecked_Deallocation (Block, Block_Access);
+
+ N_Blocks : constant := 500;
+ Blocks : array (1 .. N_Blocks) of Block_Access;
+begin
+ if Block'Alignment /= Max_Alignment then
+ raise Program_Error;
+ end if;
+
+ for K in 1 .. 4 loop
+
+ for I in Blocks'Range loop
+ Blocks (I) := new Block;
+ if Blocks (I).all'Address mod Block'Alignment /= 0 then
+ raise Program_Error;
+ end if;
+ Blocks(I).all.X := I;
+ end loop;
+
+ for I in Blocks'Range loop
+ Free (Blocks (I));
+ end loop;
+
+ end loop;
+
+end;
+
diff --git a/gcc/testsuite/gnat.dg/allocator_maxalign2.adb b/gcc/testsuite/gnat.dg/allocator_maxalign2.adb
new file mode 100644
index 00000000000..10644ea6b3c
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/allocator_maxalign2.adb
@@ -0,0 +1,33 @@
+with System, System.Storage_Elements;
+use System.Storage_Elements;
+
+package body Allocator_Maxalign2 is
+
+ Max_Align : constant Storage_Offset := Standard'Maximum_Alignment;
+
+ procedure Validate is
+ use type System.Address;
+ begin
+ if Addr mod Max_Align /= 0 then
+ raise Program_Error;
+ end if;
+ end;
+
+ procedure Check is
+ I : Integer;
+ B : Block;
+ type Block_Access is access all Block;
+ A : Block_Access;
+ begin
+ Addr := I'Address;
+ Addr := B'Address;
+ Validate;
+ for I in 1 .. 50 loop
+ A := new Block;
+ Addr := A.all'Address;
+ Validate;
+ end loop;
+
+ end;
+
+end;
diff --git a/gcc/testsuite/gnat.dg/allocator_maxalign2.ads b/gcc/testsuite/gnat.dg/allocator_maxalign2.ads
new file mode 100644
index 00000000000..43c01081cb6
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/allocator_maxalign2.ads
@@ -0,0 +1,12 @@
+with System;
+
+package Allocator_Maxalign2 is
+ type Block is record
+ X : Integer;
+ end record;
+ for Block'Alignment use Standard'Maximum_Alignment;
+
+ Addr : System.Address;
+
+ procedure Check;
+end;
diff --git a/gcc/testsuite/gnat.dg/test_allocator_maxalign2.adb b/gcc/testsuite/gnat.dg/test_allocator_maxalign2.adb
new file mode 100644
index 00000000000..144914d2dc4
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/test_allocator_maxalign2.adb
@@ -0,0 +1,8 @@
+-- { dg-do run }
+
+with Allocator_Maxalign2;
+
+procedure Test_Allocator_Maxalign2 is
+begin
+ Allocator_Maxalign2.Check;
+end;