Skip to main content

Context Generation from Formal Specifications for C Analysis Tools

  • Conference paper
  • First Online:
Logic-Based Program Synthesis and Transformation (LOPSTR 2017)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 10855))

  • 244 Accesses

Abstract

Analysis tools like abstract interpreters, symbolic execution tools and testing tools usually require a proper context to give useful results when analyzing a particular function. Such a context initializes the function parameters and global variables to comply with function requirements. However it may be error-prone to write it by hand: the handwritten context might contain bugs or not match the intended specification. A more robust approach is to specify the context in a dedicated specification language, and hold the analysis tools to support it properly. This may mean to put significant development efforts for enhancing the tools, something that is often not feasible if ever possible.

This paper presents a way to systematically generate such a context from a formal specification of a C function. This is applied to a subset of the ACSL specification language in order to generate suitable contexts for the abstract interpretation-based value analysis plug-ins of Frama-C, a framework for analysis of code written in C. The idea here presented has been implemented in a new Frama-C plug-in which is currently in use in an operational industrial setting.

M. Alberti—This work was done when the first author was at CEA LIST, Software Reliability and Security Laboratory.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others

Notes

  1. 1.

    https://tls.mbed.org/.

  2. 2.

    This kind of system-dependent information is customizable within Frama-C.

References

  1. Barnett, M., Fähndrich, M., de Halleux, P., Logozzo, F., Tillmann, N.: Exploiting the synergy between automated-test-generation and programming-by-contract. In: ICSE 2009 (2009)

    Google Scholar 

  2. Baudin, P., Filliâtre, J.-C., Marché, C., Monate, B., Moy, Y., Prevosto, V.: ACSL: ANSI/ISO C Specification Language. http://frama-c.com/acsl.html

  3. Blazy, S., Bühler, D., Yakobowski, B.: Structuring abstract interpreters through state and value abstractions. In: Bouajjani, A., Monniaux, D. (eds.) VMCAI 2017. LNCS, vol. 10145, pp. 112–130. Springer, Cham (2017). https://doi.org/10.1007/978-3-319-52234-0_7

    Chapter  MATH  Google Scholar 

  4. Blume, W., Eigenmann, R.: Symbolic range propagation. In: IPPS 1995 (1995)

    Google Scholar 

  5. Botella, B., Delahaye, M., Ha, S.H.T., Kosmatov, N., Mouy, P., Roger, M., Williams, N.: Automating structural testing of C programs: experience with PathCrawler. In: AST 2009 (2009)

    Google Scholar 

  6. Canet, G., Cuoq, P., Monate, B.: A value analysis for C programs. In: SCAM 2009 (2009)

    Google Scholar 

  7. Caspi, P., Pilaud, D., Halbwachs, N., Plaice, J.A.: LUSTRE: a declarative language for real-time programming. In: POPL 1987 (1987)

    Google Scholar 

  8. Cousot, P., Cousot, R.: Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In: POPL 1977 (1977)

    Google Scholar 

  9. Cuoq, P., Rieu-Helft, R.: Result graphs for an abstract interpretation-based static analyzer. In: JFLA 2017 (2017)

    Google Scholar 

  10. Delahaye, M., Kosmatov, N.: A late treatment of C precondition in dynamic symbolic execution. In: CSTVA 2013 (2013)

    Google Scholar 

  11. ISO. The ANSI C standard (C99). Technical report WG14 N1124, ISO/IEC (1999). http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf

  12. Kirchner, F., Kosmatov, N., Prevosto, V., Signoles, J., Yakobowski, B.: Frama-C: a software analysis perspective. Form. Asp. Comput. 27(3), 573–609 (2015)

    Article  MathSciNet  Google Scholar 

  13. Kuncak, V., Mayer, M., Piskac, R., Suter, P.: Complete functional synthesis. In: PLDI 2010 (2010)

    Google Scholar 

  14. Logozzo, F., Fähndrich, M.: Pentagons: a weakly relational abstract domain for the efficient validation of array accesses. In: SAC 2008 (2008)

    Google Scholar 

  15. Nazaré, H., Maffra, I., Santos, W., Barbosa, L., Gonnord, L., Quintão Pereira, F.M.: Validation of memory accesses through symbolic analyses. SIGPLAN Not. 49(10), 791–809 (2014)

    Article  Google Scholar 

  16. Petiot, G., Botella, B., Julliand, J., Kosmatov, N., Signoles, J.: Instrumentation of annotated C programs for test generation. In: SCAM 2014 (2014)

    Google Scholar 

  17. Polikarpova, N., Kuraj, I., Solar-Lezama, A.: Program synthesis from polymorphic refinement types. In: PLDI 2016 (2016)

    Article  Google Scholar 

  18. Pugh, W.: A practical algorithm for exact array dependence analysis. Commun. ACM 35(8), 102–114 (1992)

    Article  Google Scholar 

  19. Rugina, R., Rinard, M.: Symbolic bounds analysis of pointers, array indices, and accessed memory regions. In: PLDI 2000 (2000)

    Article  Google Scholar 

  20. Sen, K., Marinov, D., Agha, G.: CUTE: a concolic unit testing engine for C. In: FSE’13 (2005)

    Google Scholar 

  21. Solar-Lezama, A., Arnold, G., Tancau, L., Bodik, R., Saraswat, V., Seshia, S.: Sketching stencils. In: PLDI 2007 (2007)

    Article  Google Scholar 

  22. TrustInSoft. PolarSSL 1.1.8 verification kit, v1.0. Technical report. http://trust-in-soft.com/polarSSL_demo.pdf

Download references

Acknowledgments

Part of the research work leading to these results has received funding for the S3P project from French DGE and BPIFrance. The authors thank TrustInSoft for the support and, in particular, Pascal Cuoq, Benjamin Monate and Anne Pacalet for providing the initial specification, test cases and insightful comments. Thanks to the anonymous reviewers for many useful suggestions and advice.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Julien Signoles .

Editor information

Editors and Affiliations

A Response to Reviewer Comments

A Response to Reviewer Comments

1.1 A.1 Reviewer 1

  • The reviewer points out that one important issue has not been addressed in the paper: how our code generation might be tailored for.

    The reviewer is right. While we argue in the introduction that our system may be used for different analysis techniques, this is not demonstrated in the paper since CfP has only been evaluated with 2 different abstract interpreters for the time being. We are however confident about the possible tailoring because the theoretical construction, which is the core of our work, remains the same. Also, adapting the code generator to other settings would not require many efforts, even if we leave it as future work. We have clarified our stance by adding in the Conclusion the following sentence:

    “It [Future work] also includes evaluating the presented system for different techniques such as symbolic execution or testing tools.”

  • The reviewer assumes we rely implicitly on some formal semantics, and thinks that it would be better to specify them in the paper.

    Indeed, Theorem 1 relies on a formal definition of \(\varSigma \,\models \, \mathcal {C}\), while we only provide its intuition in the paper. The formal definition has been omitted because we have not enough room to add it and because it does not represent the core of our system. It should be clearer now because we have added “, its formal definition being omitted here” after introducing symbol \(\models \).

  • The reviewer thinks that work for code generation from executable specification languages should be mentioned as well (notably, Lustre and logic synthesis in hardware).

    We have added a brief comparison with Lustre, but none for logic synthesis in hardware. Indeed our paper already referred to program synthesis, which is closer to our work that logic synthesis in hardware, while still quite different.

1.2 A.2 Reviewer 2

  • The only reviewer’s important comment is about a lack of precision in our sentence “For a 64-bit architecture, 256 bytes is the size of 64 values of type unsigned long.”. The reviewer is right. We have rewritten the sentence as follows: “Assuming that the size of unsigned long is 4 bytes, 256 bytes is the size of 64 values of type unsigned long.”

    Previously, in the same section, we have also rewritten “(assuming a 64-bit architecture)” by “(assuming that the size of unsigned long is 4 bytes)” and we have added a footnote indicating that this kind of system-dependent information is customizable within Frama-C.

  • All the reviewer’s minor comments and typos have been addressed.

1.3 A.3 Reviewer 3

  • The only reviewer’s concern is that the paper gives no evidence of generating code from specifications of other functions besides that from the initial motivating example. (S)he has consequently related questions.

    We have extended the first paragraph of Sect. 5 (Implementation and Evaluation) as follows:

    “In this latter use case, CfP is used, among others, to generate contexts for customizing the initialization of structure md5_context needed by functions md5_starts, md5_update and md5_process. This structure is defined as follows.

    <code example added>”

    Also, we have extended the paragraph explaining why DNF explosion is not an issue in practice as follow: “Concretely, CfP and its use in combination with TIS-Analyzer or EVA have never suffered from the state-explosion problem or any other unefficiency issue in practice.”

1.4 A.4 Other Improvements

  • Several minor changes (fixing typos, or using better/more standard math symbols) have been made.

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer International Publishing AG, part of Springer Nature

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Alberti, M., Signoles, J. (2018). Context Generation from Formal Specifications for C Analysis Tools. In: Fioravanti, F., Gallagher, J. (eds) Logic-Based Program Synthesis and Transformation. LOPSTR 2017. Lecture Notes in Computer Science(), vol 10855. Springer, Cham. https://doi.org/10.1007/978-3-319-94460-9_6

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-94460-9_6

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-94459-3

  • Online ISBN: 978-3-319-94460-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics