Looking forward to GCC 7

Please consider subscribing to LWN Subscriptions are the lifeblood of LWN.net. If you appreciate this content and would like to see more of it, your subscription will help to ensure that LWN continues to thrive. Please visit this page to join up and keep LWN on the net.

The GNU Compiler Collection (GCC) project produces a major release on an approximately annual schedule, often in April. The next major release, GCC 7, is currently in stage 4 , otherwise known as "regression and documentation mode". As of mid-March, the project was still hoping for a mid-April release date. Whether that date holds or slips, the set of GCC 7 features is well known at this point. What follows is a shameless cribbing of the high points from the GCC 7 changes document

Compilers live or die by their optimizers, so it is unsurprising that GCC has, as usual, seen some optimization work. Some of these, like the new store merging feature ("merges constant stores to adjacent memory locations into fewer, wider, stores") are the sort of thing that can strike fear into kernel developers but should yield better performance in general. A new code-hoisting option reorganizes functions by finding the code that will be executed in all paths through the function and moving it to the beginning, yielding both size and speed improvements. Another optimization, called "loop splitting", kicks in if a loop contains a conditional test where the condition itself will not change while the loop executes. The compiler may split it into two separate loops, one for each case, moving the test and the jump out of the loop body.

The AddressSanitizer mechanism is now able to detect uses of variables after they go out of scope. Usually this problem results from taking a pointer to a variable, then dereferencing the pointer after exiting the block where that variable was in scope. LLVM has had this ability for a while, but the GCC implementation is claimed to be better by virtue of better handling of complex cases involving goto , as well as the ability to handle C++ temporaries.

Warnings are one area where GCC is said to fall short of LLVM, so one would expect improvements in that area. The C compiler, in particular, has a number of new warnings. For example, -Wimplicit-fallthrough will warn about switch -statement cases that fall through into the following case. This warning can be suppressed with a special attribute declaration — or a comment like " /* falls through */ ". There are warnings for if - else constructs with identical code in both branches, memset() calls where the size argument matches the number of elements in the array but not the size of the array, use of the (removed in C++17) register keyword, and more.

While GCC 6 was able to perform a certain amount of spell-checking on structure field names, GCC 7 expands that feature to function, macro, type, and enum names, and is now able to offer suggestions on how to fix the problem. There is an option to get those suggestions in machine-parsable form, enabling a suitably intelligent development environment to make fixes automatically. Format-string warnings now highlight the specific part of the string that is being complained about and offer fixes as well.

There are some additional warnings for situations that could create buffer overflows, including one for code that passes a huge size to a memory-allocation function. The compiler can now calculate the size of the output string in many sprintf() calls and warn if that destination array might be overrun. Similarly, possible truncation in snprintf() calls will generate a warning. A number of possible overflows in memcpy() and strcpy() calls can be detected at compile time as well.

The C++ compiler now has experimental support for the entire C++17 draft standard; a long list of new language features was added to achieve that support. Fortran has better DO -loop optimization and partial OpenMP 4.5 support. Ada code can now run without the need for an executable stack — a somewhat overdue security improvement. There is Go 1.8 support. On the other hand, the Java front end has been removed because there was nobody to maintain it.

Support for the Fuchsia operating system has been added in GCC 7.

Finally, there is now an internal unit-testing API for GCC, and a beginning suite of tests has been added. Parsing of internal-representation dumps has been added, allowing the creation of tests for specific optimization techniques. And, of course, this release will include the usual collection of bug fixes and smaller improvements.

LLVM may be the cool kid on the compiler block at the moment, but the GCC developers are not sitting still. GCC 7 will be another full-featured release from this project, which saw the 30th anniversary of the first beta release in March. Few projects have been so important to our community for so long, and GCC clearly is not done yet.

