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.
Supplemental Material
Available for Download
See ReadMe.txt
Info
- 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 Scholar
Digital Library
- M. Batty, M. Dodds, and A. Gotsman. Library abstraction for C/C++ concurrency. In POPL, 2013. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- M. Batty, S. Owens, S. Sarkar, P. Sewell, and T. Weber. Mathematizing C++ concurrency. In POPL, 2011. Google Scholar
Digital Library
- 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 Scholar
- H.-J. Boehm and B. Demsky. Outlawing ghosts: avoiding out-of-thin-air results. In MSPC, 2014. Google Scholar
Digital Library
- ISO/IEC 14882:2011. Programming language C++, 2011.Google Scholar
- ISO/IEC 9899:2011. Programming language C, 2011.Google Scholar
- X. Leroy. Formal verification of a realistic compiler. CACM, 52(7):107--115, 2009. Google Scholar
Digital Library
- J. Manson, W. Pugh, and S. V. Adve. The Java memory model. In POPL, 2005. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- B. Norris and B. Demsky. CDSChecker: Checking concurrent data structures written with C/C++ atomics. In OOPSLA, 2013. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- D. Shasha and M. Snir. Efficient and correct execution of parallel programs that share memory. TOPLAS, 10(2):282--312, 1988. Google Scholar
Digital Library
- A. Turon, V. Vafeiadis, and D. Dreyer. GPS: Navigating weak-memory with ghosts, protocols, and separation. In OOPSLA, 2014. Google Scholar
Digital Library
- V. Vafeiadis and C. Narayan. Relaxed separation logic: A program logic for C11 concurrency. In OOPSLA, 2013. Google Scholar
Digital Library
- 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 Scholar
- J. Ševčík. Safe optimisations for shared-memory concurrent programs. In PLDI, 2011. Google Scholar
Digital Library
- J. Ševčík and D. Aspinall. On validity of program transformations in the Java memory model. In ECOOP, 2008. Google Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Common Compiler Optimisations are Invalid in the C11 Memory Model and what we can do about it
Recommendations
Repairing sequential consistency in C/C++11
PLDI 2017: Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and ImplementationThe C/C++11 memory model defines the semantics of concurrent memory accesses in C/C++, and in particular supports racy "atomic" accesses at a range of different consistency levels, from very weak consistency ("relaxed") to strong, sequential ...
Simplifying ARM concurrency: multicopy-atomic axiomatic and operational models for ARMv8
ARM has a relaxed memory model, previously specified in informal prose for ARMv7 and ARMv8. Over time, and partly due to work building formal semantics for ARM concurrency, it has become clear that some of the complexity of the model is not justified by ...
Mathematizing C++ concurrency
POPL '11: Proceedings of the 38th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languagesShared-memory concurrency in C and C++ is pervasive in systems programming, but has long been poorly defined. This motivated an ongoing shared effort by the standards committees to specify concurrent behaviour in the next versions of both languages. ...







Comments