This revision was automatically updated to reflect the committed changes. Closed by commit rG2cea4c239570: Do not suggest taking the address of a const pointer to get void* (authored by krsch, committed by dblaikie).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D138426/new/ 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,25 @@ u(c); } +void accept_void(void*); + +void issue58958(const char* a, volatile char * v, const volatile char * cv) { +// CHECK: no matching function for call to 'accept_void' +// CHECK-NOT: take the address of the argument with & + accept_void(a); +// CHECK: no matching function for call to 'accept_void' +// CHECK-NOT: take the address of the argument with & + accept_void(v); +// CHECK: no matching function for call to 'accept_void' +// CHECK-NOT: take the address of the argument with & + accept_void(cv); + char b; +// CHECK: no matching function for call to 'accept_void' +// CHECK: take the address of the argument with & + accept_void(b); +// CHECK-NOT: no matching function for call to 'accept_void' +// CHECK-NOT: 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 @@ -124,7 +124,7 @@ // Check if the pointer to the argument needs to be passed: // (type -> type *) or (type & -> type *). - if (isa<PointerType>(ToQTy)) { + if (const auto *ToPtrTy = dyn_cast<PointerType>(ToQTy)) { bool CanConvert = false; OverloadFixItKind FixKind = OFIK_TakeAddress; @@ -132,6 +132,10 @@ if (!Expr->isLValue() || Expr->getObjectKind() != OK_Ordinary) return false; + // Do no take address of const pointer to get void* + if (isa<PointerType>(FromQTy) && ToPtrTy->isVoidPointerType()) + return false; + CanConvert = CompareTypes(S.Context.getPointerType(FromQTy), ToQTy, S, Begin, VK_PRValue); if (CanConvert) {
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,25 @@ u(c); } +void accept_void(void*); + +void issue58958(const char* a, volatile char * v, const volatile char * cv) { +// CHECK: no matching function for call to 'accept_void' +// CHECK-NOT: take the address of the argument with & + accept_void(a); +// CHECK: no matching function for call to 'accept_void' +// CHECK-NOT: take the address of the argument with & + accept_void(v); +// CHECK: no matching function for call to 'accept_void' +// CHECK-NOT: take the address of the argument with & + accept_void(cv); + char b; +// CHECK: no matching function for call to 'accept_void' +// CHECK: take the address of the argument with & + accept_void(b); +// CHECK-NOT: no matching function for call to 'accept_void' +// CHECK-NOT: 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 @@ -124,7 +124,7 @@ // Check if the pointer to the argument needs to be passed: // (type -> type *) or (type & -> type *). - if (isa<PointerType>(ToQTy)) { + if (const auto *ToPtrTy = dyn_cast<PointerType>(ToQTy)) { bool CanConvert = false; OverloadFixItKind FixKind = OFIK_TakeAddress; @@ -132,6 +132,10 @@ if (!Expr->isLValue() || Expr->getObjectKind() != OK_Ordinary) return false; + // Do no take address of const pointer to get void* + if (isa<PointerType>(FromQTy) && ToPtrTy->isVoidPointerType()) + return false; + CanConvert = CompareTypes(S.Context.getPointerType(FromQTy), ToQTy, S, Begin, VK_PRValue); if (CanConvert) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits