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

Alois Klink via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 7 11:50:41 PDT 2023


================
@@ -2064,13 +2064,26 @@ 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
----------------
aloisklink wrote:

I slightly disagree, since even if we do add support for this attribute, only the Clang analyzer would use it, but I've added a `'malloc' attribute ignored because Clang does not support the one/two argument form` warning in commit https://github.com/llvm/llvm-project/commit/a76561f522f628b0882572f8dabee6f7e4abd5f5.

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


More information about the cfe-commits mailing list