6.2: [VariadicGenerics] Fix memeffect of metadata accessor. #84763
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 )