diff options
author | Bernhard Schommer <bernhardschommer@gmail.com> | 2017-01-20 14:44:59 +0100 |
---|---|---|
committer | Bernhard Schommer <bernhardschommer@gmail.com> | 2017-01-20 14:44:59 +0100 |
commit | 47e818992372c1480b1052b64728a33d758637cf (patch) | |
tree | e6351d1028516561f2bb56879d4b3174850c7198 /cparser/Elab.ml | |
parent | ac2e4bb9bc63e0ea8b5cf67274bddb9ec74b771e (diff) | |
download | compcert-kvx-47e818992372c1480b1052b64728a33d758637cf.tar.gz compcert-kvx-47e818992372c1480b1052b64728a33d758637cf.zip |
Simplified version.
The problem was that sub structs are were not correctly aligned.
The new version is much simpler and uses the sizeof_struct to
calculate the individual offsets and add them up to get correct
offest.
Bug 20765
Diffstat (limited to 'cparser/Elab.ml')
-rw-r--r-- | cparser/Elab.ml | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/cparser/Elab.ml b/cparser/Elab.ml index afdf3969..6256bf1f 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -1646,16 +1646,14 @@ let elab_expr vararg loc env a = let (ty,env) = elab_type loc env spec dcl in if Cutil.incomplete_type env ty then error "offsetof of incomplete type %a" (print_typ env) ty; - let offset = - match unroll env ty with - | TStruct(id,_) - | TUnion (id,_)-> - let fld = (wrap Env.find_struct_member loc env (id,mem)) in - if List.exists (fun fld -> fld.fld_bitfield <> None) fld then - error "cannot compute the offset of bitfield '%s" mem; - Cutil.offsetof env ty fld - | _ -> - error "request offsetof for member '%s' in something not a structure" mem in + let fld = match unroll env ty with + | TStruct(id,_) ->(wrap Env.find_struct_member loc env (id,mem)) + | TUnion (id,_)->(wrap Env.find_union_member loc env (id,mem)) + | _ -> + error "request offsetof for member '%s' in something not a structure" mem in + if List.exists (fun fld -> fld.fld_bitfield <> None) fld then + error "cannot compute the offset of bitfield '%s" mem; + let offset = Cutil.offsetof env ty fld in let offsetof_const = EConst (CInt(Int64.of_int offset,size_t_ikind (),"")) in { edesc = offsetof_const; etyp = TInt(size_t_ikind(), []) },env |