aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Cutil.ml
diff options
context:
space:
mode:
authorxleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2013-10-05 08:11:34 +0000
committerxleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2013-10-05 08:11:34 +0000
commita6c369cbd63996c1571ae601b7d92070f024b22c (patch)
treedc4f3f5a52ae4ea230f307ce5f442137f014b79b /cparser/Cutil.ml
parentb55147379939553eccd4289fd18e7f161619be4d (diff)
downloadcompcert-kvx-a6c369cbd63996c1571ae601b7d92070f024b22c.tar.gz
compcert-kvx-a6c369cbd63996c1571ae601b7d92070f024b22c.zip
Merge of the "alignas" branch.
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2342 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r--cparser/Cutil.ml26
1 files changed, 26 insertions, 0 deletions
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml
index 2fc269cc..982bf785 100644
--- a/cparser/Cutil.ml
+++ b/cparser/Cutil.ml
@@ -71,6 +71,14 @@ let rec find_custom_attributes (names: string list) (al: attributes) =
| _ :: tl ->
find_custom_attributes names tl
+let rec remove_custom_attributes (names: string list) (al: attributes) =
+ match al with
+ | [] -> []
+ | Attr(name, args) :: tl when List.mem name names ->
+ remove_custom_attributes names tl
+ | a :: tl ->
+ a :: remove_custom_attributes names tl
+
(* Adding top-level attributes to a type. Doesn't need to unroll defns. *)
(* Array types cannot carry attributes, so add them to the element type. *)
@@ -147,6 +155,15 @@ let attr_is_type_related = function
| Attr(("packed" | "__packed__"), _) -> true
| _ -> false
+(* Extracting alignment value from a set of attributes. Return 0 if none. *)
+
+let alignas_attribute al =
+ let rec alignas_attr accu = function
+ | [] -> accu
+ | AAlignas n :: al -> alignas_attr (max n accu) al
+ | a :: al -> alignas_attr accu al
+ in alignas_attr 0 al
+
(* Type compatibility *)
exception Incompat
@@ -266,6 +283,8 @@ let alignof_fkind = function
let enum_ikind = IInt
let rec alignof env t =
+ let a = alignas_attribute (attributes_of_type env t) in
+ if a > 0 then Some a else
match t with
| TVoid _ -> !config.alignof_void
| TInt(ik, _) -> Some(alignof_ikind ik)
@@ -325,6 +344,13 @@ let cautious_mul (a: int64) (b: int) =
(* Return size of type, in bytes, or [None] if the type is incomplete *)
let rec sizeof env t =
+ match sizeof_aux env t with
+ | None -> None
+ | Some sz ->
+ let a = alignas_attribute (attributes_of_type env t) in
+ Some (if a > 0 then align sz a else sz)
+
+and sizeof_aux env t =
match t with
| TVoid _ -> !config.sizeof_void
| TInt(ik, _) -> Some(sizeof_ikind ik)