GCC 11 Release Series — Changes, New Features, and Fixes

# GCC 11 Release Series
Changes, New Features, and Fixes

This page is a "brief" summary of some of the huge number of improvements in GCC 11. You may also want to check out our Porting to GCC 11 page and the full GCC documentation.

## Caveats

- The default mode for C++ is now `-std=gnu++17` instead of `-std=gnu++14`. Note that C++17 changes to template template parameter matching can be disabled independently of other features with `-fno-new-ttp-matching`.
- When building GCC itself, the host compiler must now support C++11, rather than C++98. In particular bootstrapping GCC 11 using an older version of GCC requires a binary of GCC 4.8 or later, rather than of GCC 3.4 or later as was the case for bootstrapping GCC 10.
- Naming and location of auxiliary and dump output files changed. If you compile multiple input files in a single command, if you enable Link Time Optimization, or if you use `-dumpbase`, `-dumpdir`, `-save-temps=*`, and you expect any file other than the primary output file(s) to be created as a side effect, watch out for improvements and a few surprises. See the patch, particularly its textual description, for more details about the changes.
- `-gsplit-dwarf` no longer enables debug info generation on its own but requires a separate `-g` for this.
- The libstdc++ configure option `--enable-cheaders=c_std` is deprecated and will be removed in a future release. It should be possible to use `--enable-cheaders=c_global` (the default) with no change in behaviour.
- The front end for compiling BRIG format of Heterogeneous System Architecture Intermediate Language (HSAIL) has been deprecated and will likely be removed in a future release.
- Some short options of the `gcov` tool have been renamed: `-i` to `-j` and `-j` to `-H`.

## General Improvements

- ThreadSanitizer improvements to support alternative runtimes and environments. The Linux Kernel Concurrency Sanitizer (KCSAN) is now supported.
  - Add `--param tsan-distinguish-volatile` to optionally emit instrumentation distinguishing volatile accesses.
  - Add `--param tsan-instrument-func-entry-exit` to optionally control if function entries and exits should be instrumented.

- In previous releases of GCC, the "column numbers" emitted in diagnostics were actually a count of bytes from the start of the source line. This could be problematic, both because of:

  - multibyte characters (requiring more than one byte to encode), and
  - multicolumn characters (requiring more than one column to display in a monospace font)

  For example, the character π ("GREEK SMALL LETTER PI (U+03C0)") occupies one column, and its UTF-8 encoding requires two bytes; the character 🙂 ("SLIGHTLY SMILING FACE (U+1F642)") occupies two columns, and its UTF-8 encoding requires four bytes.

  In GCC 11 the column numbers default to being column numbers, respecting multi-column characters. The old behavior can be restored using a new option `-fdiagnostics-column-unit=byte`. There is also a new option `-fdiagnostics-column-origin=`, allowing the pre-existing default of the left-hand column being column 1 to be overridden if desired (e.g. for 0-based columns). The output of `-fdiagnostics-format=json` has been extended to supply both byte counts and column numbers for all source locations.

  Additionally, in previous releases of GCC, tab characters in the source would be emitted verbatim when quoting source code, but be prefixed with whitespace or line number information, leading to misalignments in the resulting output when compared with the actual source. Tab characters are now printed as an appropriate number of spaces, using the `-ftabstop` option (which defaults to 8 spaces per tab stop).

- Introduce Hardware-assisted AddressSanitizer support. This sanitizer currently only works for the AArch64 target. It helps debug address problems similarly to AddressSanitizer but is based on partial hardware assistance and provides probabilistic protection to use less RAM at run time. Hardware-assisted AddressSanitizer is not production-ready for user space, and is provided mainly for use compiling the Linux Kernel.

  To use this sanitizer the command line arguments are:
  - `-fsanitize=hwaddress` to instrument userspace code.
  - `-fsanitize=kernel-hwaddress` to instrument kernel code.

- For targets that produce DWARF debugging information GCC now defaults to DWARF version 5 (with the exception of VxWorks and Darwin/Mac OS X which default to version 2 and AIX which defaults to version 4). This can produce up to 25% more compact debug information compared to earlier versions.

  To take full advantage of DWARF version 5 GCC needs to be build against binutils version 2.35.2 or higher. When GCC is build against earlier versions of binutils GCC will still emit DWARF version 5 for most debuginfo data, but will generate version 4 debug line tables (even when explicitly given `-gdwarf-5`).

  The following debug information consumers can process DWARF version 5:

  - GDB 8.0, or higher
  - valgrind 3.17.0
  - elfutils 0.172, or higher (for use with systemtap, dwarves/pahole, perf and libabigail)
  - dwz 0.14

  Programs embedding libbacktrace are urged to upgrade to the version shipping with GCC 11.

  To make GCC 11 generate an older DWARF version use `-g` together with `-gdwarf-2`, `-gdwarf-3` or `-gdwarf-4`.

- Vectorizer improvements:
  - The straight-line code vectorizer now considers the whole function when vectorizing and can handle opportunities crossing CFG merges and backedges.
- A series of conditional expressions that compare the same variable can be transformed into a switch statement if each of them contains a comparison expression. Example:

              int IsHTMLWhitespace(int aChar) {
                return aChar == 0x0009 || aChar == 0x000A ||
                       aChar == 0x000C || aChar == 0x000D ||
                       aChar == 0x0020;
              }

  This statement can be transformed into a switch statement and then expanded into a bit-test.
- New command-line options:
  - `-fbit-tests`, enabled by default, can be used to enable or disable switch expansion using bit-tests.
- Inter-procedural optimization improvements:
  - A new IPA-modref pass was added to track side effects of function calls and improve precision of points-to-analysis. The pass can be controlled by the `-fipa-modref` option.
  - The identical code folding pass (controlled by `-fipa-icf`) was significantly improved to increase the number of unified functions and to reduce compile-time memory use.
  - IPA-CP (Interprocedural constant propagation) heuristics improved its estimation of potential usefulness of known loop bounds and strides by taking the estimated frequency of these loops into account.
- Link-time optimization improvements:
  - The LTO bytecode format was optimized for smaller object files and faster streaming.
  - Memory allocation of the linking stage was improved to reduce peak memory use.
- Profile driven optimization improvements:
  - Using `-fprofile-values`, was improved by tracking more target values for e.g. indirect calls.
  - GCOV data file format outputs smaller files by representing zero counters in a more compact way.

## New Languages and Language specific improvements

- GCC 11 adds support for non-rectangular loop nests in OpenMP constructs and the allocator routines of OpenMP 5.0, including initial `allocate` clause support in C/C++. The `OMP_TARGET_OFFLOAD` environment variable and the active-levels routines are now supported. For C/C++, the `declare variant` and `map` support has been extended. For Fortran, OpenMP 4.5 is now fully supported and OpenMP 5.0 support has been extended, including the following features which were before only available in C and C++: `order(concurrent)`, `device_type`, memorder-clauses for `flush`, `lastprivate` with `conditional` modifier, `atomic` construct and `reduction` clause extensions of OpenMP 5.0, `if` clause with `simd` and `cancel` modifiers, `target data` without `map` clause, and limited support for the `requires` construct.
- Version 2.6 of the OpenACC specification continues to be maintained and improved in the C, C++ and Fortran compilers. See the implementation status section on the OpenACC wiki page and the run-time library documentation for further information.

### C family

- New attributes:
  - The `no_stack_protector` attribute has been added to mark functions which should not be instrumented with stack protection (`-fstack-protector`).
  - The existing `malloc` attribute has been extended so that it can be used to identify allocator/deallocator API pairs. A pair of new `-Wmismatched-dealloc` and `-Wmismatched-new-delete` warnings will complain about mismatched calls, and `-Wfree-nonheap-object` about deallocation calls with pointers not obtained from allocation functions. Additionally, the static analyzer will use these attributes when checking for leaks, double-frees, use-after-frees, and similar issues.
- New warnings:
  - `-Wmismatched-dealloc`, enabled by default, warns about calls to deallocation functions with pointers returned from mismatched allocation functions.
  - `-Wsizeof-array-div`, enabled by `-Wall`, warns about divisions of two sizeof operators when the first one is applied to an array and the divisor does not equal the size of the array element.
  - `-Wstringop-overread`, enabled by default, warns about calls to string functions reading past the end of the arrays passed to them as arguments. In prior GCC releases most instances of his warning are diagnosed by `-Wstringop-overflow`.
  - `-Wtsan`, enabled by default, warns about unsupported features in ThreadSanitizer (currently `std::atomic_thread_fence`).
- Enhancements to existing warnings:
  - `-Wfree-nonheap-object` detects many more instances of calls to deallocation functions with pointers not returned from a dynamic memory allocation function.
  - `-Wmaybe-uninitialized` diagnoses passing pointers or references to uninitialized memory to functions taking `const`-qualified arguments.
  - `-Wuninitialized` detects reads from uninitialized dynamically allocated memory.

- For ELF targets that support the GNU or FreeBSD OSABIs, the `used` attribute will now save the symbol declaration it is applied to from linker garbage collection.

  To support this behavior, `used` symbols that have not been placed in specific sections (e.g. with the `section` attribute, or the `-f{function,data}-sections` options) will be placed in new, unique sections.

  This functionality requires Binutils version 2.36 or later.

### C

- Several new features from the upcoming C2X revision of the ISO C standard are supported with `-std=c2x` and `-std=gnu2x`. Some of these features are also supported as extensions when compiling for older language versions. In addition to the features listed, some features previously supported as extensions and now added to the C standard are enabled by default in C2X mode and not diagnosed with `-std=c2x -Wpedantic`.
  - The `BOOL_MAX` and `BOOL_WIDTH` macros are provided in `<limits.h>`.
  - As in C++, function definitions no longer need to give names for unused function parameters.
  - The expansions of the `true` and `false` macros in `<stdbool.h>` have changed so that they have type `bool`.
  - The `[[nodiscard]]` standard attribute is now supported.
  - The `__has_c_attribute` preprocessor operator is now supported.
  - Macros `INFINITY`, `NAN`, `FLT_SNAN`, `DBL_SNAN`, `LDBL_SNAN`, `DEC_INFINITY`, `DEC_NAN`, and corresponding signaling NaN macros for `_FloatN`, `_FloatNx` and `_DecimalN` types, are provided in `<float.h>`. There are also corresponding built-in functions `__builtin_nansdN` for decimal signaling NaNs.
  - Macros `FLT_IS_IEC_60559`, `DBL_IS_IEC_60559` and `LDBL_IS_IEC_60559` are provided in `<float.h>`.
  - The feature test macro `__STDC_WANT_IEC_60559_EXT__` is supported by `<float.h>`.
  - Labels may appear before declarations and at the end of a compound statement.
- New warnings:
  - `-Warray-parameter`, enabled by `-Wall`, warns about redeclarations of functions with ordinary array arguments declared using inconsistent forms. The warning also enables the detection of the likely out of bounds accesses in calls to such functions with smaller arrays.
  - `-Wvla-parameter`, enabled by `-Wall`, warns redeclarations of functions with variable length array arguments declared using inconsistent forms or with mismatched bounds. The warning also enables the detection of the likely out of bounds accesses in calls to such functions with smaller arrays.

### C++

- The default mode has been changed to `-std=gnu++17`.
- Several C++20 features have been implemented:
  - the compiler now supports `consteval virtual` functions
  - P2082R1, Fixing CTAD for aggregates
  - P0593R6, Pseudo-destructors end object lifetimes
  - P1907R1, Inconsistencies with non-type template parameters (complete implementation)
  - P1975R0, Fixing the wording of parenthesized aggregate-initialization
  - P1009R2, Array size deduction in new-expressions
  - P1099R5, `using enum`
  - Modules, Requires `-fmodules-ts` and some aspects are incomplete. Refer to C++ 20 Status
- The C++ front end has experimental support for some of the upcoming C++23 draft features with the `-std=c++23`, `-std=gnu++23`, `-std=c++2b` or `-std=gnu++2b` flags, including
  - P0330R8, Literal Suffix for (signed) size_t.
  For a full list of new features, see the C++ status page.
- Several C++ Defect Reports have been resolved, e.g.:
  - DR 625, Use of `auto` as a template-argument
  - DR 1512, Pointer comparison vs qualification conversions
  - DR 1722, Should lambda to function pointer conversion function be `noexcept`?
  - DR 1914, Duplicate standard attributes
  - DR 2032, Default template-arguments of variable templates
  - DR 2289, Uniqueness of decomposition declaration names
  - DR 2237, Can a template-id name a constructor?
  - DR 2303, Partial ordering and recursive variadic inheritance
  - DR 2369, Ordering between constraints and substitution
  - DR 2450, braced-init-list as a template-argument
- G++ now performs better access checking in templates (PR41437).
- `reinterpret_cast`s in constexpr evaluation are now checked more completely (PR95307).
- The diagnostic for `static_assert` has been improved: the compiler now shows the expression including its template arguments (if there were any), and can point to the failing clause if the condition comprised of any logical AND operators (PR97518).
- New warnings:
  - `-Wctad-maybe-unsupported`, disabled by default, warns about performing class template argument deduction on a type with no deduction guides.
  - `-Wrange-loop-construct`, enabled by `-Wall`, warns when a range-based for-loop is creating unnecessary and expensive copies.
  - `-Wdeprecated-enum-enum-conversion`, enabled by default in C++20, warns about deprecated arithmetic conversions on operands of enumeration types, as outlined in [depr.arith.conv.enum].
  - `-Wdeprecated-enum-float-conversion`, enabled by default in C++20, warns about deprecated arithmetic conversions on operands where one is of enumeration type and the other is of a floating-point type, as outlined in [depr.arith.conv.enum].
  - `-Wmismatched-new-delete`, enabled by `-Wall`, warns about calls to C++ `operator delete` with pointers returned from mismatched forms of `operator new` or from other mismatched allocation functions.
  - `-Wvexing-parse`, enabled by default, warns about the most vexing parse rule: the cases when a declaration looks like a variable definition, but the C++ language requires it to be interpreted as a function declaration.
- Enhancements to existing warnings:
  - `-Wnonnull` considers the implicit `this` argument of every C++ nonstatic member function to have been implicitly declared with attribute `nonnull` and triggers warnings for calls where the pointer is null.

#### Runtime Library (libstdc++)

- Improved C++17 support, including:
  - `std::from_chars` and `std::to_chars` for floating-point types.
- Improved experimental C++20 support, including:
  - Calendar additions to `<chrono>`. Thanks to Cassio Neri for optimizations.
  - `std::bit_cast`
  - `std::source_location`
  - Atomic wait and notify operations.
  - `<barrier>`, `<latch>`, and `<semaphore>`
  - `<syncstream>`
  - Efficient access to `basic_stringbuf`'s buffer.
- Experimental C++23 support, including:
  - `contains` member functions for strings, thanks to Paul Fee.
  - `std::to_underlying`, `std::is_scoped_enum`
- Experimental support for Data-Parallel Types (`simd`) from the Parallelism 2 TS, thanks to Matthias Kretz.
- Faster `std::uniform_int_distribution`, thanks to Daniel Lemire.

### Fortran

- Added `DEPRECATED` to `!GCC$`'s `attributes` directive.

## libgccjit

- libgccjit was marked as merely "Alpha" quality when originally added in GCC 5. Given that we have maintained API and ABI compatibility since then and it is in use by various projects, we have removed that caveat.
- libgccjit can now be built for MinGW
- The libgccjit API gained 10 new entry points:
  - `gcc_jit_global_set_initializer`
  - 9 entrypoints for directly embedding asm statements into a compile, analogous to inline `asm` in the C front end

## New Targets and Target Specific Improvements

### AArch64 & arm

- A number of new CPUs are supported through arguments to the `-mcpu` and `-mtune` options in both the arm and aarch64 backends (GCC identifiers in parentheses):
  - Arm Cortex-A78 (`cortex-a78`).
  - Arm Cortex-A78AE (`cortex-a78ae`).
  - Arm Cortex-A78C (`cortex-a78c`).
  - Arm Cortex-X1 (`cortex-x1`).
  - Arm Neoverse V1 (`neoverse-v1`).
  - Arm Neoverse N2 (`neoverse-n2`).
- GCC can now auto-vectorize operations performing addition, subtraction, multiplication and the accumulate/subtract variants on complex numbers, taking advantage of the Advanced SIMD instructions in the Armv8.3-a (AArch64/AArch32), SVE (AArch64), SVE2 (AArch64) and MVE (AArch32 M-profile) instruction sets.

### AArch64

- In addition to the above, the following AArch64-only CPUs are now supported:
  - Fujitsu A64FX (`a64fx`).
  - Arm Cortex-R82 (`cortex-r82`).
- The AArch64 Armv8-R architecture is now supported through the `-march=armv8-r` option.
- Mitigation against the Straight-line Speculation vulnerability is supported with the `-mharden-sls=` option. Please refer to the documentation for usage instructions.
- The availability of Advanced SIMD intrinsics available through the `arm_neon.h` header is improved and GCC 11 supports the full set of intrinsics defined by ACLE Q3 2020.

### AMD Radeon (GCN)

- Initial support for `gfx908` GPUs has been added.

### arm

- Initial auto-vectorization is now available when targeting the MVE instruction set.
- GCC can now make use of the Low Overhead Branch instruction in Armv8.1-M to optimize loop counters and checks.
- The `-mcpu=cortex-m55` option now supports the extensions `+nomve` and `+nomve.fp` to control generation of MVE and MVE floating-point instructions.

### IA-32/x86-64

- New ISA extension support for Intel TSXLDTRK was added to GCC. TSXLDTRK intrinsics are available via the `-mtsxldtrk` compiler switch.
- New ISA extension support for Intel SERIALIZE was added to GCC. SERIALIZE intrinsics are available via the `-mserialize` compiler switch.
- New ISA extension support for Intel HRESET was added to GCC. HRESET intrinsics are available via the `-mhreset` compiler switch.
- New ISA extension support for Intel UINTR was added to GCC. UINTR intrinsics are available via the `-muintr` compiler switch.
- New ISA extension support for Intel KEYLOCKER was added to GCC. KEYLOCKER intrinsics are available via the `-mkeylocker` compiler switch.
- New ISA extension support for Intel AMX-TILE, AMX-INT8, AMX-BF16 was added to GCC. AMX-TILE, AMX-INT8, AMX-BF16 intrinsics are available via the `-mamx-tile, -mamx-int8, -mamx-bf16` compiler switches.
- New ISA extension support for Intel AVX-VNNI was added to GCC. AVX-VNNI intrinsics are available via the `-mavxvnni` compiler switch.
- GCC now supports the Intel CPU named Sapphire Rapids through `-march=sapphirerapids`. The switch enables the MOVDIRI, MOVDIR64B, AVX512VP2INTERSECT, ENQCMD, CLDEMOTE, SERIALIZE, PTWRITE, WAITPKG, TSXLDTRK, AMT-TILE, AMX-INT8, AMX-BF16, and AVX-VNNI ISA extensions.
- GCC now supports the Intel CPU named Alderlake through `-march=alderlake`. The switch enables the CLDEMOTE, PTWRITE, WAITPKG, SERIALIZE, KEYLOCKER, AVX-VNNI, and HRESET ISA extensions.
- GCC now supports the Intel CPU named Rocketlake through `-march=rocketlake`. Rocket Lake is based on Icelake client and minus SGX.
- GCC now supports AMD CPUs based on the `znver3` core via `-march=znver3`.
- GCC now supports micro-architecture levels defined in the x86-64 psABI via `-march=x86-64-v2`, `-march=x86-64-v3` and `-march=x86-64-v4`.

### Nios II

- The options `-mcustom-insn=N` no longer produce compiler warnings if the custom instruction is not generated due to missing optimization options such as `-fno-math-errno`, `-ffinite-math-only`, or `-funsafe-math-optimizations`. These warnings were not consistently emitted for all custom instructions.
- The `-mcustom-fpu-cfg=fph2` option has been added to enable the custom instructions supported by the Nios II Floating Point Hardware 2 Component.

### NVPTX

- The `-misa` default has changed from `sm_30` to `sm_35`.
- The `-m32` compiler switch has been removed.
- The `-msoft-stack-reserve-local` format has been fixed. Previously, it accepted `-msoft-stack-reserve-local<n>`. It now accepts `-msoft-stack-reserve-local=<n>`.

### S/390, System z, IBM Z Systems

- The behavior when compiling with `-fexcess-precision=standard` (e.g., implied by `-std=c99`) on s390(x) targets can now be controlled at configure time with the flag `--enable-s390-excess-float-precision`. When enabled, GCC will maintain previous behavior and evaluate float expressions in double precision, which aligns with the definition of `float_t` as `double`. With the flag disabled, GCC will always evaluate float expressions in single precision. In native builds and cross compiles that have target libc headers, GCC will by default match the definition of `float_t` in the installed glibc.

### RISC-V

- Support address sanitizer for RISC-V.
- Support big-endian for RISC-V, thanks to Marcus Comstedt.
- Implement new style of architecture extension test macros, each architecture extension has corresponding feature test macro, which could use to test its existence and version information.
- Legacy architecture extension test macro like `__riscv_atomic`, are deprecated, but it will still supported for at least 2 release cycles.
- Support IFUNC for `riscv*-*-linux*`.
- Add new option -misa-spec=* to control ISA spec version, default is 2.2, this option could control the default version of each extensions.
- Introduce `--with-multilib-generator` to configure time option, this option could flexible config multi-lib settings, syntax is same as RISC-V's `multilib-generator`.
- Extend the sytax for `multilib-generator`, support expansion operator `*` to reduce the complexity of complicated multi-lib re-use rule.
- Support `-mcpu=*` option, the behavior is aligned to RISC-V clang/LLVM, it will set pipeline model and architecture extension, like `-mtune=*` plus `-march=*`.
- Support for TLS stack protector canary access, thanks to Cooper Qu.
- Support `__builtin_thread_pointer` for RISC-V.
- Introduce `shorten_memrefs` optimization, which could reduce the code size for memory access, thanks to Craig Blackmore.

## Operating Systems

### AIX

- GCC for AIX can be built as a 64 bit application and the runtime is built as FAT libraries containing both 32 bit and 64 bit objects.
- Support AIX Vector Extended ABI with -mabi=vec-extabi.
- Thread-Local uninitiated data placed in local common section.
- Use thread-safe access in ctype.
- Link with libc128.a when long-double-128 enabled.

## Improvements to Static Analyzer

- The implementation of how program state is tracked within -fanalyzer has been completely rewritten for GCC 11, fixing numerous bugs, and allowing for the analyzer to scale to larger C source files.
- The analysis of allocations and deallocations has been generalized beyond `malloc` and `free`.
  - As preliminary work towards eventually supporting C++, the `malloc`/`free` checking will also check `new`/`delete` and `new[]`/`delete[]`. However, C++ is not yet properly supported by `-fanalyzer` (for example, exception-handling is unimplemented).
  - As noted above, the existing `malloc` attribute has been extended so that it can be used to identify allocator/deallocator API pairs. The analyzer will use these attributes when checking for leaks, double-frees, use-after-frees, and similar issues.
  - A new `-Wanalyzer-mismatching-deallocation` warning has been added, covering such mismatches as using scalar `delete` rather vector `delete[]`.
- The analyzer has gained warnings `-Wanalyzer-shift-count-negative`, `-Wanalyzer-shift-count-overflow`, `-Wanalyzer-write-to-const`, and `-Wanalyzer-write-to-string-literal`, all enabled by default when `-fanalyzer` is enabled.
- The analyzer can now be extended by GCC plugins, allowing for domain-specific path-sensitive warnings. An example of using a GCC plugin to check for misuses of CPython's global interpreter lock can be seen in the test suite
- The analyzer has gained new debugging options `-fdump-analyzer-json` and `-fno-analyzer-feasibility`.

## Other significant improvements

- GCC has gained a new environment variable `GCC_EXTRA_DIAGNOSTIC_OUTPUT` which can be used by IDEs to request machine-readable fix-it hints without needing to adjust build flags.

## GCC 11.1

This is the list of problem reports (PRs) from GCC's bug tracking system that are known to be fixed in the 11.1 release. This list might not be complete (that is, it is possible that some PRs that have been fixed are not listed here).