Skip to content

Commit 615b299

Browse files
Merge pull request #84667 from nate-chandler/rdar161606892_2
[VariadicGenerics] Fix memeffect of metadata accessor call.
2 parents ed4f058 + 8332b7c commit 615b299

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

lib/IRGen/IRGenFunction.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,8 @@ class IRGenFunction {
395395

396396
// Emit a call to the given generic type metadata access function.
397397
MetadataResponse emitGenericTypeMetadataAccessFunctionCall(
398-
llvm::Function *accessFunction,
399-
ArrayRef<llvm::Value *> args,
400-
DynamicMetadataRequest request);
398+
llvm::Function *accessFunction, ArrayRef<llvm::Value *> args,
399+
DynamicMetadataRequest request, bool hasPacks = false);
401400

402401
// Emit a reference to the canonical type metadata record for the given AST
403402
// type. This can be used to identify the type at runtime. For types with

lib/IRGen/MetadataRequest.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static MetadataResponse emitNominalMetadataRef(IRGenFunction &IGF,
750750
theDecl, genericArgs.Types, NotForDefinition);
751751

752752
response = IGF.emitGenericTypeMetadataAccessFunctionCall(
753-
accessor, genericArgs.Values, request);
753+
accessor, genericArgs.Values, request, genericArgs.hasPacks);
754754
}
755755

756756
IGF.setScopedLocalTypeMetadata(theType, response);
@@ -2462,11 +2462,9 @@ void irgen::emitCacheAccessFunction(IRGenModule &IGM, llvm::Function *accessor,
24622462
IGF.Builder.CreateRet(ret);
24632463
}
24642464

2465-
MetadataResponse
2466-
IRGenFunction::emitGenericTypeMetadataAccessFunctionCall(
2467-
llvm::Function *accessFunction,
2468-
ArrayRef<llvm::Value *> args,
2469-
DynamicMetadataRequest request) {
2465+
MetadataResponse IRGenFunction::emitGenericTypeMetadataAccessFunctionCall(
2466+
llvm::Function *accessFunction, ArrayRef<llvm::Value *> args,
2467+
DynamicMetadataRequest request, bool hasPacks) {
24702468

24712469
SmallVector<llvm::Value *, 8> callArgs;
24722470

@@ -2490,7 +2488,7 @@ IRGenFunction::emitGenericTypeMetadataAccessFunctionCall(
24902488
accessFunction, callArgs);
24912489
call->setDoesNotThrow();
24922490
call->setCallingConv(IGM.SwiftCC);
2493-
call->setMemoryEffects(allocatedArgsBuffer
2491+
call->setMemoryEffects(hasPacks || allocatedArgsBuffer
24942492
? llvm::MemoryEffects::inaccessibleOrArgMemOnly()
24952493
: llvm::MemoryEffects::none());
24962494

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-build-swift \
5+
// RUN: -emit-module \
6+
// RUN: -target %target-swift-5.9-abi-triple \
7+
// RUN: %t/Library.swift \
8+
// RUN: -parse-as-library \
9+
// RUN: -module-name Library \
10+
// RUN: -emit-module-path %t/Library.swiftmodule
11+
12+
// RUN: %target-swift-frontend \
13+
// RUN: %t/Downstream.swift \
14+
// RUN: -emit-irgen \
15+
// RUN: -target %target-swift-5.9-abi-triple \
16+
// RUN: -module-name main \
17+
// RUN: -lLibrary \
18+
// RUN: -I %t \
19+
// RUN: | %FileCheck %t/Downstream.swift --check-prefixes=CHECK,CHECK-OLD
20+
21+
//--- Library.swift
22+
23+
public struct Pack<each T> {
24+
public init() {}
25+
}
26+
27+
public func sink<T>(_ t: T) {}
28+
29+
//--- Downstream.swift
30+
31+
import Library
32+
33+
// CHECK: doit
34+
// CHECK: @"$s7Library4PackVMa"{{.*}} [[CALL:#[^,]+]]
35+
36+
// CHECK: attributes [[CALL]] = { nounwind memory(argmem: readwrite, inaccessiblemem: readwrite) }
37+
@_silgen_name("doit")
38+
func doit<each T, each U>(ts: repeat each T, us: repeat each U) {
39+
sink(Pack<repeat each T, repeat each U>())
40+
}

0 commit comments

Comments
 (0)