-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang] Ignore GCC 11 [[malloc(x)]] attribute
#68059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a76561f
02a153d
b7e1258
5f6f893
0659620
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1629,6 +1629,8 @@ def IFunc : Attr, TargetSpecificAttr<TargetELF> { | |||||||||
|
|
||||||||||
| def Restrict : InheritableAttr { | ||||||||||
| let Spellings = [Declspec<"restrict">, GCC<"malloc">]; | ||||||||||
| let Args = [IdentifierArgument<"Deallocator", /*opt*/ 1>, | ||||||||||
| ParamIdxArgument<"DeallocatorPtrArgIndex", /*opt*/ 1>]; | ||||||||||
|
||||||||||
| let Args = [IdentifierArgument<"Deallocator", /*opt*/ 1>, | |
| ParamIdxArgument<"DeallocatorPtrArgIndex", /*opt*/ 1>]; | |
| let Args = [IdentifierArgument<"Deallocator", /*opt=*/1>, | |
| ParamIdxArgument<"DeallocatorPtrArgIndex", /*opt=*/ 1>]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Unfortunately we have not been consistent through our codebase in argument comment format but e should strive to be consistent with bugprone-argument-comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Fixed in b7e1258
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4122,6 +4122,9 @@ def RestrictDocs : Documentation { | |
| The ``malloc`` attribute indicates that the function acts like a system memory | ||
| allocation function, returning a pointer to allocated storage disjoint from the | ||
| storage for any other object accessible to the caller. | ||
|
|
||
| The form of ``malloc`` with one or two arguments (supported by GCC 11) is | ||
| currently ignored by Clang. | ||
|
||
| }]; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -177,6 +177,10 @@ def warn_unknown_attribute_ignored : Warning< | |||||||||||||||
| "unknown attribute %0 ignored">, InGroup<UnknownAttributes>; | ||||||||||||||||
| def warn_attribute_ignored : Warning<"%0 attribute ignored">, | ||||||||||||||||
| InGroup<IgnoredAttributes>; | ||||||||||||||||
| def warn_multiarg_malloc_attribute_ignored: Warning< | ||||||||||||||||
| "'malloc' attribute ignored because" | ||||||||||||||||
| " Clang does not support the one/two argument form">, | ||||||||||||||||
| InGroup<IgnoredAttributes>; | ||||||||||||||||
|
||||||||||||||||
| def warn_multiarg_malloc_attribute_ignored: Warning< | |
| "'malloc' attribute ignored because" | |
| " Clang does not support the one/two argument form">, | |
| InGroup<IgnoredAttributes>; | |
| def warn_attribute_form_ignored : Warning< | |
| "%0 attribute ignored; Clang does not yet support this attribute signature">, | |
| InGroup<IgnoredAttributes>; |
If we generalize the wording a bit, we can reuse this diagnostic for other circumstances where we don't yet support a particular signature.
Also, this diagnostic should be moved to DiagnosticSemaKinds.td (it's only diagnosed from clang/lib/Sema, so no need for it to be in the "common" diagnostics file for cross-lib diagnostics).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 02a153d, although I've very slightly changed the wording to match other warnings by using because instead of the ;.
I've also added a couple of other error diagnostics in other commit, so please let me know if you think it's worth generalizing them too.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2064,13 +2064,27 @@ static void handleTLSModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | |
|
|
||
| static void handleRestrictAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | ||
| QualType ResultType = getFunctionOrMethodResultType(D); | ||
| if (ResultType->isAnyPointerType() || ResultType->isBlockPointerType()) { | ||
| if (!ResultType->isAnyPointerType() && !ResultType->isBlockPointerType()) { | ||
| S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) | ||
| << AL << getFunctionOrMethodResultSourceRange(D); | ||
| return; | ||
| } | ||
|
|
||
| if (getNumAttributeArgs(AL) == 0) { | ||
| D->addAttr(::new (S.Context) RestrictAttr(S.Context, AL)); | ||
| return; | ||
| } | ||
|
|
||
| S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) | ||
| << AL << getFunctionOrMethodResultSourceRange(D); | ||
| if (AL.getAttributeSpellingListIndex() == RestrictAttr::Declspec_restrict) { | ||
| // __declspec(restrict) accepts no arguments | ||
| S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 0; | ||
| return; | ||
| } | ||
|
|
||
| // FIXME: GCC uses [[malloc(my_func)]] to specify a deallocator for the | ||
|
||
| // returned pointer, but this isn't currently supported in LLVM | ||
| // see https://github.com/llvm/llvm-project/issues/51607 | ||
| S.Diag(AL.getLoc(), diag::warn_multiarg_malloc_attribute_ignored); | ||
| } | ||
|
|
||
| static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,14 @@ | ||||||||||||||||||||||||||||||
| // RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -fsyntax-only %s | ||||||||||||||||||||||||||||||
| // RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -fsyntax-only -fdeclspec %s | ||||||||||||||||||||||||||||||
| int a; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| inline __attribute__((noreturn(a))) void *f1(void); // expected-error {{'noreturn' attribute takes no arguments}} | ||||||||||||||||||||||||||||||
| inline __attribute__((always_inline(a))) void *f2(void); // expected-error {{'always_inline' attribute takes no arguments}} | ||||||||||||||||||||||||||||||
| inline __attribute__((cdecl(a))) void *f3(void); // expected-error {{'cdecl' attribute takes no arguments}} | ||||||||||||||||||||||||||||||
| inline __attribute__((const(a))) void *f4(void); // expected-error {{'const' attribute takes no arguments}} | ||||||||||||||||||||||||||||||
| inline __attribute__((fastcall(a))) void *f5(void); // expected-error {{'fastcall' attribute takes no arguments}} | ||||||||||||||||||||||||||||||
| inline __attribute__((malloc(a))) void *f5(void); // expected-error {{'malloc' attribute takes no arguments}} | ||||||||||||||||||||||||||||||
| inline __declspec(restrict(a)) void *f6_a(void); // expected-error {{'restrict' attribute takes no arguments}} | ||||||||||||||||||||||||||||||
| inline __attribute__((malloc(a, 1, a))) void *f6_b(void); // expected-error {{'malloc' attribute takes no more than 2 arguments}} | ||||||||||||||||||||||||||||||
| inline __attribute__((malloc(a, 1))) void *f6_c(void); // expected-warning {{'malloc' attribute ignored because Clang does not support the one/two argument form}} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| int a; | |
| void func_a(void * ptr, int a); | |
| void func_b(int a); | |
| void __attribute__((overloadable)) ambigious_func(void *); // expected-note {{candidate function}} | |
| void __attribute__((overloadable)) ambigious_func(void *, int); // expected-note {{candidate function}} |
llvm-project/clang/test/Sema/attr-args.c
Lines 13 to 21 in 0659620
| inline __declspec(restrict(a)) void *f6_a(void); // expected-error {{'restrict' attribute takes no arguments}} | |
| inline __attribute__((malloc(func_a, 1, a))) void *f6_b(void); // expected-error {{'malloc' attribute takes no more than 2 arguments}} | |
| inline __attribute__((malloc(func_a, 1))) void *f6_c(void); // expected-warning {{'malloc' attribute ignored because Clang does not yet support this attribute signature}} | |
| inline __attribute__((malloc(1234))) void *f6_d(void); // expected-error {{'malloc' argument for deallocator is not a function}} | |
| inline __attribute__((malloc(a))) void *f6_e(void); // expected-error {{'malloc' argument 'a' is not a function}} | |
| inline __attribute__((malloc(ambigious_func))) void *f6_f(void); // expected-error {{'malloc' argument 'ambigious_func' is not a single function}} | |
| inline __attribute__((malloc(func_b))) void *f6_g(void); // expected-error {{'malloc' argument 'func_b' must take a pointer type as its first argument}} | |
| inline __attribute__((malloc(func_a, 3))) void *f6_h(void); // expected-error {{'malloc' attribute parameter 2 is out of bounds}} | |
| inline __attribute__((malloc(func_a, 2))) void *f6_i(void); // expected-error {{'malloc' argument '2' refers to non-pointer type 'int' of 'func_a'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry! That's my fault for being lazy and skipping build the docs! Fixed in 5f6f893