Skip to content

Commit 908424a

Browse files
authored
[CIR] Fix assertion in CIRGenTypes::isFuncParamTypeConvertible (#1487)
This PR resolves an assertion failure in `CIRGenTypes::isFuncParamTypeConvertible`, which is involved when trying to emit a vtable entry to a virtual function whose type includes a pointer-to-member-function.
1 parent 15bf54a commit 908424a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenCXXABI.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ class CIRGenCXXABI {
273273
/// (in the C++ sense) with an LLVM zeroinitializer.
274274
virtual bool isZeroInitializable(const MemberPointerType *MPT);
275275

276+
/// Return whether or not a member pointers type is convertible to an IR type.
277+
virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const {
278+
return true;
279+
}
280+
276281
/// Gets the offsets of all the virtual base pointers in a given class.
277282
virtual std::vector<CharUnits> getVBPtrOffsets(const CXXRecordDecl *RD);
278283

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ mlir::Type CIRGenTypes::convertFunctionTypeInternal(QualType QFT) {
313313
bool CIRGenTypes::isFuncParamTypeConvertible(clang::QualType Ty) {
314314
// Some ABIs cannot have their member pointers represented in LLVM IR unless
315315
// certain circumstances have been reached.
316-
assert(!Ty->getAs<MemberPointerType>() && "NYI");
316+
if (const auto *mpt = Ty->getAs<MemberPointerType>())
317+
return getCXXABI().isMemberPointerConvertible(mpt);
317318

318319
// If this isn't a tagged type, we can convert it!
319320
const TagType *TT = Ty->getAs<TagType>();

clang/test/CIR/CodeGen/pointer-to-member-func.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,11 @@ Base2MemFunc derived_to_base(DerivedMemFunc ptr) {
232232
// LLVM-NEXT: %[[#adj:]] = extractvalue { i64, i64 } %[[#arg]], 1
233233
// LLVM-NEXT: %[[#adj_adj:]] = sub i64 %[[#adj]], 16
234234
// LLVM-NEXT: %{{.+}} = insertvalue { i64, i64 } %[[#arg]], i64 %[[#adj_adj]], 1
235+
236+
struct HasVTable {
237+
virtual void test(void (Foo::*)());
238+
};
239+
240+
// Ensure that the vfunc pointer to the function involving a pointer-to-member-
241+
// func could be emitted.
242+
void HasVTable::test(void (Foo::*)()) {}

0 commit comments

Comments
 (0)