[clang] [clang] Ignore GCC 11 `[[malloc(x)]]` attribute (PR #68059)

Alois Klink via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 1 13:34:56 PDT 2023


================
@@ -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}}
----------------
aloisklink wrote:

Fixed in 0659620002757ab8bbd892a717fb47478d22aecd, although with a different error diagnostic. I've also added a bunch more error checking (adapting the code from [`handleCleanupAttr`](https://github.com/llvm/llvm-project/blob/0659620002757ab8bbd892a717fb47478d22aecd/clang/lib/Sema/SemaDeclAttr.cpp#L3793-L3818)), so now we should even be stricter than GCC on what args we accept:

https://github.com/llvm/llvm-project/blob/0659620002757ab8bbd892a717fb47478d22aecd/clang/test/Sema/attr-args.c#L2-L6

https://github.com/llvm/llvm-project/blob/0659620002757ab8bbd892a717fb47478d22aecd/clang/test/Sema/attr-args.c#L13-L21

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


More information about the cfe-commits mailing list