aboutsummaryrefslogtreecommitdiffstats
path: root/cparser
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@college-de-france.fr>2021-05-02 17:14:38 +0200
committerXavier Leroy <xavier.leroy@college-de-france.fr>2021-05-02 17:14:38 +0200
commit38b0babd5a642cea8912524debc63edc67fda08b (patch)
tree2d9c96c67de83b769c9946036b036e9239f8a881 /cparser
parent2c47585b90858a6782b6e9a88efdb43368708429 (diff)
downloadcompcert-kvx-38b0babd5a642cea8912524debc63edc67fda08b.tar.gz
compcert-kvx-38b0babd5a642cea8912524debc63edc67fda08b.zip
Fix spurious error on initialization of struct with flexible array member
The following is correct but was causing a "wrong type for array initializer" fatal error. ``` struct s { int n; int d[]; }; void f(void) { struct s x = {0}; } ``` Co-authored-by: Michael Schmidt <github@mschmidt.me>
Diffstat (limited to 'cparser')
-rw-r--r--cparser/Unblock.ml3
1 files changed, 3 insertions, 0 deletions
diff --git a/cparser/Unblock.ml b/cparser/Unblock.ml
index d25f70c6..8530ae01 100644
--- a/cparser/Unblock.ml
+++ b/cparser/Unblock.ml
@@ -31,6 +31,9 @@ let rec local_initializer env path init k =
let (ty_elt, sz) =
match unroll env path.etyp with
| TArray(ty_elt, Some sz, _) -> (ty_elt, sz)
+ (* We accept empty array initializer for flexible array members, which
+ has size zero *)
+ | TArray(ty_elt, None, _) when il = [] -> (ty_elt, 0L)
| _ -> Diagnostics.fatal_error Diagnostics.no_loc "wrong type for array initializer" in
let rec array_init pos il =
if pos >= sz then k else begin