Skip to content

Commit ad6caaa

Browse files
Merge pull request #66315 from nate-chandler/rdar110195273
[IRGen] Mask off metadata pack passed to DebugInfo
2 parents 4450b98 + 6e7952b commit ad6caaa

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

lib/IRGen/GenPack.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,23 @@ static Address emitFixedSizeMetadataPackRef(IRGenFunction &IGF,
210210
return pack;
211211
}
212212

213-
/// Use this to index into packs to correctly handle on-heap packs.
214-
static llvm::Value *loadMetadataAtIndex(IRGenFunction &IGF,
215-
llvm::Value *patternPack,
216-
llvm::Value *index) {
213+
llvm::Value *irgen::maskMetadataPackPointer(IRGenFunction &IGF,
214+
llvm::Value *patternPack) {
217215
// If the pack is on the heap, the LSB is set, so mask it off.
218216
patternPack =
219217
IGF.Builder.CreatePtrToInt(patternPack, IGF.IGM.SizeTy);
220218
patternPack =
221219
IGF.Builder.CreateAnd(patternPack, llvm::ConstantInt::get(IGF.IGM.SizeTy, -2));
222220
patternPack =
223221
IGF.Builder.CreateIntToPtr(patternPack, IGF.IGM.TypeMetadataPtrPtrTy);
222+
return patternPack;
223+
}
224+
225+
/// Use this to index into packs to correctly handle on-heap packs.
226+
static llvm::Value *loadMetadataAtIndex(IRGenFunction &IGF,
227+
llvm::Value *patternPack,
228+
llvm::Value *index) {
229+
patternPack = maskMetadataPackPointer(IGF, patternPack);
224230

225231
Address patternPackAddress(patternPack, IGF.IGM.TypeMetadataPtrTy,
226232
IGF.IGM.getPointerAlignment());

lib/IRGen/GenPack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ emitTypeMetadataPackRef(IRGenFunction &IGF,
5353
CanPackType packType,
5454
DynamicMetadataRequest request);
5555

56+
/// Given a pointer to a potentially heap-allocated pack of metadata/wtables,
57+
/// mask off the bit that indicates whether it is heap allocated.
58+
llvm::Value *maskMetadataPackPointer(IRGenFunction &IGF, llvm::Value *);
59+
5660
void bindOpenedElementArchetypesAtIndex(IRGenFunction &IGF,
5761
GenericEnvironment *env,
5862
llvm::Value *index);

lib/IRGen/LocalTypeData.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Fulfillment.h"
2020
#include "GenMeta.h"
2121
#include "GenOpaque.h"
22+
#include "GenPack.h"
2223
#include "GenProto.h"
2324
#include "IRGenDebugInfo.h"
2425
#include "IRGenFunction.h"
@@ -350,6 +351,9 @@ static void maybeEmitDebugInfoForLocalTypeData(IRGenFunction &IGF,
350351

351352
llvm::Value *data = value.getMetadata();
352353

354+
if (key.Type->is<PackArchetypeType>())
355+
data = maskMetadataPackPointer(IGF, data);
356+
353357
// At -O0, create an alloca to keep the type alive. Not for async functions
354358
// though; see the comment in IRGenFunctionSIL::emitShadowCopyIfNeeded().
355359
if (!IGF.IGM.IRGen.Opts.shouldOptimize() && !IGF.isAsync()) {

test/DebugInfo/variadic-generics.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-swift-frontend -emit-ir %s -g -o - \
2-
// RUN: -parse-as-library -module-name a | %FileCheck %s
2+
// RUN: -parse-as-library -module-name a | %IRGenFileCheck %s
33

44
public func foo<each T>(args: repeat each T) {
55
// CHECK: define {{.*}} @"$s1a3foo4argsyxxQp_tRvzlF"
@@ -8,9 +8,12 @@ public func foo<each T>(args: repeat each T) {
88
// CHECK: call void @llvm.dbg.declare(metadata %swift.type*** %[[TYPE_PACK_ALLOCA]], metadata ![[TYPE_PACK_VAR:[0-9]+]], metadata !DIExpression())
99
// CHECK: %[[ARGS_ALLOCA:.*]] = alloca %swift.opaque**
1010
// CHECK-DAG: call void @llvm.dbg.declare(metadata %swift.opaque*** %[[ARGS_ALLOCA]], metadata ![[ARGS_VAR:[0-9]+]], metadata !DIExpression(DW_OP_deref))
11-
// CHECK-DAG: store %swift.type** %[[TYPE_PACK_ARG]], %swift.type*** %[[TYPE_PACK_ALLOCA]]
11+
// CHECK-DAG: %[[TYPE_PACK_ARG_INT:[^,]+]] = ptrtoint %swift.type** %[[TYPE_PACK_ARG]] to [[INT]]
12+
// CHECK-DAG: %[[TYPE_PACK_ARG_MASKED_INT:[^,]+]] = and [[INT]] %[[TYPE_PACK_ARG_INT]], -2
13+
// CHECK-DAG: %[[TYPE_PACK_ARG_MASKED:[^,]+]] = inttoptr [[INT]] %[[TYPE_PACK_ARG_MASKED_INT]] to %swift.type**
14+
// CHECK-DAG: store %swift.type** %[[TYPE_PACK_ARG_MASKED]], %swift.type*** %[[TYPE_PACK_ALLOCA]]
1215
// CHECK-DAG: store %swift.opaque** %0, %swift.opaque*** %[[ARGS_ALLOCA]]
13-
// CHECK-DAG: ![[ARGS_VAR]] = !DILocalVariable(name: "args", arg: 1, {{.*}}line: [[@LINE-9]], type: ![[ARGS_LET_TY:[0-9]+]])
16+
// CHECK-DAG: ![[ARGS_VAR]] = !DILocalVariable(name: "args", arg: 1, {{.*}}line: [[@LINE-12]], type: ![[ARGS_LET_TY:[0-9]+]])
1417
// CHECK-DAG: ![[ARGS_LET_TY]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: ![[ARGS_TY:[0-9]+]])
1518
// CHECK-DAG: ![[ARGS_TY]] = !DICompositeType({{.*}}identifier: "$sxxQp_QSiD")
1619
// CHECK-DAG: ![[TYPE_PACK_VAR]] = !DILocalVariable(name: "$\CF\84_0_0", {{.*}}type: ![[TYPE_PACK_TYD:[0-9]+]], flags: DIFlagArtificial)

test/IRGen/run_variadic_generics.sil

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) -parse-stdlib %S/../Inputs/print-shims-stdlib.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule
33
// RUN: %target-codesign %t/%target-library-name(PrintShims)
4-
// RUN: %target-build-swift -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL
4+
// RUN: %target-build-swift -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim -Onone | %FileCheck %s --check-prefixes=CHECK-LL,CHECK-LL-UNOPT
5+
// RUN: %target-build-swift -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim -O | %FileCheck %s --check-prefixes=CHECK-LL,CHECK-LL-OPT
56
// RUN: %target-build-swift -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t)
67
// RUN: %target-codesign %t/main
78
// RUN: %target-run %t/main %t/%target-library-name(PrintShims) | %FileCheck %s
@@ -568,6 +569,7 @@ entry(%intIndex : $Builtin.Word):
568569

569570
// Verify that we just gep into a parameter pack when that's all that the pack consists of.
570571
// CHECK-LL: define {{.*}}void @direct_access_from_parameter(i{{(32|64)}} [[INDEX:%[^,]+]], i{{(32|64)}} {{%[^,]+}}, %swift.type** [[PACK:%[^,]+]])
572+
// CHECK-LL-UNOPT: [[PACK_ADDR_FOR_DI:%.*]] = ptrtoint %swift.type** [[PACK]] to i{{(32|64)}}
571573
// CHECK-LL: [[PACK_ADDR:%.*]] = ptrtoint %swift.type** [[PACK]] to i{{(32|64)}}
572574
// CHECK-LL: [[PACK_ADDR2:%.*]] = and i{{(32|64)}} [[PACK_ADDR]], -2
573575
// CHECK-LL: [[PACK:%.*]] = inttoptr i{{(32|64)}} [[PACK_ADDR2]] to %swift.type**
@@ -591,6 +593,7 @@ entry(%intIndex : $Builtin.Word):
591593
// CHECK-LL-SAME: i{{(32|64)}} {{%[^,]+}},
592594
// CHECK-LL-SAME: %swift.type** [[METADATA_PACK:%[^,]+]],
593595
// CHECK-LL-SAME: i8*** [[WTABLE_PACK:%[^,]+]])
596+
// CHECK-LL-UNOPT: [[PACK_ADDR_FOR_DI:%.*]] = ptrtoint %swift.type** [[METADATA_PACK]] to i{{(32|64)}}
594597
// CHECK-LL: [[PACK_ADDR:%.*]] = ptrtoint %swift.type** [[METADATA_PACK]] to i{{(32|64)}}
595598
// CHECK-LL: [[PACK_ADDR2:%.*]] = and i{{(32|64)}} [[PACK_ADDR]], -2
596599
// CHECK-LL: [[METADATA_PACK:%.*]] = inttoptr i{{(32|64)}} [[PACK_ADDR2]] to %swift.type**

test/IRGen/variadic_generic_outlining.sil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct Wrapper<Value> {
1111
// an opened element type.
1212
//
1313
// CHECK-LABEL: define{{.*}}void @test_outlining
14+
// CHECK: [[PACK_ADDR_FOR_DEBUGINFO:%.*]] = ptrtoint %swift.type** %"each T" to [[INT]]
1415
// CHECK: [[PACK_ADDR:%.*]] = ptrtoint %swift.type** %"each T" to [[INT]]
1516
// CHECK-NEXT: [[PACK_ADDR2:%.*]] = and [[INT]] [[PACK_ADDR]], -2
1617
// CHECK-NEXT: [[PACK:%.*]] = inttoptr [[INT]] [[PACK_ADDR2]] to %swift.type**

0 commit comments

Comments
 (0)