A defaulted copy or move assignment operator for a union is synthesized
with an empty body. `DefineImplicitCopyAssignment` /
`DefineImplicitMoveAssignment` skip union members in the memberwise
loop, and the implied copy of the object representation has no AST
representation, a FIXME that has sat at that skip for a long time. The
operator ends up copying nothing.
Classic CodeGen hides this at ordinary call sites by lowering a trivial
assignment to a memcpy at the call site, so `u1 = u2` works even though
the operator body is a no-op. But when the operator is genuinely called,
through a pointer-to-member for instance, it silently copies nothing.
ClangIR calls the assignment operator at the call site rather than
eliding it, so it hits the empty body directly and drops every union
assignment. The no-op is then deleted at `-O3`. That is the MultiSource
`kc` miscompile, where a `YYSTYPE` union assignment (`*++yyvsp =
yylval`) becomes a no-op.
This implements the FIXME by mirroring the defaulted union copy
constructor (`CGClass.cpp`: "union copy constructor, we must emit a
memcpy") in the AST: when the class is a union,
`DefineImplicit{Copy,Move}Assignment` emits a single whole-object copy
through `buildMemcpyForAssignmentOp`, the helper already used for
trivially-copyable array members, instead of the skipped per-member
assignments. The operator stays trivial (triviality is fixed at
declaration time, before the body is synthesized), so constant
evaluation, which copies trivial unions through its own semantic path
and never executes the body, is unchanged.
Copying the object representation is correct even when a union member is
not trivially copyable, but the synthesized memcpy would then trip
`-Wnontrivial-memcall`. A `void*` cast would drop pointee qualifiers
such as the address space and inject an explicit cast node the source
never wrote. Instead the call keeps its typed union-pointer arguments,
and the union branch in `DefineImplicit{Copy,Move}Assignment` wraps the
build in `IgnoreAllWarningDiagRAII`, a save-and-restore around the
engine's existing ignore-all-warnings state. `CheckMemaccessArguments`
defers the warning and its note through `DiagRuntimeBehavior`, and that
queue flushes after the RAII has restored the previous ignore state, so
`DiagIfReachable` samples that state as it enqueues and drops what is
not error-class. Under `-w` the same queue is discarded before it
flushes, so nothing outside the scoped region changes.
Classic CodeGen now emits the copy when the operator is odr-used, and
ClangIR's union assignment lowers to a real memcpy. On the Sema side,
tests cover the synthesized AST for the implicit-`this` and C++23
explicit-object spellings, the `-Wnontrivial-memcall` suppression, the
preserved address space, the clean `-ast-print` output, and constexpr
active-member copy. The classic and ClangIR lowering is checked across
named, anonymous, and tail-padded unions.
#198918 added a defaulted-union `errorNYI` in ClangIR and deferred this
AST fix to a separate change. This PR makes that fix and drops the
guard, so the now-non-empty body lowers to a `cir.call @memcpy` instead
of erroring. Its own `union-copy-move-assignment.cpp` CIR test, which
expects that call, is the regression check.
21 KiB
| myst | ||||
|---|---|---|---|---|
|
% If you want to modify sections/contents permanently, you should modify both % ReleaseNotes.md and ReleaseNotesTemplate.txt.
{#clang-release-releasenotestitle}
Clang {{ (('(In-Progress) ' if env.app.tags.has('PreRelease') else '') ~ 'Release Notes') if env.config.project == 'Clang' else '|ReleaseNotesTitle|' }}
:depth: 2
:local:
Written by the LLVM Team
```{warning}
These are in-progress notes for the upcoming Clang {{env.config.version}} release.
Release notes for previous releases can be found on
[the Releases Page](https://llvm.org/releases/).
```
Introduction
This document contains the release notes for the Clang C/C++/Objective-C frontend, part of the LLVM Compiler Infrastructure, release {{env.config.release}}. Here we describe the status of Clang in some detail, including major improvements from the previous release and new feature work. For the general LLVM release notes, see the LLVM documentation. For the libc++ release notes, see this page. All LLVM releases may be downloaded from the LLVM releases web site.
For more information about Clang or LLVM, including information about the latest release, please see the Clang Web Site or the LLVM Web Site.
Potentially Breaking Changes
C/C++ Language Potentially Breaking Changes
-Wunicode-whitespacenow defaults to an error. The previous behavior can be restored with-Wno-error=unicode-whitespace. Clang will stop accepting non-ascii whitespaces as token separators in a future version of Clang.
C++ Specific Potentially Breaking Changes
ABI Changes in This Version
-
Except on PlayStation, Clang now derives the x86-64 System V AVX ABI level for 256- and 512-bit vector arguments and returns from effective per-function target features. Features and
arch=CPUs that imply AVX or AVX512F are honored, and calls use the caller's features, matching GCC. Per-function features cannot lower the translation-unit ABI level;-fclang-abi-compat=23restores the previous behavior. (#GH193298) -
On MIPS, a
_Complexvalue with an integer element type is now returned packed into a single integer register when it fits in one, matching GCC. A_Complex charor_Complex short, and on N32/N64 also a_Complex int, is no longer returned with one part per register.-fclang-abi-compat=23restores the previous behavior. (#GH212109) -
On MIPS N32/N64, a
_Complex floator_Complex doubleargument is now packed into integer registers, or onto the stack, once there is no longer room to give each of its parts a floating-point register, matching GCC. Clang previously always passed the parts separately.-fclang-abi-compat=23restores the previous behavior. (#GH212109)
AST Dumping Potentially Breaking Changes
Clang Frontend Potentially Breaking Changes
- Templight support has been removed.
Clang Python Bindings Potentially Breaking Changes
-
CompletionChunkKindinstance's__str__representation has been adapted to be consistent with other enums in the library. The representation now follows theCompletionChunkKind.VARIANT_NAMEscheme instead ofVariantName. -
Remove the deprecated
SPELLING_CACHEalias. All usage should be migrated to useCompletionChunk.SPELLING_CACHEinstead. Note that this usesCompletionChunkKindenumeration as keys, instead of integer values. -
Remove the deprecated
CompletionChunk.isKind...methods. Existing uses should be adapted to directly compare equality of theCompletionChunkkind with the correspondingCompletionChunkKindvariant.Affected methods:
isKindOptional,isKindTypedText,isKindPlaceHolder,isKindInformativeandisKindResultType. -
CompletionString.availabilitynow returns instances ofAvailabilityKind. As a result, the__str__representation of its return values changed. Like other libclang enums, it now follows theCompletionChunkKind.VARIANT_NAMEscheme instead ofVariantName.
OpenCL Potentially Breaking Changes
What's New in Clang {{env.config.release}}?
C++ Language Changes
C++2d Feature Support
- Clang now supports P3658R1 (Adjust identifier following new Unicode recommendations), applied as a DR to all C++ language modes.
C++2c Feature Support
- Clang now supports P3533R2 (constexpr virtual inheritance).
C++23 Feature Support
C++20 Feature Support
C++17 Feature Support
Resolutions to C++ Defect Reports
C Language Changes
C2y Feature Support
- Clang now supports C2y's new syntax for
ifandswitchstatements with initializer and condition variables, as specified in N3356_. For example:
if (bool x = true; x) {
// ...
}
if (bool x = true) {
// ...
}
// attribute list on declarations are also supported
switch ([[maybe_unused]] int x = 1) {
default:
// ...
}
if (bool x [[maybe_unused]] = true; x) {
// ...
}
C23 Feature Support
Objective-C Language Changes
Non-comprehensive list of changes in this release
New Compiler Flags
-
New option
-fdefined-pointer-subtractionadded to preserve stable semantics when subtracting pointers to unrelated objects. -
Added
--print-cxx-stdliband--print-cxx-stdlib-include-dirsto print the C++ standard library selected by the driver and the include directories added for it.
Deprecated Compiler Flags
Modified Compiler Flags
- All options of the
-fzero-call-used-regscompiler flag are now allowed on RISC-V.
Removed Compiler Flags
Attribute Changes in Clang
- Clang now properly propagates attributes on class and variable templates to their redeclarations, which will result in redeclarations not interfering with diagnostics. (#GH209812)
Improvements to Clang's diagnostics
-
More consistent rendering of Unicode characters in diagnostic messages.
-
Fixed bug in
-Wdocumentationso that it correctly handles explicit function template instantiations (#64087). -
Fixed concept template parameters not being recognized in
-Wdocumentationwhen mentioned in tparam comments. (#GH64087) -
-Wunused-but-set-variablenow diagnoses file-scope variables with internal linkage (staticstorage class) that are assigned but never used. This new coverage is added under the subgroup-Wunused-but-set-global, allowing it to be disabled independently with-Wno-unused-but-set-global. (#GH148361) -
-Wunused-templateis now part of-Wunused(which is enabled by-Wall). It diagnoses unused function and variable templates with internal linkage, which in a header is a latent ODR hazard. It can be disabled with-Wno-unused-template. (#GH202945) -
Added
-Wlifetime-safetyto enable lifetime safety analysis, a CFG-based intra-procedural analysis that detects use-after-free and related temporal safety bugs. See the RFC for more details. By design, this warning is enabled in-Weverything. To disable the analysis, use-Wno-lifetime-safetyor-fno-lifetime-safety. -
Added
-Wlifetime-safety-suggestionsto enable lifetime annotation suggestions. This provides suggestions for function parameters that should be marked[[clang::lifetimebound]]based on lifetime analysis. For example, for the following function:int* p(int *in) { return in; }Clang will suggest:
warning: parameter in intra-TU function should be marked [[clang::lifetimebound]] int* p(int *in) { return in; } ^~~~~~~ [[clang::lifetimebound]] note: param returned here int* p(int *in) { return in; } ^~ -
Added
-Wlifetime-safety-noescapeto detect misuse of[[clang::noescape]]annotation where the parameter escapes through return. For example:int* p(int *in [[clang::noescape]]) { return in; }Clang will warn:
warning: parameter is marked [[clang::noescape]] but escapes int* p(int *in [[clang::noescape]]) { return in; } ^~~~~~~ note: returned here int* p(int *in [[clang::noescape]]) { return in; } ^~ -
Added
-Wlifetime-safety-dangling-fieldto detect dangling field references when stack memory escapes to class fields. This is part of-Wlifetime-safetyand detects cases where local variables or parameters are stored in fields but outlive their scope. For example:struct DanglingView { std::string_view view; DanglingView(std::string s) : view(s) {} // warning: address of stack memory escapes to a field }; -
Improved
-Wassign-enumperformance by caching enum enumerator values. (#GH176454) -
Fixed a false negative in
-Warray-boundswhere the warning was suppressed when accessing a member function on a past-the-end array element. (#GH179128) -
Added a missing space to the FixIt for the
implicit-intgroup of diagnostics and made sure that only one such diagnostic and FixIt is emitted per declaration group. (#GH179354) -
Fixed the Fix-It insertion point for
expected ';' after alias declarationwhen parsing alias declarations involving a token-split>>sequence (for example,using A = X<int>>;). (#GH184425) -
Fixed incorrect
implicitly deleteddiagnostic for explicitly deleted candidate function. (#GH185693) -
The
-Wloop-analysiswarning has been extended to catch more cases of variable modification inside lambda expressions (#GH132038). -
Clang now emits
-Wsizeof-pointer-memaccesswhen snprintf/vsnprintf use the sizeof the destination buffer(dynamically allocated) in the len parameter(#GH162366) -
Added
-Wmodule-map-path-outside-directory(off by default) to warn on header and umbrella directory paths that use..to refer outside the module directory in module maps found via implicit search (-fimplicit-module-maps). This does not affect module maps specified explicitly via-fmodule-map-file=. -
Honour
[[maybe_unused]]attribute on private fields.-Wunused-private-fieldno longer emits a warning for annotated private fields. -
Improved
-Wgnu-zero-variadic-macro-argumentsto suggest using__VA_OPT__if the current language version supports it(#GH188624) -
Clang now emits an error when implicitly casting a complex type to a built-in vector type. (#GH186805)
-
Added
-Wnonportable-include-path-separator(off by default) to catch #include directives that use backslashes as a path separator. The warning includes a FixIt to change all the backslashes to forward slashes, so that the code can automatically be made portable to other host platforms that don't support backslashes. -
Clang now explains why template deduction fails for explicit template arguments.
-
No longer emitting a
-Wpre-c2y-compator extension diagnostic about use of octal literals with a0oprefix, and no longer emitting a-Wdeprecated-octal-literalsdiagnostic for use of octal literals without a0oprefix, when the literal is expanded from a macro defined in a system header. (#GH192389) -
Improved error recovery for missing semicolons after class members. Clang now avoids skipping subsequent valid declarations when their previous decl is missing semicolon.
-
Removed the body of lambdas from some diagnostic messages.
-
Fixed false positive host-device mismatch errors in discarded
if constexprbranches for CUDA/HIP; such calls are now correctly skipped. -
Clang now errors when a function declaration aliases a variable or vice versa. (#GH195550)
-
Added
-Wattribute-aliasto diagnose type mismatches between an alias and its aliased function. (#GH195550) -
The diagnostics around
__blocknow explain why a variable cannot be marked__block. (#GH197213) -
Extended
-Wnonportable-include-pathto warn about trailing whitespace and dots in#includepaths. (#GH190610) -
Clang now emits error when attribute is missing closing
]]followed by;;. (#GH187223) -
Clang now rejects inline asm constraints and clobbers that contain an embedded null character, instead of silently truncating them. (#GH173900)
-
Added
-Wstringop-overreadto warn whenmemcpy,memmove,memcmp, and related builtins read more bytes than the source buffer size (#GH83728). -
Diagnostics for the C++11 range-based for statement now report the correct iterator type in notes for invalid iterator types.
-
-Wfortify-sourcenow warns when the constant-evaluated argument toumaskhas bits set outside0777. Those bits are silently discarded by the kernel, so setting them is almost always a typo (matching the bionic libcdiagnose_ifcheck). -
Improved how Unicode characters are displayed in diagnostic messages.
-
-Wtautological-pointer-compareand-Wpointer-bool-conversionnow diagnose a reference to a function (e.g. of typevoid (&)()) compared against or converted to a null pointer, the same as a bare function name. (#GH46362) -
Clang now attempts to print enumerator names rather than C-style cast expressions in more diagnostics.
Improvements to Clang's time-trace
Improvements to Coverage Mapping
Bug Fixes in This Version
- Fixed an assertion failure when passing a wide string literal to
__builtin_nan. (#GH212108) - Fixed a constraint comparison bug in partial ordering. (#GH182671)
- Fixed a rejected-valid case that used an explicit object parameter in an out-of-line definition of a nested class member. (#GH136472)
- Fixed an assertion on omp taskloop transparent (#GH197162)
- Fixed a bug where
__func__,__PRETTY_FUNCTION__and__FUNCTION__were not resolving to the proper function when inside a lambda return type (#GH211811) - Fixed USR generation for declarations whose signature mentions a class-type non-type template parameter. (#GH212351)
Bug Fixes to Compiler Builtins
- Fixed a crash when classifying a call to a builtin with dependent arguments,
such as when the call is used as an
autonon-type template argument. - Fixed a crash in
__builtin_dump_structwhen-Werrorpromotes format warnings to errors. (#GH211943)
Bug Fixes to Attribute Support
- The
counted_by/counted_by_or_nulldiagnostic that rejects a pointer whose pointee is a struct with a flexible array member (e.g.struct with_fam * __sized_by(size) ptr;) was incorrectly also applied to thesized_by/sized_by_or_nullattributes. Becausesized_byandsized_by_or_nulldescribe the size in bytes rather than a count of elements, they are now correctly accepted on such pointers. - Propagate attributes on redeclarations across modules.
Bug Fixes to C++ Support
-
Fixed an issue where
__typeof__incorrectly rejected cv-qualified function types. -
Fixed a bug where top-level CV qualifiers (such as
const) were dropped from pointers modified by Microsoft pointer attributes (like__ptr32and__ptr64) and WebAssembly's__funcref. -
Fixed an issue where we tried to compare invalid NTTPs for variable declarations, which ended up in hitting an assertion with a constrained non-plain-auto NTTP, which we don't quite implement yet. (#GH208658)
-
Fixed a crash when a using-declaration naming an unresolvable member of a dependent base was shadowed by an invalid using-declaration. (#GH209427)
-
Fixed a regression where an internal-linkage function (e.g. a
staticor anonymous-namespace helper) declared in the global module fragment of the current translation unit was removed from the overload set when the calling template was instantiated after the global module fragment was closed, producing a spurious "no matching function" error with no candidate notes. (#GH210822) -
Fixed a crash when a lambda parameter pack was given a default argument that is a pack expansion referencing an enclosing function's parameter pack (e.g.
[](Types... = args...) {}). Clang now diagnoses the illegal default argument instead of asserting. (#GH210714) -
Fixed a crash on invalid code where a
decltypenot followed by(was parsed where a nested-name-specifier could appear (e.g.int decltype = 0;). Clang now diagnoses the error instead of asserting. (#GH211207) -
Fixed a crash when computing the implicit deletion of a defaulted comparison operator required an access check that ran while an enclosing declaration was still being parsed. (#GH210692)
-
A workaround that was introduced to fix an issue with the
<format>header present in some versions of libstdc++15 has been extended to support preprocessed input. Previously, splitting the preprocessing and compilation step would result in the fix not being applied. (#GH160314) -
A defaulted copy or move assignment operator for a union was left with an empty body and copied nothing when the operator was actually called, for example through a pointer to member. Clang now synthesizes a whole-object copy so the union's object representation is copied, matching the defaulted union copy constructor.
Bug Fixes to AST Handling
- Fixed a non-deterministic ordering of unused local typedefs that made
serialized PCH/AST files and
-Wunused-local-typedefdiagnostics non-reproducible across runs. (#GH209639)
Miscellaneous Bug Fixes
Miscellaneous Clang Crashes Fixed
- Fixed a crash when instantiating an invalid dependent friend destructor declaration in a class template. (#GH210234)
- Fixed an assertion failure in
-extract-apiwhen a documentation comment contains invalid UTF-8. (#GH212393)
OpenACC Specific Changes
OpenCL Specific Changes
- Extensions
cl_khr_extended_bit_ops,cl_khr_integer_dot_product,cl_khr_subgroup_extended_types,cl_khr_subgroup_rotate,cl_khr_subgroup_shuffle, andcl_khr_subgroup_shuffle_relativeare promoted to core features in OpenCL C 3.1. A target claiming OpenCL C 3.1 conformance without supporting one of these features is now diagnosed.
Target Specific Changes
AMDGPU Support
- Deprecated the following builtins in favor of
__builtin_amdgcn_ballot_w32or__builtin_amdgcn_ballot_w64:__builtin_amdgcn_uicmp__builtin_amdgcn_uicmpl__builtin_amdgcn_sicmpl__builtin_amdgcn_fcmp__builtin_amdgcn_fcmpf
NVPTX Support
X86 Support
Arm and AArch64 Support
Android Support
Windows Support
- Fixed a bug where Clang did not match the MSVC ABI on Arm64 when an over-aligned base class is followed by another base class. MSVC on Arm64 (but not Arm64EC or x64) reuses the tail padding of the over-aligned base for the subsequent base; Clang now does the same. (#210174)
LoongArch Support
RISC-V Support
CUDA/HIP Language Changes
CUDA Support
AIX Support
NetBSD Support
WebAssembly Support
AVR Support
SystemZ Support
DWARF Support in Clang
Floating Point Support in Clang
Fixed Point Support in Clang
AST Matchers
clang-format
- Add
SpacesInBlockCommentsoption to control spacing after/*and before*/in ordinary block comments.
libclang
- visit identifier initializers in lambda capture as VarDecl instead of VariableRef. Warning: this changes behaviour.
Code Completion
Static Analyzer
Crash and bug fixes
% comment:
% This is for the Static Analyzer.
% Use #### headings for subsections:
% - Crash and bug fixes
% - New checkers and features
% - Improvements
% - Moved checkers
% - Diagnostic changes
Improvements
- The lock-order-reversal check in
alpha.unix.PthreadLockis now disabled by default. It can be re-enabled with theWarnOnLockOrderReversaloption.
Moved checkers
Diagnostic changes
- For self-assignments during initialization (
T v = v;),core.uninitialized.Assignwill not report them as uninitialized accesses (except C++ reference types), and the checks will be delayed until the first accesses of these variables;deadcode.DeadStoreswill not report them as dead stores. (#GH187530)
(release-notes-sanitizers)=
Sanitizers
Python Binding Changes
OpenMP Support
- Added parsing and semantic support for
dimsmodifier innum_teamsandthread_limitclauses for OpenMP 6.1 or later.
SYCL Support
Improvements
Additional Information
A wide variety of additional information is available on the Clang web
page. The web page contains versions of the
API documentation which are up-to-date with the Git version of
the source code. You can access versions of these documents specific to
this release by going into the "clang/docs/" directory in the Clang
tree.
If you have any questions or comments about Clang, please feel free to contact us on the Discourse forums (Clang Frontend category).