Skip to content

Commit af5ac6d

Browse files
committed
Re-instate the allocVector builtin
Although it's not used anymore we still have to support it to be able to read old Swift.interface files which still contain the builtin. rdar://144781646
1 parent 725bd91 commit af5ac6d

File tree

7 files changed

+40
-0
lines changed

7 files changed

+40
-0
lines changed

include/swift/AST/Builtins.def

+5
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ BUILTIN_MISC_OPERATION(UnprotectedStackAlloc, "unprotectedStackAlloc", "", Speci
638638
/// Builtin.stackAlloc(), is deallocated from the stack.
639639
BUILTIN_MISC_OPERATION(StackDealloc, "stackDealloc", "", Special)
640640

641+
// Obsolete: only there to be able to read old Swift.interface files which still
642+
// contain the builtin.
643+
/// allocVector<Element>(Element.Type, Builtin.Word) -> Builtin.RawPointer
644+
BUILTIN_MISC_OPERATION(AllocVector, "allocVector", "", Special)
645+
641646
/// Fence has type () -> ().
642647
BUILTIN_MISC_OPERATION(Fence, "fence", "", None)
643648

lib/AST/Builtins.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,15 @@ static ValueDecl *getStackDeallocOperation(ASTContext &ctx, Identifier id) {
11371137
_void);
11381138
}
11391139

1140+
// Obsolete: only there to be able to read old Swift.interface files which still
1141+
// contain the builtin.
1142+
static ValueDecl *getAllocVectorOperation(ASTContext &ctx, Identifier id) {
1143+
return getBuiltinFunction(ctx, id, _thin,
1144+
_generics(_unrestricted),
1145+
_parameters(_metatype(_typeparam(0)), _word),
1146+
_rawPointer);
1147+
}
1148+
11401149
static ValueDecl *getFenceOperation(ASTContext &ctx, Identifier id) {
11411150
return getBuiltinFunction(ctx, id, _thin, _parameters(), _void);
11421151
}
@@ -3042,6 +3051,9 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
30423051
case BuiltinValueKind::StackDealloc:
30433052
return getStackDeallocOperation(Context, Id);
30443053

3054+
case BuiltinValueKind::AllocVector:
3055+
return getAllocVectorOperation(Context, Id);
3056+
30453057
case BuiltinValueKind::CastToNativeObject:
30463058
case BuiltinValueKind::UnsafeCastToNativeObject:
30473059
case BuiltinValueKind::CastFromNativeObject:

lib/IRGen/GenBuiltin.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,17 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
14751475
return;
14761476
}
14771477

1478+
if (Builtin.ID == BuiltinValueKind::AllocVector) {
1479+
// Obsolete: only there to be able to read old Swift.interface files which still
1480+
// contain the builtin.
1481+
(void)args.claimAll();
1482+
IGF.emitTrap("vector allocation not supported anymore", /*EmitUnreachable=*/true);
1483+
out.add(llvm::UndefValue::get(IGF.IGM.Int8PtrTy));
1484+
llvm::BasicBlock *contBB = llvm::BasicBlock::Create(IGF.IGM.getLLVMContext());
1485+
IGF.Builder.emitBlock(contBB);
1486+
return;
1487+
}
1488+
14781489
if (Builtin.ID == BuiltinValueKind::GetEnumTag) {
14791490
auto arg = args.claimNext();
14801491
auto ty = argTypes[0];

lib/SIL/IR/OperandOwnership.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, SSubOver)
866866
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, StackAlloc)
867867
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, UnprotectedStackAlloc)
868868
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, StackDealloc)
869+
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, AllocVector)
869870
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, SToSCheckedTrunc)
870871
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, SToUCheckedTrunc)
871872
BUILTIN_OPERAND_OWNERSHIP(InstantaneousUse, Expect)

lib/SIL/IR/ValueOwnership.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ CONSTANT_OWNERSHIP_BUILTIN(None, UToSCheckedTrunc)
560560
CONSTANT_OWNERSHIP_BUILTIN(None, StackAlloc)
561561
CONSTANT_OWNERSHIP_BUILTIN(None, UnprotectedStackAlloc)
562562
CONSTANT_OWNERSHIP_BUILTIN(None, StackDealloc)
563+
CONSTANT_OWNERSHIP_BUILTIN(None, AllocVector)
563564
CONSTANT_OWNERSHIP_BUILTIN(None, SToSCheckedTrunc)
564565
CONSTANT_OWNERSHIP_BUILTIN(None, SToUCheckedTrunc)
565566
CONSTANT_OWNERSHIP_BUILTIN(None, UToUCheckedTrunc)

lib/SILOptimizer/Transforms/AccessEnforcementReleaseSinking.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ static bool isBarrier(SILInstruction *inst) {
157157
case BuiltinValueKind::StackAlloc:
158158
case BuiltinValueKind::UnprotectedStackAlloc:
159159
case BuiltinValueKind::StackDealloc:
160+
case BuiltinValueKind::AllocVector:
160161
case BuiltinValueKind::AssumeAlignment:
161162
case BuiltinValueKind::GetEnumTag:
162163
case BuiltinValueKind::InjectEnumTag:

test/IRGen/builtins.swift

+9
Original file line numberDiff line numberDiff line change
@@ -861,4 +861,13 @@ func injectEnumTag<T>(_ x: inout T, tag: UInt32) {
861861
Builtin.injectEnumTag(&x, tag._value)
862862
}
863863

864+
// Check that we still support the obsolete allocVector builtin in old Swift.interface files.
865+
866+
// CHECK-LABEL: define {{.*}} swiftcc ptr @"$s8builtins14allocateVector11elementType8capacityBpxm_BwtlF"
867+
// CHECK: trap()
868+
// CHECK: unreachable
869+
func allocateVector<Element>(elementType: Element.Type, capacity: Builtin.Word) -> Builtin.RawPointer {
870+
return Builtin.allocVector(elementType, capacity)
871+
}
872+
864873
// CHECK: ![[R]] = !{i64 0, i64 9223372036854775807}

0 commit comments

Comments
 (0)