blob: ba96ba9c23f4869f954de61f32d3bc98d8f0ef4c [file] [log] [blame]
Richard Smithc202b282012-04-14 00:33:13 +00001//===--- SemaStmtAttr.cpp - Statement Attribute Handling ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements stmt-related attribute processing.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Sema/SemaInternal.h"
Richard Smithc202b282012-04-14 00:33:13 +000015#include "clang/AST/ASTContext.h"
Eli Bendersky06a40422014-06-06 20:31:48 +000016#include "clang/Basic/SourceManager.h"
17#include "clang/Sema/DelayedDiagnostic.h"
18#include "clang/Sema/Lookup.h"
19#include "clang/Sema/LoopHint.h"
20#include "clang/Sema/ScopeInfo.h"
21#include "llvm/ADT/StringExtras.h"
22
Richard Smithc202b282012-04-14 00:33:13 +000023using namespace clang;
24using namespace sema;
25
Erich Keanee891aa92018-07-13 15:07:47 +000026static Attr *handleFallThroughAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Richard Smith84837d52012-05-03 18:27:39 +000027 SourceRange Range) {
Richard Smith4f902c72016-03-08 00:32:55 +000028 FallThroughAttr Attr(A.getRange(), S.Context,
29 A.getAttributeSpellingListIndex());
Richard Smith84837d52012-05-03 18:27:39 +000030 if (!isa<NullStmt>(St)) {
31 S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_wrong_target)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000032 << Attr.getSpelling() << St->getBeginLoc();
Richard Smith84837d52012-05-03 18:27:39 +000033 if (isa<SwitchCase>(St)) {
Alp Tokerb6cc5922014-05-03 03:45:55 +000034 SourceLocation L = S.getLocForEndOfToken(Range.getEnd());
Richard Smith84837d52012-05-03 18:27:39 +000035 S.Diag(L, diag::note_fallthrough_insert_semi_fixit)
36 << FixItHint::CreateInsertion(L, ";");
37 }
Craig Topperc3ec1492014-05-26 06:22:03 +000038 return nullptr;
Richard Smith84837d52012-05-03 18:27:39 +000039 }
Richard Smith4f902c72016-03-08 00:32:55 +000040 auto *FnScope = S.getCurFunction();
41 if (FnScope->SwitchStack.empty()) {
Richard Smith84837d52012-05-03 18:27:39 +000042 S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_outside_switch);
Craig Topperc3ec1492014-05-26 06:22:03 +000043 return nullptr;
Richard Smith84837d52012-05-03 18:27:39 +000044 }
Richard Smith4f902c72016-03-08 00:32:55 +000045
Aaron Ballmanc351fba2017-12-04 20:27:34 +000046 // If this is spelled as the standard C++17 attribute, but not in C++17, warn
Richard Smith4f902c72016-03-08 00:32:55 +000047 // about using it as an extension.
Aaron Ballmanc351fba2017-12-04 20:27:34 +000048 if (!S.getLangOpts().CPlusPlus17 && A.isCXX11Attribute() &&
Richard Smith4f902c72016-03-08 00:32:55 +000049 !A.getScopeName())
Richard Smithb115e5d2017-08-13 23:37:29 +000050 S.Diag(A.getLoc(), diag::ext_cxx17_attr) << A.getName();
Richard Smith4f902c72016-03-08 00:32:55 +000051
52 FnScope->setHasFallthroughStmt();
53 return ::new (S.Context) auto(Attr);
Eli Bendersky06a40422014-06-06 20:31:48 +000054}
55
Erich Keanee891aa92018-07-13 15:07:47 +000056static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Matthias Gehre01a63382017-03-27 19:45:24 +000057 SourceRange Range) {
58 if (A.getNumArgs() < 1) {
Erich Keane44bacdf2018-08-09 13:21:32 +000059 S.Diag(A.getLoc(), diag::err_attribute_too_few_arguments) << A << 1;
Matthias Gehre01a63382017-03-27 19:45:24 +000060 return nullptr;
61 }
62
63 std::vector<StringRef> DiagnosticIdentifiers;
64 for (unsigned I = 0, E = A.getNumArgs(); I != E; ++I) {
65 StringRef RuleName;
66
67 if (!S.checkStringLiteralArgumentAttr(A, I, RuleName, nullptr))
68 return nullptr;
69
70 // FIXME: Warn if the rule name is unknown. This is tricky because only
71 // clang-tidy knows about available rules.
72 DiagnosticIdentifiers.push_back(RuleName);
73 }
74
75 return ::new (S.Context) SuppressAttr(
76 A.getRange(), S.Context, DiagnosticIdentifiers.data(),
77 DiagnosticIdentifiers.size(), A.getAttributeSpellingListIndex());
78}
79
Erich Keanee891aa92018-07-13 15:07:47 +000080static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Eli Bendersky06a40422014-06-06 20:31:48 +000081 SourceRange) {
Mark Heffernanbd26f5e2014-07-21 18:08:34 +000082 IdentifierLoc *PragmaNameLoc = A.getArgAsIdent(0);
83 IdentifierLoc *OptionLoc = A.getArgAsIdent(1);
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +000084 IdentifierLoc *StateLoc = A.getArgAsIdent(2);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +000085 Expr *ValueExpr = A.getArgAsExpr(3);
86
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +000087 bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
88 bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
David Greenc8e39242018-08-01 14:36:12 +000089 bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == "unroll_and_jam";
90 bool PragmaNoUnrollAndJam =
91 PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
Eli Bendersky06a40422014-06-06 20:31:48 +000092 if (St->getStmtClass() != Stmt::DoStmtClass &&
93 St->getStmtClass() != Stmt::ForStmtClass &&
94 St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
95 St->getStmtClass() != Stmt::WhileStmtClass) {
Mark Heffernanc888e412014-07-24 18:09:38 +000096 const char *Pragma =
97 llvm::StringSwitch<const char *>(PragmaNameLoc->Ident->getName())
98 .Case("unroll", "#pragma unroll")
99 .Case("nounroll", "#pragma nounroll")
David Greenc8e39242018-08-01 14:36:12 +0000100 .Case("unroll_and_jam", "#pragma unroll_and_jam")
101 .Case("nounroll_and_jam", "#pragma nounroll_and_jam")
Mark Heffernanc888e412014-07-24 18:09:38 +0000102 .Default("#pragma clang loop");
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000103 S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << Pragma;
Eli Bendersky06a40422014-06-06 20:31:48 +0000104 return nullptr;
105 }
106
Erich Keanebe89f4c52017-08-09 15:27:36 +0000107 LoopHintAttr::Spelling Spelling =
108 LoopHintAttr::Spelling(A.getAttributeSpellingListIndex());
Mark Heffernan397a98d2015-08-10 17:29:39 +0000109 LoopHintAttr::OptionType Option;
110 LoopHintAttr::LoopHintState State;
111 if (PragmaNoUnroll) {
112 // #pragma nounroll
Mark Heffernan397a98d2015-08-10 17:29:39 +0000113 Option = LoopHintAttr::Unroll;
114 State = LoopHintAttr::Disable;
115 } else if (PragmaUnroll) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000116 if (ValueExpr) {
117 // #pragma unroll N
118 Option = LoopHintAttr::UnrollCount;
119 State = LoopHintAttr::Numeric;
120 } else {
121 // #pragma unroll
122 Option = LoopHintAttr::Unroll;
123 State = LoopHintAttr::Enable;
124 }
David Greenc8e39242018-08-01 14:36:12 +0000125 } else if (PragmaNoUnrollAndJam) {
126 // #pragma nounroll_and_jam
127 Option = LoopHintAttr::UnrollAndJam;
128 State = LoopHintAttr::Disable;
129 } else if (PragmaUnrollAndJam) {
130 if (ValueExpr) {
131 // #pragma unroll_and_jam N
132 Option = LoopHintAttr::UnrollAndJamCount;
133 State = LoopHintAttr::Numeric;
134 } else {
135 // #pragma unroll_and_jam
136 Option = LoopHintAttr::UnrollAndJam;
137 State = LoopHintAttr::Enable;
138 }
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000139 } else {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000140 // #pragma clang loop ...
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000141 assert(OptionLoc && OptionLoc->Ident &&
142 "Attribute must have valid option info.");
Mark Heffernan397a98d2015-08-10 17:29:39 +0000143 Option = llvm::StringSwitch<LoopHintAttr::OptionType>(
144 OptionLoc->Ident->getName())
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000145 .Case("vectorize", LoopHintAttr::Vectorize)
146 .Case("vectorize_width", LoopHintAttr::VectorizeWidth)
147 .Case("interleave", LoopHintAttr::Interleave)
148 .Case("interleave_count", LoopHintAttr::InterleaveCount)
149 .Case("unroll", LoopHintAttr::Unroll)
150 .Case("unroll_count", LoopHintAttr::UnrollCount)
Adam Nemet2de463e2016-06-14 12:04:26 +0000151 .Case("distribute", LoopHintAttr::Distribute)
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000152 .Default(LoopHintAttr::Vectorize);
Mark Heffernan397a98d2015-08-10 17:29:39 +0000153 if (Option == LoopHintAttr::VectorizeWidth ||
154 Option == LoopHintAttr::InterleaveCount ||
155 Option == LoopHintAttr::UnrollCount) {
156 assert(ValueExpr && "Attribute must have a valid value expression.");
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000157 if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc()))
Mark Heffernan397a98d2015-08-10 17:29:39 +0000158 return nullptr;
159 State = LoopHintAttr::Numeric;
160 } else if (Option == LoopHintAttr::Vectorize ||
161 Option == LoopHintAttr::Interleave ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000162 Option == LoopHintAttr::Unroll ||
163 Option == LoopHintAttr::Distribute) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000164 assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument");
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000165 if (StateLoc->Ident->isStr("disable"))
166 State = LoopHintAttr::Disable;
Tyler Nowicki9d268e12015-06-11 23:23:17 +0000167 else if (StateLoc->Ident->isStr("assume_safety"))
168 State = LoopHintAttr::AssumeSafety;
Mark Heffernan397a98d2015-08-10 17:29:39 +0000169 else if (StateLoc->Ident->isStr("full"))
170 State = LoopHintAttr::Full;
171 else if (StateLoc->Ident->isStr("enable"))
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000172 State = LoopHintAttr::Enable;
Mark Heffernan397a98d2015-08-10 17:29:39 +0000173 else
174 llvm_unreachable("bad loop hint argument");
175 } else
176 llvm_unreachable("bad loop hint");
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000177 }
Eli Bendersky06a40422014-06-06 20:31:48 +0000178
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000179 return LoopHintAttr::CreateImplicit(S.Context, Spelling, Option, State,
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000180 ValueExpr, A.getRange());
Eli Bendersky06a40422014-06-06 20:31:48 +0000181}
182
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000183static void
184CheckForIncompatibleAttributes(Sema &S,
185 const SmallVectorImpl<const Attr *> &Attrs) {
David Greenc8e39242018-08-01 14:36:12 +0000186 // There are 5 categories of loop hints attributes: vectorize, interleave,
187 // unroll, unroll_and_jam and distribute. Except for distribute they come
188 // in two variants: a state form and a numeric form. The state form
189 // selectively defaults/enables/disables the transformation for the loop
190 // (for unroll, default indicates full unrolling rather than enabling the
191 // transformation). The numeric form form provides an integer hint (for
192 // example, unroll count) to the transformer. The following array accumulates
193 // the hints encountered while iterating through the attributes to check for
194 // compatibility.
Eli Bendersky86483b32014-06-11 17:56:26 +0000195 struct {
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000196 const LoopHintAttr *StateAttr;
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000197 const LoopHintAttr *NumericAttr;
Adam Nemet2de463e2016-06-14 12:04:26 +0000198 } HintAttrs[] = {{nullptr, nullptr},
199 {nullptr, nullptr},
200 {nullptr, nullptr},
David Greenc8e39242018-08-01 14:36:12 +0000201 {nullptr, nullptr},
Adam Nemet2de463e2016-06-14 12:04:26 +0000202 {nullptr, nullptr}};
Eli Bendersky06a40422014-06-06 20:31:48 +0000203
204 for (const auto *I : Attrs) {
205 const LoopHintAttr *LH = dyn_cast<LoopHintAttr>(I);
206
207 // Skip non loop hint attributes
208 if (!LH)
209 continue;
210
Craig Topperec9be542015-12-23 05:44:43 +0000211 LoopHintAttr::OptionType Option = LH->getOption();
David Greenc8e39242018-08-01 14:36:12 +0000212 enum { Vectorize, Interleave, Unroll, UnrollAndJam, Distribute } Category;
Eli Bendersky06a40422014-06-06 20:31:48 +0000213 switch (Option) {
214 case LoopHintAttr::Vectorize:
215 case LoopHintAttr::VectorizeWidth:
Mark Heffernan450c2382014-07-23 17:31:31 +0000216 Category = Vectorize;
Eli Bendersky06a40422014-06-06 20:31:48 +0000217 break;
218 case LoopHintAttr::Interleave:
219 case LoopHintAttr::InterleaveCount:
Mark Heffernan450c2382014-07-23 17:31:31 +0000220 Category = Interleave;
Eli Bendersky06a40422014-06-06 20:31:48 +0000221 break;
Eli Bendersky86483b32014-06-11 17:56:26 +0000222 case LoopHintAttr::Unroll:
223 case LoopHintAttr::UnrollCount:
Mark Heffernan450c2382014-07-23 17:31:31 +0000224 Category = Unroll;
Eli Bendersky86483b32014-06-11 17:56:26 +0000225 break;
David Greenc8e39242018-08-01 14:36:12 +0000226 case LoopHintAttr::UnrollAndJam:
227 case LoopHintAttr::UnrollAndJamCount:
228 Category = UnrollAndJam;
229 break;
Adam Nemet2de463e2016-06-14 12:04:26 +0000230 case LoopHintAttr::Distribute:
231 // Perform the check for duplicated 'distribute' hints.
232 Category = Distribute;
233 break;
Eli Bendersky86483b32014-06-11 17:56:26 +0000234 };
Eli Bendersky06a40422014-06-06 20:31:48 +0000235
David Greenc8e39242018-08-01 14:36:12 +0000236 assert(Category < sizeof(HintAttrs) / sizeof(HintAttrs[0]));
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000237 auto &CategoryState = HintAttrs[Category];
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000238 const LoopHintAttr *PrevAttr;
Eli Bendersky86483b32014-06-11 17:56:26 +0000239 if (Option == LoopHintAttr::Vectorize ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000240 Option == LoopHintAttr::Interleave || Option == LoopHintAttr::Unroll ||
David Greenc8e39242018-08-01 14:36:12 +0000241 Option == LoopHintAttr::UnrollAndJam ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000242 Option == LoopHintAttr::Distribute) {
Tyler Nowicki9d268e12015-06-11 23:23:17 +0000243 // Enable|Disable|AssumeSafety hint. For example, vectorize(enable).
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000244 PrevAttr = CategoryState.StateAttr;
245 CategoryState.StateAttr = LH;
Eli Bendersky06a40422014-06-06 20:31:48 +0000246 } else {
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000247 // Numeric hint. For example, vectorize_width(8).
248 PrevAttr = CategoryState.NumericAttr;
249 CategoryState.NumericAttr = LH;
Eli Bendersky06a40422014-06-06 20:31:48 +0000250 }
251
Tyler Nowicki884fc612014-07-29 17:21:32 +0000252 PrintingPolicy Policy(S.Context.getLangOpts());
253 SourceLocation OptionLoc = LH->getRange().getBegin();
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000254 if (PrevAttr)
255 // Cannot specify same type of attribute twice.
256 S.Diag(OptionLoc, diag::err_pragma_loop_compatibility)
Tyler Nowicki884fc612014-07-29 17:21:32 +0000257 << /*Duplicate=*/true << PrevAttr->getDiagnosticName(Policy)
258 << LH->getDiagnosticName(Policy);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000259
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000260 if (CategoryState.StateAttr && CategoryState.NumericAttr &&
David Greenc8e39242018-08-01 14:36:12 +0000261 (Category == Unroll || Category == UnrollAndJam ||
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000262 CategoryState.StateAttr->getState() == LoopHintAttr::Disable)) {
Mark Heffernan450c2382014-07-23 17:31:31 +0000263 // Disable hints are not compatible with numeric hints of the same
264 // category. As a special case, numeric unroll hints are also not
Mark Heffernan397a98d2015-08-10 17:29:39 +0000265 // compatible with enable or full form of the unroll pragma because these
266 // directives indicate full unrolling.
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000267 S.Diag(OptionLoc, diag::err_pragma_loop_compatibility)
Eli Bendersky86483b32014-06-11 17:56:26 +0000268 << /*Duplicate=*/false
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000269 << CategoryState.StateAttr->getDiagnosticName(Policy)
Tyler Nowicki884fc612014-07-29 17:21:32 +0000270 << CategoryState.NumericAttr->getDiagnosticName(Policy);
Eli Bendersky86483b32014-06-11 17:56:26 +0000271 }
Eli Bendersky06a40422014-06-06 20:31:48 +0000272 }
273}
274
Erich Keanee891aa92018-07-13 15:07:47 +0000275static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000276 SourceRange Range) {
Egor Churaev24939d42016-12-13 14:02:35 +0000277 // Although the feature was introduced only in OpenCL C v2.0 s6.11.5, it's
278 // useful for OpenCL 1.x too and doesn't require HW support.
279 // opencl_unroll_hint can have 0 arguments (compiler
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000280 // determines unrolling factor) or 1 argument (the unroll factor provided
281 // by the user).
282
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000283 unsigned NumArgs = A.getNumArgs();
284
285 if (NumArgs > 1) {
Erich Keane44bacdf2018-08-09 13:21:32 +0000286 S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << A << 1;
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000287 return nullptr;
288 }
289
290 unsigned UnrollFactor = 0;
291
292 if (NumArgs == 1) {
293 Expr *E = A.getArgAsExpr(0);
294 llvm::APSInt ArgVal(32);
295
296 if (!E->isIntegerConstantExpr(ArgVal, S.Context)) {
297 S.Diag(A.getLoc(), diag::err_attribute_argument_type)
Erich Keane44bacdf2018-08-09 13:21:32 +0000298 << A << AANT_ArgumentIntegerConstant << E->getSourceRange();
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000299 return nullptr;
300 }
301
302 int Val = ArgVal.getSExtValue();
303
304 if (Val <= 0) {
305 S.Diag(A.getRange().getBegin(),
306 diag::err_attribute_requires_positive_integer)
Erich Keane44bacdf2018-08-09 13:21:32 +0000307 << A;
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000308 return nullptr;
309 }
310 UnrollFactor = Val;
311 }
312
313 return OpenCLUnrollHintAttr::CreateImplicit(S.Context, UnrollFactor);
314}
315
Erich Keanee891aa92018-07-13 15:07:47 +0000316static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
Eli Bendersky06a40422014-06-06 20:31:48 +0000317 SourceRange Range) {
318 switch (A.getKind()) {
Erich Keanee891aa92018-07-13 15:07:47 +0000319 case ParsedAttr::UnknownAttribute:
Michael Han23214e52012-10-03 01:56:22 +0000320 S.Diag(A.getLoc(), A.isDeclspecAttribute() ?
321 diag::warn_unhandled_ms_attribute_ignored :
322 diag::warn_unknown_attribute_ignored) << A.getName();
Eli Bendersky06a40422014-06-06 20:31:48 +0000323 return nullptr;
Erich Keanee891aa92018-07-13 15:07:47 +0000324 case ParsedAttr::AT_FallThrough:
Eli Bendersky06a40422014-06-06 20:31:48 +0000325 return handleFallThroughAttr(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000326 case ParsedAttr::AT_LoopHint:
Eli Bendersky06a40422014-06-06 20:31:48 +0000327 return handleLoopHintAttr(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000328 case ParsedAttr::AT_OpenCLUnrollHint:
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000329 return handleOpenCLUnrollHint(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000330 case ParsedAttr::AT_Suppress:
Matthias Gehre01a63382017-03-27 19:45:24 +0000331 return handleSuppressAttr(S, St, A, Range);
Eli Bendersky06a40422014-06-06 20:31:48 +0000332 default:
333 // if we're here, then we parsed a known attribute, but didn't recognize
334 // it as a statement attribute => it is declaration attribute
Richard Smith4f902c72016-03-08 00:32:55 +0000335 S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000336 << A.getName() << St->getBeginLoc();
Craig Topperc3ec1492014-05-26 06:22:03 +0000337 return nullptr;
Richard Smithc202b282012-04-14 00:33:13 +0000338 }
339}
340
Erich Keanec480f302018-07-12 21:09:05 +0000341StmtResult Sema::ProcessStmtAttributes(Stmt *S,
342 const ParsedAttributesView &AttrList,
Richard Smithc202b282012-04-14 00:33:13 +0000343 SourceRange Range) {
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000344 SmallVector<const Attr*, 8> Attrs;
Erich Keanee891aa92018-07-13 15:07:47 +0000345 for (const ParsedAttr &AL : AttrList) {
Erich Keanec480f302018-07-12 21:09:05 +0000346 if (Attr *a = ProcessStmtAttribute(*this, S, AL, Range))
Eli Bendersky06a40422014-06-06 20:31:48 +0000347 Attrs.push_back(a);
348 }
349
350 CheckForIncompatibleAttributes(*this, Attrs);
351
352 if (Attrs.empty())
353 return S;
354
Richard Smithc202b282012-04-14 00:33:13 +0000355 return ActOnAttributedStmt(Range.getBegin(), Attrs, S);
356}