diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2013-10-04 13:15:01 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2013-10-04 13:15:01 +0000 |
commit | 5ed9453be66703578f260450e4dde0b5a7125113 (patch) | |
tree | f76401c06d06f8976dfd7bca67ca6d0260aaaabd /cparser/Elab.ml | |
parent | 364176f170cf4b5e554cb62b4fedb86cfc0d52c3 (diff) | |
download | compcert-5ed9453be66703578f260450e4dde0b5a7125113.tar.gz compcert-5ed9453be66703578f260450e4dde0b5a7125113.zip |
Elab:
- bad error recovery on bitfield with 'long long' type
- check for redefinition of function parameters
Bitfields:
- when assigning to a bitfield, cast the RHS to "unsigned int"
(it matters if the RHS is long long).
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2339 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'cparser/Elab.ml')
-rw-r--r-- | cparser/Elab.ml | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 0dea8f9c..4cbda399 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -510,6 +510,8 @@ and elab_parameter env (spec, name) = if sto <> Storage_default && sto <> Storage_register then error (loc_of_name name) "'extern' or 'static' storage not supported for function parameter"; + if redef Env.lookup_ident env id <> None then + error (loc_of_name name) "redefinition of parameter '%s'" id; (* replace array and function types by pointer types *) let ty1 = argument_conversion env1 ty in let (id', env2) = Env.enter_ident env1 id sto ty1 in @@ -565,28 +567,31 @@ and elab_field_group loc env (spec, fieldlist) = | TInt(ik, _) -> ik | TEnum(_, _) -> enum_ikind | _ -> ILongLong (* trigger next error message *) in - if integer_rank ik > integer_rank IInt then - error loc - "the type of '%s' must be an integer type \ - no bigger than 'int'" id; - match Ceval.integer_expr env' (!elab_expr_f loc env sz) with - | Some n -> - if n < 0L then begin - error loc "bit size of '%s' (%Ld) is negative" id n; - None - end else - if n > Int64.of_int(sizeof_ikind ik * 8) then begin - error loc "bit size of '%s' (%Ld) exceeds its type" id n; - None - end else - if n = 0L && id <> "" then begin - error loc "member '%s' has zero size" id; + if integer_rank ik > integer_rank IInt then begin + error loc + "the type of bitfield '%s' must be an integer type \ + no bigger than 'int'" id; + None + end else begin + match Ceval.integer_expr env' (!elab_expr_f loc env sz) with + | Some n -> + if n < 0L then begin + error loc "bit size of '%s' (%Ld) is negative" id n; + None + end else + if n > Int64.of_int(sizeof_ikind ik * 8) then begin + error loc "bit size of '%s' (%Ld) exceeds its type" id n; + None + end else + if n = 0L && id <> "" then begin + error loc "member '%s' has zero size" id; + None + end else + Some(Int64.to_int n) + | None -> + error loc "bit size of '%s' is not a compile-time constant" id; None - end else - Some(Int64.to_int n) - | None -> - error loc "bit size of '%s' is not a compile-time constant" id; - None in + end in { fld_name = id; fld_typ = ty; fld_bitfield = optbitsize' } in (List.map2 elab_bitfield fieldlist names, env') @@ -1460,7 +1465,7 @@ let enter_typedef loc env (s, sto, ty) = if sto <> Storage_default then error loc "Non-default storage on 'typedef' definition"; if redef Env.lookup_typedef env s <> None then - error loc "Redefinition of typedef '%s'" s; + error loc "redefinition of typedef '%s'" s; let (id, env') = Env.enter_typedef env s ty in emit_elab (elab_loc loc) (Gtypedef(id, ty)); |