Skip to content

Commit b141285

Browse files
authored
[SYCL] Remove manual diagnostic checking for stmt attrs. (#3442)
Statement attributes now have automatic diagnostic checking, so let's use that. This does have a change in behavior in that passing the wrong number of arguments is now an error instead of a warning, but that behavior is more consistent with other attributes.
1 parent 9e41f82 commit b141285

File tree

5 files changed

+15
-80
lines changed

5 files changed

+15
-80
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ def SYCLIntelFPGAInitiationInterval : DeclOrStmtAttr {
18811881
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt, Function],
18821882
ErrorDiag,
18831883
"'for', 'while', 'do' statements, and functions">;
1884-
let Args = [ExprArgument<"IntervalExpr", /*opt*/1>];
1884+
let Args = [ExprArgument<"IntervalExpr">];
18851885
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
18861886
let HasCustomTypeTransform = 1;
18871887
let Documentation = [SYCLIntelFPGAInitiationIntervalAttrDocs];
@@ -1928,7 +1928,7 @@ def SYCLIntelFPGAMaxInterleaving : StmtAttr {
19281928
CXX11<"intel","max_interleaving">];
19291929
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
19301930
ErrorDiag, "'for', 'while', and 'do' statements">;
1931-
let Args = [ExprArgument<"NExpr", /*opt*/1>];
1931+
let Args = [ExprArgument<"NExpr">];
19321932
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
19331933
let HasCustomTypeTransform = 1;
19341934
let Documentation = [SYCLIntelFPGAMaxInterleavingAttrDocs];
@@ -1939,7 +1939,7 @@ def SYCLIntelFPGASpeculatedIterations : StmtAttr {
19391939
CXX11<"intel","speculated_iterations">];
19401940
let Subjects = SubjectList<[ForStmt, CXXForRangeStmt, WhileStmt, DoStmt],
19411941
ErrorDiag, "'for', 'while', and 'do' statements">;
1942-
let Args = [ExprArgument<"NExpr", /*opt*/1>];
1942+
let Args = [ExprArgument<"NExpr">];
19431943
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
19441944
let HasCustomTypeTransform = 1;
19451945
let Documentation = [SYCLIntelFPGASpeculatedIterationsAttrDocs];

clang/include/clang/Parse/Parser.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,18 +2823,6 @@ class Parser : public CodeCompletionHandler {
28232823
void ParseBorlandTypeAttributes(ParsedAttributes &attrs);
28242824
void ParseOpenCLKernelAttributes(ParsedAttributes &attrs);
28252825
void ParseOpenCLQualifiers(ParsedAttributes &Attrs);
2826-
/// Parses opencl_unroll_hint attribute if language is OpenCL v2.0
2827-
/// or higher.
2828-
/// \return false if error happens.
2829-
bool MaybeParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs) {
2830-
if (getLangOpts().OpenCL)
2831-
return ParseOpenCLUnrollHintAttribute(Attrs);
2832-
return true;
2833-
}
2834-
/// Parses opencl_unroll_hint attribute.
2835-
/// \return false if error happens.
2836-
bool ParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs);
2837-
28382826
void ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs);
28392827
VersionTuple ParseVersionTuple(SourceRange &Range);
28402828
void ParseAvailabilityAttribute(IdentifierInfo &Availability,

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -70,40 +70,15 @@ static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
7070

7171
template <typename FPGALoopAttrT>
7272
static Attr *handleIntelFPGALoopAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
73-
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
74-
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
75-
<< A << "'for', 'while', and 'do' statements";
76-
return nullptr;
77-
}
78-
79-
unsigned NumArgs = A.getNumArgs();
80-
if (NumArgs == 0) {
81-
if (A.getKind() == ParsedAttr::AT_SYCLIntelFPGAInitiationInterval ||
82-
A.getKind() == ParsedAttr::AT_SYCLIntelFPGAMaxConcurrency ||
83-
A.getKind() == ParsedAttr::AT_SYCLIntelFPGAMaxInterleaving ||
84-
A.getKind() == ParsedAttr::AT_SYCLIntelFPGASpeculatedIterations) {
85-
S.Diag(A.getLoc(), diag::warn_attribute_too_few_arguments) << A << 1;
86-
return nullptr;
87-
}
88-
}
89-
9073
S.CheckDeprecatedSYCLAttributeSpelling(A);
9174

9275
return S.BuildSYCLIntelFPGALoopAttr<FPGALoopAttrT>(
9376
A, A.getNumArgs() ? A.getArgAsExpr(0) : nullptr);
9477
}
9578

96-
template <>
97-
Attr *handleIntelFPGALoopAttr<SYCLIntelFPGADisableLoopPipeliningAttr>(
98-
Sema &S, Stmt *St, const ParsedAttr &A) {
99-
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
100-
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
101-
<< A << "'for', 'while', and 'do' statements";
102-
return nullptr;
103-
}
104-
79+
static Attr *handleSYCLIntelFPGADisableLoopPipeliningAttr(Sema &S, Stmt *,
80+
const ParsedAttr &A) {
10581
S.CheckDeprecatedSYCLAttributeSpelling(A);
106-
10782
return new (S.Context) SYCLIntelFPGADisableLoopPipeliningAttr(S.Context, A);
10883
}
10984

@@ -259,12 +234,6 @@ CheckRedundantSYCLIntelFPGAIVDepAttrs(Sema &S, ArrayRef<const Attr *> Attrs) {
259234
}
260235

261236
static Attr *handleIntelFPGAIVDepAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
262-
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
263-
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
264-
<< A << "'for', 'while', and 'do' statements";
265-
return nullptr;
266-
}
267-
268237
unsigned NumArgs = A.getNumArgs();
269238

270239
S.CheckDeprecatedSYCLAttributeSpelling(A);
@@ -276,12 +245,6 @@ static Attr *handleIntelFPGAIVDepAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
276245

277246
static Attr *handleIntelFPGANofusionAttr(Sema &S, Stmt *St,
278247
const ParsedAttr &A) {
279-
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
280-
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
281-
<< A << "'for', 'while', and 'do' statements";
282-
return nullptr;
283-
}
284-
285248
return new (S.Context) SYCLIntelFPGANofusionAttr(S.Context, A);
286249
}
287250

@@ -726,28 +689,13 @@ static Attr *handleLoopUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
726689
// determines unrolling factor) or 1 argument (the unroll factor provided
727690
// by the user).
728691

729-
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
730-
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
731-
<< A << "'for', 'while', and 'do' statements";
732-
return nullptr;
733-
}
734-
735692
Expr *E = A.getNumArgs() ? A.getArgAsExpr(0) : nullptr;
736693
if (A.getParsedKind() == ParsedAttr::AT_OpenCLUnrollHint)
737694
return S.BuildOpenCLLoopUnrollHintAttr(A, E);
738-
else if (A.getParsedKind() == ParsedAttr::AT_LoopUnrollHint) {
739-
// FIXME: this should be hoisted up to the top level, but can't be placed
740-
// there until the opencl attribute has its parsing error converted into a
741-
// semantic error. See: Parser::ParseOpenCLUnrollHintAttribute().
742-
if (!isa<ForStmt, CXXForRangeStmt, DoStmt, WhileStmt>(St)) {
743-
S.Diag(A.getLoc(), diag::err_attribute_wrong_decl_type_str)
744-
<< A << "'for', 'while', and 'do' statements";
745-
return nullptr;
746-
}
695+
if (A.getParsedKind() == ParsedAttr::AT_LoopUnrollHint)
747696
return S.BuildLoopUnrollHintAttr(A, E);
748-
}
749697

750-
return nullptr;
698+
llvm_unreachable("Unknown loop unroll hint");
751699
}
752700

753701
static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
@@ -788,8 +736,7 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
788736
case ParsedAttr::AT_SYCLIntelFPGALoopCoalesce:
789737
return handleIntelFPGALoopAttr<SYCLIntelFPGALoopCoalesceAttr>(S, St, A);
790738
case ParsedAttr::AT_SYCLIntelFPGADisableLoopPipelining:
791-
return handleIntelFPGALoopAttr<SYCLIntelFPGADisableLoopPipeliningAttr>(
792-
S, St, A);
739+
return handleSYCLIntelFPGADisableLoopPipeliningAttr(S, St, A);
793740
case ParsedAttr::AT_SYCLIntelFPGAMaxInterleaving:
794741
return handleIntelFPGALoopAttr<SYCLIntelFPGAMaxInterleavingAttr>(S, St, A);
795742
case ParsedAttr::AT_SYCLIntelFPGASpeculatedIterations:

clang/test/SemaSYCL/initiation_interval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[[intel::initiation_interval(-1)]] void func1() {} // expected-error{{'initiation_interval' attribute requires a positive integral compile time constant expression}}
1111

12-
[[intel::initiation_interval(0, 1)]] void func2() {} // expected-error{{'initiation_interval' attribute takes no more than 1 argument}}
12+
[[intel::initiation_interval(0, 1)]] void func2() {} // expected-error{{'initiation_interval' attribute takes one argument}}
1313

1414
// Tests for Intel FPGA initiation_interval function attribute duplication.
1515
// No diagnostic is emitted because the arguments match. Duplicate attribute is silently ignored.

clang/test/SemaSYCL/intel-fpga-loops.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ void boo() {
7575
// expected-error@+1 {{duplicate argument to 'ivdep'; attribute requires one or both of a safelen and array}}
7676
[[intel::ivdep(2, 2)]] for (int i = 0; i != 10; ++i)
7777
a[i] = 0;
78-
// expected-warning@+1 {{'initiation_interval' attribute takes at least 1 argument; attribute ignored}}
78+
// expected-error@+1 {{'initiation_interval' attribute takes one argument}}
7979
[[intel::initiation_interval]] for (int i = 0; i != 10; ++i)
8080
a[i] = 0;
81-
// expected-error@+1 {{'initiation_interval' attribute takes no more than 1 argument}}
81+
// expected-error@+1 {{'initiation_interval' attribute takes one argument}}
8282
[[intel::initiation_interval(2, 2)]] for (int i = 0; i != 10; ++i)
8383
a[i] = 0;
8484
// expected-error@+1 {{'max_concurrency' attribute takes one argument}}
@@ -104,16 +104,16 @@ void boo() {
104104
// expected-error@+1 {{'loop_coalesce' attribute takes no more than 1 argument}}
105105
[[intel::loop_coalesce(2, 3)]] for (int i = 0; i != 10; ++i)
106106
a[i] = 0;
107-
// expected-warning@+1 {{'max_interleaving' attribute takes at least 1 argument; attribute ignored}}
107+
// expected-error@+1 {{'max_interleaving' attribute takes one argument}}
108108
[[intel::max_interleaving]] for (int i = 0; i != 10; ++i)
109109
a[i] = 0;
110-
// expected-error@+1 {{'max_interleaving' attribute takes no more than 1 argument}}
110+
// expected-error@+1 {{'max_interleaving' attribute takes one argument}}
111111
[[intel::max_interleaving(2, 4)]] for (int i = 0; i != 10; ++i)
112112
a[i] = 0;
113-
// expected-warning@+1 {{'speculated_iterations' attribute takes at least 1 argument; attribute ignored}}
113+
// expected-error@+1 {{'speculated_iterations' attribute takes one argument}}
114114
[[intel::speculated_iterations]] for (int i = 0; i != 10; ++i)
115115
a[i] = 0;
116-
// expected-error@+1 {{'speculated_iterations' attribute takes no more than 1 argument}}
116+
// expected-error@+1 {{'speculated_iterations' attribute takes one argument}}
117117
[[intel::speculated_iterations(1, 2)]] for (int i = 0; i != 10; ++i)
118118
a[i] = 0;
119119
// expected-error@+1 {{'nofusion' attribute takes no arguments}}

0 commit comments

Comments
 (0)