Skip to content

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Oct 8, 2025

Explanation: Fix a miscompile caused by incorrect function and call attributes applied by IRGen to metadata accessors for types with variadic generic arguments.

Metadata accessors are used to obtain the runtime representation of a type (i.e. its metadata). If the type is generic, the generic arguments (types and conformances) are provided as arguments. Each of a type's generic arguments which is variadic is specified by a list of types or conformances. Each such list is passed to the accessor in a buffer. In its implementation (in fact, in the runtime which the accessor calls into), the metadata is instantiated by examining those arguments, including any variadic generic arguments. To be explicit, it reads the data in such buffers.

Previously, both the metadata accessor and calls to it were annotated memory(none) even when it had variadic generic arguments. This annotation told the LLVM optimizer that it was free to move memory operations (such as stores) around the function call because the function would not read that memory. When it was profitable to do so, the optimizer did just this. The result was to leave these buffers partially uninitialized, resulting in runtime crashes during metadata instantiation when attempting to read from the buffers.

Here, this is fixed by removing the incorrect annotation. Now, whenever a metadata accessor includes in its argument list a variadic generic, neither the accessor itself is annotated memory(none) nor are calls to it annotated thus.
Scope: Affects code with variadic generics.
Issue: rdar://161606892
Original PR: #84635 , #84667
Risk: Low. The patch worsens the effects applied to functions and function calls, obstructing optimizations.
Testing: Added tests.
Reviewer: John McCall ( @rjmccall ), Arnold Schwaighofer ( @aschwaighofer )

The metadata accessor for a variadic generic type takes as arguments
packs of metadata records and witness tables, and each such pack is
passed in a buffer.  So any such accessor is not correctly annotated
`memory(none)`.

rdar://161606892
Follow up to swiftlang#84635.

The metadata accessor for a variadic generic type takes as arguments
packs of metadata records and witness tables, and each such pack is
passed in a buffer. So the call to any such accessor is not correctly
annotated memory(none).

rdar://161606892
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review October 8, 2025 18:31
@nate-chandler nate-chandler requested a review from a team as a code owner October 8, 2025 18:31
@nate-chandler nate-chandler merged commit b5fed15 into swiftlang:release/6.2 Oct 8, 2025
5 checks passed
@nate-chandler nate-chandler deleted the cherrypick/release/6.2/rdar161606892_2 branch October 8, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants