Skip to content

Commit da6814d

Browse files
committed
[SwiftCompiler] Make BridgedArrayRef.data nullable
ArrayRef.data() can be nullptr when the array is empty.
1 parent 7486cd1 commit da6814d

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extension Optional where Wrapped == UnsafeMutablePointer<BridgedSwiftObject> {
7070

7171
extension BridgedArrayRef {
7272
public func withElements<T, R>(ofType ty: T.Type, _ c: (UnsafeBufferPointer<T>) -> R) -> R {
73-
let start = data.bindMemory(to: ty, capacity: numElements);
73+
let start = data?.bindMemory(to: ty, capacity: numElements);
7474
let buffer = UnsafeBufferPointer(start: start, count: numElements);
7575
return c(buffer)
7676
}

SwiftCompilerSources/Sources/SIL/BasicBlock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public struct SuccessorArray : RandomAccessCollection, FormattedLikeArray {
9696

9797
public subscript(_ index: Int) -> BasicBlock {
9898
precondition(index >= 0 && index < endIndex)
99-
let s = BridgedSuccessor(succ: succArray.data + index &* BridgedSuccessorSize);
99+
let s = BridgedSuccessor(succ: succArray.data! + index &* BridgedSuccessorSize);
100100
return SILSuccessor_getTargetBlock(s).block
101101
}
102102
}

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
6767

6868
public subscript(_ index: Int) -> Operand {
6969
precondition(index >= 0 && index < endIndex)
70-
return Operand(BridgedOperand(op: opArray.data + index &* BridgedOperandSize))
70+
return Operand(BridgedOperand(op: opArray.data! + index &* BridgedOperandSize))
7171
}
7272

7373
public func getIndex(of operand: Operand) -> Int {
74-
let idx = (operand.bridged.op - UnsafeRawPointer(opArray.data)) /
74+
let idx = (operand.bridged.op - UnsafeRawPointer(opArray.data!)) /
7575
BridgedOperandSize
7676
precondition(self[idx].bridged.op == operand.bridged.op)
7777
return idx
@@ -86,7 +86,7 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
8686
precondition(bounds.lowerBound >= 0)
8787
precondition(bounds.upperBound <= endIndex)
8888
return OperandArray(opArray: BridgedArrayRef(
89-
data: opArray.data + bounds.lowerBound &* BridgedOperandSize,
89+
data: opArray.data! + bounds.lowerBound &* BridgedOperandSize,
9090
numElements: bounds.upperBound - bounds.lowerBound))
9191
}
9292
}

include/swift/Basic/BasicBridging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ typedef struct {
3131
} BridgedStringRef;
3232

3333
typedef struct {
34-
const void * _Nonnull data;
34+
const void * _Nullable data;
3535
size_t numElements;
3636
} BridgedArrayRef;
3737

0 commit comments

Comments
 (0)