diff options
author | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2022-11-03 16:02:44 +0100 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@college-de-france.fr> | 2022-11-03 16:06:21 +0100 |
commit | 5a9f24b4e739b6ef830f526845dd4d1557d0adee (patch) | |
tree | aa8d94065cc5a6574ebeacb76a51155edd20103a | |
parent | 8eadd08af4602de399a94313d4fb2b8980f7ceb0 (diff) | |
download | compcert-5a9f24b4e739b6ef830f526845dd4d1557d0adee.tar.gz compcert-5a9f24b4e739b6ef830f526845dd4d1557d0adee.zip |
Ignore debug statements before the first case of a `switch`
This can occur in debug mode if there are declarations before the
first case, as in
```
switch (x) {
int x;
case 0:
...
}
```
Without this commit, the code above is a structured switch if -g is not given,
and a non-structured switch if -g is given.
Co-authored-by: Michael Schmidt <github@mschmidt.me>
-rw-r--r-- | cparser/SwitchNorm.ml | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/cparser/SwitchNorm.ml b/cparser/SwitchNorm.ml index 2493c63d..65d10cb2 100644 --- a/cparser/SwitchNorm.ml +++ b/cparser/SwitchNorm.ml @@ -118,6 +118,12 @@ let substitute_cases case_table body end_label = | sd -> sd } in transf false body +let rec is_skip_or_debug s = + match s.sdesc with + | Sseq (a, b) -> is_skip_or_debug a && is_skip_or_debug b + | Sskip -> true + | _ -> Cutil.is_debug_stmt s + let new_label = ref 0 let gen_label () = incr new_label; sprintf "@%d" !new_label @@ -125,7 +131,7 @@ let gen_label () = incr new_label; sprintf "@%d" !new_label let normalize_switch loc e body = let (init, cases) = [body] |> flatten_switch |> group_switch and allcases = List.rev (all_cases [] body) in - if init.sdesc = Sskip && List.length cases = List.length allcases then + if is_skip_or_debug init && List.length cases = List.length allcases then (* This is a structured switch *) make_normalized_switch e cases else begin |