1 // RUN: %clang_cc1 %s -fsyntax-only -verify
3 const char *some_function();
5 void foo(float *[[clang::annotate_type("foo")]] a
) {
6 int [[clang::annotate_type("bar")]] x1
;
7 int *[[clang::annotate_type("bar")]] x2
;
8 int *[[clang::annotate_type("bar", 1)]] x3
;
9 int *[[clang::annotate_type("bar", 1 + 2)]] x4
;
10 struct {} [[clang::annotate_type("foo")]] x5
;
11 int [[clang::annotate_type("int")]] *[[clang::annotate_type("ptr")]] array
[10] [[clang::annotate_type("arr")]];
13 typedef int [[clang::annotate_type("bar")]] my_typedef
;
15 // GNU spelling is not supported
16 int __attribute__((annotate_type("bar"))) y1
; // expected-warning {{unknown attribute 'annotate_type' ignored}}
17 int *__attribute__((annotate_type("bar"))) y2
; // expected-warning {{unknown attribute 'annotate_type' ignored}}
19 // Various error cases
20 [[clang::annotate_type("bar")]] int *z1
; // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
21 int *z2
[[clang::annotate_type("bar")]]; // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
22 [[clang::annotate_type("bar")]]; // expected-error {{'annotate_type' attribute cannot be applied to a statement}}
23 int *[[clang::annotate_type(1)]] z3
; // expected-error {{expected string literal as argument of 'annotate_type' attribute}}
24 int *[[clang::annotate_type()]] z4
; // expected-error {{'annotate_type' attribute takes at least 1 argument}}
25 int *[[clang::annotate_type
]] z5
; // expected-error {{'annotate_type' attribute takes at least 1 argument}}
26 int *[[clang::annotate_type(some_function())]] z6
; // expected-error {{expected string literal as argument of 'annotate_type' attribute}}
27 int *[[clang::annotate_type("bar", some_function())]] z7
; // expected-error {{'annotate_type' attribute requires parameter 1 to be a constant expression}} expected-note{{subexpression not valid in a constant expression}}
28 int *[[clang::annotate_type("bar", z7
)]] z8
; // expected-error {{'annotate_type' attribute requires parameter 1 to be a constant expression}} expected-note{{subexpression not valid in a constant expression}}
29 int *[[clang::annotate_type("bar", int)]] z9
; // expected-error {{expected expression}}
31 // More error cases: Prohibit adding the attribute to declarations.
32 // Different declarations hit different code paths, so they need separate tests.
33 [[clang::annotate_type("bar")]] int *global
; // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
34 [[clang::annotate_type("bar")]] void annotated_function(); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
35 void g([[clang::annotate_type("bar")]] int); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
36 struct [[clang::annotate_type("foo")]] S
; // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
37 struct [[clang::annotate_type("foo")]] S
{ // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
38 [[clang::annotate_type("foo")]] int member
; // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
39 [[clang::annotate_type("foo")]] union { // expected-error {{an attribute list cannot appear here}}