Skip to content

Commit 4a6c406

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.6-beta.1 [skip ci]
1 parent 4faebad commit 4a6c406

File tree

16 files changed

+278
-147
lines changed

16 files changed

+278
-147
lines changed

libcxx/include/__config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ typedef __char32_t char32_t;
490490
# define _LIBCPP_EXCEPTIONS_SIG e
491491
# endif
492492

493-
# if __has_feature(pointer_field_protection)
493+
# if __has_extension(pointer_field_protection)
494494
# define _LIBCPP_PFP_SIG p
495495
# else
496496
# define _LIBCPP_PFP_SIG
@@ -1275,7 +1275,7 @@ typedef __char32_t char32_t;
12751275
# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0
12761276
# endif
12771277

1278-
# if __has_feature(pointer_field_protection)
1278+
# if __has_extension(pointer_field_protection)
12791279
# define _LIBCPP_NO_PFP [[clang::no_field_protection]]
12801280
# else
12811281
# define _LIBCPP_NO_PFP

libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void unique_ptr_test() {
256256
ComparePrettyPrintToRegex(std::move(forty_two),
257257
R"(std::unique_ptr<int> containing = {__ptr_ = 0x[a-f0-9]+})");
258258

259-
#if !__has_feature(pointer_field_protection)
259+
#if !__has_extension(pointer_field_protection)
260260
// GDB doesn't know how to read PFP fields correctly yet.
261261
std::unique_ptr<int> this_is_null;
262262
ComparePrettyPrintToChars(std::move(this_is_null),
@@ -479,7 +479,7 @@ void vector_test() {
479479
"std::vector of length "
480480
"3, capacity 3 = {5, 6, 7}");
481481

482-
#if !__has_feature(pointer_field_protection)
482+
#if !__has_extension(pointer_field_protection)
483483
// GDB doesn't know how to read PFP fields correctly yet.
484484
std::vector<int, UncompressibleAllocator<int>> test3({7, 8});
485485
ComparePrettyPrintToChars(std::move(test3),
@@ -656,7 +656,7 @@ void shared_ptr_test() {
656656
test0,
657657
R"(std::shared_ptr<int> count [3\?], weak [0\?]( \(libc\+\+ missing debug info\))? containing = {__ptr_ = 0x[a-f0-9]+})");
658658

659-
#if !__has_feature(pointer_field_protection)
659+
#if !__has_extension(pointer_field_protection)
660660
// GDB doesn't know how to read PFP fields correctly yet.
661661
std::shared_ptr<const int> test3;
662662
ComparePrettyPrintToChars(test3, "std::shared_ptr is nullptr");

libcxx/test/libcxx/type_traits/is_trivially_relocatable.compile.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# include <locale>
2929
#endif
3030

31-
#if __has_feature(pointer_field_protection)
31+
#if __has_extension(pointer_field_protection)
3232
constexpr bool pfp_disabled = false;
3333
#else
3434
constexpr bool pfp_disabled = true;

libcxxabi/include/__cxxabi_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
#endif
111111

112112
#if defined(_LIBCXXABI_COMPILER_CLANG)
113-
# if __has_feature(pointer_field_protection)
113+
# if __has_extension(pointer_field_protection)
114114
# define _LIBCXXABI_NO_PFP [[clang::no_field_protection]]
115115
# else
116116
# define _LIBCXXABI_NO_PFP

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
11751175
<< " cannot be used against ifunc symbol '" << &sym << "'";
11761176
printLocation(diag, *sec, sym, offset);
11771177
} else {
1178-
part.relaDyn->addReloc({ctx.target->iRelativeRel, sec, offset,
1179-
DynamicReloc::AddendOnlyWithTargetVA, sym,
1180-
addend, R_ABS});
1178+
part.relaDyn->addReloc({ctx.target->iRelativeRel, sec, offset, false,
1179+
sym, addend, R_ABS});
11811180
return;
11821181
}
11831182
}

llvm/docs/LangRef.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31200,14 +31200,14 @@ third argument is 1). When loading from the pointer, the inverse operation
3120031200
is done on the loaded pointer after it is loaded. Specifically, when the
3120131201
third argument is 1, the pointer is signed (using pointer authentication
3120231202
instructions or emulated PAC if not supported by the hardware) using
31203-
the struct address before being stored, and authenticated after being
31203+
the discriminator before being stored, and authenticated after being
3120431204
loaded. Note that it is currently unsupported to have the third argument
3120531205
be 1 on targets other than AArch64. When the third argument is 0, it is
3120631206
rotated left by 16 bits and the discriminator is subtracted before being
3120731207
stored, and the discriminator is added and the pointer is rotated right
3120831208
by 16 bits after being loaded.
3120931209

31210-
If the pointer is used otherwise than for loading or storing (e.g. its
31210+
If the pointer is used other than for loading or storing (e.g. its
3121131211
address escapes), that will disable all blending operations using
3121231212
the deactivation symbol specified in the intrinsic's operand bundle.
3121331213
The deactivation symbol operand bundle is copied onto any sign and auth

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ LLVM_ABI bool EliminateDuplicatePHINodes(BasicBlock *BB);
182182
LLVM_ABI bool EliminateDuplicatePHINodes(BasicBlock *BB,
183183
SmallPtrSetImpl<PHINode *> &ToRemove);
184184

185-
/// Returns whether it is allowed and beneficial for optimizations to transform
186-
/// phi(load(ptr)) into load(phi(ptr)) or a similar transformation for stores.
187-
bool shouldFoldLoadStoreWithPointerOperandThroughPhi(const Value *Ptr);
185+
/// Returns whether it is allowed and beneficial for optimizations to fold this
186+
/// operand through a phi, for example when transforming phi(load(ptr)) into
187+
/// load(phi(ptr)).
188+
bool shouldFoldOperandThroughPhi(const Value *Ptr);
188189

189190
/// This function is used to do simplification of a CFG. For example, it
190191
/// adjusts branches to branches to eliminate the extra hop, it eliminates

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 40 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
#include "llvm/Transforms/Utils/LowerMemIntrinsics.h"
4040
#include "llvm/Transforms/Utils/LowerVectorIntrinsics.h"
4141

42-
#include <set>
43-
4442
using namespace llvm;
4543

4644
/// Threshold to leave statically sized memory intrinsic calls. Calls of known
@@ -476,8 +474,8 @@ enum class PointerEncoding {
476474
bool expandProtectedFieldPtr(Function &Intr) {
477475
Module &M = *Intr.getParent();
478476

479-
std::set<GlobalValue *> DSsToDeactivate;
480-
std::set<Instruction *> LoadsStores;
477+
SmallPtrSet<GlobalValue *, 2> DSsToDeactivate;
478+
SmallPtrSet<Instruction *, 2> LoadsStores;
481479

482480
Type *Int8Ty = Type::getInt8Ty(M.getContext());
483481
Type *Int64Ty = Type::getInt64Ty(M.getContext());
@@ -520,111 +518,75 @@ bool expandProtectedFieldPtr(Function &Intr) {
520518
for (User *U : Intr.users()) {
521519
auto *Call = cast<CallInst>(U);
522520
auto *DS = GetDeactivationSymbol(Call);
523-
std::set<PHINode *> VisitedPhis;
524-
525-
std::function<void(Instruction *)> FindLoadsStores;
526-
FindLoadsStores = [&](Instruction *I) {
527-
for (Use &U : I->uses()) {
528-
if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {
529-
if (isa<PointerType>(LI->getType())) {
530-
LoadsStores.insert(LI);
531-
continue;
532-
}
533-
}
534-
if (auto *SI = dyn_cast<StoreInst>(U.getUser())) {
535-
if (U.getOperandNo() == 1 &&
536-
isa<PointerType>(SI->getValueOperand()->getType())) {
537-
LoadsStores.insert(SI);
538-
continue;
539-
}
540-
}
541-
if (auto *P = dyn_cast<PHINode>(U.getUser())) {
542-
if (VisitedPhis.insert(P).second)
543-
FindLoadsStores(P);
521+
522+
for (Use &U : Call->uses()) {
523+
if (auto *LI = dyn_cast<LoadInst>(U.getUser())) {
524+
if (isa<PointerType>(LI->getType())) {
525+
LoadsStores.insert(LI);
544526
continue;
545527
}
546-
// Comparisons against null cannot be used to recover the original
547-
// pointer so we allow them.
548-
if (auto *CI = dyn_cast<ICmpInst>(U.getUser())) {
549-
if (auto *Op = dyn_cast<Constant>(CI->getOperand(0)))
550-
if (Op->isNullValue())
551-
continue;
552-
if (auto *Op = dyn_cast<Constant>(CI->getOperand(1)))
553-
if (Op->isNullValue())
554-
continue;
555-
}
556-
if (DS)
557-
DSsToDeactivate.insert(DS);
558528
}
559-
};
560-
561-
FindLoadsStores(Call);
562-
}
563-
564-
for (Instruction *I : LoadsStores) {
565-
std::set<Value *> Pointers;
566-
std::set<Value *> Discs;
567-
std::set<GlobalValue *> DSs;
568-
std::set<PHINode *> VisitedPhis;
569-
bool UseHWEncoding = false;
570-
571-
std::function<void(Value *)> FindFields;
572-
FindFields = [&](Value *V) {
573-
if (auto *Call = dyn_cast<CallInst>(V)) {
574-
if (Call->getCalledOperand() == &Intr) {
575-
Pointers.insert(Call->getArgOperand(0));
576-
Discs.insert(Call->getArgOperand(1));
577-
if (cast<ConstantInt>(Call->getArgOperand(2))->getZExtValue())
578-
UseHWEncoding = true;
579-
DSs.insert(GetDeactivationSymbol(Call));
580-
return;
529+
if (auto *SI = dyn_cast<StoreInst>(U.getUser())) {
530+
if (U.getOperandNo() == 1 &&
531+
isa<PointerType>(SI->getValueOperand()->getType())) {
532+
LoadsStores.insert(SI);
533+
continue;
581534
}
582535
}
583-
if (auto *P = dyn_cast<PHINode>(V)) {
584-
if (VisitedPhis.insert(P).second)
585-
for (Value *V : P->incoming_values())
586-
FindFields(V);
587-
return;
536+
// Comparisons against null cannot be used to recover the original
537+
// pointer so we allow them.
538+
if (auto *CI = dyn_cast<ICmpInst>(U.getUser())) {
539+
if (auto *Op = dyn_cast<Constant>(CI->getOperand(0)))
540+
if (Op->isNullValue())
541+
continue;
542+
if (auto *Op = dyn_cast<Constant>(CI->getOperand(1)))
543+
if (Op->isNullValue())
544+
continue;
588545
}
589-
Pointers.insert(nullptr);
590-
};
591-
FindFields(isa<StoreInst>(I) ? cast<StoreInst>(I)->getPointerOperand()
592-
: cast<LoadInst>(I)->getPointerOperand());
593-
if (Pointers.size() != 1 || Discs.size() != 1 || DSs.size() != 1) {
594-
for (GlobalValue *DS : DSs)
595-
if (DS)
596-
DSsToDeactivate.insert(DS);
597-
continue;
546+
if (DS)
547+
DSsToDeactivate.insert(DS);
598548
}
549+
}
550+
551+
for (Instruction *I : LoadsStores) {
552+
auto *PointerOperand = isa<StoreInst>(I)
553+
? cast<StoreInst>(I)->getPointerOperand()
554+
: cast<LoadInst>(I)->getPointerOperand();
555+
auto *Call = cast<CallInst>(PointerOperand);
556+
557+
auto *Disc = Call->getArgOperand(1);
558+
bool UseHWEncoding = cast<ConstantInt>(Call->getArgOperand(2))->getZExtValue();
599559

600-
GlobalValue *DS = *DSs.begin();
560+
GlobalValue *DS = GetDeactivationSymbol(Call);
601561
OperandBundleDef DSBundle("deactivation-symbol", DS);
602562

603563
if (auto *LI = dyn_cast<LoadInst>(I)) {
604564
IRBuilder<> B(LI->getNextNode());
605565
auto *LIInt = cast<Instruction>(B.CreatePtrToInt(LI, B.getInt64Ty()));
606566
Value *Auth;
607567
if (UseHWEncoding) {
608-
Auth = CreateAuth(B, LIInt, *Discs.begin(), DSBundle);
568+
Auth = CreateAuth(B, LIInt, Disc, DSBundle);
609569
} else {
610-
Auth = B.CreateAdd(LIInt, *Discs.begin());
570+
Auth = B.CreateAdd(LIInt, Disc);
611571
Auth = B.CreateIntrinsic(
612572
Auth->getType(), Intrinsic::fshr,
613573
{Auth, Auth, ConstantInt::get(Auth->getType(), 16)});
614574
}
615575
LI->replaceAllUsesWith(B.CreateIntToPtr(Auth, B.getPtrTy()));
616576
LIInt->setOperand(0, LI);
617-
} else if (auto *SI = dyn_cast<StoreInst>(I)) {
577+
} else {
578+
auto *SI = cast<StoreInst>(I);
618579
IRBuilder<> B(SI);
619580
auto *SIValInt =
620581
B.CreatePtrToInt(SI->getValueOperand(), B.getInt64Ty());
621582
Value *Sign;
622583
if (UseHWEncoding) {
623-
Sign = CreateSign(B, SIValInt, *Discs.begin(), DSBundle);
584+
Sign = CreateSign(B, SIValInt, Disc, DSBundle);
624585
} else {
625586
Sign = B.CreateIntrinsic(
626587
SIValInt->getType(), Intrinsic::fshl,
627588
{SIValInt, SIValInt, ConstantInt::get(SIValInt->getType(), 16)});
589+
Sign = B.CreateSub(Sign, Disc);
628590
}
629591
SI->setOperand(0, B.CreateIntToPtr(Sign, B.getPtrTy()));
630592
}

llvm/lib/IR/Verifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,11 @@ void Verifier::visitConstantPtrAuth(const ConstantPtrAuth *CPA) {
26272627

26282628
Check(CPA->getDiscriminator()->getBitWidth() == 64,
26292629
"signed ptrauth constant discriminator must be i64 constant integer");
2630+
2631+
Check(isa<GlobalValue>(CPA->getDeactivationSymbol()) ||
2632+
CPA->getDeactivationSymbol()->isNullValue(),
2633+
"signed ptrauth constant deactivation symbol must be a global value "
2634+
"or null");
26302635
}
26312636

26322637
bool Verifier::verifyAttributeCount(AttributeList Attrs, unsigned Params) {

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static bool isSafeAndProfitableToSinkLoad(LoadInst *L) {
697697
Instruction *InstCombinerImpl::foldPHIArgLoadIntoPHI(PHINode &PN) {
698698
LoadInst *FirstLI = cast<LoadInst>(PN.getIncomingValue(0));
699699

700-
if (!shouldFoldLoadStoreWithPointerOperandThroughPhi(FirstLI->getOperand(0)))
700+
if (!shouldFoldOperandThroughPhi(FirstLI->getOperand(0)))
701701
return nullptr;
702702

703703
// FIXME: This is overconservative; this transform is allowed in some cases
@@ -736,7 +736,7 @@ Instruction *InstCombinerImpl::foldPHIArgLoadIntoPHI(PHINode &PN) {
736736
LI->getPointerAddressSpace() != LoadAddrSpace)
737737
return nullptr;
738738

739-
if (!shouldFoldLoadStoreWithPointerOperandThroughPhi(LI->getOperand(0)))
739+
if (!shouldFoldOperandThroughPhi(LI->getOperand(0)))
740740
return nullptr;
741741

742742
// We can't sink the load if the loaded value could be modified between

0 commit comments

Comments
 (0)