Upcoming features in GCC 6
The GCC project has traditionally made major releases yearly in the March/April timeframe. March is rapidly approaching and the GCC project’s engineers are busy polishing things up for the GCC 6 release. I’m going to take a short break from my own release efforts to briefly talk about some of the new features.
Warnings GCC strives to implement warnings which help developers catch errors at compile time rather than allow potentially dangerous code to be silently accepted and ultimately deployed. For GCC 6, the major warning additions are:
Misleading indentation: The goal of the misleading indentation warning is to detect code where the block structure likely does not match how a human would read the code. The most obvious example is the the “Apple SSL bug” from 2014 where mis-indented code made it look like a GOTO was guarded by a prior IF conditional, when in fact it was not guarded at all. This will be covered in more detail in a blog post from David Malcolm.
Tautological comparisons: Code which compares an object to itself and which always evaluates to the same result often represents a typo/bug in the source code. GCC 6 will now warn for such comparisons.
Duplicated Condition: GCC 6 will now warn when a condition is repeated in an IF-ELSE-IF chain.
Negative shift value and shift overflow: GCC now warns when left shifting a negative value or when a left shift overflows. These have always had undefined behavior and catching them at compile time rather than allowing runtime undefined behaviour is always advisable.
null-dereference: GCC is more aggressive about detecting paths that trigger erroneous or undefined behaviour by dereferencing a NULL pointer or using a NULL value in a return or as a function argument when a NULL value for that argument/return value has been explicitly disallowed by the function’s attributes.
Features: Each release of GCC brings a variety of new features designed to make development using GCC easier in some way or another. Highlights from the upcoming GCC 6 release include:
OpenMP 4.5: OpenMP is an API to provide a simple, but highly flexible interface for developing parallel C, C++ and Fortran programs. The OpenMP 4.5 specification was released in November 2015 and includes many new changes since the prior OpenMP 4.0 specification. GCC 6 will include support for OpenMP 4.5 for C and C++ and OpenMP 4.0 support for Fortran with some degree of offloading support, particularly for the Intel MIC processor.
Segment register support: The x86/x86_64 is a segmented memory architecture, yet GCC has largely ignored this aspect of the Intel architecture and relied on implicit segment registers. Low level code such as the Linux kernel & glibc often have to be aware of the segmented architecture and have traditionally resorted to asm statements to use explicit segment registers for memory accesses. Starting with GCC 6, variables may be declared as being relative to a particular segment. Explicit segment registers will then be used to access those variables in memory.
Rich locations and other diagnostic work: GCC 6 adds the concept of “rich locations” to its diagnostic machinery. This allows GCC to track ranges rather than just points for diagnostic messages. So, for example, the problematical subexpression within a more complex expression can be identified and highlighted to the developer. Diagnostics can now include “fix-it” hints which can suggest how incorrect code can be fixed. This will be covered in more depth in a separate blog post from David Malcolm.
Target Clones: GCC 6 adds the new “target_clones” attribute which specifies that a particular function should be compiled multiple times for different ISA variants and a runtime dispatcher created to check the in-use ISA and call the appropriate clone. This makes it much easier to support runtime-specialized routines for different versions of a particular ISA.
Scalar Storage Order: GCC 6 adds an new pragma “scalar_storage_order” which can be used to specify the endianness of fields within a structure. GCC will automatically generate code to byte swap these objects as-needed if the target’s endianness differs from the endianness of the objects being accessed.
Offloading/HSA: GCC 5 had initial support for offloading to MIC via OpenMP and to NVidia GPUs via OpenACC. GCC 6 improves on those existing capabilities and also adds offloading via HSA accelerators.
Languages and Runtime Libraries:
GCC 6 now defaults to C++ 14. GCC 6 now includes C++ Concepts.
The C++ runtime library now supports mathematical special functions (ISO/IEC 29124:2010)
Experimental support for C++17 features
try_emplace and insert_or_assign for unique_key maps
non-member functions std::size, std::empty and std::data for accessing containers and arrays
std::void_t and std::bool_constant
Experimental support for the File System TS
Experimental support for most of the second version of the Library Fundamentals TS, including polymorphic memory resources and array support in shared_ptr
MATMUL intrinsic is now inlined for simple cases in the Fortran front-end
And, of course more optimizations and bugfixes than you can shake a stick at. I won’t even try to enumerate all that’s happened in this space. As is the case with ever release, we strive to improve the generated code in as many cases as we can and fix as many reported bugs as we can.
Join the Red Hat Developer Program (it’s free) and get access to related cheat sheets, books, and product downloads.