blob: 353cd60c4a42c1c3a300f3d27fab012ae930ca20 [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"
Eli Bendersky06a40422014-06-06 20:31:48 +000019#include "clang/Sema/ScopeInfo.h"
20#include "llvm/ADT/StringExtras.h"
21
Richard Smithc202b282012-04-14 00:33:13 +000022using namespace clang;
23using namespace sema;
24
Erich Keanee891aa92018-07-13 15:07:47 +000025static Attr *handleFallThroughAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Richard Smith84837d52012-05-03 18:27:39 +000026 SourceRange Range) {
Richard Smith4f902c72016-03-08 00:32:55 +000027 FallThroughAttr Attr(A.getRange(), S.Context,
28 A.getAttributeSpellingListIndex());
Richard Smith84837d52012-05-03 18:27:39 +000029 if (!isa<NullStmt>(St)) {
30 S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_wrong_target)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000031 << Attr.getSpelling() << St->getBeginLoc();
Richard Smith84837d52012-05-03 18:27:39 +000032 if (isa<SwitchCase>(St)) {
Alp Tokerb6cc5922014-05-03 03:45:55 +000033 SourceLocation L = S.getLocForEndOfToken(Range.getEnd());
Richard Smith84837d52012-05-03 18:27:39 +000034 S.Diag(L, diag::note_fallthrough_insert_semi_fixit)
35 << FixItHint::CreateInsertion(L, ";");
36 }
Craig Topperc3ec1492014-05-26 06:22:03 +000037 return nullptr;
Richard Smith84837d52012-05-03 18:27:39 +000038 }
Richard Smith4f902c72016-03-08 00:32:55 +000039 auto *FnScope = S.getCurFunction();
40 if (FnScope->SwitchStack.empty()) {
Richard Smith84837d52012-05-03 18:27:39 +000041 S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_outside_switch);
Craig Topperc3ec1492014-05-26 06:22:03 +000042 return nullptr;
Richard Smith84837d52012-05-03 18:27:39 +000043 }
Richard Smith4f902c72016-03-08 00:32:55 +000044
Aaron Ballmanc351fba2017-12-04 20:27:34 +000045 // If this is spelled as the standard C++17 attribute, but not in C++17, warn
Richard Smith4f902c72016-03-08 00:32:55 +000046 // about using it as an extension.
Aaron Ballmanc351fba2017-12-04 20:27:34 +000047 if (!S.getLangOpts().CPlusPlus17 && A.isCXX11Attribute() &&
Richard Smith4f902c72016-03-08 00:32:55 +000048 !A.getScopeName())
Richard Smithb115e5d2017-08-13 23:37:29 +000049 S.Diag(A.getLoc(), diag::ext_cxx17_attr) << A.getName();
Richard Smith4f902c72016-03-08 00:32:55 +000050
51 FnScope->setHasFallthroughStmt();
52 return ::new (S.Context) auto(Attr);
Eli Bendersky06a40422014-06-06 20:31:48 +000053}
54
Erich Keanee891aa92018-07-13 15:07:47 +000055static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Matthias Gehre01a63382017-03-27 19:45:24 +000056 SourceRange Range) {
57 if (A.getNumArgs() < 1) {
Erich Keane44bacdf2018-08-09 13:21:32 +000058 S.Diag(A.getLoc(), diag::err_attribute_too_few_arguments) << A << 1;
Matthias Gehre01a63382017-03-27 19:45:24 +000059 return nullptr;
60 }
61
62 std::vector<StringRef> DiagnosticIdentifiers;
63 for (unsigned I = 0, E = A.getNumArgs(); I != E; ++I) {
64 StringRef RuleName;
65
66 if (!S.checkStringLiteralArgumentAttr(A, I, RuleName, nullptr))
67 return nullptr;
68
69 // FIXME: Warn if the rule name is unknown. This is tricky because only
70 // clang-tidy knows about available rules.
71 DiagnosticIdentifiers.push_back(RuleName);
72 }
73
74 return ::new (S.Context) SuppressAttr(
75 A.getRange(), S.Context, DiagnosticIdentifiers.data(),
76 DiagnosticIdentifiers.size(), A.getAttributeSpellingListIndex());
77}
78
Erich Keanee891aa92018-07-13 15:07:47 +000079static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Eli Bendersky06a40422014-06-06 20:31:48 +000080 SourceRange) {
Mark Heffernanbd26f5e2014-07-21 18:08:34 +000081 IdentifierLoc *PragmaNameLoc = A.getArgAsIdent(0);
82 IdentifierLoc *OptionLoc = A.getArgAsIdent(1);
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +000083 IdentifierLoc *StateLoc = A.getArgAsIdent(2);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +000084 Expr *ValueExpr = A.getArgAsExpr(3);
85
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +000086 bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
87 bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
David Greenc8e39242018-08-01 14:36:12 +000088 bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == "unroll_and_jam";
89 bool PragmaNoUnrollAndJam =
90 PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
Eli Bendersky06a40422014-06-06 20:31:48 +000091 if (St->getStmtClass() != Stmt::DoStmtClass &&
92 St->getStmtClass() != Stmt::ForStmtClass &&
93 St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
94 St->getStmtClass() != Stmt::WhileStmtClass) {
Mark Heffernanc888e412014-07-24 18:09:38 +000095 const char *Pragma =
96 llvm::StringSwitch<const char *>(PragmaNameLoc->Ident->getName())
97 .Case("unroll", "#pragma unroll")
98 .Case("nounroll", "#pragma nounroll")
David Greenc8e39242018-08-01 14:36:12 +000099 .Case("unroll_and_jam", "#pragma unroll_and_jam")
100 .Case("nounroll_and_jam", "#pragma nounroll_and_jam")
Mark Heffernanc888e412014-07-24 18:09:38 +0000101 .Default("#pragma clang loop");
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000102 S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << Pragma;
Eli Bendersky06a40422014-06-06 20:31:48 +0000103 return nullptr;
104 }
105
Erich Keanebe89f4c52017-08-09 15:27:36 +0000106 LoopHintAttr::Spelling Spelling =
107 LoopHintAttr::Spelling(A.getAttributeSpellingListIndex());
Mark Heffernan397a98d2015-08-10 17:29:39 +0000108 LoopHintAttr::OptionType Option;
109 LoopHintAttr::LoopHintState State;
110 if (PragmaNoUnroll) {
111 // #pragma nounroll
Mark Heffernan397a98d2015-08-10 17:29:39 +0000112 Option = LoopHintAttr::Unroll;
113 State = LoopHintAttr::Disable;
114 } else if (PragmaUnroll) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000115 if (ValueExpr) {
116 // #pragma unroll N
117 Option = LoopHintAttr::UnrollCount;
118 State = LoopHintAttr::Numeric;
119 } else {
120 // #pragma unroll
121 Option = LoopHintAttr::Unroll;
122 State = LoopHintAttr::Enable;
123 }
David Greenc8e39242018-08-01 14:36:12 +0000124 } else if (PragmaNoUnrollAndJam) {
125 // #pragma nounroll_and_jam
126 Option = LoopHintAttr::UnrollAndJam;
127 State = LoopHintAttr::Disable;
128 } else if (PragmaUnrollAndJam) {
129 if (ValueExpr) {
130 // #pragma unroll_and_jam N
131 Option = LoopHintAttr::UnrollAndJamCount;
132 State = LoopHintAttr::Numeric;
133 } else {
134 // #pragma unroll_and_jam
135 Option = LoopHintAttr::UnrollAndJam;
136 State = LoopHintAttr::Enable;
137 }
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000138 } else {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000139 // #pragma clang loop ...
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000140 assert(OptionLoc && OptionLoc->Ident &&
141 "Attribute must have valid option info.");
Mark Heffernan397a98d2015-08-10 17:29:39 +0000142 Option = llvm::StringSwitch<LoopHintAttr::OptionType>(
143 OptionLoc->Ident->getName())
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000144 .Case("vectorize", LoopHintAttr::Vectorize)
145 .Case("vectorize_width", LoopHintAttr::VectorizeWidth)
146 .Case("interleave", LoopHintAttr::Interleave)
147 .Case("interleave_count", LoopHintAttr::InterleaveCount)
148 .Case("unroll", LoopHintAttr::Unroll)
149 .Case("unroll_count", LoopHintAttr::UnrollCount)
Adam Nemet2de463e2016-06-14 12:04:26 +0000150 .Case("distribute", LoopHintAttr::Distribute)
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000151 .Default(LoopHintAttr::Vectorize);
Mark Heffernan397a98d2015-08-10 17:29:39 +0000152 if (Option == LoopHintAttr::VectorizeWidth ||
153 Option == LoopHintAttr::InterleaveCount ||
154 Option == LoopHintAttr::UnrollCount) {
155 assert(ValueExpr && "Attribute must have a valid value expression.");
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000156 if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc()))
Mark Heffernan397a98d2015-08-10 17:29:39 +0000157 return nullptr;
158 State = LoopHintAttr::Numeric;
159 } else if (Option == LoopHintAttr::Vectorize ||
160 Option == LoopHintAttr::Interleave ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000161 Option == LoopHintAttr::Unroll ||
162 Option == LoopHintAttr::Distribute) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000163 assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument");
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000164 if (StateLoc->Ident->isStr("disable"))
165 State = LoopHintAttr::Disable;
Tyler Nowicki9d268e12015-06-11 23:23:17 +0000166 else if (StateLoc->Ident->isStr("assume_safety"))
167 State = LoopHintAttr::AssumeSafety;
Mark Heffernan397a98d2015-08-10 17:29:39 +0000168 else if (StateLoc->Ident->isStr("full"))
169 State = LoopHintAttr::Full;
170 else if (StateLoc->Ident->isStr("enable"))
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000171 State = LoopHintAttr::Enable;
Mark Heffernan397a98d2015-08-10 17:29:39 +0000172 else
173 llvm_unreachable("bad loop hint argument");
174 } else
175 llvm_unreachable("bad loop hint");
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000176 }
Eli Bendersky06a40422014-06-06 20:31:48 +0000177
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000178 return LoopHintAttr::CreateImplicit(S.Context, Spelling, Option, State,
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000179 ValueExpr, A.getRange());
Eli Bendersky06a40422014-06-06 20:31:48 +0000180}
181
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000182static void
183CheckForIncompatibleAttributes(Sema &S,
184 const SmallVectorImpl<const Attr *> &Attrs) {
David Greenc8e39242018-08-01 14:36:12 +0000185 // There are 5 categories of loop hints attributes: vectorize, interleave,
186 // unroll, unroll_and_jam and distribute. Except for distribute they come
187 // in two variants: a state form and a numeric form. The state form
188 // selectively defaults/enables/disables the transformation for the loop
189 // (for unroll, default indicates full unrolling rather than enabling the
190 // transformation). The numeric form form provides an integer hint (for
191 // example, unroll count) to the transformer. The following array accumulates
192 // the hints encountered while iterating through the attributes to check for
193 // compatibility.
Eli Bendersky86483b32014-06-11 17:56:26 +0000194 struct {
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000195 const LoopHintAttr *StateAttr;
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000196 const LoopHintAttr *NumericAttr;
Adam Nemet2de463e2016-06-14 12:04:26 +0000197 } HintAttrs[] = {{nullptr, nullptr},
198 {nullptr, nullptr},
199 {nullptr, nullptr},
David Greenc8e39242018-08-01 14:36:12 +0000200 {nullptr, nullptr},
Adam Nemet2de463e2016-06-14 12:04:26 +0000201 {nullptr, nullptr}};
Eli Bendersky06a40422014-06-06 20:31:48 +0000202
203 for (const auto *I : Attrs) {
204 const LoopHintAttr *LH = dyn_cast<LoopHintAttr>(I);
205
206 // Skip non loop hint attributes
207 if (!LH)
208 continue;
209
Craig Topperec9be542015-12-23 05:44:43 +0000210 LoopHintAttr::OptionType Option = LH->getOption();
David Greenc8e39242018-08-01 14:36:12 +0000211 enum { Vectorize, Interleave, Unroll, UnrollAndJam, Distribute } Category;
Eli Bendersky06a40422014-06-06 20:31:48 +0000212 switch (Option) {
213 case LoopHintAttr::Vectorize:
214 case LoopHintAttr::VectorizeWidth:
Mark Heffernan450c2382014-07-23 17:31:31 +0000215 Category = Vectorize;
Eli Bendersky06a40422014-06-06 20:31:48 +0000216 break;
217 case LoopHintAttr::Interleave:
218 case LoopHintAttr::InterleaveCount:
Mark Heffernan450c2382014-07-23 17:31:31 +0000219 Category = Interleave;
Eli Bendersky06a40422014-06-06 20:31:48 +0000220 break;
Eli Bendersky86483b32014-06-11 17:56:26 +0000221 case LoopHintAttr::Unroll:
222 case LoopHintAttr::UnrollCount:
Mark Heffernan450c2382014-07-23 17:31:31 +0000223 Category = Unroll;
Eli Bendersky86483b32014-06-11 17:56:26 +0000224 break;
David Greenc8e39242018-08-01 14:36:12 +0000225 case LoopHintAttr::UnrollAndJam:
226 case LoopHintAttr::UnrollAndJamCount:
227 Category = UnrollAndJam;
228 break;
Adam Nemet2de463e2016-06-14 12:04:26 +0000229 case LoopHintAttr::Distribute:
230 // Perform the check for duplicated 'distribute' hints.
231 Category = Distribute;
232 break;
Eli Bendersky86483b32014-06-11 17:56:26 +0000233 };
Eli Bendersky06a40422014-06-06 20:31:48 +0000234
David Greenc8e39242018-08-01 14:36:12 +0000235 assert(Category < sizeof(HintAttrs) / sizeof(HintAttrs[0]));
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000236 auto &CategoryState = HintAttrs[Category];
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000237 const LoopHintAttr *PrevAttr;
Eli Bendersky86483b32014-06-11 17:56:26 +0000238 if (Option == LoopHintAttr::Vectorize ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000239 Option == LoopHintAttr::Interleave || Option == LoopHintAttr::Unroll ||
David Greenc8e39242018-08-01 14:36:12 +0000240 Option == LoopHintAttr::UnrollAndJam ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000241 Option == LoopHintAttr::Distribute) {
Tyler Nowicki9d268e12015-06-11 23:23:17 +0000242 // Enable|Disable|AssumeSafety hint. For example, vectorize(enable).
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000243 PrevAttr = CategoryState.StateAttr;
244 CategoryState.StateAttr = LH;
Eli Bendersky06a40422014-06-06 20:31:48 +0000245 } else {
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000246 // Numeric hint. For example, vectorize_width(8).
247 PrevAttr = CategoryState.NumericAttr;
248 CategoryState.NumericAttr = LH;
Eli Bendersky06a40422014-06-06 20:31:48 +0000249 }
250
Tyler Nowicki884fc612014-07-29 17:21:32 +0000251 PrintingPolicy Policy(S.Context.getLangOpts());
252 SourceLocation OptionLoc = LH->getRange().getBegin();
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000253 if (PrevAttr)
254 // Cannot specify same type of attribute twice.
255 S.Diag(OptionLoc, diag::err_pragma_loop_compatibility)
Tyler Nowicki884fc612014-07-29 17:21:32 +0000256 << /*Duplicate=*/true << PrevAttr->getDiagnosticName(Policy)
257 << LH->getDiagnosticName(Policy);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000258
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000259 if (CategoryState.StateAttr && CategoryState.NumericAttr &&
David Greenc8e39242018-08-01 14:36:12 +0000260 (Category == Unroll || Category == UnrollAndJam ||
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000261 CategoryState.StateAttr->getState() == LoopHintAttr::Disable)) {
Mark Heffernan450c2382014-07-23 17:31:31 +0000262 // Disable hints are not compatible with numeric hints of the same
263 // category. As a special case, numeric unroll hints are also not
Mark Heffernan397a98d2015-08-10 17:29:39 +0000264 // compatible with enable or full form of the unroll pragma because these
265 // directives indicate full unrolling.
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000266 S.Diag(OptionLoc, diag::err_pragma_loop_compatibility)
Eli Bendersky86483b32014-06-11 17:56:26 +0000267 << /*Duplicate=*/false
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000268 << CategoryState.StateAttr->getDiagnosticName(Policy)
Tyler Nowicki884fc612014-07-29 17:21:32 +0000269 << CategoryState.NumericAttr->getDiagnosticName(Policy);
Eli Bendersky86483b32014-06-11 17:56:26 +0000270 }
Eli Bendersky06a40422014-06-06 20:31:48 +0000271 }
272}
273
Erich Keanee891aa92018-07-13 15:07:47 +0000274static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000275 SourceRange Range) {
Egor Churaev24939d42016-12-13 14:02:35 +0000276 // Although the feature was introduced only in OpenCL C v2.0 s6.11.5, it's
277 // useful for OpenCL 1.x too and doesn't require HW support.
278 // opencl_unroll_hint can have 0 arguments (compiler
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000279 // determines unrolling factor) or 1 argument (the unroll factor provided
280 // by the user).
281
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000282 unsigned NumArgs = A.getNumArgs();
283
284 if (NumArgs > 1) {
Erich Keane44bacdf2018-08-09 13:21:32 +0000285 S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << A << 1;
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000286 return nullptr;
287 }
288
289 unsigned UnrollFactor = 0;
290
291 if (NumArgs == 1) {
292 Expr *E = A.getArgAsExpr(0);
293 llvm::APSInt ArgVal(32);
294
295 if (!E->isIntegerConstantExpr(ArgVal, S.Context)) {
296 S.Diag(A.getLoc(), diag::err_attribute_argument_type)
Erich Keane44bacdf2018-08-09 13:21:32 +0000297 << A << AANT_ArgumentIntegerConstant << E->getSourceRange();
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000298 return nullptr;
299 }
300
301 int Val = ArgVal.getSExtValue();
302
303 if (Val <= 0) {
304 S.Diag(A.getRange().getBegin(),
305 diag::err_attribute_requires_positive_integer)
Andrew Savonichev1a5623482018-09-17 10:39:46 +0000306 << A << /* positive */ 0;
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000307 return nullptr;
308 }
309 UnrollFactor = Val;
310 }
311
312 return OpenCLUnrollHintAttr::CreateImplicit(S.Context, UnrollFactor);
313}
314
Erich Keanee891aa92018-07-13 15:07:47 +0000315static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
Eli Bendersky06a40422014-06-06 20:31:48 +0000316 SourceRange Range) {
317 switch (A.getKind()) {
Erich Keanee891aa92018-07-13 15:07:47 +0000318 case ParsedAttr::UnknownAttribute:
Michael Han23214e52012-10-03 01:56:22 +0000319 S.Diag(A.getLoc(), A.isDeclspecAttribute() ?
320 diag::warn_unhandled_ms_attribute_ignored :
321 diag::warn_unknown_attribute_ignored) << A.getName();
Eli Bendersky06a40422014-06-06 20:31:48 +0000322 return nullptr;
Erich Keanee891aa92018-07-13 15:07:47 +0000323 case ParsedAttr::AT_FallThrough:
Eli Bendersky06a40422014-06-06 20:31:48 +0000324 return handleFallThroughAttr(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000325 case ParsedAttr::AT_LoopHint:
Eli Bendersky06a40422014-06-06 20:31:48 +0000326 return handleLoopHintAttr(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000327 case ParsedAttr::AT_OpenCLUnrollHint:
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000328 return handleOpenCLUnrollHint(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000329 case ParsedAttr::AT_Suppress:
Matthias Gehre01a63382017-03-27 19:45:24 +0000330 return handleSuppressAttr(S, St, A, Range);
Eli Bendersky06a40422014-06-06 20:31:48 +0000331 default:
332 // if we're here, then we parsed a known attribute, but didn't recognize
333 // it as a statement attribute => it is declaration attribute
Richard Smith4f902c72016-03-08 00:32:55 +0000334 S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000335 << A.getName() << St->getBeginLoc();
Craig Topperc3ec1492014-05-26 06:22:03 +0000336 return nullptr;
Richard Smithc202b282012-04-14 00:33:13 +0000337 }
338}
339
Erich Keanec480f302018-07-12 21:09:05 +0000340StmtResult Sema::ProcessStmtAttributes(Stmt *S,
341 const ParsedAttributesView &AttrList,
Richard Smithc202b282012-04-14 00:33:13 +0000342 SourceRange Range) {
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000343 SmallVector<const Attr*, 8> Attrs;
Erich Keanee891aa92018-07-13 15:07:47 +0000344 for (const ParsedAttr &AL : AttrList) {
Erich Keanec480f302018-07-12 21:09:05 +0000345 if (Attr *a = ProcessStmtAttribute(*this, S, AL, Range))
Eli Bendersky06a40422014-06-06 20:31:48 +0000346 Attrs.push_back(a);
347 }
348
349 CheckForIncompatibleAttributes(*this, Attrs);
350
351 if (Attrs.empty())
352 return S;
353
Richard Smithc202b282012-04-14 00:33:13 +0000354 return ActOnAttributedStmt(Range.getBegin(), Attrs, S);
355}