[clang] 3765799 - Fix a crash with [[clang::acquire_handle]] when written as a type

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 25 05:45:41 PDT 2020


Author: Aaron Ballman
Date: 2020-06-25T08:45:32-04:00
New Revision: 37657991d17a274b1ac9c6ee63697a0138eab317

URL: https://github.com/llvm/llvm-project/commit/37657991d17a274b1ac9c6ee63697a0138eab317
DIFF: https://github.com/llvm/llvm-project/commit/37657991d17a274b1ac9c6ee63697a0138eab317.diff

LOG: Fix a crash with [[clang::acquire_handle]] when written as a type
attribute with no arguments provided.

Added: 
    

Modified: 
    clang/lib/Sema/SemaType.cpp
    clang/test/Sema/attr-handles.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 81a0c4a2a9c2..08d12fc25bf7 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8110,6 +8110,15 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
     case ParsedAttr::AT_AcquireHandle: {
       if (!type->isFunctionType())
         return;
+
+      if (attr.getNumArgs() != 1) {
+        state.getSema().Diag(attr.getLoc(),
+                             diag::err_attribute_wrong_number_arguments)
+            << attr << 1;
+        attr.setInvalid();
+        return;
+      }
+
       StringRef HandleType;
       if (!state.getSema().checkStringLiteralArgumentAttr(attr, 0, HandleType))
         return;

diff  --git a/clang/test/Sema/attr-handles.cpp b/clang/test/Sema/attr-handles.cpp
index 5abb1e8d00bc..135467b6c0a8 100644
--- a/clang/test/Sema/attr-handles.cpp
+++ b/clang/test/Sema/attr-handles.cpp
@@ -17,6 +17,7 @@ int (* __attribute__((acquire_handle("Fuchsia"))) fpt)(char *); // expected-warn
 auto lambdat = [](int handle __attribute__((use_handle("Fuchsia"))))
     __attribute__((acquire_handle("Fuchsia"))) -> int { return 0; };
 int __attribute((acquire_handle("Fuchsia"))) ta; // expected-warning {{'acquire_handle' attribute only applies to functions, typedefs, and parameters}}
+int open(const char *path, int flags, ...) [[clang::acquire_handle]]; // expected-error {{'acquire_handle' attribute takes one argument}}
 
 // Typedefs.
 typedef int callback(char *) __attribute__((acquire_handle("Fuchsia")));


        


More information about the cfe-commits mailing list