Skip to content

Commit e3be7a5

Browse files
committed
[CodeGen] Don't re-sign null member function pointers
rdar://86731786
1 parent 4358955 commit e3be7a5

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,16 @@ ItaniumCXXABI::EmitMemberPointerConversion(const CastExpr *E,
10171017
QualType srcType = E->getSubExpr()->getType();
10181018
const auto &curAuthInfo = CGM.getMemberFunctionPointerAuthInfo(srcType);
10191019
llvm::Constant *memFnPtr = llvm::ConstantExpr::getExtractValue(src, 0);
1020-
llvm::Constant *constPtr =
1021-
pointerAuthResignConstant(cast<llvm::User>(memFnPtr)->getOperand(0),
1022-
curAuthInfo, newAuthInfo, CGM);
1023-
constPtr = llvm::ConstantExpr::getPtrToInt(constPtr, memFnPtr->getType());
1024-
src = llvm::ConstantExpr::getInsertValue(src, constPtr, 0);
1020+
if (memFnPtr->getNumOperands() == 0) {
1021+
// src must be a pair of null pointers.
1022+
assert(isa<llvm::ConstantInt>(memFnPtr) && "constant int expected");
1023+
} else {
1024+
llvm::Constant *constPtr = pointerAuthResignConstant(
1025+
memFnPtr->getOperand(0), curAuthInfo, newAuthInfo, CGM);
1026+
constPtr =
1027+
llvm::ConstantExpr::getPtrToInt(constPtr, memFnPtr->getType());
1028+
src = llvm::ConstantExpr::getInsertValue(src, constPtr, 0);
1029+
}
10251030
}
10261031

10271032
// Under Itanium, reinterprets don't require any additional processing.

clang/test/CodeGenCXX/ptrauth-member-function-pointer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,11 @@ void test_builtin_ptrauth_type_discriminator() {
386386
MethodTy1 gmethod0 = reinterpret_cast<MethodTy1>(&Base0::nonvirtual0);
387387
MethodTy0 gmethod1 = reinterpret_cast<MethodTy0>(&Derived0::nonvirtual5);
388388
MethodTy0 gmethod2 = reinterpret_cast<MethodTy0>(&Derived0::virtual1);
389+
390+
// CHECK: define void @_Z15testConvertNullv(
391+
// CHECK: %[[T:.*]] = alloca { i64, i64 },
392+
// store { i64, i64 } zeroinitializer, { i64, i64 }* %[[T]],
393+
394+
void testConvertNull() {
395+
VariadicMethodTy0 t = (VariadicMethodTy0)(MethodTy0{});
396+
}

0 commit comments

Comments
 (0)