@@ -1193,16 +1193,23 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
11931193 ivarAddr = ivarAddr.withElementType (bitcastType);
11941194 llvm::LoadInst *load = Builder.CreateLoad (ivarAddr, " load" );
11951195 load->setAtomic (llvm::AtomicOrdering::Unordered);
1196+ llvm::Value *ivarVal = load;
1197+ if (PointerAuthQualifier PAQ = ivar->getType ().getPointerAuth ()) {
1198+ CGPointerAuthInfo SrcInfo = EmitPointerAuthInfo (PAQ, ivarAddr);
1199+ CGPointerAuthInfo TargetInfo =
1200+ CGM.getPointerAuthInfoForType (getterMethod->getReturnType ());
1201+ ivarVal = emitPointerAuthResign (ivarVal, ivar->getType (), SrcInfo,
1202+ TargetInfo, /* isKnownNonNull=*/ false );
1203+ }
11961204
11971205 // Store that value into the return address. Doing this with a
11981206 // bitcast is likely to produce some pretty ugly IR, but it's not
11991207 // the *most* terrible thing in the world.
12001208 llvm::Type *retTy = ConvertType (getterMethod->getReturnType ());
12011209 uint64_t retTySize = CGM.getDataLayout ().getTypeSizeInBits (retTy);
1202- llvm::Value *ivarVal = load;
12031210 if (ivarSize > retTySize) {
12041211 bitcastType = llvm::Type::getIntNTy (getLLVMContext (), retTySize);
1205- ivarVal = Builder.CreateTrunc (load , bitcastType);
1212+ ivarVal = Builder.CreateTrunc (ivarVal , bitcastType);
12061213 }
12071214 Builder.CreateStore (ivarVal, ReturnValue.withElementType (bitcastType));
12081215
@@ -1214,6 +1221,16 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
12141221 case PropertyImplStrategy::GetSetProperty: {
12151222 llvm::FunctionCallee getPropertyFn =
12161223 CGM.getObjCRuntime ().GetPropertyGetFunction ();
1224+
1225+ if (ivar->getType ().getPointerAuth ()) {
1226+ // This currently cannot be hit, but if we ever allow objc pointers
1227+ // to be signed, this will become possible. Reaching here would require
1228+ // a copy, weak, etc property backed by an authenticated pointer.
1229+ CGM.ErrorUnsupported (propImpl,
1230+ " Obj-C getter requiring pointer authentication" );
1231+ return ;
1232+ }
1233+
12171234 if (!getPropertyFn) {
12181235 CGM.ErrorUnsupported (propImpl, " Obj-C getter requiring atomic copy" );
12191236 return ;
@@ -1269,7 +1286,9 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
12691286 LValue LV = EmitLValueForIvar (TypeOfSelfObject (), LoadObjCSelf (), ivar, 0 );
12701287
12711288 QualType ivarType = ivar->getType ();
1272- switch (getEvaluationKind (ivarType)) {
1289+ auto EvaluationKind = getEvaluationKind (ivarType);
1290+ assert (!ivarType.getPointerAuth () || EvaluationKind == TEK_Scalar);
1291+ switch (EvaluationKind) {
12731292 case TEK_Complex: {
12741293 ComplexPairTy pair = EmitLoadOfComplex (LV, SourceLocation ());
12751294 EmitStoreOfComplex (pair, MakeAddrLValue (ReturnValue, ivarType),
@@ -1287,6 +1306,11 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
12871306 case TEK_Scalar: {
12881307 llvm::Value *value;
12891308 if (propType->isReferenceType ()) {
1309+ if (ivarType.getPointerAuth ()) {
1310+ CGM.ErrorUnsupported (propImpl,
1311+ " Obj-C getter for authenticated reference type" );
1312+ return ;
1313+ }
12901314 value = LV.getAddress ().emitRawPointer (*this );
12911315 } else {
12921316 // We want to load and autoreleaseReturnValue ARC __weak ivars.
@@ -1300,7 +1324,19 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
13001324 // Otherwise we want to do a simple load, suppressing the
13011325 // final autorelease.
13021326 } else {
1303- value = EmitLoadOfLValue (LV, SourceLocation ()).getScalarVal ();
1327+ if (PointerAuthQualifier PAQ = ivar->getType ().getPointerAuth ()) {
1328+ Address ivarAddr = LV.getAddress ();
1329+ llvm::LoadInst *LoadInst = Builder.CreateLoad (ivarAddr, " load" );
1330+ llvm::Value *Load = LoadInst;
1331+ auto SrcInfo = EmitPointerAuthInfo (PAQ, ivarAddr);
1332+ auto TargetInfo =
1333+ CGM.getPointerAuthInfoForType (getterMethod->getReturnType ());
1334+ Load = emitPointerAuthResign (Load, ivarType, SrcInfo, TargetInfo,
1335+ /* isKnownNonNull=*/ false );
1336+ value = Load;
1337+ } else
1338+ value = EmitLoadOfLValue (LV, SourceLocation ()).getScalarVal ();
1339+
13041340 AutoreleaseResult = false ;
13051341 }
13061342
@@ -1490,6 +1526,14 @@ CodeGenFunction::generateObjCSetterBody(const ObjCImplementationDecl *classImpl,
14901526
14911527 llvm::Value *load = Builder.CreateLoad (argAddr);
14921528
1529+ if (PointerAuthQualifier PAQ = ivar->getType ().getPointerAuth ()) {
1530+ QualType PropertyType = propImpl->getPropertyDecl ()->getType ();
1531+ CGPointerAuthInfo SrcInfo = CGM.getPointerAuthInfoForType (PropertyType);
1532+ CGPointerAuthInfo TargetInfo = EmitPointerAuthInfo (PAQ, ivarAddr);
1533+ load = emitPointerAuthResign (load, ivar->getType (), SrcInfo, TargetInfo,
1534+ /* isKnownNonNull=*/ false );
1535+ }
1536+
14931537 // Perform an atomic store. There are no memory ordering requirements.
14941538 llvm::StoreInst *store = Builder.CreateStore (load, ivarAddr);
14951539 store->setAtomic (llvm::AtomicOrdering::Unordered);
0 commit comments