Commit 95331614 by Olivier Hainque Committed by Olivier Hainque

tm.texi (MALLOC_ABI_ALIGNMENT): New macro.

	* 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.

From-SVN: r137984
parent d1a296c1
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
......
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
......@@ -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
......
......@@ -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
......
......@@ -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
......
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.
......
/* 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;
}
-- { 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;
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;
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;
-- { dg-do run }
with Allocator_Maxalign2;
procedure Test_Allocator_Maxalign2 is
begin
Allocator_Maxalign2.Check;
end;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment