|
20 | 20 | #include "BitPatternBuilder.h" |
21 | 21 | #include "ExtraInhabitants.h" |
22 | 22 | #include "GenCall.h" |
| 23 | +#include "GenPointerAuth.h" |
23 | 24 | #include "GenProto.h" |
24 | 25 | #include "GenType.h" |
25 | 26 | #include "IRGenDebugInfo.h" |
@@ -584,22 +585,50 @@ struct EmbeddedSwiftResultTypeOptionRecordTraits { |
584 | 585 | IGF.Builder.CreateStore( |
585 | 586 | TI.getStaticAlignmentMask(IGF.IGM), |
586 | 587 | IGF.Builder.CreateStructGEP(optionsRecord, 2, Size())); |
| 588 | + |
| 589 | + auto schema = IGF.getOptions().PointerAuth.ValueWitnesses; |
587 | 590 | // initializeWithCopy witness |
588 | | - IGF.Builder.CreateStore( |
589 | | - IGF.IGM.getOrCreateValueWitnessFunction( |
590 | | - ValueWitness::InitializeWithCopy, packing, canType, lowered, TI), |
591 | | - IGF.Builder.CreateStructGEP(optionsRecord, 3, Size())); |
| 591 | + { |
| 592 | + auto gep = IGF.Builder.CreateStructGEP(optionsRecord, 3, Size()); |
| 593 | + llvm::Value *witness = IGF.IGM.getOrCreateValueWitnessFunction( |
| 594 | + ValueWitness::InitializeWithCopy, packing, canType, lowered, TI); |
| 595 | + auto discriminator = llvm::ConstantInt::get( |
| 596 | + IGF.IGM.Int64Ty, |
| 597 | + SpecialPointerAuthDiscriminators::InitializeWithCopy); |
| 598 | + auto storageAddress = gep.getAddress(); |
| 599 | + auto info = |
| 600 | + PointerAuthInfo::emit(IGF, schema, storageAddress, discriminator); |
| 601 | + if (schema) witness = emitPointerAuthSign(IGF, witness, info); |
| 602 | + IGF.Builder.CreateStore(witness, gep); |
| 603 | + } |
592 | 604 | // storeEnumTagSinglePayload witness |
593 | | - IGF.Builder.CreateStore( |
594 | | - IGF.IGM.getOrCreateValueWitnessFunction( |
595 | | - ValueWitness::StoreEnumTagSinglePayload, packing, canType, lowered, |
596 | | - TI), |
597 | | - IGF.Builder.CreateStructGEP(optionsRecord, 4, Size())); |
| 605 | + { |
| 606 | + auto gep = IGF.Builder.CreateStructGEP(optionsRecord, 4, Size()); |
| 607 | + llvm::Value *witness = IGF.IGM.getOrCreateValueWitnessFunction( |
| 608 | + ValueWitness::StoreEnumTagSinglePayload, packing, canType, lowered, |
| 609 | + TI); |
| 610 | + auto discriminator = llvm::ConstantInt::get( |
| 611 | + IGF.IGM.Int64Ty, |
| 612 | + SpecialPointerAuthDiscriminators::StoreEnumTagSinglePayload); |
| 613 | + auto storageAddress = gep.getAddress(); |
| 614 | + auto info = |
| 615 | + PointerAuthInfo::emit(IGF, schema, storageAddress, discriminator); |
| 616 | + if (schema) witness = emitPointerAuthSign(IGF, witness, info); |
| 617 | + IGF.Builder.CreateStore(witness, gep); |
| 618 | + } |
598 | 619 | // destroy witness |
599 | | - IGF.Builder.CreateStore( |
600 | | - IGF.IGM.getOrCreateValueWitnessFunction(ValueWitness::Destroy, packing, |
601 | | - canType, lowered, TI), |
602 | | - IGF.Builder.CreateStructGEP(optionsRecord, 5, Size())); |
| 620 | + { |
| 621 | + auto gep = IGF.Builder.CreateStructGEP(optionsRecord, 5, Size()); |
| 622 | + llvm::Value *witness = IGF.IGM.getOrCreateValueWitnessFunction( |
| 623 | + ValueWitness::Destroy, packing, canType, lowered, TI); |
| 624 | + auto discriminator = llvm::ConstantInt::get( |
| 625 | + IGF.IGM.Int64Ty, SpecialPointerAuthDiscriminators::Destroy); |
| 626 | + auto storageAddress = gep.getAddress(); |
| 627 | + auto info = |
| 628 | + PointerAuthInfo::emit(IGF, schema, storageAddress, discriminator); |
| 629 | + if (schema) witness = emitPointerAuthSign(IGF, witness, info); |
| 630 | + IGF.Builder.CreateStore(witness, gep); |
| 631 | + } |
603 | 632 | } |
604 | 633 | }; |
605 | 634 | } // end anonymous namespace |
|
0 commit comments