[clang-tools-extra] [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (PR #90566)

2024-05-01 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/90566
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (PR #90566)

2024-05-01 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/90566
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (PR #90566)

2024-04-30 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.


https://github.com/llvm/llvm-project/pull/90566
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (PR #90566)

2024-04-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Improved bugprone-casting-through-void check by ignoring casts where source is 
already a void pointer, making middle void pointer casts bug-free.

Closes #87069

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp 
(+2-3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp 
(+7) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
index 4c2416a89aef9b..9e714b4be4dfea 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
@@ -7,12 +7,10 @@
 
//===--===//
 
 #include "CastingThroughVoidCheck.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Type.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "llvm/ADT/StringSet.h"
 
 using namespace clang::ast_matchers;
 
@@ -27,7 +25,8 @@ void CastingThroughVoidCheck::registerMatchers(MatchFinder 
*Finder) {
   hasSourceExpression(
   explicitCastExpr(
   hasSourceExpression(
-  expr(hasType(qualType().bind("source_type",
+  expr(hasType(qualType(unless(pointsTo(voidType(
+   .bind("source_type",
   hasDestinationType(
   qualType(pointsTo(voidType())).bind("void_type")))
   .bind("cast"))),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3038d2b125f20d..9eba64b45629f4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -173,6 +173,11 @@ Changes in existing checks
   ` check by detecting side
   effect from calling a method with non-const reference parameters.
 
+- Improved :doc:`bugprone-casting-through-void
+  ` check by ignoring casts
+  where source is already a ``void``` pointer, making middle ``void`` pointer
+  casts bug-free.
+
 - Improved :doc:`bugprone-forwarding-reference-overload
   `
   check to ignore deleted constructors which won't hide other overloads.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
index 3913d2d8a295c7..a784e498858738 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
@@ -89,3 +89,10 @@ void bit_cast() {
   __builtin_bit_cast(int *, static_cast());
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not cast 'double *' to 'int 
*' through 'void *' [bugprone-casting-through-void]
 }
+
+namespace PR87069 {
+  void castconstVoidToVoid() {
+const void* ptr = nullptr;
+int* numberPtr = static_cast(const_cast(ptr));
+  }
+}

``




https://github.com/llvm/llvm-project/pull/90566
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Ignore casts from void to void in bugprone-casting-through-void (PR #90566)

2024-04-30 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/90566

Improved bugprone-casting-through-void check by ignoring casts where source is 
already a void pointer, making middle void pointer casts bug-free.

Closes #87069

>From f516abcfbcb0a9bca13a416b73b0d59bb144bbbf Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 30 Apr 2024 06:20:17 +
Subject: [PATCH] [clang-tidy] Ignore casts from void to void in
 bugprone-casting-through-void

Improved bugprone-casting-through-void check by ignoring casts
where source is already a void pointer, making middle void pointer
casts bug-free.

Closes #87069
---
 .../clang-tidy/bugprone/CastingThroughVoidCheck.cpp| 5 ++---
 clang-tools-extra/docs/ReleaseNotes.rst| 5 +
 .../clang-tidy/checkers/bugprone/casting-through-void.cpp  | 7 +++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
index 4c2416a89aef9b..9e714b4be4dfea 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.cpp
@@ -7,12 +7,10 @@
 
//===--===//
 
 #include "CastingThroughVoidCheck.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Type.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "llvm/ADT/StringSet.h"
 
 using namespace clang::ast_matchers;
 
@@ -27,7 +25,8 @@ void CastingThroughVoidCheck::registerMatchers(MatchFinder 
*Finder) {
   hasSourceExpression(
   explicitCastExpr(
   hasSourceExpression(
-  expr(hasType(qualType().bind("source_type",
+  expr(hasType(qualType(unless(pointsTo(voidType(
+   .bind("source_type",
   hasDestinationType(
   qualType(pointsTo(voidType())).bind("void_type")))
   .bind("cast"))),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3038d2b125f20d..9eba64b45629f4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -173,6 +173,11 @@ Changes in existing checks
   ` check by detecting side
   effect from calling a method with non-const reference parameters.
 
+- Improved :doc:`bugprone-casting-through-void
+  ` check by ignoring casts
+  where source is already a ``void``` pointer, making middle ``void`` pointer
+  casts bug-free.
+
 - Improved :doc:`bugprone-forwarding-reference-overload
   `
   check to ignore deleted constructors which won't hide other overloads.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
index 3913d2d8a295c7..a784e498858738 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.cpp
@@ -89,3 +89,10 @@ void bit_cast() {
   __builtin_bit_cast(int *, static_cast());
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: do not cast 'double *' to 'int 
*' through 'void *' [bugprone-casting-through-void]
 }
+
+namespace PR87069 {
+  void castconstVoidToVoid() {
+const void* ptr = nullptr;
+int* numberPtr = static_cast(const_cast(ptr));
+  }
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits