From: Aaron Ballman Date: Thu, 25 Jun 2020 12:44:13 +0000 (-0400) Subject: Fix a crash with [[clang::acquire_handle]] when written as a type X-Git-Tag: llvmorg-12-init~1961 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37657991d17a274b1ac9c6ee63697a0138eab317;p=platform%2Fupstream%2Fllvm.git Fix a crash with [[clang::acquire_handle]] when written as a type attribute with no arguments provided. --- diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 81a0c4a2..08d12fc 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 5abb1e8..135467b 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")));