Skip to content

Commit 607967d

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents c5d10aa + 6069462 commit 607967d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "GenDecl.h"
2727
#include "GenMeta.h"
2828
#include "GenOpaque.h"
29+
#include "GenPointerAuth.h"
2930
#include "GenProto.h"
3031
#include "GenType.h"
3132
#include "IRGenDebugInfo.h"
@@ -588,9 +589,26 @@ static llvm::Value *lookupWitnessTable(IRGenFunction &IGF, llvm::Value *witness,
588589
assert(Lowering::TypeConverter::protocolRequiresWitnessTable(protocol));
589590

590591
auto &IGM = IGF.IGM;
591-
auto *protocolDescriptor = IGM.getAddrOfProtocolDescriptor(protocol);
592+
llvm::Value *protocolDescriptor = IGM.getAddrOfProtocolDescriptor(protocol);
593+
594+
bool signedProtocolDescriptor = IGM.getAvailabilityRange().isContainedIn(
595+
IGM.Context.getSignedConformsToProtocolAvailability());
596+
597+
auto conformsToProtocolFunctionPointer = signedProtocolDescriptor ?
598+
IGM.getConformsToProtocol2FunctionPointer() :
599+
IGM.getConformsToProtocolFunctionPointer();
600+
601+
// Sign the protocol descriptor.
602+
auto schema = IGF.IGM.getOptions().PointerAuth.ProtocolDescriptorsAsArguments;
603+
if (schema && signedProtocolDescriptor) {
604+
auto authInfo = PointerAuthInfo::emit(
605+
IGF, schema, nullptr,
606+
PointerAuthEntity::Special::ProtocolDescriptorAsArgument);
607+
protocolDescriptor = emitPointerAuthSign(IGF, protocolDescriptor, authInfo);
608+
}
609+
592610
auto *witnessTable = IGF.Builder.CreateCall(
593-
IGM.getConformsToProtocolFunctionPointer(), {witness, protocolDescriptor});
611+
conformsToProtocolFunctionPointer, {witness, protocolDescriptor});
594612

595613
auto failBB = IGF.createBasicBlock("missing-witness");
596614
auto contBB = IGF.createBasicBlock("");

0 commit comments

Comments
 (0)