<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/clang/lib/AST/Mangle.cpp, branch main</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/'/>
<entry>
<title>[clang][Mangle] Inject structor type into mangled name when mangling for LLDB JIT expressions (#155485)</title>
<updated>2025-09-09T08:08:50+00:00</updated>
<author>
<name>Michael Buch</name>
<email>michaelbuch12@gmail.com</email>
</author>
<published>2025-09-09T08:08:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=db8cad0c8d00a691d1365e9b2962a7f2f4ff0890'/>
<id>db8cad0c8d00a691d1365e9b2962a7f2f4ff0890</id>
<content type='text'>
Part of https://github.com/llvm/llvm-project/pull/149827

This patch adds special handling for `AsmLabel`s created by LLDB. LLDB
uses `AsmLabel`s to encode information about a function declaration to
make it easier to locate function symbols when JITing C++ expressions.
For constructors/destructors LLDB doesn't know at the time of creating
the `AsmLabelAttr` which structor variant the expression evaluator will
need to call (this is decided when compiling the expression). So we make
the Clang mangler inject this information into our custom label when
we're JITting the expression.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Part of https://github.com/llvm/llvm-project/pull/149827

This patch adds special handling for `AsmLabel`s created by LLDB. LLDB
uses `AsmLabel`s to encode information about a function declaration to
make it easier to locate function symbols when JITing C++ expressions.
For constructors/destructors LLDB doesn't know at the time of creating
the `AsmLabelAttr` which structor variant the expression evaluator will
need to call (this is decided when compiling the expression). So we make
the Clang mangler inject this information into our custom label when
we're JITting the expression.</pre>
</div>
</content>
</entry>
<entry>
<title>[clang][Attr] Remove 'literal label' form of AsmLabelAttr (#151858)</title>
<updated>2025-08-04T13:34:45+00:00</updated>
<author>
<name>Michael Buch</name>
<email>michaelbuch12@gmail.com</email>
</author>
<published>2025-08-04T13:34:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=cd8f348c69345755f559049f415ce8b6c0d6edc1'/>
<id>cd8f348c69345755f559049f415ce8b6c0d6edc1</id>
<content type='text'>
This was added purely for the needs of LLDB. However, starting with
https://github.com/llvm/llvm-project/pull/151355 and
https://github.com/llvm/llvm-project/pull/148877 we no longer create
literal AsmLabels in LLDB either. So this is unused and we can get rid
of it.

In the near future LLDB will want to add special support for mangling
`AsmLabel`s (specifically
https://github.com/llvm/llvm-project/pull/149827).</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This was added purely for the needs of LLDB. However, starting with
https://github.com/llvm/llvm-project/pull/151355 and
https://github.com/llvm/llvm-project/pull/148877 we no longer create
literal AsmLabels in LLDB either. So this is unused and we can get rid
of it.

In the near future LLDB will want to add special support for mangling
`AsmLabel`s (specifically
https://github.com/llvm/llvm-project/pull/149827).</pre>
</div>
</content>
</entry>
<entry>
<title>[clang AST] move mangling API to namespace clang to allow calls from swift-frontend (#137884)</title>
<updated>2025-04-30T16:37:55+00:00</updated>
<author>
<name>Peter Rong</name>
<email>peterrong96@gmail.com</email>
</author>
<published>2025-04-30T16:37:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=0bd992a8d7193e15191f14a4bd39fd4dd181dbdb'/>
<id>0bd992a8d7193e15191f14a4bd39fd4dd181dbdb</id>
<content type='text'>
When implementing `@objcDirect` in Swift, Swift needs to mangle a native
`Decl` that is not a clang Node, which in turn don't have access to
`clang::MangleContext`. Reimplementing mangling logic in Swift is
redundant.

This patch moves mangling logic from `clang::MangleContext` to `clang`
using only basic types (`StringRef`, `std::optional`, etc.), such that
Swift can we can just call Clang API: Swift depends on Clang already.

We are separating this from #126639 so we can draft the proposal on the
Swift side. #126639 will be worked to depend on this PR.

Tests: No new tests, old ones should pass with no problem.

---------

Signed-off-by: Peter Rong &lt;PeterRong@meta.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When implementing `@objcDirect` in Swift, Swift needs to mangle a native
`Decl` that is not a clang Node, which in turn don't have access to
`clang::MangleContext`. Reimplementing mangling logic in Swift is
redundant.

This patch moves mangling logic from `clang::MangleContext` to `clang`
using only basic types (`StringRef`, `std::optional`, etc.), such that
Swift can we can just call Clang API: Swift depends on Clang already.

We are separating this from #126639 so we can draft the proposal on the
Swift side. #126639 will be worked to depend on this PR.

Tests: No new tests, old ones should pass with no problem.

---------

Signed-off-by: Peter Rong &lt;PeterRong@meta.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>Fix crash with -ast-dump=json (#137324)</title>
<updated>2025-04-29T11:55:32+00:00</updated>
<author>
<name>Aaron Ballman</name>
<email>aaron@aaronballman.com</email>
</author>
<published>2025-04-29T11:55:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=c5bf901b1b2804eede51b07d9d171c5656dd49fa'/>
<id>c5bf901b1b2804eede51b07d9d171c5656dd49fa</id>
<content type='text'>
When given an invalid Objective-C extension, Clang would crash when
trying to emit the mangled name of the method to the JSON dump output.

Fixes #137320</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When given an invalid Objective-C extension, Clang would crash when
trying to emit the mangled name of the method to the JSON dump output.

Fixes #137320</pre>
</div>
</content>
</entry>
<entry>
<title>[Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (#115821)</title>
<updated>2025-04-08T04:59:30+00:00</updated>
<author>
<name>Aniket Lal</name>
<email>lalaniket8@gmail.com</email>
</author>
<published>2025-04-08T04:59:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=642481a4286c9006958274531ee173b347866c50'/>
<id>642481a4286c9006958274531ee173b347866c50</id>
<content type='text'>
This feature is currently not supported in the compiler.
To facilitate this we emit a stub version of each kernel
function body with different name mangling scheme, and
replaces the respective kernel call-sites appropriately.
    
Fixes https://github.com/llvm/llvm-project/issues/60313
    
D120566 was an earlier attempt made to upstream a solution
for this issue.

---------

Co-authored-by: anikelal &lt;anikelal@amd.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This feature is currently not supported in the compiler.
To facilitate this we emit a stub version of each kernel
function body with different name mangling scheme, and
replaces the respective kernel call-sites appropriately.
    
Fixes https://github.com/llvm/llvm-project/issues/60313
    
D120566 was an earlier attempt made to upstream a solution
for this issue.

---------

Co-authored-by: anikelal &lt;anikelal@amd.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[Clang] Make `MangleContext::mangleMSGuidDecl()`, `MangleContext::mangleObjCMethodName()` and `MangleContext::mangleObjCMethodNameAsSourceName()` const methods (#130613)</title>
<updated>2025-03-10T20:17:01+00:00</updated>
<author>
<name>Boaz Brickner</name>
<email>brickner@google.com</email>
</author>
<published>2025-03-10T20:17:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=6b5b0821e3d879390a262679d05ad268b62c0a19'/>
<id>6b5b0821e3d879390a262679d05ad268b62c0a19</id>
<content type='text'>
Unfortunately, making `MangleContext::mangleName()` would require a lot
of const escapes due to lazy initialization and id creations:

`Mangle.h`:
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/include/clang/AST/Mangle.h#L82-L85
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/include/clang/AST/Mangle.h#L97-L99

`ItaniumMangle.cpp`:
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/lib/AST/ItaniumMangle.cpp#L158-L161
*
https://github.com/llvm/llvm-project/blob/4508d6aa72b0f31056ae01aff0e8009a252e4683/clang/lib/AST/ItaniumMangle.cpp#L641

`MicrosoftMangle.cpp`:
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/lib/AST/MicrosoftMangle.cpp#L243-L245
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/lib/AST/MicrosoftMangle.cpp#L284</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Unfortunately, making `MangleContext::mangleName()` would require a lot
of const escapes due to lazy initialization and id creations:

`Mangle.h`:
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/include/clang/AST/Mangle.h#L82-L85
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/include/clang/AST/Mangle.h#L97-L99

`ItaniumMangle.cpp`:
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/lib/AST/ItaniumMangle.cpp#L158-L161
*
https://github.com/llvm/llvm-project/blob/4508d6aa72b0f31056ae01aff0e8009a252e4683/clang/lib/AST/ItaniumMangle.cpp#L641

`MicrosoftMangle.cpp`:
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/lib/AST/MicrosoftMangle.cpp#L243-L245
*
https://github.com/llvm/llvm-project/blob/dffbc030e75b758e7512518abd499a0f680addbf/clang/lib/AST/MicrosoftMangle.cpp#L284</pre>
</div>
</content>
</entry>
<entry>
<title>[clang] Use TargetInfo to decide Mangling for C (#129920)</title>
<updated>2025-03-06T01:26:52+00:00</updated>
<author>
<name>Prabhuk</name>
<email>prabhukr@google.com</email>
</author>
<published>2025-03-06T01:26:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=45ca613c135ea7b5fbc63bff003f20bf20f62081'/>
<id>45ca613c135ea7b5fbc63bff003f20bf20f62081</id>
<content type='text'>
Instead of hardcoding the decision on what mangling scheme to use based
on targets, use TargetInfo to make the decision.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Instead of hardcoding the decision on what mangling scheme to use based
on targets, use TargetInfo to make the decision.</pre>
</div>
</content>
</entry>
<entry>
<title>[AST] Remove unused includes (NFC) (#116549)</title>
<updated>2024-11-17T17:36:48+00:00</updated>
<author>
<name>Kazu Hirata</name>
<email>kazu@google.com</email>
</author>
<published>2024-11-17T17:36:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=dec6324cb05ac1d339c1b2bd43add968f2931c62'/>
<id>dec6324cb05ac1d339c1b2bd43add968f2931c62</id>
<content type='text'>
Identified with misc-include-cleaner.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Identified with misc-include-cleaner.</pre>
</div>
</content>
</entry>
<entry>
<title>[clang] Nits on uses of raw_string_ostream (NFC)</title>
<updated>2024-09-14T09:29:40+00:00</updated>
<author>
<name>JOE1994</name>
<email>joseph942010@gmail.com</email>
</author>
<published>2024-09-14T09:23:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=223e2efa5e886502a9467b7ef700ebce9b7886e8'/>
<id>223e2efa5e886502a9467b7ef700ebce9b7886e8</id>
<content type='text'>
* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Strip unneeded calls to raw_string_ostream::str(), to avoid extra indirection.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Strip unneeded calls to raw_string_ostream::str(), to avoid extra indirection.
</pre>
</div>
</content>
</entry>
<entry>
<title> [clang] Implement pointer authentication for C++ virtual functions, v-tables, and VTTs (#94056)</title>
<updated>2024-06-27T01:35:10+00:00</updated>
<author>
<name>Oliver Hunt</name>
<email>oliver@apple.com</email>
</author>
<published>2024-06-27T01:35:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=1b8ab2f08998d3220e5d95003d47bb3d7cac966b'/>
<id>1b8ab2f08998d3220e5d95003d47bb3d7cac966b</id>
<content type='text'>
Virtual function pointer entries in v-tables are signed with address
discrimination in addition to declaration-based discrimination, where an
integer discriminator the string hash (see
`ptrauth_string_discriminator`) of the mangled name of the overridden
method. This notably provides diversity based on the full signature of
the overridden method, including the method name and parameter types.
This patch introduces ItaniumVTableContext logic to find the original
declaration of the overridden method.
On AArch64, these pointers are signed using the `IA` key (the
process-independent code key.)

V-table pointers can be signed with either no discrimination, or a
similar scheme using address and decl-based discrimination. In this
case, the integer discriminator is the string hash of the mangled
v-table identifier of the class that originally introduced the vtable
pointer.
On AArch64, these pointers are signed using the `DA` key (the
process-independent data key.)

Not using discrimination allows attackers to simply copy valid v-table
pointers from one object to another. However, using a uniform
discriminator of 0 does have positive performance and code-size
implications on AArch64, and diversity for the most important v-table
access pattern (virtual dispatch) is already better assured by the
signing schemas used on the virtual functions. It is also known that
some code in practice copies objects containing v-tables with `memcpy`,
and while this is not permitted formally, it is something that may be
invasive to eliminate.

This is controlled by:
```
  -fptrauth-vtable-pointer-type-discrimination
  -fptrauth-vtable-pointer-address-discrimination
```

In addition, this provides fine-grained controls in the
ptrauth_vtable_pointer attribute, which allows overriding the default
ptrauth schema for vtable pointers on a given class hierarchy, e.g.:
```
  [[clang::ptrauth_vtable_pointer(no_authentication, no_address_discrimination, 
                                  no_extra_discrimination)]]
  [[clang::ptrauth_vtable_pointer(default_key, default_address_discrimination,
                                  custom_discrimination, 0xf00d)]]
```

The override is then mangled as a parametrized vendor extension:
```
"__vtptrauth" I
 &lt;key&gt;
 &lt;addressDiscriminated&gt;
 &lt;extraDiscriminator&gt;
E
```

To support this attribute, this patch adds a small extension to the
attribute-emitter tablegen backend.

Note that there are known areas where signing is either missing
altogether or can be strengthened. Some will be addressed in later
changes (e.g., member function pointers, some RTTI).
`dynamic_cast` in particular is handled by emitting an artificial
v-table pointer load (in a way that always authenticates it) before the
runtime call itself, as the runtime doesn't have enough information
today to properly authenticate it. Instead, the runtime is currently
expected to strip the v-table pointer.

---------

Co-authored-by: John McCall &lt;rjmccall@apple.com&gt;
Co-authored-by: Ahmed Bougacha &lt;ahmed@bougacha.org&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Virtual function pointer entries in v-tables are signed with address
discrimination in addition to declaration-based discrimination, where an
integer discriminator the string hash (see
`ptrauth_string_discriminator`) of the mangled name of the overridden
method. This notably provides diversity based on the full signature of
the overridden method, including the method name and parameter types.
This patch introduces ItaniumVTableContext logic to find the original
declaration of the overridden method.
On AArch64, these pointers are signed using the `IA` key (the
process-independent code key.)

V-table pointers can be signed with either no discrimination, or a
similar scheme using address and decl-based discrimination. In this
case, the integer discriminator is the string hash of the mangled
v-table identifier of the class that originally introduced the vtable
pointer.
On AArch64, these pointers are signed using the `DA` key (the
process-independent data key.)

Not using discrimination allows attackers to simply copy valid v-table
pointers from one object to another. However, using a uniform
discriminator of 0 does have positive performance and code-size
implications on AArch64, and diversity for the most important v-table
access pattern (virtual dispatch) is already better assured by the
signing schemas used on the virtual functions. It is also known that
some code in practice copies objects containing v-tables with `memcpy`,
and while this is not permitted formally, it is something that may be
invasive to eliminate.

This is controlled by:
```
  -fptrauth-vtable-pointer-type-discrimination
  -fptrauth-vtable-pointer-address-discrimination
```

In addition, this provides fine-grained controls in the
ptrauth_vtable_pointer attribute, which allows overriding the default
ptrauth schema for vtable pointers on a given class hierarchy, e.g.:
```
  [[clang::ptrauth_vtable_pointer(no_authentication, no_address_discrimination, 
                                  no_extra_discrimination)]]
  [[clang::ptrauth_vtable_pointer(default_key, default_address_discrimination,
                                  custom_discrimination, 0xf00d)]]
```

The override is then mangled as a parametrized vendor extension:
```
"__vtptrauth" I
 &lt;key&gt;
 &lt;addressDiscriminated&gt;
 &lt;extraDiscriminator&gt;
E
```

To support this attribute, this patch adds a small extension to the
attribute-emitter tablegen backend.

Note that there are known areas where signing is either missing
altogether or can be strengthened. Some will be addressed in later
changes (e.g., member function pointers, some RTTI).
`dynamic_cast` in particular is handled by emitting an artificial
v-table pointer load (in a way that always authenticates it) before the
runtime call itself, as the runtime doesn't have enough information
today to properly authenticate it. Instead, the runtime is currently
expected to strip the v-table pointer.

---------

Co-authored-by: John McCall &lt;rjmccall@apple.com&gt;
Co-authored-by: Ahmed Bougacha &lt;ahmed@bougacha.org&gt;</pre>
</div>
</content>
</entry>
</feed>
