@@ -1193,16 +1193,23 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
1193
1193
ivarAddr = ivarAddr.withElementType (bitcastType);
1194
1194
llvm::LoadInst *load = Builder.CreateLoad (ivarAddr, " load" );
1195
1195
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
+ }
1196
1204
1197
1205
// Store that value into the return address. Doing this with a
1198
1206
// bitcast is likely to produce some pretty ugly IR, but it's not
1199
1207
// the *most* terrible thing in the world.
1200
1208
llvm::Type *retTy = ConvertType (getterMethod->getReturnType ());
1201
1209
uint64_t retTySize = CGM.getDataLayout ().getTypeSizeInBits (retTy);
1202
- llvm::Value *ivarVal = load;
1203
1210
if (ivarSize > retTySize) {
1204
1211
bitcastType = llvm::Type::getIntNTy (getLLVMContext (), retTySize);
1205
- ivarVal = Builder.CreateTrunc (load , bitcastType);
1212
+ ivarVal = Builder.CreateTrunc (ivarVal , bitcastType);
1206
1213
}
1207
1214
Builder.CreateStore (ivarVal, ReturnValue.withElementType (bitcastType));
1208
1215
@@ -1214,6 +1221,16 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
1214
1221
case PropertyImplStrategy::GetSetProperty: {
1215
1222
llvm::FunctionCallee getPropertyFn =
1216
1223
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
+
1217
1234
if (!getPropertyFn) {
1218
1235
CGM.ErrorUnsupported (propImpl, " Obj-C getter requiring atomic copy" );
1219
1236
return ;
@@ -1269,7 +1286,9 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
1269
1286
LValue LV = EmitLValueForIvar (TypeOfSelfObject (), LoadObjCSelf (), ivar, 0 );
1270
1287
1271
1288
QualType ivarType = ivar->getType ();
1272
- switch (getEvaluationKind (ivarType)) {
1289
+ auto EvaluationKind = getEvaluationKind (ivarType);
1290
+ assert (!ivarType.getPointerAuth () || EvaluationKind == TEK_Scalar);
1291
+ switch (EvaluationKind) {
1273
1292
case TEK_Complex: {
1274
1293
ComplexPairTy pair = EmitLoadOfComplex (LV, SourceLocation ());
1275
1294
EmitStoreOfComplex (pair, MakeAddrLValue (ReturnValue, ivarType),
@@ -1287,6 +1306,11 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
1287
1306
case TEK_Scalar: {
1288
1307
llvm::Value *value;
1289
1308
if (propType->isReferenceType ()) {
1309
+ if (ivarType.getPointerAuth ()) {
1310
+ CGM.ErrorUnsupported (propImpl,
1311
+ " Obj-C getter for authenticated reference type" );
1312
+ return ;
1313
+ }
1290
1314
value = LV.getAddress ().emitRawPointer (*this );
1291
1315
} else {
1292
1316
// We want to load and autoreleaseReturnValue ARC __weak ivars.
@@ -1300,7 +1324,19 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl,
1300
1324
// Otherwise we want to do a simple load, suppressing the
1301
1325
// final autorelease.
1302
1326
} 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
+
1304
1340
AutoreleaseResult = false ;
1305
1341
}
1306
1342
@@ -1490,6 +1526,14 @@ CodeGenFunction::generateObjCSetterBody(const ObjCImplementationDecl *classImpl,
1490
1526
1491
1527
llvm::Value *load = Builder.CreateLoad (argAddr);
1492
1528
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
+
1493
1537
// Perform an atomic store. There are no memory ordering requirements.
1494
1538
llvm::StoreInst *store = Builder.CreateStore (load, ivarAddr);
1495
1539
store->setAtomic (llvm::AtomicOrdering::Unordered);
0 commit comments