[clang] [clang][-Wunsafe-buffer-usage] Warn on annotated unsafe container construction (PR #227108)

Ziqing Luo via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 20:58:34 PDT 2026


================
@@ -503,8 +503,8 @@ static const Expr *getSubExprInSizeOfExpr(const Expr &E) {
 // Providing that `Ptr` is a pointer and `Size` is an unsigned-integral
 // expression, returns true iff they follow one of the following safe
 // patterns:
-//  1. Ptr is `DRE.data()` and Size is `DRE.size()`, where DRE is a hardened
-//     container or view;
+//  1. Ptr is `DRE.data()` and Size is `DRE.size()` (or `DRE.size_bytes()` for
+//     char pointers), called on the same container or view object `DRE`;
----------------
ziqingluo-90 wrote:

hmm...   I believe well-developed libraries should follow the semantics conventions for `data() `and `size()`. Project-local data types might be sloppy with this convention. How about we only let functions annotated with `[[clang::unsafe_buffer_usage("container")]]` use this duck typing approach?

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


More information about the cfe-commits mailing list