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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 5 10:34:16 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
----------------
erichkeane wrote:

I think I'd like this to be diagnosed.  We shouldn't be silently ignoring the attribute.

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


More information about the cfe-commits mailing list