llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: ayaan (def3r)

<details>
<summary>Changes</summary>

`CodeGenFunction::EmitNullabilityChecks` did not handle member pointer checks 
correctly. Use `EmitMemberPointerIsNotNull` in case of aggregate instead of 
`icmp ne` check used for ptrs.

closes #<!-- -->224434 

---
Full diff: https://github.com/llvm/llvm-project/pull/227738.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDecl.cpp (+8-1) 
- (modified) clang/test/CodeGenCXX/ubsan-nullability-assign.cpp (+13) 


``````````diff
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.
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/227738
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to