[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 17:49:38 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")
----------------
ziqingluo-90 wrote:
Is there a way to check that `Attr` has no arguments? I was thinking that if we add another category, this line of code will need to change again.
https://github.com/llvm/llvm-project/pull/227108
More information about the cfe-commits
mailing list