[PATCH] D138426: Fix #58958 on github

Alexey Kreshchuk via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 21 06:13:44 PST 2022


krsch created this revision.
krsch added reviewers: NoQ, xazax.hun.
Herald added a subscriber: rnkovacs.
Herald added a project: All.
krsch requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Do not suggest to take the address of a const pointer to get void*


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138426

Files:
  clang/lib/Sema/SemaFixItUtils.cpp
  clang/test/FixIt/fixit-function-call.cpp


Index: clang/test/FixIt/fixit-function-call.cpp
===================================================================
--- clang/test/FixIt/fixit-function-call.cpp
+++ clang/test/FixIt/fixit-function-call.cpp
@@ -115,4 +115,16 @@
   u(c);
 }
 
+void accept_void(void*);
+
+void issue58958(const char* a) {
+// CHECK: no matching function for call to 'accept_void'
+// CHECK-NOT: take the address of the argument with &
+    accept_void(a);
+    char b;
+// CHECK: no matching function for call to 'accept_void'
+// CHECK: take the address of the argument with &
+    accept_void(b);
+}
+
 // CHECK: errors generated
Index: clang/lib/Sema/SemaFixItUtils.cpp
===================================================================
--- clang/lib/Sema/SemaFixItUtils.cpp
+++ clang/lib/Sema/SemaFixItUtils.cpp
@@ -132,6 +132,13 @@
     if (!Expr->isLValue() || Expr->getObjectKind() != OK_Ordinary)
       return false;
 
+    // Do no take address of const pointer to get void*
+    const PointerType *FromPtrTy = dyn_cast<PointerType>(FromQTy);
+    const PointerType *ToPtrTy = dyn_cast<PointerType>(ToQTy);
+    if (FromPtrTy && FromPtrTy->getPointeeType().isConstQualified() &&
+        ToPtrTy->isVoidPointerType())
+      return false;
+
     CanConvert = CompareTypes(S.Context.getPointerType(FromQTy), ToQTy, S,
                               Begin, VK_PRValue);
     if (CanConvert) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138426.476875.patch
Type: text/x-patch
Size: 1383 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221121/0c9ffb09/attachment.bin>


More information about the cfe-commits mailing list