Skip to content

Commit 8de3359

Browse files
Merge pull request #81213 from AnthonyLatsis/fix-rebranch-2
[rebranch] IRGen: Fix omission in hash computation after switching API
2 parents 378286e + 442825d commit 8de3359

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

lib/IRGen/GenPointerAuth.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,10 @@ PointerAuthInfo::getOtherDiscriminator(IRGenModule &IGM,
325325
llvm_unreachable("bad kind");
326326
}
327327

328-
static llvm::ConstantInt *getDiscriminatorForHash(IRGenModule &IGM,
329-
uint64_t rawHash) {
330-
uint16_t reducedHash = (rawHash % 0xFFFF) + 1;
331-
return llvm::ConstantInt::get(IGM.Int64Ty, reducedHash);
332-
}
333-
334328
static llvm::ConstantInt *getDiscriminatorForString(IRGenModule &IGM,
335329
StringRef string) {
336-
uint64_t rawHash = llvm::getPointerAuthStableSipHash(string);
337-
return getDiscriminatorForHash(IGM, rawHash);
330+
return llvm::ConstantInt::get(IGM.Int64Ty,
331+
llvm::getPointerAuthStableSipHash(string));
338332
}
339333

340334
static std::string mangle(AssociatedTypeDecl *assocType) {
@@ -571,7 +565,8 @@ static void hashStringForFunctionType(IRGenModule &IGM, CanSILFunctionType type,
571565
}
572566
}
573567

574-
static uint64_t getTypeHash(IRGenModule &IGM, CanSILFunctionType type) {
568+
static llvm::ConstantInt *getTypeDiscriminator(IRGenModule &IGM,
569+
CanSILFunctionType type) {
575570
// The hash we need to do here ignores:
576571
// - thickness, so that we can promote thin-to-thick without rehashing;
577572
// - error results, so that we can promote nonthrowing-to-throwing
@@ -591,10 +586,11 @@ static uint64_t getTypeHash(IRGenModule &IGM, CanSILFunctionType type) {
591586
hashStringForFunctionType(
592587
IGM, type, Out,
593588
genericSig.getCanonicalSignature().getGenericEnvironment());
594-
return llvm::getPointerAuthStableSipHash(Out.str());
589+
return getDiscriminatorForString(IGM, Out.str());
595590
}
596591

597-
static uint64_t getYieldTypesHash(IRGenModule &IGM, CanSILFunctionType type) {
592+
static llvm::ConstantInt *
593+
getCoroutineYieldTypesDiscriminator(IRGenModule &IGM, CanSILFunctionType type) {
598594
SmallString<32> buffer;
599595
llvm::raw_svector_ostream out(buffer);
600596
auto genericSig = type->getInvocationGenericSignature();
@@ -630,7 +626,7 @@ static uint64_t getYieldTypesHash(IRGenModule &IGM, CanSILFunctionType type) {
630626
out << ":";
631627
}
632628

633-
return llvm::getPointerAuthStableSipHash(out.str());
629+
return getDiscriminatorForString(IGM, out.str());
634630
}
635631

636632
llvm::ConstantInt *
@@ -650,8 +646,7 @@ PointerAuthEntity::getTypeDiscriminator(IRGenModule &IGM) const {
650646
llvm::ConstantInt *&cache = IGM.getPointerAuthCaches().Types[fnType];
651647
if (cache) return cache;
652648

653-
auto hash = getTypeHash(IGM, fnType);
654-
cache = getDiscriminatorForHash(IGM, hash);
649+
cache = ::getTypeDiscriminator(IGM, fnType);
655650
return cache;
656651
}
657652

@@ -668,15 +663,6 @@ PointerAuthEntity::getTypeDiscriminator(IRGenModule &IGM) const {
668663
llvm_unreachable("invalid representation");
669664
};
670665

671-
auto getCoroutineYieldTypesDiscriminator = [&](CanSILFunctionType fnType) {
672-
llvm::ConstantInt *&cache = IGM.getPointerAuthCaches().Types[fnType];
673-
if (cache) return cache;
674-
675-
auto hash = getYieldTypesHash(IGM, fnType);
676-
cache = getDiscriminatorForHash(IGM, hash);
677-
return cache;
678-
};
679-
680666
switch (StoredKind) {
681667
case Kind::None:
682668
case Kind::Special:
@@ -688,7 +674,13 @@ PointerAuthEntity::getTypeDiscriminator(IRGenModule &IGM) const {
688674

689675
case Kind::CoroutineYieldTypes: {
690676
auto fnType = Storage.get<CanSILFunctionType>(StoredKind);
691-
return getCoroutineYieldTypesDiscriminator(fnType);
677+
678+
llvm::ConstantInt *&cache = IGM.getPointerAuthCaches().Types[fnType];
679+
if (cache)
680+
return cache;
681+
682+
cache = getCoroutineYieldTypesDiscriminator(IGM, fnType);
683+
return cache;
692684
}
693685

694686
case Kind::CanSILFunctionType: {

0 commit comments

Comments
 (0)