Skip to content

Commit f879a3a

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merge amd-gfx12 and amd-gfx into amd-gfx-gfx12
3 parents bd8878f + deb87db + e2f1a79 commit f879a3a

File tree

259 files changed

+7107
-1111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

259 files changed

+7107
-1111
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
=========================
2+
C++ Type Aware Allocators
3+
=========================
4+
5+
.. contents::
6+
:local:
7+
8+
Introduction
9+
============
10+
11+
Clang includes an implementation of P2719 "Type-aware allocation and deallocation
12+
functions".
13+
14+
This is a feature that extends the semantics of `new`, `new[]`, `delete` and
15+
`delete[]` operators to expose the type being allocated to the operator. This
16+
can be used to customize allocation of types without needing to modify the
17+
type declaration, or via template definitions fully generic type aware
18+
allocators.
19+
20+
P2719 introduces a type-identity tag as valid parameter type for all allocation
21+
operators. This tag is a default initialized value of type `std::type_identity<T>`
22+
where T is the type being allocated or deallocated. Unlike the other placement
23+
arguments this tag is passed as the first parameter to the operator.
24+
25+
The most basic use case is as follows
26+
27+
.. code-block:: c++
28+
29+
#include <new>
30+
#include <type_traits>
31+
32+
struct S {
33+
// ...
34+
};
35+
36+
void *operator new(std::type_identity<S>, size_t, std::align_val_t);
37+
void operator delete(std::type_identity<S>, void *, size_t, std::align_val_t);
38+
39+
void f() {
40+
S *s = new S; // calls ::operator new(std::type_identity<S>(), sizeof(S), alignof(S))
41+
delete s; // calls ::operator delete(std::type_identity<S>(), s, sizeof(S), alignof(S))
42+
}
43+
44+
While this functionality alone is powerful and useful, the true power comes
45+
by using templates. In addition to adding the type-identity tag, P2719 allows
46+
the tag parameter to be a dependent specialization of `std::type_identity`,
47+
updates the overload resolution rules to support full template deduction and
48+
constraint semantics, and updates the definition of usual deallocation functions
49+
to include `operator delete` definitions that are templatized on the
50+
type-identity tag.
51+
52+
This allows arbitrarily constrained definitions of the operators that resolve
53+
as would be expected for any other template function resolution, e.g (only
54+
showing `operator new` for brevity)
55+
56+
.. code-block:: c++
57+
58+
template <typename T, unsigned Size> struct Array {
59+
T buffer[Size];
60+
};
61+
62+
// Starting with a concrete type
63+
void *operator new(std::type_identity<Array<int, 5>>, size_t, std::align_val_t);
64+
65+
// Only care about five element arrays
66+
template <typename T>
67+
void *operator new(std::type_identity<Array<T, 5>>, size_t, std::align_val_t);
68+
69+
// An array of N floats
70+
template <unsigned N>
71+
void *operator new(std::type_identity<Array<float, N>>, size_t, std::align_val_t);
72+
73+
// Any array
74+
template <typename T, unsigned N>
75+
void *operator new(std::type_identity<Array<T, N>>, size_t, std::align_val_t);
76+
77+
// A handy concept
78+
template <typename T> concept Polymorphic = std::is_polymorphic_v<T>;
79+
80+
// Only applies is T is Polymorphic
81+
template <Polymorphic T, unsigned N>
82+
void *operator new(std::type_identity<Array<T, N>>, size_t, std::align_val_t);
83+
84+
// Any even length array
85+
template <typename T, unsigned N>
86+
void *operator new(std::type_identity<Array<T, N>>, size_t, std::align_val_t)
87+
requires(N%2 == 0);
88+
89+
Operator selection then proceeds according to the usual rules for choosing
90+
the best/most constrained match.
91+
92+
Any declaration of a type aware operator new or operator delete must include a
93+
matching complimentary operator defined in the same scope.
94+
95+
Notes
96+
=====
97+
98+
Unconstrained Global Operators
99+
------------------------------
100+
101+
Declaring an unconstrained type aware global operator `new` or `delete` (or
102+
`[]` variants) creates numerous hazards, similar to, but different from, those
103+
created by attempting to replace the non-type aware global operators. For that
104+
reason unconstrained operators are strongly discouraged.
105+
106+
Mismatching Constraints
107+
-----------------------
108+
109+
When declaring global type aware operators you should ensure the constraints
110+
applied to new and delete match exactly, and declare them together. This
111+
limits the risk of having mismatching operators selected due to differing
112+
constraints resulting in changes to prioritization when determining the most
113+
viable candidate.
114+
115+
Declarations Across Libraries
116+
-----------------------------
117+
118+
Declaring a typed allocator for a type in a separate TU or library creates
119+
similar hazards as different libraries and TUs may see (or select) different
120+
definitions.
121+
122+
Under this model something like this would be risky
123+
124+
.. code-block:: c++
125+
126+
template<typename T>
127+
void *operator new(std::type_identity<std::vector<T>>, size_t, std::align_val_t);
128+
129+
However this hazard is not present simply due to the use of the a type from
130+
another library:
131+
132+
.. code-block:: c++
133+
134+
template<typename T>
135+
struct MyType {
136+
T thing;
137+
};
138+
template<typename T>
139+
void *operator new(std::type_identity<MyType<std::vector<T>>>, size_t, std::align_val_t);
140+
141+
Here we see `std::vector` being used, but that is not the actual type being
142+
allocated.
143+
144+
Implicit and Placement Parameters
145+
---------------------------------
146+
147+
Type aware allocators are always passed both the implicit alignment and size
148+
parameters in all cases. Explicit placement parameters are supported after the
149+
mandatory implicit parameters.
150+
151+
Publication
152+
===========
153+
154+
`Type-aware allocation and deallocation functions <https://wg21.link/P2719>`_.
155+
Louis Dionne, Oliver Hunt.

clang/docs/LanguageExtensions.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Clang Language Extensions
1515
AutomaticReferenceCounting
1616
PointerAuthentication
1717
MatrixTypes
18+
CXXTypeAwareAllocators
1819

1920
Introduction
2021
============
@@ -1540,6 +1541,13 @@ Use ``__has_feature(cxx_variable_templates)`` or
15401541
``__has_extension(cxx_variable_templates)`` to determine if support for
15411542
templated variable declarations is enabled.
15421543

1544+
C++ type aware allocators
1545+
^^^^^^^^^^^^^^^^^^^^^^^^^
1546+
1547+
Use ``__has_extension(cxx_type_aware_allocators)`` to determine the existence of
1548+
support for the future C++2d type aware allocator feature. For full details see
1549+
:doc:`C++ Type Aware Allocators <CXXTypeAwareAllocators>` for additional details.
1550+
15431551
C11
15441552
---
15451553

clang/docs/ReleaseNotes.rst

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ C++2c Feature Support
133133

134134
- Implemented `P0963R3 Structured binding declaration as a condition <https://wg21.link/P0963R3>`_.
135135

136-
- Implemented `P2719R4 Type-aware allocation and deallocation functions <https://wg21.link/P2719>`_.
137-
138136
- Implemented `P3618R0 Allow attaching main to the global module <https://wg21.link/P3618>`_.
139137

140138
C++23 Feature Support
@@ -707,6 +705,11 @@ Improvements to Clang's diagnostics
707705
- Improve the diagnostics for placement new expression when const-qualified
708706
object was passed as the storage argument. (#GH143708)
709707

708+
- Clang now does not issue a warning about returning from a function declared with
709+
the ``[[noreturn]]`` attribute when the function body is ended with a call via
710+
pointer, provided it can be proven that the pointer only points to
711+
``[[noreturn]]`` functions.
712+
710713
Improvements to Clang's time-trace
711714
----------------------------------
712715

@@ -1024,15 +1027,29 @@ Arm and AArch64 Support
10241027
`as specified here <https://github.com/ARM-software/acle/blob/main/main/acle.md#modal-8-bit-floating-point-extensions>`_
10251028
is now available.
10261029
- Support has been added for the following processors (command-line identifiers in parentheses):
1030+
10271031
- Arm Cortex-A320 (``cortex-a320``)
1032+
10281033
- For ARM targets, cc1as now considers the FPU's features for the selected CPU or Architecture.
10291034
- The ``+nosimd`` attribute is now fully supported for ARM. Previously, this had no effect when being used with
10301035
ARM targets, however this will now disable NEON instructions being generated. The ``simd`` option is
10311036
also now printed when the ``--print-supported-extensions`` option is used.
10321037
- When a feature that depends on NEON (``simd``) is used, NEON is now automatically enabled.
10331038
- When NEON is disabled (``+nosimd``), all features that depend on NEON will now be disabled.
10341039

1035-
- Support for __ptrauth type qualifier has been added.
1040+
- Pointer authentication
1041+
1042+
- Support for __ptrauth type qualifier has been added.
1043+
- Objective-C adoption of pointer authentication
1044+
1045+
- ``isa`` and ``super`` pointers are protected with address diversity and separate
1046+
usage specific discriminators.
1047+
- methodlist pointers and content are protected with address diversity and methodlist
1048+
pointers have a usage specific discriminator.
1049+
- ``class_ro_t`` pointers are protected with address diversity and usage specific
1050+
discriminators.
1051+
- ``SEL`` typed ivars are protected with address diversity and usage specific
1052+
discriminators.
10361053

10371054
- For AArch64, added support for generating executable-only code sections by using the
10381055
``-mexecute-only`` or ``-mpure-code`` compiler flags. (#GH125688)
@@ -1196,6 +1213,9 @@ New features
11961213
so frequent 'not yet implemented' diagnostics should be expected. Also, the
11971214
ACC MLIR dialect does not currently implement any lowering to LLVM-IR, so no
11981215
code generation is possible for OpenACC.
1216+
- Implemented `P2719R5 Type-aware allocation and deallocation functions <https://wg21.link/P2719>`_
1217+
as an extension in all C++ language modes.
1218+
11991219

12001220
Crash and bug fixes
12011221
^^^^^^^^^^^^^^^^^^^

clang/docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Using Clang as a Compiler
6161
APINotes
6262
DebuggingCoroutines
6363
AMDGPUSupport
64+
CXXTypeAwareAllocators
6465
CommandGuide/index
6566
FAQ
6667

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
23002300
return getTypeDeclType(getObjCSelDecl());
23012301
}
23022302

2303+
PointerAuthQualifier getObjCMemberSelTypePtrAuth();
2304+
23032305
/// Retrieve the typedef declaration corresponding to the predefined
23042306
/// Objective-C 'Class' type.
23052307
TypedefDecl *getObjCClassDecl() const;

clang/include/clang/Analysis/Analyses/UninitializedValues.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class UninitUse {
5050
/// Is this use a const reference to this variable?
5151
bool ConstRefUse = false;
5252

53+
/// Is this use a const pointer to this variable?
54+
bool ConstPtrUse = false;
55+
5356
/// This use is always uninitialized if it occurs after any of these branches
5457
/// is taken.
5558
SmallVector<Branch, 2> UninitBranches;
@@ -65,11 +68,14 @@ class UninitUse {
6568
void setUninitAfterCall() { UninitAfterCall = true; }
6669
void setUninitAfterDecl() { UninitAfterDecl = true; }
6770
void setConstRefUse() { ConstRefUse = true; }
71+
void setConstPtrUse() { ConstPtrUse = true; }
6872

6973
/// Get the expression containing the uninitialized use.
7074
const Expr *getUser() const { return User; }
7175

7276
bool isConstRefUse() const { return ConstRefUse; }
77+
bool isConstPtrUse() const { return ConstPtrUse; }
78+
bool isConstRefOrPtrUse() const { return ConstRefUse || ConstPtrUse; }
7379

7480
/// The kind of uninitialized use.
7581
enum Kind {

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,11 @@ def UninitializedMaybe : DiagGroup<"conditional-uninitialized">;
952952
def UninitializedSometimes : DiagGroup<"sometimes-uninitialized">;
953953
def UninitializedStaticSelfInit : DiagGroup<"static-self-init">;
954954
def UninitializedConstReference : DiagGroup<"uninitialized-const-reference">;
955+
def UninitializedConstPointer : DiagGroup<"uninitialized-const-pointer">;
955956
def Uninitialized : DiagGroup<"uninitialized", [UninitializedSometimes,
956957
UninitializedStaticSelfInit,
957-
UninitializedConstReference]>;
958+
UninitializedConstReference,
959+
UninitializedConstPointer]>;
958960
def IgnoredPragmaIntrinsic : DiagGroup<"ignored-pragma-intrinsic">;
959961
// #pragma optimize is often used to avoid to work around MSVC codegen bugs or
960962
// to disable inlining. It's not completely clear what alternative to suggest

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,6 +2548,10 @@ def warn_uninit_const_reference : Warning<
25482548
"variable %0 is uninitialized when passed as a const reference argument "
25492549
"here">, InGroup<UninitializedConstReference>, DefaultIgnore;
25502550

2551+
def warn_uninit_const_pointer : Warning<
2552+
"variable %0 is uninitialized when passed as a const pointer argument here">,
2553+
InGroup<UninitializedConstPointer>, DefaultIgnore;
2554+
25512555
def warn_unsequenced_mod_mod : Warning<
25522556
"multiple unsequenced modifications to %0">, InGroup<Unsequenced>;
25532557
def warn_unsequenced_mod_use : Warning<
@@ -10081,11 +10085,8 @@ def err_destroying_operator_delete_not_usual : Error<
1008110085
def err_type_aware_destroying_operator_delete : Error<
1008210086
"destroying delete is not permitted to be type aware">;
1008310087

10084-
def ext_cxx26_type_aware_allocators : ExtWarn<
10085-
"type aware allocators are a C++2c extension">, InGroup<CXX26>;
10086-
def warn_cxx26_type_aware_allocators : Warning<
10087-
"type aware allocators are incompatible with C++ standards before C++2c">,
10088-
DefaultIgnore, InGroup<CXXPre26Compat>;
10088+
def warn_ext_type_aware_allocators : ExtWarn<
10089+
"type aware allocators are a Clang extension">, InGroup<DiagGroup<"ext-cxx-type-aware-allocators">>;
1008910090
def err_type_aware_allocator_missing_matching_operator : Error<
1009010091
"declaration of type aware %0 in %1 must have matching type aware %2"
1009110092
>;

clang/include/clang/Basic/Features.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ FEATURE(ptrauth_indirect_gotos, LangOpts.PointerAuthIndirectGotos)
160160
FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
161161
FEATURE(ptrauth_init_fini_address_discrimination, LangOpts.PointerAuthInitFiniAddressDiscrimination)
162162
FEATURE(ptrauth_elf_got, LangOpts.PointerAuthELFGOT)
163+
164+
FEATURE(ptrauth_objc_isa, LangOpts.PointerAuthObjcIsa)
165+
FEATURE(ptrauth_objc_interface_sel, LangOpts.PointerAuthObjcInterfaceSel)
166+
FEATURE(ptrauth_objc_signable_class, true)
167+
FEATURE(ptrauth_objc_method_list_pointer, LangOpts.PointerAuthCalls)
168+
163169
EXTENSION(swiftcc,
164170
PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
165171
clang::TargetInfo::CCCR_OK)
@@ -366,5 +372,8 @@ FEATURE(clang_atomic_attributes, true)
366372
FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
367373
EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && LangOpts.OffloadImplicitHostDeviceTemplates)
368374

375+
// C++2d type-aware allocators
376+
EXTENSION(cxx_type_aware_allocators, true)
377+
369378
#undef EXTENSION
370379
#undef FEATURE

clang/include/clang/Basic/LangOptions.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ LANGOPT(PointerAuthInitFiniAddressDiscrimination, 1, 0, NotCompatible,
133133
LANGOPT(PointerAuthELFGOT, 1, 0, NotCompatible, "authenticate pointers from GOT")
134134
LANGOPT(AArch64JumpTableHardening, 1, 0, NotCompatible, "use hardened lowering for jump-table dispatch")
135135

136+
LANGOPT(PointerAuthObjcIsa, 1, 0, NotCompatible, "authentication of isa and super pointers in ObjC instances")
137+
LANGOPT(PointerAuthObjcInterfaceSel, 1, 0, NotCompatible, "authentication of SEL fields of ObjC interfaces")
138+
LANGOPT(PointerAuthObjcInterfaceSelKey, 16, 0, NotCompatible, "authentication key for SEL fields of ObjC interfaces")
139+
LANGOPT(PointerAuthObjcClassROPointers, 1, 0, Benign, "class_ro_t pointer authentication")
140+
136141
LANGOPT(DoubleSquareBracketAttributes, 1, 0, NotCompatible, "'[[]]' attributes extension for all language standard modes")
137142
LANGOPT(ExperimentalLateParseAttributes, 1, 0, NotCompatible, "experimental late parsing of attributes")
138143

0 commit comments

Comments
 (0)