Skip to content

Commit 93ecb2b

Browse files
authored
[CodeGen] Don't re-sign null member function pointers (#4131)
rdar://86731786 (cherry picked from commit e3be7a5)
1 parent adaddb9 commit 93ecb2b

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
@@ -1070,11 +1070,16 @@ ItaniumCXXABI::EmitMemberPointerConversion(const CastExpr *E,
10701070
QualType srcType = E->getSubExpr()->getType();
10711071
const auto &curAuthInfo = CGM.getMemberFunctionPointerAuthInfo(srcType);
10721072
llvm::Constant *memFnPtr = llvm::ConstantExpr::getExtractValue(src, 0);
1073-
llvm::Constant *constPtr =
1074-
pointerAuthResignConstant(cast<llvm::User>(memFnPtr)->getOperand(0),
1075-
curAuthInfo, newAuthInfo, CGM);
1076-
constPtr = llvm::ConstantExpr::getPtrToInt(constPtr, memFnPtr->getType());
1077-
src = llvm::ConstantExpr::getInsertValue(src, constPtr, 0);
1073+
if (memFnPtr->getNumOperands() == 0) {
1074+
// src must be a pair of null pointers.
1075+
assert(isa<llvm::ConstantInt>(memFnPtr) && "constant int expected");
1076+
} else {
1077+
llvm::Constant *constPtr = pointerAuthResignConstant(
1078+
memFnPtr->getOperand(0), curAuthInfo, newAuthInfo, CGM);
1079+
constPtr =
1080+
llvm::ConstantExpr::getPtrToInt(constPtr, memFnPtr->getType());
1081+
src = llvm::ConstantExpr::getInsertValue(src, constPtr, 0);
1082+
}
10781083
}
10791084

10801085
// 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)