From 8a26cc219f8c8211301f021bd0ee4a27153528f8 Mon Sep 17 00:00:00 2001 From: xleroy Date: Wed, 7 Mar 2012 13:10:47 +0000 Subject: Cprint: export Cprint.attributes PackedStructs: honor 'aligned' attribute on packed struct fields C2C: warn for ignored 'aligned' attributes git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1837 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cfrontend/C2C.ml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'cfrontend') diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml index 1a2a453..14e345b 100644 --- a/cfrontend/C2C.ml +++ b/cfrontend/C2C.ml @@ -342,8 +342,6 @@ let convertTyp env t = and convertFieldList seen = function | [] -> Fnil | f :: fl -> - if f.fld_bitfield <> None then - unsupported "bit field in struct or union"; Fcons(intern_string f.fld_name, convertTyp seen f.fld_typ, convertFieldList seen fl) @@ -784,6 +782,17 @@ let convertGlobvar env (sto, id, ty, optinit) = (id', {gvar_info = ty'; gvar_init = init'; gvar_readonly = readonly; gvar_volatile = volatile}) +(** Sanity checks on composite declarations. *) + +let checkComposite env si id attr flds = + let checkField f = + if f.fld_bitfield <> None then + unsupported "bit field in struct or union"; + if Cutil.find_custom_attributes ["aligned"; "__aligned__"] + (Cutil.attributes_of_type env f.fld_typ) <> [] then + warning ("ignoring 'aligned' attribute on field " ^ f.fld_name) + in List.iter checkField flds + (** Convert a list of global declarations. Result is a pair [(funs, vars)] where [funs] are the function definitions (internal and external) @@ -812,11 +821,14 @@ let rec convertGlobdecls env funs vars gl = end | C.Gfundef fd -> convertGlobdecls env (convertFundef env fd :: funs) vars gl' - | C.Gcompositedecl _ | C.Gcompositedef _ - | C.Gtypedef _ | C.Genumdef _ -> + | C.Gcompositedecl _ | C.Gtypedef _ | C.Genumdef _ -> (* typedefs are unrolled, structs are expanded inline, and enum tags are folded. So we just skip their declarations. *) convertGlobdecls env funs vars gl' + | C.Gcompositedef(su, id, attr, flds) -> + (* sanity checks on fields *) + checkComposite env su id attr flds; + convertGlobdecls env funs vars gl' | C.Gpragma s -> if not (!process_pragma_hook s) then warning ("'#pragma " ^ s ^ "' directive ignored"); -- cgit v1.2.3