Skip to content

Commit b5a16b6

Browse files
authored
[Clang] [Parser] Support [[omp::assume]] (#84582)
This pr implements the `[[omp::assume]]` spelling for the `__attribute__((assume))` attribute. It does not change anything about how that attribute is handled by the rest of Clang.
1 parent ffe4181 commit b5a16b6

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ Python Binding Changes
500500

501501
- Exposed `CXRewriter` API as `class Rewriter`.
502502

503+
OpenMP Support
504+
--------------
505+
506+
- Added support for the `[[omp::assume]]` attribute.
507+
503508
Additional Information
504509
======================
505510

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4159,7 +4159,7 @@ def OMPDeclareVariant : InheritableAttr {
41594159
}
41604160

41614161
def OMPAssume : InheritableAttr {
4162-
let Spellings = [Clang<"assume">];
4162+
let Spellings = [Clang<"assume">, CXX11<"omp", "assume">];
41634163
let Subjects = SubjectList<[Function, ObjCMethod]>;
41644164
let InheritEvenIfAlreadyPresent = 1;
41654165
let Documentation = [OMPAssumeDocs];

clang/lib/Basic/Attributes.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ int clang::hasAttribute(AttributeCommonInfo::Syntax Syntax,
4747
// attributes. We support those, but not through the typical attribute
4848
// machinery that goes through TableGen. We support this in all OpenMP modes
4949
// so long as double square brackets are enabled.
50-
if (LangOpts.OpenMP && ScopeName == "omp")
51-
return (Name == "directive" || Name == "sequence") ? 1 : 0;
50+
//
51+
// Other OpenMP attributes (e.g. [[omp::assume]]) are handled via the
52+
// regular attribute parsing machinery.
53+
if (LangOpts.OpenMP && ScopeName == "omp" &&
54+
(Name == "directive" || Name == "sequence"))
55+
return 1;
5256

5357
int res = hasAttributeImpl(Syntax, Name, ScopeName, Target, LangOpts);
5458
if (res)

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4634,7 +4634,9 @@ bool Parser::ParseCXX11AttributeArgs(
46344634
return true;
46354635
}
46364636

4637-
if (ScopeName && ScopeName->isStr("omp")) {
4637+
// [[omp::directive]] and [[omp::sequence]] need special handling.
4638+
if (ScopeName && ScopeName->isStr("omp") &&
4639+
(AttrName->isStr("directive") || AttrName->isStr("sequence"))) {
46384640
Diag(AttrNameLoc, getLangOpts().OpenMP >= 51
46394641
? diag::warn_omp51_compat_attributes
46404642
: diag::ext_omp_attributes);

clang/test/OpenMP/attr-assume.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -fsyntax-only -fopenmp -verify %s
2+
[[omp::assume(3)]] void f1(); // expected-error {{expected string literal as argument of 'assume' attribute}}
3+
[[omp::assume(int)]] void f2(); // expected-error {{expected string literal as argument of 'assume' attribute}}
4+
[[omp::assume(for)]] void f3(); // expected-error {{expected string literal as argument of 'assume' attribute}}
5+
[[omp::assume("QQQQ")]] void f4(); // expected-warning {{unknown assumption string 'QQQQ'; attribute is potentially ignored}}
6+
[[omp::assume("omp_no_openmp")]] void f5();
7+
[[omp::assume("omp_noopenmp")]] void f6(); // expected-warning {{unknown assumption string 'omp_noopenmp' may be misspelled; attribute is potentially ignored, did you mean 'omp_no_openmp'?}}
8+
[[omp::assume("omp_no_openmp_routine")]] void f7(); // expected-warning {{unknown assumption string 'omp_no_openmp_routine' may be misspelled; attribute is potentially ignored, did you mean 'omp_no_openmp_routines'?}}
9+
[[omp::assume("omp_no_openmp1")]] void f8(); // expected-warning {{unknown assumption string 'omp_no_openmp1' may be misspelled; attribute is potentially ignored, did you mean 'omp_no_openmp'?}}
10+
[[omp::assume("omp_no_openmp", "omp_no_openmp")]] void f9(); // expected-error {{'assume' attribute takes one argument}}
11+
12+
[[omp::assume(3)]] int g1; // expected-error {{expected string literal as argument of 'assume' attribute}}
13+
[[omp::assume("omp_no_openmp")]] int g2; // expected-warning {{'assume' attribute only applies to functions and Objective-C methods}}

0 commit comments

Comments
 (0)