1 // RUN: %clang_cc1 -std=c++17 -fopenmp -fopenmp-version=51 -fsyntax-only -verify %s 2 3 // This file tests the custom parsing logic for the OpenMP 5.1 attribute 4 // syntax. It does not test actual OpenMP directive syntax, just the attribute 5 // parsing bits. 6 7 // FIXME: the diagnostic here is a bit unsatisfying. We handle the custom omp 8 // attribute parsing logic when parsing the attribute argument list, and we 9 // only process an attribute argument list when we see an open paren after the 10 // attribute name. So this means we never hit the omp-specific parsing and 11 // instead handle this through the usual Sema attribute handling in 12 // SemaDeclAttr.cpp, which diagnoses this as an unknown attribute. 13 [[omp::directive]]; // expected-warning {{unknown attribute 'directive' ignored}} 14 [[omp::sequence]]; // expected-warning {{unknown attribute 'sequence' ignored}} 15 [[omp::unknown]]; // expected-warning {{unknown attribute 'unknown' ignored}} 16 17 [[omp::directive()]]; // expected-error {{expected an OpenMP directive}} 18 [[omp::sequence()]]; // expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 19 20 // Both sequence and directive require an argument list, test that we diagnose 21 // when the inner directive or sequence is missing its argument list. 22 [[omp::sequence(directive)]]; // expected-error {{expected '('}} 23 [[omp::sequence(sequence)]]; // expected-error {{expected '('}} 24 [[omp::sequence(omp::directive)]]; // expected-error {{expected '('}} 25 [[omp::sequence(omp::sequence)]]; // expected-error {{expected '('}} 26 27 // All of the diagnostics here come from the inner sequence and directive not 28 // being given an argument, but this tests that we can parse either with or 29 // without the 'omp::'. 30 [[omp::sequence(directive(), sequence())]]; // expected-error {{expected an OpenMP directive}} expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 31 [[omp::sequence(omp::directive(), sequence())]]; // expected-error {{expected an OpenMP directive}} expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 32 [[omp::sequence(directive(), omp::sequence())]]; // expected-error {{expected an OpenMP directive}} expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 33 [[omp::sequence(omp::directive(), omp::sequence())]]; // expected-error {{expected an OpenMP directive}} expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 34 35 // Test that we properly diagnose missing parens within the inner arguments of 36 // a sequence attribute. 37 [[omp::sequence( // expected-note {{to match this '('}} 38 directive( 39 )]]; // expected-error {{expected ')'}} expected-error {{expected an OpenMP directive}} 40 [[omp::sequence( // expected-note {{to match this '('}} 41 sequence( 42 )]]; // expected-error {{expected ')'}} expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 43 44 // Test that we properly handle the using attribute syntax. 45 [[using omp: directive()]]; // expected-error {{expected an OpenMP directive}} 46 [[using omp: sequence()]]; // expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 47 [[using omp: sequence(omp::directive())]]; // expected-error {{expected an OpenMP directive}} 48 [[using omp: sequence(directive())]]; // expected-error {{expected an OpenMP directive}} 49 50 // Test that we give a sensible error on an unknown attribute in the omp 51 // namespace that has an argument list. 52 [[omp::unknown()]]; // expected-warning {{unknown attribute 'unknown' ignored}} 53 [[using omp: unknown()]]; // expected-warning {{unknown attribute 'unknown' ignored}} 54 55 // Test that unknown arguments to the omp::sequence are rejected, regardless of 56 // what level they're at. 57 [[omp::sequence(unknown)]]; // expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 58 [[omp::sequence(sequence(unknown))]]; // expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 59 [[omp::sequence(omp::unknown)]]; // expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 60 [[omp::sequence(sequence(omp::unknown))]]; // expected-error {{expected an OpenMP 'directive' or 'sequence' attribute argument}} 61 62 // FIXME: combining non-openmp attributes with openmp attributes has surprising 63 // results due to the replay of tokens. We properly parse the non-openmp 64 // attributes, but we also replay the OpenMP tokens. The attributes then get 65 // passed to the OpenMP parsing functions and it does not attach the attribute 66 // to the declaration statement AST node as you might expect. This means that 67 // the expected diagnostics are not issued. Thankfully, due to the positioning 68 // of OpenMP attributes and what they appertain to, this should not be a 69 // frequent issue (hopefully). 70 int x; 71 [[deprecated, omp::directive(threadprivate(x))]] int y; // FIXME-expected-note {{'y' has been explicitly marked deprecated here}} 72 [[omp::directive(threadprivate(x)), deprecated]] int z; // FIXME-expected-note {{'z' has been explicitly marked deprecated here}} 73 void test() { 74 x = 1; 75 y = 1; // FIXME-expected-warning {{warning: 'y' is deprecated}} 76 z = 1; // FIXME-expected-warning {{warning: 'z' is deprecated}} 77 } 78