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

Make code generation more compliant with Frama-C. #3

Merged
merged 2 commits into from
Nov 21, 2020

Conversation

lambdaxdotx
Copy link

  • Use Frama-C project to enable analysis chaining.
  • Register globals in Frama-C tables.
  • Compute CFG for the generated function.
  • Use pointer arithmetic for array in loop since type is TPtr.

- Use Frama-C project to enable analysis chaining.
- Register globals in Frama-C tables.
- Compute CFG for the generated function.
- Use pointer arithmetic for array in loop since type is TPtr.
@lambdaxdotx
Copy link
Author

I admit this is a more controversial PR than the previous ones.

Indeed, you may not want to ensure Frama-C compliance wrt the generated AST since ldrgen does not need to. That being said, at the moment, the generated AST is not "correct", and in particular, whenever one wants to chain another Frama-C analysis on the generated code, a crash is very probable.

This PR makes the AST more correct in that sense, and allows analysis chaining w/o apparent problems. Well, to be fair, computing the CFG for the generated function makes appear an undesired/useless statement of the form label: ; after every while loop. I did not find the cause of this, it may be a problem in the way the code is generated or a Frama-C bug (I would dare to say, less likely).

In the case you are interested in this PR in general, but are annoyed by the problems it raises, I could try to make the changes needed more by Frama-C than ldrgen itself conditional to some command line option (say, -fc-compliant?). It might be possible, it might.

Let me know if you need more details about the code changes.

Copy link
Owner

@gergo- gergo- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I'm happy to have better compatibility with Frama-C.
It looks like the spurious break labels are introduced by CFG.prepareCFG. In my opinion it would be better if these weren't generated for loops that have no breaks, but I don't really mind.

generate.ml Outdated Show resolved Hide resolved
@lambdaxdotx
Copy link
Author

It looks like the spurious break labels are introduced by CFG.prepareCFG. In my opinion it would be better if these weren't generated for loops that have no breaks, but I don't really mind.

I agree, having such spurious labels is not perfect.

For sure, they are introduced by CFG.prepareCFG. The question is: is it a bug in CFG or rather a correct behavior in the presence of a malformed AST (hence, a ldrgen bug)? I didn't quite get if you think more of the former.

Anyway, I could open an issue to record such problem for the future once this PR gets merged.

@gergo- gergo- merged commit 7f9b87d into gergo-:master Nov 21, 2020
@gergo-
Copy link
Owner

gergo- commented Nov 21, 2020

For sure, they are introduced by CFG.prepareCFG. The question is: is it a bug in CFG or rather a correct behavior in the presence of a malformed AST (hence, a ldrgen bug)? I didn't quite get if you think more of the former.

I think the core issue is in CFG. But if it's easy to work around it in ldrgen and harder to change CFG, then I'm fine with a workaround/fix/whatever we want to call it here.

Anyway, I could open an issue to record such problem for the future once this PR gets merged.

Please do.

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

Successfully merging this pull request may close these issues.

2 participants