[clang] [attributes][-Wunsafe-buffer-usage] Support adding unsafe_buffer_usage attribute to struct fields (PR #101585)
Malavika Samak via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 2 15:56:43 PDT 2024
================
@@ -927,21 +927,28 @@ class CArrayToPtrAssignmentGadget : public FixableGadget {
/// over one of its pointer parameters.
class UnsafeBufferUsageAttrGadget : public WarningGadget {
constexpr static const char *const OpTag = "call_expr";
- const CallExpr *Op;
+ const Expr *Op;
public:
UnsafeBufferUsageAttrGadget(const MatchFinder::MatchResult &Result)
: WarningGadget(Kind::UnsafeBufferUsageAttr),
- Op(Result.Nodes.getNodeAs<CallExpr>(OpTag)) {}
+ Op(Result.Nodes.getNodeAs<Expr>(OpTag)) {}
static bool classof(const Gadget *G) {
return G->getKind() == Kind::UnsafeBufferUsageAttr;
}
static Matcher matcher() {
+ auto HasUnsafeFielDecl =
+ member(fieldDecl(allOf(
+ anyOf(hasPointerType(), hasArrayType()),
----------------
malavikasamak wrote:
I was discussing offline about this with Devin and he said it is a good idea to not restrict what types of fields we allow the attribute to be attached to. This could be useful if someone accidentally only updates a field that stores the bounds information.
https://github.com/llvm/llvm-project/pull/101585
More information about the cfe-commits
mailing list