GCC 12 Release Series — Changes, New Features, and Fixes
GCC 12 Release Series
Changes, New Features, and Fixes
This page is a "brief" summary of some of the huge number of improvements in GCC 12. You may also want to check out ourPorting to GCC 12 page and thefull GCC documentation.
Caveats
- An ABI incompatibility between C and C++ when passing or returning by value certain aggregates containing zero width bit-fields has been discovered on various targets. As mentioned in PR102024, since the PR42217 fix in GCC 4.5 the C++ front-end has been removing zero width bit-fields from the internal representation of the aggregates after the layout of those aggregates, but the C front-end kept them, so passing e.g.
struct S { float a; int : 0; float b; }
orstruct T { float c; int : 0; }
by value could differ between C and C++. Starting with GCC 12 the C++ front-end no longer removes those bit-fields from the internal representation and per clarified psABI some targets have been changed, so that they either ignore those bit-fields in the argument passing by value decisions in both C and C++, or they always take them into account. x86-64, ARM and AArch64 will always ignore them (so there is a C ABI incompatibility between GCC 11 and earlier with GCC 12 or later), PowerPC64 ELFv2 and S/390 always take them into account (so there is a C++ ABI incompatibility, GCC 4.4 and earlier compatible with GCC 12 or later, incompatible with GCC 4.5 through GCC 11). RISC-V has changed the handling of these already starting with GCC 10. As the ABI requires, MIPS takes them into account handling function return values so there is a C++ ABI incompatibility with GCC 4.5 through 11. For function arguments on MIPS, refer tothe MIPS specific entry. GCC 12 on the above targets will report such incompatibilities as warnings or other diagnostics unless-Wno-psabi
is used. - C: Computed gotos require a pointer type now.
- C++: Two non-standard
std::pair
constructors have been deprecated. These allowed the use of an rvalue and a literal0
to construct a pair containing a move-only type and a pointer. Thenullptr
keyword should be used to initialize the pointer member instead of a literal0
, as this is portable to other C++ implementations. - The configuration option
--enable-libstdcxx-allocator
no longer supports thebitmap
,mt
, andpool
arguments. Those configurations had been broken for some time. - D: Building and bootstrapping GDC, the D compiler, now requires a working GDC (GCC version 9.1 or later) and D runtime library, libphobos, as the D front end is written in D. On some targets, libphobos isn't enabled by default, but compiles and works if
--enable-libphobos
is used. Other targets may require a more recent version of GCC to bootstrap. Specifics are documented for affected targets in theInstalling GCC manual. - Fortran: OpenMP code using the
omp_lib.h
include file can no longer be compiled with-std=f95
but now requires at least-std=f2003
. Alternatively, use theomp_lib
module, which still supports-std=f95
and is recommended to be used instead in general. - OpenMP offloading to Intel MIC has been deprecated and will be removed in a future release.
- The
cr16
target with thecr16-*-*
configuration has been obsoleted and will be removed in a future release. - The
hppa[12]*-*-hpux10*
andhppa[12]*-*-hpux11*
configurations targeting 32-bit PA-RISC with HP-UX have been obsoleted and will be removed in a future release. - The
m32c*-*-rtems*
configuration has been obsoleted and will be removed in a future release. - The support for the
m32r-*-linux*
,m32rle-*-linux*
,m68k*-*-openbsd*
andvax-*-openbsd*
configurations has been removed. - STABS: Support for emitting the STABS debugging format is deprecated and will be removed in the next release. All ports now default to emit DWARF (version 2 or later) debugging info or are obsoleted.
- The optimization level
-Ofast
now implies-fno-semantic-interposition
.
General Improvements
- Vectorization is enabled at
-O2
which is now equivalent to what would have been-O2 -ftree-vectorize -fvect-cost-model=very-cheap
in the past. Note that the default vectorizer cost model has been changed; it used to behave as if-fvect-cost-model=cheap
had been specified. - GCC now supports the ShadowCallStack sanitizer, which can be enabled using the command-line option -fsanitize=shadow-call-stack. This sanitizer currently only works on AArch64 targets and it requires an environment in which all code has been compiled with
-ffixed-r18
. Its primary initial user is the Linux kernel.
New Languages and Language specific improvements
- OpenMP
- OpenMP 5.0 support has been extended: The
close
map modifier and theaffinity
clause are now supported. In addition, Fortran gained the following features which were available in C and C++ before:declare variant
is now available,depobj
,mutexinoutset
anditerator
can now also be used with thedepend
clause,defaultmap
has been updated for OpenMP 5.0, and theloop
directive and combined directives involving themaster
directive have been added. - The following OpenMP 5.1 features have been added: support for expressing OpenMP directives as C++ 11 attributes, the
masked
andscope
constructs, thenothing
anderror
directives, and usingprimary
with theproc_bind
clause andOMP_PROC_BIND
environment variable, thereproducible
andunconstrained
modifiers to theorder
clause, and, for C/C++ only, thealign
andallocator
modifiers to theallocate
clause and theatomic
extensions are now available. TheOMP_PLACE
environment variable supports the OpenMP 5.1 features. In addition, theOMP_NUM_TEAMS
andOMP_TEAMS_THREAD_LIMIT
environment variables and their associated API routines are now supported as well as the memory-allocation routines added for Fortran and extended for C/C++ in OpenMP 5.1. In Fortran code, strictly structured blocks can be used. - The OpenMP Implementation Status can be found in the libgomp manual.
- OpenMP 5.0 support has been extended: The
- 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. In addition to general performance tuning and bug fixing, new features include:
- OpenACC worker parallelism for AMD GPUs (already for a long time supported for Nvidia GPUs).
- Data privatization/sharing at the OpenACC gang level.
- Considerable improvements for the experimental OpenACC 'kernels' decomposition (--param openacc-kernels=decompose).
- A new warning flag -Wopenacc-parallelism to warn about potentially suboptimal choices related to OpenACC parallelism.
- The offload target code generation for OpenMP and OpenACC can now be better adjusted using the new -foffload-options= flag and the pre-existing but now documented -foffload= flag.
Ada
- Ada 2022
- Added the
-gnat2022
flag to indicate strict Ada 2022 compliance. The old-gnat2020
flag is now deprecated. - Support for Big Numbers (Annex G) has seen continuous improvements. It is now considered complete. It is compatible with SPARK, i.e. can be used from SPARK code.
- Continuous improvements to the Ada 2022 standard since GCC 11.
- Greatly improved compile time support. More functions can now have the
with Static
aspect and can be used in more contexts.
- Added the
- Ada 2022 extensions. The use of the
-gnatX
flag is necessary to access these features as they are not considered stable or standard.- Fixed lower bound for unconstrained arrays.
*type Matrix is array (Natural range 0 .. <>, Natural range 0 .. <>) of Integer;
is now valid.
* Subtypes can also specify a lower bound:subtype String_1 is String (1 .. <>);
. Boundaries from slices will "slide" to the correct lower bound of the subtype. - Generalized
Object.Operand
notation. The following code is now validV.Add_Element(42);
, withV
being a vector, for example. - Additional
when
constructs. Keywordsreturn
,goto
andraise
can now usewhen
in addition to the existingexit when
. The following expression is therefore now validraise Constraint_Error with "Element is null" when Element = null;
- Pattern matching
* Thecase
statement has been extended to cover records and arrays as well as finer grained casing on scalar types. In the future it is expected to provide more compile time guarantees when accessing discriminated fields. Case exhaustion is supported for pattern matching. An example would be
type Sign is (Neg, Zero, Pos);
function Multiply (S1, S2 : Sign) return Sign is
(case (S1, S2) is
when (Neg, Neg) | (Pos, Pos) => Pos,
when (Zero, <>) | (<>, Zero) => Zero,
when (Neg, Pos) | (Pos, Neg) => Neg);
- Fixed lower bound for unconstrained arrays.
gnatfind
andgnatxref
, which were already deprecated, have been removed.- Greatly expanded code covered by contracts. Thanks to this work, there are now several Ada standard libraries fully proven in SPARK which means they have no runtime nor logical errors. They are mostly numeric and string handling libraries.
- Enable return-slot optimization for
Pure
functions. - General optimizations, improvements and additions to the standard library. Performance, correctness and in some cases stability was improved. Memory pools have also seen some minor enhancements.
- Improvements to embedded-RTOS targets such as RTEMS, VxWorks and QNX. Older targets were removed or cleaned.
- Added some hardening features.
C family
- Support for
__builtin_shufflevector
compatible with the clang language extension was added. - Support for attribute
unavailable
was added. - A new built-in function,
__builtin_assoc_barrier
, was added. It can be used to inhibit re-association of floating-point expressions. - Support for
__builtin_dynamic_object_size
compatible with the clang language extension was added. - New warnings:
- -Wbidi-chars warns about potentially misleading UTF-8 bidirectional control characters. The default is
-Wbidi-chars=unpaired
(PR103026) - -Warray-compare warns about comparisons between two operands of array type (PR97573)
- -Wbidi-chars warns about potentially misleading UTF-8 bidirectional control characters. The default is
- Enhancements to existing warnings:
- -Wattributes has been extended so that it's possible to use
-Wno-attributes=ns::attr
or-Wno-attributes=ns::
to suppress warnings about unknown scoped attributes (in C++11 and C2X). Similarly,#pragma GCC diagnostic ignored_attributes "vendor::attr"
can be used to achieve the same effect (PR101940)
- -Wattributes has been extended so that it's possible to use
C
- Some 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
.- Digit separators (as in C++) are supported for C2X.
- The
#elifdef
and#elifndef
preprocessing directives are now supported. - The
printf
andscanf
format checking with -Wformat now supports the%b
format specified by C2X for binary integers, and the%B
format recommended by C2X forprintf
.
C++
- Several C++23 features have been implemented:
- P1938R3,
if consteval
(PR100974) - P0849R8,
auto(x)
: decay-copy in the language (PR103049) - P2242R3, Non-literal variables (and labels and gotos) in constexpr functions (PR102612)
- P2334R1, Support for preprocessing directives
elifdef
andelifndef
(PR102616) - P2360R0, Extend init-statement to allow alias-declaration (PR102617)
- P2128R6, Multidimensional subscript operator
- DR 2397,
auto
specifier for pointers and references to arrays (PR100975)
- P1938R3,
- Several C++ Defect Reports have been resolved, e.g.:
- DR 960, Covariant functions and lvalue/rvalue references
- DR 1227, Mixing immediate and non-immediate contexts in deduction failure
- DR 1315, Restrictions on non-type template arguments in partial specializations
- DR 2082, Referring to parameters in unevaluated operands of default arguments
- DR 2351,
void{}
- DR 2374, Overly permissive specification of
enum
direct-list-initialization - DR 2397,
auto
specifier for pointers and references to arrays - DR 2446, Questionable type-dependency of concept-ids
- New command-line option
-fimplicit-constexpr
can be used to make inline functions implicitly constexpr (git) - New command-line option
-ffold-simple-inlines
can be used to fold calls to certain trivial inline functions (currentlystd::move
,std::forward
,std::addressof
andstd::as_const
). In contrast to inlining such calls, folding means that no intermediate code or debug information will be generated for them; this minimizes the abstraction penalty incurred for using these functions versus using the fundamental operations from which they're defined (e.g.std::move
versusstatic_cast
). This flag is enabled by default when-fno-inline
is not active. - Deduction guides can be declared at class scope (PR79501)
- -Wuninitialized warns about using uninitialized variables in member initializer lists (PR19808)
- -Wint-in-bool-context is now disabled when instantiating a template (git)
- Stricter checking of attributes on friend declarations: if a friend declaration has an attribute, that declaration must be a definition. Moreover, a C++11 attribute cannot appear in the middle of the_decl-specifier-seq_. (PR99032)
- New warning options for C++ language mismatches:
-Wc++11-extensions
,-Wc++14-extensions
,-Wc++17-extensions
,-Wc++20-extensions
, and-Wc++23-extensions
. They are enabled by default and can be used to control existing pedwarns about occurrences of new C++ constructs in code using an old C++ standard dialect. - New warning-Wmissing-requires warns about missing
requires
(git) - The existing
std::is_constant_evaluated
inif
warning was extended to warn in more cases (PR100995) - -Waddress has been enhanced so that it now warns about, for instance, comparing the address of a nonstatic member function to null (PR102103)
- Errors about narrowing are no longer hidden if they occur in system headers
- Ordered comparison of null pointers is now rejected (PR99701)
- Anonymous structs with bases are now rejected (git)
- The compiler rejects taking the address of an immediate member function (PR102753)
- The compiler has support for C++20
__cpp_lib_is_pointer_interconvertible
and__cpp_lib_is_layout_compatible
to help the C++ library implement P0466, Layout-compatibility and Pointer-interconvertibility Traits (PR101539) - Memory usage of constraint subsumption has been improved (PR100828)
constinit thread_local
variables are optimized better (PR101786)- Support for C++17
std::hardware_destructive_interference_size
was added, along with the-Winterference-size warning (git) - Many bugs in the CTAD handling have been fixed (PR101344,PR101883,PR89062,PR101233,PR88252,PR86439,PR98832,PR102933 ...)
- Two-stage name lookup for dependent operator expressions has been corrected (PR51577)
- Several issues with constrained variable templates have been fixed (PR98486)
- The compiler performs less instantiating when doing speculative constant evaluation (git)
- Various diagnostic improvements; e.g., a more precise caret location for pointer-to-member expressions
- The new
-fconstexpr-fp-except
flag allows IEC559 floating point exceptions in constant-expressions.
Runtime Library (libstdc++)
- Improved experimental C++20 support, including:
std::vector
,std::basic_string
,std::optional
, andstd::variant
can be used inconstexpr
functions.std::make_shared
for arrays with default initialization, andstd::atomic<std::shared_ptr<T>>
.- Layout-compatibility and pointer-interconvertibility traits.
- Improved experimental C++23 support, including:
- Monadic operations for
std::optional
. std::expected
std::move_only_function
<spanstream>
std::basic_string::resize_and_overwrite
std::unique_ptr
can be used inconstexpr
functions.<stacktrace>
(not built by default, requires linking to an extra library).<stdatomic.h>
std::invoke_r
constexpr std::type_info::operator==
- Monadic operations for
D
- New features:
- Support for the D programming language has been updated to version 2.100.1 of the language and run-time library. Full changelog for this release and previous releases can be found on thedlang.org website.
- On supported targets, the
__traits(compiles)
expression can now be used to determine whether a target-specific built-in is available without error during CTFE (PR101127). - Functions annotated with
pragma(inline, true)
are now compiled into every module where they are used from (PR106563). - Partial support for directly importing C99 sources into a D compilation (ImportC) has been added to the language. A notable missing feature is support for preprocessing C imports, which can be worked around by preprocessing all C sources used for importing ahead of time.
- New language options:
-fcheck=
, enables or disables the code generation of specific run-time contract checks.-fcheckaction=
, controls the run-time behavior on an assert, array bounds check, or final switch contract failure. The default is-fcheckaction=throw
.-fdump-c++-spec=
, dumps all compiledextern(C++)
declarations as C++ code to the given file. The supplementary option-fdump-c++-spec-verbose
turns on emission of comments for ignored declarations in the generated spec.-fextern-std=
, controls which C++ standardextern(C++)
declarations are compiled to be compatible with. The default is-fextern-std=c++17
.-fpreview=
, added to enable upcoming D language features in the compiler.-frevert=
, added to revert D language changes to support older D codebases that need more time to transition.-fsave-mixins=
, saves mixins expanded at compile-time to a file.
- Deprecated and removed features:
- The
-Wtemplates
compiler switch has been removed, as it had been superceded by-ftransition=templates
, which more accurately reports on which templates have been instantiated. - The
-ftransition=dip25
and-ftransition=dip1000
compiler switches have been renamed to-fpreview=dip25
and-fpreview=dip1000
.
- The
Fortran
- WG5/N1942, "TS 29113 Further Interoperability of Fortran with C", is now fully supported. In addition to implementing previously missing functionality, such as support for character arguments of length greater than one in functions marked
bind(c)
and gaps in the handling for assumed-rank arrays, numerous other bugs have been fixed, and an extensive set of new conformance test cases has been added. - GCC 12 now uses
OPERATION
as the name of the function to theCO_REDUCE
intrinsic for the pairwise reduction, thus conforming to the Fortran 2018 standard. Previous versions usedOPERATOR
which conforms to TS 18508. - On POWER systems which support it, the
-mabi=ieeelongdouble
option now selects the IEEE 128-bit floating point format forREAL(KIND=16)
.R16_IBM
andR16_IEEE
have been added to the-fconvert
option, theCONVERT
specifier of theOPEN
statement and theGFORTRAN_CONVERT_UNIT
environment variable.
Go
- GCC 12 provides a complete implementation of the Go 1.18 user packages.
- Although Go 1.18 includes support for generic programming, that support is not yet available in GCC.
libgccjit
- The libgccjit API gained 30 new entry points:
- 17 new "reflection" entry points for querying functions and types (LIBGCCJIT_ABI_16)
- gcc_jit_lvalue_set_tls_model for supporting thread-local variables (LIBGCCJIT_ABI_17)
- gcc_jit_lvalue_set_link_section for setting the link section of global variables, analogous to__attribute__((section(".section"))) (LIBGCCJIT_ABI_18)
- 4 new entry points for initializing global variables and creating constructors for rvalues (LIBGCCJIT_ABI_19)
- Support for sized integer types, including 128-bit integers and helper functions for such types (LIBGCCJIT_ABI_20)
- gcc_jit_context_new_bitcast for reinterpreting the bits of an rvalue as a different type (LIBGCCJIT_ABI_21)
- gcc_jit_lvalue_set_register_name for setting a specific register for a variable (LIBGCCJIT_ABI_22)
- gcc_jit_context_set_bool_print_errors_to_stderr (LIBGCCJIT_ABI_23)
- 2 new entry points for setting the alignment of a variable (LIBGCCJIT_ABI_24)
- libgccjit has gained support for the use of various atomic builtins (PR96066,PR96067)
- gcc_jit_context_new_cast is now able to handle truncation and extension between different integer types (PR95498)
New Targets and Target Specific Improvements
AArch64 & arm
- Newer revisions of the Arm Architecture are supported as arguments to the
-march
option:armv8.7-a
,armv8.8-a
,armv9-a
. - The Arm Cortex-A510 CPU is now supported through the
cortex-a510
argument to the-mcpu
and-mtune
options. - GCC can now auto-vectorize operations performing sign-differing dot-product operations, taking advantage of instructions in the Advanced SIMD (AArch64/AArch32) and SVE (AArch64) instruction sets.
AArch64
- A number of new CPUs are supported through the
-mcpu
and-mtune
options (GCC identifiers in parentheses).- Ampere-1 (
ampere1
). - Arm Cortex-A710 (
cortex-a710
). - Arm Cortex-X2 (
cortex-x2
).
- Ampere-1 (
- The 64-byte atomic load/store intrinsics to accelerator memory from the 2020 Arm Architecture extensions are supported through the
+ls64
option extension. - Initial code generation support is supported for hardware instructions used to accelerate the
memcpy
,memmove
andmemset
standard functions. These instructions can be generated when compiling with the+mops
option extension. - The ACLE Advanced SIMD intrinsics accessible through the
arm_neon.h
header have been significantly reimplemented and generate higher-performing code than previous GCC versions. - The option
-mtune=neoverse-512tvb
is added to tune for Arm Neoverse cores that have a total vector bandwidth of 512 bits. Please refer to the documentation for more details.
AMD Radeon (GCN)
- Debug experience with ROCGDB has been improved.
- Support for the type
__int128_t
/integer(kind=16)
was added. - For offloading, the limitation of using only one wavefront per compute unit (CU) has been lifted. Up to 40 workgroups per CU and 16 wavefronts per workgroup are supported (up to a limit of 40 wavefronts in total, per CU). Additionally, the number of used wavefronts and workgroups was tuned for performance.
arm
- Support is added for accessing the stack canary value via the TLS register through the
-fstack-protector-guard=tls
and-mstack-protector-guard-offset=
options. This intended for use in Linux kernel development. Please refer to the documentation for more details.
BPF
- Support for CO-RE (compile-once, run-everywhere) has been added to the BPF back end. CO-RE allows to compile portable BPF programs that are able to run among different versions of the Linux kernel.
IA-32/x86-64
- New ISA extension support for Intel AVX512-FP16 was added. AVX512-FP16 intrinsics are available via the
-mavx512fp16
compiler switch. - For both C and C++ the
_Float16
type is supported on x86 systems with SSE2 enabled. Without{-mavx512fp16}
, all operations will be emulated in software andfloat
instructions. - Mitigation against straight line speculation (SLS) for function return and indirect jump is supported via
-mharden-sls=[none|all|return|indirect-jmp]
. - Add CS prefix to call and jmp to indirect thunk with branch target in r8-r15 registers via
-mindirect-branch-cs-prefix
. - Always use global offset table (GOT) to access external data and function symbols when the new
-mno-direct-extern-access
command-line option is specified.
LoongArch
- Support for the LoongArch architecture instruction set has been added.
- The Loongson CPU codename LA464 and LoongArch 64-bit generic CPU codename loongarch64 are supported through the
-march=
and-mtune=
options (GCC identifiers in parentheses).- Loongson LA464 core (
la464
). - LoongArch 64-bit generic core (
loongarch64
).
- Loongson LA464 core (
MIPS
- The ABI passing arguments containing zero-width fields (for example, C/C++ zero-width bit-fields, GNU C/C++ zero-length arrays, and GNU C empty structs) has changed. Now a zero-width field will not prevent an aligned 64-bit floating-point field next to it from being passed through FPR. This is compatible with LLVM, but incompatible with previous GCC releases. GCC 12 on MIPS will report such incompatibilities as an inform unless
-Wno-psabi
is used. - The ABI returning values containing C++17 empty bases has changed. Now an empty base will not prevent an aggregate containing only one or two floating-point fields from being returned through FPR. This is compatible with GCC 6 and earlier, but incompatible with GCC 7 through 11. GCC 12 on MIPS will report such incompatibilities as an inform unless
-Wno-psabi
is used.
NVPTX
- The
-march
flag has been added. The-misa
flag is now considered an alias of the-march
flag. - Support for PTX ISA target architectures
sm_53
,sm_70
,sm_75
andsm_80
has been added. These can be specified using the-march
flag. - The default PTX ISA target architecture has been set back to
sm_30
, to fix support forsm_30
boards. - The
-march-map
flag has been added. The-march-map
value will be mapped to an valid-march
flag value. For instance,-march-map=sm_50
maps to-march=sm_35
. This can be used to specify that generated code is to be executed on a board with at least some specific compute capability, without having to know the valid values for the-march
flag. - The
-mptx
flag has been added to specify the PTX ISA version for the generated code; permitted values are3.1
(matches previous GCC versions),6.0
,6.3
, and7.0
. If not specified, the used version is the minimal version required for-march
but at least6.0
. - An
mptx-3.1
multilib was added. This allows using older drivers which do not support PTX ISA version 6.0. - The new
__PTX_SM__
predefined macro allows code to check the PTX ISA target architecture being targeted by the compiler. - The new
__PTX_ISA_VERSION_MAJOR__
and__PTX_ISA_VERSION_MINOR__
predefined macros allows code to check the PTX ISA version being targeted by the compiler.
PowerPC / PowerPC64 / RS6000
- The internal implementation of Power's target-specific built-in functions has been rewritten to be easier and less error-prone to maintain. Every attempt has been made to ensure that the new behavior matches the old behavior, but inevitably some bugs can be expected. Please report any problems.
- The built-in functions
__builtin_get_texasr
,__builtin_get_texasru
,__builtin_get_tfhar
,__builtin_get_tfiar
,__builtin_set_texasr
,__builtin_set_texasru
,__builtin_set_tfhar
, and__builtin_set_tfiar
now behave as documented in all supported configurations. On prior releases, the arguments and return values of these functions were treated asunsigned long long
instead of asunsigned long
, when the options-m32 -mpowerpc64
were in effect. - The overloaded built-in functions
vec_cntlz_lsbb
andvec_cnttz_lsbb
now behave as documented. On prior releases, these built-in functions had incorrect semantics on little-endian targets.
PRU
- The __regio_symbol variable qualifier has been added. It allows easier access in C programs to the
__R30
and__R31
CPU I/O registers.
RISC-V
- The default ISA spec version was bumped to 20191213; see this announcement for details.
- New ISA extension support for zba, zbb, zbc, zbs was added.
- New ISA extension support for vector and scalar crypto was added, only support architecture testing macro and
-march=
parsing. - The option
-mtune=thead-c906
is added to tune for T-HEAD c906 cores. - libstdc++ no longer attempts to detect built-in atomics. Distributions that have out-of-tree workarounds for
-latomic
should check their ABIs again.
Operating Systems
Improvements to Static Analyzer
- The analyzer has gained a -Wanalyzer-use-of-uninitialized-value warning, similar to-Wuninitialized and-Wmaybe-uninitialized, but based on an interprocedural path-sensitive analysis (PR95006).
Such warnings are not disabled by the new-ftrivial-auto-var-init (see below), as the latter is considered a mitigation option. - -Wanalyzer-write-to-const and-Wanalyzer-write-to-string-literal will now check for__attribute__ ((access, ....)) on calls to externally-defined functions, and complain about read-only regions pointed to by arguments marked with a
write_only
orread_write
attribute (PR104793). - The analyzer's "taint" mode, activated by-fanalyzer-checker=taint (in addition to -fanalyzer), has gained four new taint-based warnings:
- -Wanalyzer-tainted-allocation-size for e.g. attacker-controlled
malloc
andalloca
, - -Wanalyzer-tainted-divisor for detecting where an attacker can inject a divide-by-zero,
- -Wanalyzer-tainted-offset for attacker-controlled pointer offsets,
- -Wanalyzer-tainted-size for attacker-controlled values being used as a size parameter to calls to
memset
or to functions marked with__attribute__ ((access, ....)).
The existing-Wanalyzer-tainted-array-index has been reworded to talk about "attacker-controlled" rather than "tainted" values, for consistency with the new warnings.
A new __attribute__ ((tainted_args)) has been added to the C and C++ front ends, usable on functions, and on function pointer callback fields in structs. The analyzer's taint mode will treat all parameters and buffers pointed to by parameters of such functions as being attacker-controlled, such as for annotating system calls in an operating system kernel as being an "attack surface".
- -Wanalyzer-tainted-allocation-size for e.g. attacker-controlled
- The analyzer now respects__attribute__((const)): it will treat such functions as returning the same value when given the same inputs (PR104434), and as having no side effects (PR104576).
- The analyzer is now able to split its analysis into multiple execution paths in places where there isn't a split in the control flow graph. For example, it now handles
realloc
calls by splitting the execution path into three possible outcomes for the call:- failure, returning
NULL
- success, growing the buffer in-place without moving it
- success, allocating a new buffer, copying the content of the old buffer to it, and freeing the old buffer
- failure, returning
- The analyzer's interprocedural path exploration logic is now able to track calls through function pointers.
- The analyzer now makes the assumption that if we know PTR is non-NULL, then (PTR + OFFSET) is also non-NULL. This isn't strictly true, but eliminates false positives in practice (PR101962).
- The analyzer has gained some initial support for inline assembler code. This is extremely limited, and is purely to help suppress false positives when analyzing the Linux kernel, which makes heavy use of inline assembler (PR101570).
- The way the analyzer tracks the state of memory along an execution path has been improved in various ways for GCC 12:
- An optimization for representing bulk updates to memory (e.g. zero fills) has been removed as it never worked well. In GCC 12 it has been replaced with a simpler and more accurate approach, eliminating many false positives (PR95006).
- Various optimizations have been added, speeding up the analysis on a particularly problematic source file from 4 minutes down to 17 seconds (PR104943,PR104954, andPR104955).
- The analyzer now tracks the sizes of dynamically-allocated regions, both on the heap (via
malloc
etc) and stack (viaalloca
), though none of the analyzer warnings make use of this yet in GCC 12.
- The analyzer's handling of switch statements has been rewritten, fixing various bugs.
Other significant improvements
Eliminating uninitialized variables
- GCC can now initialize all stack variables implicitly, including padding. This is intended to eliminate all classes of uninitialized stack variable flaws. Lack of explicit initialization will still warn when-Wuninitialized is active. For best debugging, use of the new command-line option-ftrivial-auto-var-init=pattern can be used to fill variables with a repeated
0xFE
pattern, which tends to illuminate many bugs (e.g. pointers receive invalid addresses, sizes and indices are very large). For best production results, the new command-line option-ftrivial-auto-var-init=zero can be used to fill variables with0x00
, which tends to provide a safer state for bugs (e.g. pointers areNULL
, strings areNUL
filled, and sizes and indices are0
).
Debugging formats
- GCC can now generate debugging information in CTF, a lightweight debugging format that provides information about C types and the association between functions and data symbols and types. This format is designed to be embedded in ELF files and to be very compact and simple. A new command-line option
-gctf
enables the generation of CTF. - GCC can now generate debugging information in BTF. This is a debugging format mainly used in BPF programs and the Linux kernel. The compiler can generate BTF for any target, when enabled with the command-line option
-gbtf
This is the list of problem reports (PRs) from GCC's bug tracking system that are known to be fixed in the 12.1 release. This list might not be complete (that is, it is possible that some PRs that have been fixed are not listed here).
GCC 12.2
This is the list of problem reports (PRs) from GCC's bug tracking system that are known to be fixed in the 12.2 release. This list might not be complete (that is, it is possible that some PRs that have been fixed are not listed here).
Target Specific Changes
LoongArch
- The default setting of
-m[check|no-check]-zero-division
is changed for optimized code. Now-mno-check-zero-division
is the default for all optimization levels but-O0
and-Og
. The old behavior can be obtained by explicitly passing-mcheck-zero-division
to GCC.
GCC 12.3
Target Specific Changes
x86-64
- GCC now supports AMD CPUs based on the
znver4
core via-march=znver4
. The switch makes GCC consider using 512-bit vectors when auto-vectorizing.
This is the list of problem reports (PRs) from GCC's bug tracking system that are known to be fixed in the 12.3 release. This list might not be complete (that is, it is possible that some PRs that have been fixed are not listed here).
GCC 12.4
This is the list of problem reports (PRs) from GCC's bug tracking system that are known to be fixed in the 12.4 release. This list might not be complete (that is, it is possible that some PRs that have been fixed are not listed here).