Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious break labels generated along with while statements #8

Open
lambdaxdotx opened this issue Dec 6, 2020 · 0 comments
Open

Spurious break labels generated along with while statements #8

lambdaxdotx opened this issue Dec 6, 2020 · 0 comments

Comments

@lambdaxdotx
Copy link

The merged PR #3 makes ldrgen generate a spurious "break" label along each while statement. Such a label seems to be related to some exit condition/statement for the loop which, however, does not exist.
Snippet of such a generation:

while (i < N) {
    v_29 = *(arr + i);
    v_19 += ! ((unsigned int)v_27 / (v_29 + 660U));
    i ++;
}
while_0_break: ;

This not a dreadful issue, but it would be better not to generate such useless labels (and respective; statements).

Hypothesis on the problem

The problem seems to be related to the -simplify-cfg machinery of Frama-C, which ldrgen seems to activate in some unclear way.
Indeed, the Frama-C's pretty-printer typically recognizes code patterns like:

while(1) { if (!cond) break; ... }

and turns them into:

while (cond) { ... }

When -simplify-cfg is activated and has called on a code, the first code pattern is turned into:

while(1) { if (!cond) goto while_0_break; ... } while_0_break: ;

and the pretty-printer goes on with its job but does not remove the label as it would be difficult to do in general.

This seems the most plausible explanation of the issue, at least this is what the senior devs of Frama-C told me, but I haven't found any evident mention of -simplify-cfg nor programmatic use of it in ldrgen.

@lambdaxdotx lambdaxdotx changed the title Spurious break labels generated along while statements Spurious break labels generated along with while statements Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant