[clang] [attributes][-Wunsafe-buffer-usage] Support adding unsafe_buffer_usage attribute to struct fields (PR #101585)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 2 10:58:57 PDT 2024


================
@@ -6763,15 +6763,18 @@ attribute requires a string literal argument to identify the handle being releas
 def UnsafeBufferUsageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
-The attribute ``[[clang::unsafe_buffer_usage]]`` should be placed on functions
-that need to be avoided as they are prone to buffer overflows. It is designed to
-work together with the off-by-default compiler warning ``-Wunsafe-buffer-usage``
-to help codebases transition away from raw pointer based buffer management,
-in favor of safer abstractions such as C++20 ``std::span``. The attribute causes
-``-Wunsafe-buffer-usage`` to warn on every use of the function, and it may
-enable ``-Wunsafe-buffer-usage`` to emit automatic fix-it hints
-which would help the user replace such unsafe functions with safe
-alternatives, though the attribute can be used even when the fix can't be automated.
+The attribute ``[[clang::unsafe_buffer_usage]]`` should be placed on functions or
----------------
jkorous-apple wrote:

What would you think about this wording?
```
The attribute ``[[clang::unsafe_buffer_usage]]`` should be placed on functions
that need to be avoided as they are prone to buffer overflows or unsafe buffer struct fields.
```

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


More information about the cfe-commits mailing list