Skip to content

Commit 22570af

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.8-beta.1 [skip ci]
1 parent 5397b6b commit 22570af

File tree

19 files changed

+134
-111
lines changed

19 files changed

+134
-111
lines changed

clang/docs/AllocToken.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ Token Assignment Mode
3131

3232
The default mode to calculate tokens is:
3333

34-
* *TypeHash* (mode=2): This mode assigns a token ID based on the hash of
35-
the allocated type's name.
34+
* ``typehash``: This mode assigns a token ID based on the hash of the allocated
35+
type's name.
3636

3737
Other token ID assignment modes are supported, but they may be subject to
3838
change or removal. These may (experimentally) be selected with ``-mllvm
3939
-alloc-token-mode=<mode>``:
4040

41-
* *Random* (mode=1): This mode assigns a statically-determined random token ID
42-
to each allocation site.
41+
* ``random``: This mode assigns a statically-determined random token ID to each
42+
allocation site.
4343

44-
* *Increment* (mode=0): This mode assigns a simple, incrementally increasing
45-
token ID to each allocation site.
44+
* ``increment``: This mode assigns a simple, incrementally increasing token ID
45+
to each allocation site.
4646

4747
Allocation Token Instrumentation
4848
================================
@@ -69,7 +69,7 @@ In addition, it is typically recommended to configure the following:
6969

7070
* ``-falloc-token-max=<N>``
7171
Configures the maximum number of tokens. No max by default (tokens bounded
72-
by ``UINT64_MAX``).
72+
by ``SIZE_MAX``).
7373

7474
.. code-block:: console
7575
@@ -80,21 +80,21 @@ Runtime Interface
8080

8181
A compatible runtime must be provided that implements the token-enabled
8282
allocation functions. The instrumentation generates calls to functions that
83-
take a final ``uint64_t token_id`` argument.
83+
take a final ``size_t token_id`` argument.
8484

8585
.. code-block:: c
8686
8787
// C standard library functions
88-
void *__alloc_token_malloc(size_t size, uint64_t token_id);
89-
void *__alloc_token_calloc(size_t count, size_t size, uint64_t token_id);
90-
void *__alloc_token_realloc(void *ptr, size_t size, uint64_t token_id);
88+
void *__alloc_token_malloc(size_t size, size_t token_id);
89+
void *__alloc_token_calloc(size_t count, size_t size, size_t token_id);
90+
void *__alloc_token_realloc(void *ptr, size_t size, size_t token_id);
9191
// ...
9292
9393
// C++ operators (mangled names)
94-
// operator new(size_t, uint64_t)
95-
void *__alloc_token_Znwm(size_t size, uint64_t token_id);
96-
// operator new[](size_t, uint64_t)
97-
void *__alloc_token_Znam(size_t size, uint64_t token_id);
94+
// operator new(size_t, size_t)
95+
void *__alloc_token_Znwm(size_t size, size_t token_id);
96+
// operator new[](size_t, size_t)
97+
void *__alloc_token_Znam(size_t size, size_t token_id);
9898
// ... other variants like nothrow, etc., are also instrumented.
9999
100100
Fast ABI

clang/include/clang/Driver/SanitizerArgs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class SanitizerArgs {
7474
bool HwasanUseAliases = false;
7575
llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
7676
llvm::AsanDetectStackUseAfterReturnMode::Invalid;
77+
7778
std::string MemtagMode;
7879
bool AllocTokenFastABI = false;
7980
bool AllocTokenExtended = false;

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,7 @@ void CodeGenFunction::EmitBoundsCheckImpl(const Expr *E, llvm::Value *Bound,
12721272
EmitCheck(std::make_pair(Check, CheckKind), CheckHandler, StaticData, Index);
12731273
}
12741274

1275-
void CodeGenFunction::EmitAllocTokenHint(llvm::CallBase *CB,
1276-
QualType AllocType) {
1275+
void CodeGenFunction::EmitAllocToken(llvm::CallBase *CB, QualType AllocType) {
12771276
assert(SanOpts.has(SanitizerKind::AllocToken) &&
12781277
"Only needed with -fsanitize=alloc-token");
12791278

@@ -1285,7 +1284,7 @@ void CodeGenFunction::EmitAllocTokenHint(llvm::CallBase *CB,
12851284

12861285
// Format: !{<type-name>}
12871286
auto *MDN = llvm::MDNode::get(CGM.getLLVMContext(), {TypeMDS});
1288-
CB->setMetadata(llvm::LLVMContext::MD_alloc_token_hint, MDN);
1287+
CB->setMetadata(llvm::LLVMContext::MD_alloc_token, MDN);
12891288
}
12901289

12911290
CodeGenFunction::ComplexPairTy CodeGenFunction::

clang/lib/CodeGen/CGExprCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,8 +1713,8 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
17131713
CGDI->addHeapAllocSiteMetadata(newCall, allocType, E->getExprLoc());
17141714
}
17151715
if (SanOpts.has(SanitizerKind::AllocToken)) {
1716-
// Set !alloc_token_hint metadata.
1717-
EmitAllocTokenHint(newCall, allocType);
1716+
// Set !alloc_token metadata.
1717+
EmitAllocToken(newCall, allocType);
17181718
}
17191719
}
17201720

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3349,7 +3349,7 @@ class CodeGenFunction : public CodeGenTypeCache {
33493349
SanitizerHandler Handler);
33503350

33513351
/// Emit additional metadata used by the AllocToken instrumentation.
3352-
void EmitAllocTokenHint(llvm::CallBase *CB, QualType AllocType);
3352+
void EmitAllocToken(llvm::CallBase *CB, QualType AllocType);
33533353

33543354
llvm::Value *GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FD,
33553355
const FieldDecl *CountDecl);

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,11 +2374,10 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
23742374
if (const auto *Arg = Args.getLastArg(options::OPT_falloc_token_max_EQ)) {
23752375
StringRef S = Arg->getValue();
23762376
uint64_t Value = 0;
2377-
if (S.getAsInteger(0, Value)) {
2377+
if (S.getAsInteger(0, Value))
23782378
Diags.Report(diag::err_drv_invalid_value) << Arg->getAsString(Args) << S;
2379-
} else {
2379+
else
23802380
Opts.AllocTokenMax = Value;
2381-
}
23822381
}
23832382

23842383
Opts.EmitVersionIdentMetadata = Args.hasFlag(OPT_Qy, OPT_Qn, true);

clang/test/CodeGenCXX/alloc-token.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ void test_operator_new_nothrow() {
6969

7070
// CHECK-LABEL: @_Z8test_newv(
7171
int *test_new() {
72-
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 4, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token_hint
72+
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 4, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token
7373
return new int;
7474
}
7575

7676
// CHECK-LABEL: @_Z14test_new_arrayv(
7777
int *test_new_array() {
78-
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 40, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token_hint
78+
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 40, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token
7979
return new int[10];
8080
}
8181

8282
// CHECK-LABEL: @_Z16test_new_nothrowv(
8383
int *test_new_nothrow() {
84-
// CHECK: call {{.*}} ptr @__alloc_token_ZnwmRKSt9nothrow_t(i64 noundef 4, ptr {{.*}} @_ZSt7nothrow, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token_hint
84+
// CHECK: call {{.*}} ptr @__alloc_token_ZnwmRKSt9nothrow_t(i64 noundef 4, ptr {{.*}} @_ZSt7nothrow, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token
8585
return new (std::nothrow) int;
8686
}
8787

8888
// CHECK-LABEL: @_Z22test_new_array_nothrowv(
8989
int *test_new_array_nothrow() {
90-
// CHECK: call {{.*}} ptr @__alloc_token_ZnamRKSt9nothrow_t(i64 noundef 40, ptr {{.*}} @_ZSt7nothrow, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token_hint
90+
// CHECK: call {{.*}} ptr @__alloc_token_ZnamRKSt9nothrow_t(i64 noundef 40, ptr {{.*}} @_ZSt7nothrow, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token
9191
return new (std::nothrow) int[10];
9292
}
9393

@@ -123,7 +123,7 @@ void may_throw();
123123
TestClass *test_exception_handling_new() {
124124
try {
125125
// CHECK: invoke {{.*}} ptr @__alloc_token_Znwm(i64 noundef 72, i64 {{[1-9][0-9]*}})
126-
// CHECK-NEXT: !alloc_token_hint
126+
// CHECK-NEXT: !alloc_token
127127
TestClass *obj = new TestClass();
128128
may_throw();
129129
return obj;
@@ -134,15 +134,15 @@ TestClass *test_exception_handling_new() {
134134

135135
// CHECK-LABEL: @_Z14test_new_classv(
136136
TestClass *test_new_class() {
137-
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 72, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token_hint
137+
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 72, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token
138138
TestClass *obj = new TestClass();
139139
obj->data[0] = 42;
140140
return obj;
141141
}
142142

143143
// CHECK-LABEL: @_Z20test_new_class_arrayv(
144144
TestClass *test_new_class_array() {
145-
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 728, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token_hint
145+
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 728, i64 {{[1-9][0-9]*}}){{.*}} !alloc_token
146146
TestClass* arr = new TestClass[10];
147147
arr[0].data[0] = 123;
148148
return arr;

llvm/docs/LangRef.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ For example:
24282428
attributed with ``sanitize_realtime``.
24292429
This attribute is incompatible with the ``sanitize_realtime`` attribute.
24302430
``sanitize_alloc_token``
2431-
This attributes indicates that implicit allocation token instrumentation
2431+
This attribute indicates that implicit allocation token instrumentation
24322432
is enabled for this function.
24332433
``speculative_load_hardening``
24342434
This attribute indicates that
@@ -8392,6 +8392,13 @@ Example:
83928392
The ``nofree`` metadata indicates the memory pointed by the pointer will not be
83938393
freed after the attached instruction.
83948394

8395+
'``alloc_token``' Metadata
8396+
^^^^^^^^^^^^^^^^^^^^^^^^^^
8397+
8398+
The ``alloc_token`` metadata may be attached to calls to memory allocation
8399+
functions, and contains richer semantic information about the type of the
8400+
allocation. This information is consumed by the ``alloc-token`` pass to
8401+
instrument such calls with allocation token IDs.
83958402

83968403
Module Flags Metadata
83978404
=====================

llvm/docs/ReleaseNotes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ Changes to Sanitizers
166166
Other Changes
167167
-------------
168168

169-
* Introduces the `AllocToken` pass, an instrumentation pass designed to provide
170-
tokens to memory allocators enabling various heap organization strategies,
171-
such as heap partitioning.
169+
* Introduces the `AllocToken` pass, an instrumentation pass providing tokens to
170+
memory allocators enabling various heap organization strategies, such as heap
171+
partitioning.
172172

173173
External Open Source Projects Using LLVM {{env.config.release}}
174174
===============================================================

llvm/include/llvm/IR/FixedMetadataKinds.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ LLVM_FIXED_MD_KIND(MD_mmra, "mmra", 40)
5555
LLVM_FIXED_MD_KIND(MD_noalias_addrspace, "noalias.addrspace", 41)
5656
LLVM_FIXED_MD_KIND(MD_callee_type, "callee_type", 42)
5757
LLVM_FIXED_MD_KIND(MD_nofree, "nofree", 43)
58-
LLVM_FIXED_MD_KIND(MD_alloc_token_hint, "alloc_token_hint", 44)
58+
LLVM_FIXED_MD_KIND(MD_alloc_token, "alloc_token", 44)

0 commit comments

Comments
 (0)