[clang] [clang] ownership_returns attribute takes no more than 2 arguments (PR #137897)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 29 16:47:09 PDT 2025
https://github.com/halbi2 created https://github.com/llvm/llvm-project/pull/137897
Fixes #137896
>From 1497e17e86b437b59f35e80624a33034a97d2426 Mon Sep 17 00:00:00 2001
From: halbi2 <hehiralbi at gmail.com>
Date: Tue, 29 Apr 2025 19:41:27 -0400
Subject: [PATCH] [clang] ownership_returns attribute takes no more than 2
arguments
Fixes #137896
---
clang/lib/Sema/SemaDeclAttr.cpp | 2 +-
clang/test/Sema/attr-ownership.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 413999b95b998..8499141c30bce 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1483,7 +1483,7 @@ static void handleOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
break;
case OwnershipAttr::Returns:
if (AL.getNumArgs() > 2) {
- S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
+ S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 2;
return;
}
break;
diff --git a/clang/test/Sema/attr-ownership.c b/clang/test/Sema/attr-ownership.c
index d2e40538a40f0..515428d7d6c44 100644
--- a/clang/test/Sema/attr-ownership.c
+++ b/clang/test/Sema/attr-ownership.c
@@ -1,7 +1,7 @@
// RUN: %clang_cc1 %s -verify -fsyntax-only -Wno-strict-prototypes
void f1(void) __attribute__((ownership_takes("foo"))); // expected-error {{'ownership_takes' attribute requires parameter 1 to be an identifier}}
-void *f2(void) __attribute__((ownership_returns(foo, 1, 2))); // expected-error {{'ownership_returns' attribute takes no more than 1 argument}}
+void *f2(void) __attribute__((ownership_returns(foo, 1, 2))); // expected-error {{'ownership_returns' attribute takes no more than 2 arguments}}
void f3(void) __attribute__((ownership_holds(foo, 1))); // expected-error {{'ownership_holds' attribute parameter 1 is out of bounds}}
void *f4(void) __attribute__((ownership_returns(foo)));
void f5(void) __attribute__((ownership_holds(foo))); // expected-error {{'ownership_holds' attribute takes at least 2 arguments}}
More information about the cfe-commits
mailing list