[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:58:00 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:

Also, we do not emit any warning when it is placed on other types, which could be confusing. I will handle this in the next version and allow it to be added to all types.

https://github.com/llvm/llvm-project/pull/101585


More information about the cfe-commits mailing list