https://github.com/def3r updated https://github.com/llvm/llvm-project/pull/227738
>From 3e85ab54be07e16a7929131a1c556d50c4c9aaf9 Mon Sep 17 00:00:00 2001 From: Ayaan Khan <[email protected]> Date: Wed, 30 Sep 2026 19:56:15 +0530 Subject: [PATCH 1/2] emit member ptr not null check --- clang/lib/CodeGen/CGDecl.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index e1ed66ae71243e..10ca7504262834 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -783,7 +783,14 @@ void CodeGenFunction::EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, auto CheckOrdinal = SanitizerKind::SO_NullabilityAssign; auto CheckHandler = SanitizerHandler::TypeMismatch; SanitizerDebugLocation SanScope(this, {CheckOrdinal}, CheckHandler); - llvm::Value *IsNotNull = Builder.CreateIsNotNull(RHS); + llvm::Value *IsNotNull; + if (RHS->getType()->isAggregateType()) { + const MemberPointerType *MPT = LHS.getType()->getAs<MemberPointerType>(); + assert(MPT && "Aggregate Type is not a Member Pointer Type"); + IsNotNull = CGM.getCXXABI().EmitMemberPointerIsNotNull(*this, RHS, MPT); + } else { + IsNotNull = Builder.CreateIsNotNull(RHS); + } llvm::Constant *StaticData[] = { EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(LHS.getType()), llvm::ConstantInt::get(Int8Ty, 0), // The LogAlignment info is unused. >From 5a08ae381e989222e28ee29890c349e83c027bdf Mon Sep 17 00:00:00 2001 From: Ayaan Khan <[email protected]> Date: Thu, 1 Oct 2026 00:19:26 +0530 Subject: [PATCH 2/2] add test --- clang/test/CodeGenCXX/ubsan-nullability-assign.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clang/test/CodeGenCXX/ubsan-nullability-assign.cpp b/clang/test/CodeGenCXX/ubsan-nullability-assign.cpp index 08c7f0090220ee..0897424a75e643 100644 --- a/clang/test/CodeGenCXX/ubsan-nullability-assign.cpp +++ b/clang/test/CodeGenCXX/ubsan-nullability-assign.cpp @@ -2,6 +2,7 @@ struct S1 { int *_Nonnull p; + void q() {} }; struct S2 { @@ -29,6 +30,18 @@ void f1(int *p) { // CHECK: store u.s2.s1.p = p; + using MemberPtr = void (S1::*)(void); + + // CHECK: br i1 true, label %cont{{.*}}, !nosanitize + // CHECK: call void @__ubsan_handle_type_mismatch{{.*}} !nosanitize + // CHECK: store + MemberPtr _Nonnull qptr = &S1::q; + + // CHECK: br i1 false, label %cont{{.*}}, !nosanitize + // CHECK: call void @__ubsan_handle_type_mismatch{{.*}} !nosanitize + // CHECK: store + MemberPtr _Nonnull nqptr = nullptr; + // CHECK-NOT: __ubsan_handle_type_mismatch // CHECK-NOT: store // CHECK: ret void _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
