Microsoft continues its plan to revitalize its decades-old C/++ compiler, with a focus on areas such as diagnostics and standards compliance, while striving for backward compatibility.
The company, in fact, has been working on a major overhaul of the compiler for three years now, said Microsoft’s Jim Springfield, principal software engineer, in a blog post on Friday. “About three years ago, we embarked on a project to finally perform a major overhaul of our compiler code base. We wanted to fix problems we have had for a long time and we knew new features such as constexpr were going to need a different approach. The goal was to fundamentally change the way our compiler parses and analyzes code.”
The July release of Visual Studio 2015 represented the first fruits of the compiler work. “We have changed a lot of the guts in the compiler’s internal implementation, although not much is directly visible. The most visible change is that c1ast.dll and c1xxast.dll are no longer present. We now handle all compilation for static analysis using the same binary as the one we do for code generation.”
Additionally, the 6,000-plus #if blocks are gone, and there are fewer than 200 runtime checks for analysis. This is why code analysis was disabled in some of the release candidate builds of the C++ compiler, Springfield explained. Now, a full tree is generated for functions and can use the same data structure to generate code or perform static analysis. “These same trees are used to evaluate constexpr functions as well, which is a feature we just shipped. We also now track full source position information (including column) for all constructs. We aren’t currently using column information, but we want to be able to provide better diagnostics in the future.”
Further investments are ongoing. “We have started work on parsing templates into an AST (abstract syntax tree), and this will yield some immediate improvements in our support for expression SFINAE (substitution failure is not an error} and our parsing of ‘qualified names’,” Springfield said. “ We will continue to invest in improving our compiler with a goal toward making it fully standards-compliant.”
Backward compatibility remains a goal as Microsoft fixes bugs and implements new features, said Springfield. To this end, the Gauntlet automated system, featuring more than 50 machines building all versions of the compiler, runs tests across 32- and 64-bit and ARM architectures.
In the post, Springfield points out how long it has been -- more than 30 years -- since the compiler was initially developed. “Our compiler is old. There are comments in the source from 1982, which was when Microsoft was starting its own C compiler project.”
A commenter on a Hacker News thread called Microsoft’s efforts “excellent” news. “MSVC [Microsoft Visual C++] is a big pain in the ass for me, as I tend to write C code (not ++ usually) and Microsoft's C compiler is the one with the worst support for language-level features (out of widely used compilers).”
Microsoft also wants to improve its support for Clang, a compiler front end for the C family of languages and built on the LLVM compiler infrastructure project. The blog links to a session description from Microsoft about Clang at the recent CppCon C++ conference in Bellevue, Wash. “The talk will disclose the architecture of how we tied the CLANG open source front end with the Microsoft optimizing back ends (several configurations are needed) and how far we are from providing a CTP [community technology preview] for public consumption targeting four different architectures.”