aboutsummaryrefslogtreecommitdiffstats
path: root/cparser
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@college-de-france.fr>2021-09-25 12:03:55 +0200
committerXavier Leroy <xavier.leroy@college-de-france.fr>2021-09-28 10:24:49 +0200
commit2892e2caa89f927062824ca901562d085a76d619 (patch)
tree5f0d111c6e3960e7df30edc1ce4cf0095cf1b224 /cparser
parent627ab2dbe51decddff281d986367d0790643dd40 (diff)
downloadcompcert-kvx-2892e2caa89f927062824ca901562d085a76d619.tar.gz
compcert-kvx-2892e2caa89f927062824ca901562d085a76d619.zip
Ignore unnamed plain members of structs and unions
E.g. `struct { int; int x; };`. The `int;` declaration provides no name, is not a bit field, and is not a C11 anonymous struct/union member. Such declarations are not allowed by the C99 grammar, even though GCC, Clang and CompCert tolerate them. The C11 grammar allows these declarations but the standard text gives them no meaning. CompCert used to warn about such declarations, yet include them in the struct or union as unnamed members, similar to an unnamed bit field. This is incorrect and inconsistent with what GCC and Clang do. With this commit, CompCert still warns, then ignores the declaration and does not create an unnamed member. This is consistent with GCC and Clang. Fixes: #411
Diffstat (limited to 'cparser')
-rw-r--r--cparser/Elab.ml25
1 files changed, 15 insertions, 10 deletions
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index a5b87e2e..a78dc9d9 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -125,14 +125,15 @@ let rec mmap f env = function
let (tl', env2) = mmap f env1 tl in
(hd' :: tl', env2)
-let rec mmap2 f env l1 l2 =
+let rec mmap2_filter f env l1 l2 =
match l1,l2 with
- | [],[] -> [],env
- | a1::l1,a2::l2 ->
- let hd,env1 = f env a1 a2 in
- let tl,env2 = mmap2 f env1 l1 l2 in
- (hd::tl,env2)
- | _, _ -> invalid_arg "mmap2"
+ | [], [] -> ([], env)
+ | a1 :: l1, a2 :: l2 ->
+ let (opt_hd, env1) = f env a1 a2 in
+ let (tl, env2) = mmap2_filter f env1 l1 l2 in
+ ((match opt_hd with Some hd -> hd :: tl | None -> tl), env2)
+ | _, _ ->
+ invalid_arg "mmap2_filter"
(* To detect redefinitions within the same scope *)
@@ -1034,11 +1035,15 @@ and elab_field_group env = function
if is_qualified_array ty then
error loc "type qualifier used in array declarator outside of function prototype";
let anon_composite = is_anonymous_composite ty in
- if id = "" && not anon_composite && optbitsize = None then
+ if id = "" && not anon_composite && optbitsize = None then begin
warning loc Missing_declarations "declaration does not declare anything";
- { fld_name = id; fld_typ = ty; fld_bitfield = optbitsize'; fld_anonymous = id = "" && anon_composite},env'
+ None, env'
+ end else
+ Some { fld_name = id; fld_typ = ty; fld_bitfield = optbitsize';
+ fld_anonymous = id = "" && anon_composite},
+ env'
in
- (mmap2 elab_bitfield env' fieldlist names)
+ (mmap2_filter elab_bitfield env' fieldlist names)
| Field_group_static_assert(exp, loc_exp, msg, loc_msg, loc) ->
elab_static_assert env exp loc_exp msg loc_msg loc;