skip to main content
research-article

Common Compiler Optimisations are Invalid in the C11 Memory Model and what we can do about it

Published:14 January 2015Publication History
Skip Abstract Section

Abstract

We show that the weak memory model introduced by the 2011 C and C++ standards does not permit many common source-to-source program transformations (such as expression linearisation and "roach motel" reorderings) that modern compilers perform and that are deemed to be correct. As such it cannot be used to define the semantics of intermediate languages of compilers, as, for instance, LLVM aimed to. We consider a number of possible local fixes, some strengthening and some weakening the model. We evaluate the proposed fixes by determining which program transformations are valid with respect to each of the patched models. We provide formal Coq proofs of their correctness or counterexamples as appropriate.

Skip Supplemental Material Section

Supplemental Material

p209-sidebyside.mpg

References

  1. J. Alglave, L. Maranget, and M. Tautschnig. Herding cats: modelling, simulation, testing, and data-mining for weak memory. TOPLAS, 36(2):7:1--7:74, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. M. Batty, M. Dodds, and A. Gotsman. Library abstraction for C/C++ concurrency. In POPL, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. M. Batty, K. Memarian, S. Owens, S. Sarkar, and P. Sewell. Clarifying and compiling C/C++ concurrency: From C++ 11 to POWER. In POPL, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. M. Batty, S. Owens, S. Sarkar, P. Sewell, and T. Weber. Mathematizing C++ concurrency. In POPL, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. H.-J. Boehm. N3710: Specifying the absence of "out of thin air" results, 2013. Available at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3710.html.Google ScholarGoogle Scholar
  6. H.-J. Boehm and B. Demsky. Outlawing ghosts: avoiding out-of-thin-air results. In MSPC, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. ISO/IEC 14882:2011. Programming language C++, 2011.Google ScholarGoogle Scholar
  8. ISO/IEC 9899:2011. Programming language C, 2011.Google ScholarGoogle Scholar
  9. X. Leroy. Formal verification of a realistic compiler. CACM, 52(7):107--115, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Manson, W. Pugh, and S. V. Adve. The Java memory model. In POPL, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. R. Morisset, P. Pawan, and F. Zappa Nardelli. Compiler testing via a theory of sound optimisations in the C11/C++ 11 memory model. In PLDI, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. B. Norris and B. Demsky. CDSChecker: Checking concurrent data structures written with C/C++ atomics. In OOPSLA, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. S. Sarkar, K. Memarian, S. Owens, M. Batty, P. Sewell, L. Maranget, J. Alglave, and D. Williams. Synchronising C/C++ and POWER. In PLDI 2012, pages 311--322. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. D. Shasha and M. Snir. Efficient and correct execution of parallel programs that share memory. TOPLAS, 10(2):282--312, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. A. Turon, V. Vafeiadis, and D. Dreyer. GPS: Navigating weak-memory with ghosts, protocols, and separation. In OOPSLA, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. V. Vafeiadis and C. Narayan. Relaxed separation logic: A program logic for C11 concurrency. In OOPSLA, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. J. Ševčík. The Sun Hotspot JVM does not conform with the Java memory model. Technical Report EDI-INF-RR-1252, School of Informatics, University of Edinburgh, 2008.Google ScholarGoogle Scholar
  18. J. Ševčík. Safe optimisations for shared-memory concurrent programs. In PLDI, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. J. Ševčík and D. Aspinall. On validity of program transformations in the Java memory model. In ECOOP, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. J. Ševčík, V. Vafeiadis, F. Zappa Nardelli, S. Jagannathan, and P. Sewell. CompCertTSO: A verified compiler for relaxed-memory concurrency. J. ACM, 60(3):22:1--22:50, June 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Common Compiler Optimisations are Invalid in the C11 Memory Model and what we can do about it

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 50, Issue 1
          POPL '15
          January 2015
          682 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2775051
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            POPL '15: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages
            January 2015
            716 pages
            ISBN:9781450333009
            DOI:10.1145/2676726

          Copyright © 2015 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 14 January 2015

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!