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/4] 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 e1ed66ae71243..10ca750426283 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/4] 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 08c7f0090220e..0897424a75e64 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 >From 7dab9303d28fa7cea3c09c8da8b735c10e987425 Mon Sep 17 00:00:00 2001 From: Ayaan Khan <[email protected]> Date: Thu, 1 Oct 2026 01:49:52 +0530 Subject: [PATCH 3/4] fix impl --- clang/lib/CodeGen/CGDecl.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 10ca750426283..35de80f55cbab 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -784,13 +784,11 @@ void CodeGenFunction::EmitNullabilityCheck(LValue LHS, llvm::Value *RHS, auto CheckHandler = SanitizerHandler::TypeMismatch; SanitizerDebugLocation SanScope(this, {CheckOrdinal}, CheckHandler); llvm::Value *IsNotNull; - if (RHS->getType()->isAggregateType()) { - const MemberPointerType *MPT = LHS.getType()->getAs<MemberPointerType>(); - assert(MPT && "Aggregate Type is not a Member Pointer Type"); + if (auto *MPT = LHS.getType()->getAs<MemberPointerType>()) IsNotNull = CGM.getCXXABI().EmitMemberPointerIsNotNull(*this, RHS, MPT); - } else { + else IsNotNull = Builder.CreateIsNotNull(RHS); - } + llvm::Constant *StaticData[] = { EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(LHS.getType()), llvm::ConstantInt::get(Int8Ty, 0), // The LogAlignment info is unused. >From 8c1496ee2bd4f395833a4168ee66145728577d3d Mon Sep 17 00:00:00 2001 From: Ayaan Khan <[email protected]> Date: Thu, 1 Oct 2026 10:20:24 +0530 Subject: [PATCH 4/4] test for -1 --- clang/test/CodeGenCXX/ubsan-nullability-assign.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clang/test/CodeGenCXX/ubsan-nullability-assign.cpp b/clang/test/CodeGenCXX/ubsan-nullability-assign.cpp index 0897424a75e64..4b31b5c54c26a 100644 --- a/clang/test/CodeGenCXX/ubsan-nullability-assign.cpp +++ b/clang/test/CodeGenCXX/ubsan-nullability-assign.cpp @@ -42,6 +42,16 @@ void f1(int *p) { // CHECK: store MemberPtr _Nonnull nqptr = nullptr; + // CHECK: br i1 true, label %cont{{.*}}, !nosanitize + // CHECK: call void @__ubsan_handle_type_mismatch{{.*}} !nosanitize + // CHECK: store + int* S1::* _Nonnull pptr = &S1::p; + + // CHECK: br i1 false, label %cont{{.*}}, !nosanitize + // CHECK: call void @__ubsan_handle_type_mismatch{{.*}} !nosanitize + // CHECK: store + int* S1::* _Nonnull npptr = 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
