[clang] [clang][-Wunsafe-buffer-usage] Warn on annotated unsafe container construction (PR #227108)
Phoebe Liang via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 14:55:27 PDT 2026
================
@@ -2190,16 +2271,25 @@ class UnsafeBufferUsageAttrGadget : public WarningGadget {
static bool matches(const Stmt *S, const ASTContext &Ctx,
MatchResult &Result) {
if (auto *CE = dyn_cast<CallExpr>(S)) {
- if (CE->getDirectCallee() &&
- CE->getDirectCallee()->hasAttr<UnsafeBufferUsageAttr>()) {
- Result.addNode(OpTag, DynTypedNode::create(*CE));
- return true;
+ if (const auto *Callee = CE->getDirectCallee()) {
+ if (const auto *Attr = Callee->getAttr<UnsafeBufferUsageAttr>()) {
+ // Skip if this is annotated with
+ // `[[clang::unsafe_buffer_usage("container")]]` as that case is
+ // handled by UnsafeBufferUsageContainerAttrGadget.
+ if (Attr->getCategory() == "container")
----------------
pl98 wrote:
Good point, updated the code.
https://github.com/llvm/llvm-project/pull/227108
More information about the cfe-commits
mailing list