blob: 3d91893b40650af62b3c8ecef3aa5abd1d0e6225 [file] [log] [blame]
Richard Smithc202b282012-04-14 00:33:13 +00001//===--- SemaStmtAttr.cpp - Statement Attribute Handling ------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Richard Smithc202b282012-04-14 00:33:13 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements stmt-related attribute processing.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Sema/SemaInternal.h"
Richard Smithc202b282012-04-14 00:33:13 +000014#include "clang/AST/ASTContext.h"
Eli Bendersky06a40422014-06-06 20:31:48 +000015#include "clang/Basic/SourceManager.h"
16#include "clang/Sema/DelayedDiagnostic.h"
17#include "clang/Sema/Lookup.h"
Eli Bendersky06a40422014-06-06 20:31:48 +000018#include "clang/Sema/ScopeInfo.h"
19#include "llvm/ADT/StringExtras.h"
20
Richard Smithc202b282012-04-14 00:33:13 +000021using namespace clang;
22using namespace sema;
23
Erich Keanee891aa92018-07-13 15:07:47 +000024static Attr *handleFallThroughAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Richard Smith84837d52012-05-03 18:27:39 +000025 SourceRange Range) {
Erich Keane6a24e802019-09-13 17:39:31 +000026 FallThroughAttr Attr(S.Context, A);
Richard Smith84837d52012-05-03 18:27:39 +000027 if (!isa<NullStmt>(St)) {
28 S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_wrong_target)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000029 << Attr.getSpelling() << St->getBeginLoc();
Richard Smith84837d52012-05-03 18:27:39 +000030 if (isa<SwitchCase>(St)) {
Alp Tokerb6cc5922014-05-03 03:45:55 +000031 SourceLocation L = S.getLocForEndOfToken(Range.getEnd());
Richard Smith84837d52012-05-03 18:27:39 +000032 S.Diag(L, diag::note_fallthrough_insert_semi_fixit)
33 << FixItHint::CreateInsertion(L, ";");
34 }
Craig Topperc3ec1492014-05-26 06:22:03 +000035 return nullptr;
Richard Smith84837d52012-05-03 18:27:39 +000036 }
Richard Smith4f902c72016-03-08 00:32:55 +000037 auto *FnScope = S.getCurFunction();
38 if (FnScope->SwitchStack.empty()) {
Richard Smith84837d52012-05-03 18:27:39 +000039 S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_outside_switch);
Craig Topperc3ec1492014-05-26 06:22:03 +000040 return nullptr;
Richard Smith84837d52012-05-03 18:27:39 +000041 }
Richard Smith4f902c72016-03-08 00:32:55 +000042
Aaron Ballmanc351fba2017-12-04 20:27:34 +000043 // If this is spelled as the standard C++17 attribute, but not in C++17, warn
Richard Smith4f902c72016-03-08 00:32:55 +000044 // about using it as an extension.
Aaron Ballmanc351fba2017-12-04 20:27:34 +000045 if (!S.getLangOpts().CPlusPlus17 && A.isCXX11Attribute() &&
Richard Smith4f902c72016-03-08 00:32:55 +000046 !A.getScopeName())
Erich Keane6a24e802019-09-13 17:39:31 +000047 S.Diag(A.getLoc(), diag::ext_cxx17_attr) << A;
Richard Smith4f902c72016-03-08 00:32:55 +000048
49 FnScope->setHasFallthroughStmt();
Erich Keane6a24e802019-09-13 17:39:31 +000050 return ::new (S.Context) FallThroughAttr(S.Context, A);
Eli Bendersky06a40422014-06-06 20:31:48 +000051}
52
Erich Keanee891aa92018-07-13 15:07:47 +000053static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Matthias Gehre01a63382017-03-27 19:45:24 +000054 SourceRange Range) {
55 if (A.getNumArgs() < 1) {
Erich Keane44bacdf2018-08-09 13:21:32 +000056 S.Diag(A.getLoc(), diag::err_attribute_too_few_arguments) << A << 1;
Matthias Gehre01a63382017-03-27 19:45:24 +000057 return nullptr;
58 }
59
60 std::vector<StringRef> DiagnosticIdentifiers;
61 for (unsigned I = 0, E = A.getNumArgs(); I != E; ++I) {
62 StringRef RuleName;
63
64 if (!S.checkStringLiteralArgumentAttr(A, I, RuleName, nullptr))
65 return nullptr;
66
67 // FIXME: Warn if the rule name is unknown. This is tricky because only
68 // clang-tidy knows about available rules.
69 DiagnosticIdentifiers.push_back(RuleName);
70 }
71
72 return ::new (S.Context) SuppressAttr(
Erich Keane6a24e802019-09-13 17:39:31 +000073 S.Context, A, DiagnosticIdentifiers.data(), DiagnosticIdentifiers.size());
Matthias Gehre01a63382017-03-27 19:45:24 +000074}
75
Erich Keanee891aa92018-07-13 15:07:47 +000076static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Eli Bendersky06a40422014-06-06 20:31:48 +000077 SourceRange) {
Mark Heffernanbd26f5e2014-07-21 18:08:34 +000078 IdentifierLoc *PragmaNameLoc = A.getArgAsIdent(0);
79 IdentifierLoc *OptionLoc = A.getArgAsIdent(1);
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +000080 IdentifierLoc *StateLoc = A.getArgAsIdent(2);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +000081 Expr *ValueExpr = A.getArgAsExpr(3);
82
Sjoerd Meijer6b615192019-07-10 13:34:57 +000083 StringRef PragmaName =
84 llvm::StringSwitch<StringRef>(PragmaNameLoc->Ident->getName())
85 .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
86 PragmaNameLoc->Ident->getName())
87 .Default("clang loop");
88
Eli Bendersky06a40422014-06-06 20:31:48 +000089 if (St->getStmtClass() != Stmt::DoStmtClass &&
90 St->getStmtClass() != Stmt::ForStmtClass &&
91 St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
92 St->getStmtClass() != Stmt::WhileStmtClass) {
Sjoerd Meijer6b615192019-07-10 13:34:57 +000093 std::string Pragma = "#pragma " + std::string(PragmaName);
Stephen Kellyf2ceec42018-08-09 21:08:08 +000094 S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << Pragma;
Eli Bendersky06a40422014-06-06 20:31:48 +000095 return nullptr;
96 }
97
Mark Heffernan397a98d2015-08-10 17:29:39 +000098 LoopHintAttr::OptionType Option;
99 LoopHintAttr::LoopHintState State;
Sjoerd Meijer6b615192019-07-10 13:34:57 +0000100
101 auto SetHints = [&Option, &State](LoopHintAttr::OptionType O,
102 LoopHintAttr::LoopHintState S) {
103 Option = O;
104 State = S;
105 };
106
107 if (PragmaName == "nounroll") {
108 SetHints(LoopHintAttr::Unroll, LoopHintAttr::Disable);
109 } else if (PragmaName == "unroll") {
110 // #pragma unroll N
111 if (ValueExpr)
112 SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Numeric);
113 else
114 SetHints(LoopHintAttr::Unroll, LoopHintAttr::Enable);
115 } else if (PragmaName == "nounroll_and_jam") {
116 SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Disable);
117 } else if (PragmaName == "unroll_and_jam") {
118 // #pragma unroll_and_jam N
119 if (ValueExpr)
120 SetHints(LoopHintAttr::UnrollAndJamCount, LoopHintAttr::Numeric);
121 else
122 SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000123 } else {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000124 // #pragma clang loop ...
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000125 assert(OptionLoc && OptionLoc->Ident &&
126 "Attribute must have valid option info.");
Mark Heffernan397a98d2015-08-10 17:29:39 +0000127 Option = llvm::StringSwitch<LoopHintAttr::OptionType>(
128 OptionLoc->Ident->getName())
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000129 .Case("vectorize", LoopHintAttr::Vectorize)
130 .Case("vectorize_width", LoopHintAttr::VectorizeWidth)
131 .Case("interleave", LoopHintAttr::Interleave)
Sjoerd Meijera48f58c2019-07-25 07:33:13 +0000132 .Case("vectorize_predicate", LoopHintAttr::VectorizePredicate)
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000133 .Case("interleave_count", LoopHintAttr::InterleaveCount)
134 .Case("unroll", LoopHintAttr::Unroll)
135 .Case("unroll_count", LoopHintAttr::UnrollCount)
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000136 .Case("pipeline", LoopHintAttr::PipelineDisabled)
137 .Case("pipeline_initiation_interval",
138 LoopHintAttr::PipelineInitiationInterval)
Adam Nemet2de463e2016-06-14 12:04:26 +0000139 .Case("distribute", LoopHintAttr::Distribute)
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000140 .Default(LoopHintAttr::Vectorize);
Mark Heffernan397a98d2015-08-10 17:29:39 +0000141 if (Option == LoopHintAttr::VectorizeWidth ||
142 Option == LoopHintAttr::InterleaveCount ||
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000143 Option == LoopHintAttr::UnrollCount ||
144 Option == LoopHintAttr::PipelineInitiationInterval) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000145 assert(ValueExpr && "Attribute must have a valid value expression.");
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000146 if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc()))
Mark Heffernan397a98d2015-08-10 17:29:39 +0000147 return nullptr;
148 State = LoopHintAttr::Numeric;
149 } else if (Option == LoopHintAttr::Vectorize ||
150 Option == LoopHintAttr::Interleave ||
Sjoerd Meijera48f58c2019-07-25 07:33:13 +0000151 Option == LoopHintAttr::VectorizePredicate ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000152 Option == LoopHintAttr::Unroll ||
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000153 Option == LoopHintAttr::Distribute ||
154 Option == LoopHintAttr::PipelineDisabled) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000155 assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument");
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000156 if (StateLoc->Ident->isStr("disable"))
157 State = LoopHintAttr::Disable;
Tyler Nowicki9d268e12015-06-11 23:23:17 +0000158 else if (StateLoc->Ident->isStr("assume_safety"))
159 State = LoopHintAttr::AssumeSafety;
Mark Heffernan397a98d2015-08-10 17:29:39 +0000160 else if (StateLoc->Ident->isStr("full"))
161 State = LoopHintAttr::Full;
162 else if (StateLoc->Ident->isStr("enable"))
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000163 State = LoopHintAttr::Enable;
Mark Heffernan397a98d2015-08-10 17:29:39 +0000164 else
165 llvm_unreachable("bad loop hint argument");
166 } else
167 llvm_unreachable("bad loop hint");
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000168 }
Eli Bendersky06a40422014-06-06 20:31:48 +0000169
Erich Keane6a24e802019-09-13 17:39:31 +0000170 return LoopHintAttr::CreateImplicit(S.Context, Option, State, ValueExpr, A);
Eli Bendersky06a40422014-06-06 20:31:48 +0000171}
172
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000173static void
174CheckForIncompatibleAttributes(Sema &S,
175 const SmallVectorImpl<const Attr *> &Attrs) {
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000176 // There are 6 categories of loop hints attributes: vectorize, interleave,
177 // unroll, unroll_and_jam, pipeline and distribute. Except for distribute they
178 // come in two variants: a state form and a numeric form. The state form
David Greenc8e39242018-08-01 14:36:12 +0000179 // selectively defaults/enables/disables the transformation for the loop
180 // (for unroll, default indicates full unrolling rather than enabling the
181 // transformation). The numeric form form provides an integer hint (for
182 // example, unroll count) to the transformer. The following array accumulates
183 // the hints encountered while iterating through the attributes to check for
184 // compatibility.
Eli Bendersky86483b32014-06-11 17:56:26 +0000185 struct {
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000186 const LoopHintAttr *StateAttr;
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000187 const LoopHintAttr *NumericAttr;
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000188 } HintAttrs[] = {{nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr},
Sjoerd Meijera48f58c2019-07-25 07:33:13 +0000189 {nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr},
190 {nullptr, nullptr}};
Eli Bendersky06a40422014-06-06 20:31:48 +0000191
192 for (const auto *I : Attrs) {
193 const LoopHintAttr *LH = dyn_cast<LoopHintAttr>(I);
194
195 // Skip non loop hint attributes
196 if (!LH)
197 continue;
198
Craig Topperec9be542015-12-23 05:44:43 +0000199 LoopHintAttr::OptionType Option = LH->getOption();
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000200 enum {
201 Vectorize,
202 Interleave,
203 Unroll,
204 UnrollAndJam,
205 Distribute,
Sjoerd Meijera48f58c2019-07-25 07:33:13 +0000206 Pipeline,
207 VectorizePredicate
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000208 } Category;
Eli Bendersky06a40422014-06-06 20:31:48 +0000209 switch (Option) {
210 case LoopHintAttr::Vectorize:
211 case LoopHintAttr::VectorizeWidth:
Mark Heffernan450c2382014-07-23 17:31:31 +0000212 Category = Vectorize;
Eli Bendersky06a40422014-06-06 20:31:48 +0000213 break;
214 case LoopHintAttr::Interleave:
215 case LoopHintAttr::InterleaveCount:
Mark Heffernan450c2382014-07-23 17:31:31 +0000216 Category = Interleave;
Eli Bendersky06a40422014-06-06 20:31:48 +0000217 break;
Eli Bendersky86483b32014-06-11 17:56:26 +0000218 case LoopHintAttr::Unroll:
219 case LoopHintAttr::UnrollCount:
Mark Heffernan450c2382014-07-23 17:31:31 +0000220 Category = Unroll;
Eli Bendersky86483b32014-06-11 17:56:26 +0000221 break;
David Greenc8e39242018-08-01 14:36:12 +0000222 case LoopHintAttr::UnrollAndJam:
223 case LoopHintAttr::UnrollAndJamCount:
224 Category = UnrollAndJam;
225 break;
Adam Nemet2de463e2016-06-14 12:04:26 +0000226 case LoopHintAttr::Distribute:
227 // Perform the check for duplicated 'distribute' hints.
228 Category = Distribute;
229 break;
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000230 case LoopHintAttr::PipelineDisabled:
231 case LoopHintAttr::PipelineInitiationInterval:
232 Category = Pipeline;
233 break;
Sjoerd Meijera48f58c2019-07-25 07:33:13 +0000234 case LoopHintAttr::VectorizePredicate:
235 Category = VectorizePredicate;
236 break;
Eli Bendersky86483b32014-06-11 17:56:26 +0000237 };
Eli Bendersky06a40422014-06-06 20:31:48 +0000238
David Greenc8e39242018-08-01 14:36:12 +0000239 assert(Category < sizeof(HintAttrs) / sizeof(HintAttrs[0]));
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000240 auto &CategoryState = HintAttrs[Category];
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000241 const LoopHintAttr *PrevAttr;
Eli Bendersky86483b32014-06-11 17:56:26 +0000242 if (Option == LoopHintAttr::Vectorize ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000243 Option == LoopHintAttr::Interleave || Option == LoopHintAttr::Unroll ||
David Greenc8e39242018-08-01 14:36:12 +0000244 Option == LoopHintAttr::UnrollAndJam ||
Sjoerd Meijera48f58c2019-07-25 07:33:13 +0000245 Option == LoopHintAttr::VectorizePredicate ||
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000246 Option == LoopHintAttr::PipelineDisabled ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000247 Option == LoopHintAttr::Distribute) {
Tyler Nowicki9d268e12015-06-11 23:23:17 +0000248 // Enable|Disable|AssumeSafety hint. For example, vectorize(enable).
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000249 PrevAttr = CategoryState.StateAttr;
250 CategoryState.StateAttr = LH;
Eli Bendersky06a40422014-06-06 20:31:48 +0000251 } else {
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000252 // Numeric hint. For example, vectorize_width(8).
253 PrevAttr = CategoryState.NumericAttr;
254 CategoryState.NumericAttr = LH;
Eli Bendersky06a40422014-06-06 20:31:48 +0000255 }
256
Tyler Nowicki884fc612014-07-29 17:21:32 +0000257 PrintingPolicy Policy(S.Context.getLangOpts());
258 SourceLocation OptionLoc = LH->getRange().getBegin();
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000259 if (PrevAttr)
260 // Cannot specify same type of attribute twice.
261 S.Diag(OptionLoc, diag::err_pragma_loop_compatibility)
Tyler Nowicki884fc612014-07-29 17:21:32 +0000262 << /*Duplicate=*/true << PrevAttr->getDiagnosticName(Policy)
263 << LH->getDiagnosticName(Policy);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000264
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000265 if (CategoryState.StateAttr && CategoryState.NumericAttr &&
David Greenc8e39242018-08-01 14:36:12 +0000266 (Category == Unroll || Category == UnrollAndJam ||
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000267 CategoryState.StateAttr->getState() == LoopHintAttr::Disable)) {
Mark Heffernan450c2382014-07-23 17:31:31 +0000268 // Disable hints are not compatible with numeric hints of the same
269 // category. As a special case, numeric unroll hints are also not
Mark Heffernan397a98d2015-08-10 17:29:39 +0000270 // compatible with enable or full form of the unroll pragma because these
271 // directives indicate full unrolling.
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000272 S.Diag(OptionLoc, diag::err_pragma_loop_compatibility)
Eli Bendersky86483b32014-06-11 17:56:26 +0000273 << /*Duplicate=*/false
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000274 << CategoryState.StateAttr->getDiagnosticName(Policy)
Tyler Nowicki884fc612014-07-29 17:21:32 +0000275 << CategoryState.NumericAttr->getDiagnosticName(Policy);
Eli Bendersky86483b32014-06-11 17:56:26 +0000276 }
Eli Bendersky06a40422014-06-06 20:31:48 +0000277 }
278}
279
Erich Keanee891aa92018-07-13 15:07:47 +0000280static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000281 SourceRange Range) {
Egor Churaev24939d42016-12-13 14:02:35 +0000282 // Although the feature was introduced only in OpenCL C v2.0 s6.11.5, it's
283 // useful for OpenCL 1.x too and doesn't require HW support.
284 // opencl_unroll_hint can have 0 arguments (compiler
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000285 // determines unrolling factor) or 1 argument (the unroll factor provided
286 // by the user).
287
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000288 unsigned NumArgs = A.getNumArgs();
289
290 if (NumArgs > 1) {
Erich Keane44bacdf2018-08-09 13:21:32 +0000291 S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << A << 1;
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000292 return nullptr;
293 }
294
295 unsigned UnrollFactor = 0;
296
297 if (NumArgs == 1) {
298 Expr *E = A.getArgAsExpr(0);
299 llvm::APSInt ArgVal(32);
300
301 if (!E->isIntegerConstantExpr(ArgVal, S.Context)) {
302 S.Diag(A.getLoc(), diag::err_attribute_argument_type)
Erich Keane44bacdf2018-08-09 13:21:32 +0000303 << A << AANT_ArgumentIntegerConstant << E->getSourceRange();
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000304 return nullptr;
305 }
306
307 int Val = ArgVal.getSExtValue();
308
309 if (Val <= 0) {
310 S.Diag(A.getRange().getBegin(),
311 diag::err_attribute_requires_positive_integer)
Andrew Savonichev1a5623482018-09-17 10:39:46 +0000312 << A << /* positive */ 0;
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000313 return nullptr;
314 }
315 UnrollFactor = Val;
316 }
317
318 return OpenCLUnrollHintAttr::CreateImplicit(S.Context, UnrollFactor);
319}
320
Erich Keanee891aa92018-07-13 15:07:47 +0000321static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
Eli Bendersky06a40422014-06-06 20:31:48 +0000322 SourceRange Range) {
323 switch (A.getKind()) {
Erich Keanee891aa92018-07-13 15:07:47 +0000324 case ParsedAttr::UnknownAttribute:
Simon Pilgrim6d2d96e2018-12-17 12:25:42 +0000325 S.Diag(A.getLoc(), A.isDeclspecAttribute()
326 ? (unsigned)diag::warn_unhandled_ms_attribute_ignored
327 : (unsigned)diag::warn_unknown_attribute_ignored)
Erich Keane6a24e802019-09-13 17:39:31 +0000328 << A;
Eli Bendersky06a40422014-06-06 20:31:48 +0000329 return nullptr;
Erich Keanee891aa92018-07-13 15:07:47 +0000330 case ParsedAttr::AT_FallThrough:
Eli Bendersky06a40422014-06-06 20:31:48 +0000331 return handleFallThroughAttr(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000332 case ParsedAttr::AT_LoopHint:
Eli Bendersky06a40422014-06-06 20:31:48 +0000333 return handleLoopHintAttr(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000334 case ParsedAttr::AT_OpenCLUnrollHint:
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000335 return handleOpenCLUnrollHint(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000336 case ParsedAttr::AT_Suppress:
Matthias Gehre01a63382017-03-27 19:45:24 +0000337 return handleSuppressAttr(S, St, A, Range);
Eli Bendersky06a40422014-06-06 20:31:48 +0000338 default:
339 // if we're here, then we parsed a known attribute, but didn't recognize
340 // it as a statement attribute => it is declaration attribute
Richard Smith4f902c72016-03-08 00:32:55 +0000341 S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
Erich Keane6a24e802019-09-13 17:39:31 +0000342 << A << St->getBeginLoc();
Craig Topperc3ec1492014-05-26 06:22:03 +0000343 return nullptr;
Richard Smithc202b282012-04-14 00:33:13 +0000344 }
345}
346
Erich Keanec480f302018-07-12 21:09:05 +0000347StmtResult Sema::ProcessStmtAttributes(Stmt *S,
348 const ParsedAttributesView &AttrList,
Richard Smithc202b282012-04-14 00:33:13 +0000349 SourceRange Range) {
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000350 SmallVector<const Attr*, 8> Attrs;
Erich Keanee891aa92018-07-13 15:07:47 +0000351 for (const ParsedAttr &AL : AttrList) {
Erich Keanec480f302018-07-12 21:09:05 +0000352 if (Attr *a = ProcessStmtAttribute(*this, S, AL, Range))
Eli Bendersky06a40422014-06-06 20:31:48 +0000353 Attrs.push_back(a);
354 }
355
356 CheckForIncompatibleAttributes(*this, Attrs);
357
358 if (Attrs.empty())
359 return S;
360
Richard Smithc202b282012-04-14 00:33:13 +0000361 return ActOnAttributedStmt(Range.getBegin(), Attrs, S);
362}