================
@@ -122,17 +122,47 @@ void MemoryUnsafeCastChecker::checkASTCodeBody(const Decl
*D,
.bind(DerivedNode)))))),
unless(anyOf(hasSourceExpression(hasDescendant(cxxThisExpr())),
hasType(templateTypeParmDecl()))));
+ auto MatchExprPtrVoidCast = allOf(
+ anyOf(hasSourceExpression(explicitCastExpr(
+ hasType(pointerType(pointee(voidType()))),
+ hasSourceExpression(ignoringImpCasts(
+ hasTypePointingTo(cxxRecordDecl().bind(BaseNode)))))),
+ hasSourceExpression(
+ callExpr(hasType(pointerType(pointee(voidType()))),
+ hasAnyArgument(ignoringImpCasts(hasTypePointingTo(
+ cxxRecordDecl().bind(BaseNode))))))),
+ hasTypePointingTo(cxxRecordDecl(isDerivedFrom(equalsBoundNode(BaseNode)))
+ .bind(DerivedNode)));
- auto ExplicitCast = explicitCastExpr(anyOf(MatchExprPtr, MatchExprRefTypeDef,
- MatchExprPtrObjC))
- .bind(WarnRecordDecl);
+ auto ExplicitCast =
+ explicitCastExpr(anyOf(MatchExprPtr, MatchExprRefTypeDef,
+ MatchExprPtrObjC, MatchExprPtrVoidCast))
+ .bind(WarnRecordDecl);
auto Cast = stmt(ExplicitCast);
auto Matches =
match(stmt(forEachDescendant(Cast)), *D->getBody(), AM.getASTContext());
for (BoundNodes Match : Matches)
emitDiagnostics(Match, BR, ADC, this, BT);
+ // Match calls returning derived type where an argument is
+ // a void pointer
----------------
steakhal wrote:
```suggestion
// Match calls returning derived type where an argument is a void pointer.
```
This fits in a single line nicely. Also added punctuation as per llvm-style.
https://github.com/llvm/llvm-project/pull/200294
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits