From fbc778079d50a4af45b9a648eab56cef29ac75f4 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Tue, 27 Mar 2018 17:15:42 +0200 Subject: Sizeof and _Alignof are not allowed on bit-fields (#67) Sizeof and _Alignof are not allowed on bit-fields Sizeof and _Alignof are not allowed to be applied to a expression that designates a bit-field member. Bug 23311 --- cparser/Elab.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cparser/Elab.ml') diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 3ef489c1..204bc515 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -1619,6 +1619,8 @@ let elab_expr vararg loc env a = let b1,env = elab env a1 in if wrap incomplete_type loc env b1.etyp then error "invalid application of 'sizeof' to an incomplete type %a" (print_typ env) b1.etyp; + if wrap is_bitfield loc env b1 then + error "invalid application of 'sizeof' to a bit-field"; let bdesc = (* Catch special cases sizeof("string literal") *) match b1.edesc with @@ -1641,7 +1643,9 @@ let elab_expr vararg loc env a = | EXPR_ALIGNOF a1 -> let b1,env = elab env a1 in if wrap incomplete_type loc env b1.etyp then - error "invalid application of 'alignof' to an incomplete type %a" (print_typ env) b1.etyp; + error "invalid application of '_Alignof' to an incomplete type %a" (print_typ env) b1.etyp; + if wrap is_bitfield loc env b1 then + error "invalid application of '_Alignof' to a bit-field"; { edesc = EAlignof b1.etyp; etyp = TInt(size_t_ikind(), []) },env | TYPE_ALIGNOF (spec, dcl) -> -- cgit