blob: 623f6ef8e853da9618deb4a15e95a56101af8c34 [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) {
Richard Smith4f902c72016-03-08 00:32:55 +000026 FallThroughAttr Attr(A.getRange(), S.Context,
27 A.getAttributeSpellingListIndex());
Richard Smith84837d52012-05-03 18:27:39 +000028 if (!isa<NullStmt>(St)) {
29 S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_wrong_target)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000030 << Attr.getSpelling() << St->getBeginLoc();
Richard Smith84837d52012-05-03 18:27:39 +000031 if (isa<SwitchCase>(St)) {
Alp Tokerb6cc5922014-05-03 03:45:55 +000032 SourceLocation L = S.getLocForEndOfToken(Range.getEnd());
Richard Smith84837d52012-05-03 18:27:39 +000033 S.Diag(L, diag::note_fallthrough_insert_semi_fixit)
34 << FixItHint::CreateInsertion(L, ";");
35 }
Craig Topperc3ec1492014-05-26 06:22:03 +000036 return nullptr;
Richard Smith84837d52012-05-03 18:27:39 +000037 }
Richard Smith4f902c72016-03-08 00:32:55 +000038 auto *FnScope = S.getCurFunction();
39 if (FnScope->SwitchStack.empty()) {
Richard Smith84837d52012-05-03 18:27:39 +000040 S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_outside_switch);
Craig Topperc3ec1492014-05-26 06:22:03 +000041 return nullptr;
Richard Smith84837d52012-05-03 18:27:39 +000042 }
Richard Smith4f902c72016-03-08 00:32:55 +000043
Aaron Ballmanc351fba2017-12-04 20:27:34 +000044 // If this is spelled as the standard C++17 attribute, but not in C++17, warn
Richard Smith4f902c72016-03-08 00:32:55 +000045 // about using it as an extension.
Aaron Ballmanc351fba2017-12-04 20:27:34 +000046 if (!S.getLangOpts().CPlusPlus17 && A.isCXX11Attribute() &&
Richard Smith4f902c72016-03-08 00:32:55 +000047 !A.getScopeName())
Richard Smithb115e5d2017-08-13 23:37:29 +000048 S.Diag(A.getLoc(), diag::ext_cxx17_attr) << A.getName();
Richard Smith4f902c72016-03-08 00:32:55 +000049
50 FnScope->setHasFallthroughStmt();
51 return ::new (S.Context) auto(Attr);
Eli Bendersky06a40422014-06-06 20:31:48 +000052}
53
Erich Keanee891aa92018-07-13 15:07:47 +000054static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Matthias Gehre01a63382017-03-27 19:45:24 +000055 SourceRange Range) {
56 if (A.getNumArgs() < 1) {
Erich Keane44bacdf2018-08-09 13:21:32 +000057 S.Diag(A.getLoc(), diag::err_attribute_too_few_arguments) << A << 1;
Matthias Gehre01a63382017-03-27 19:45:24 +000058 return nullptr;
59 }
60
61 std::vector<StringRef> DiagnosticIdentifiers;
62 for (unsigned I = 0, E = A.getNumArgs(); I != E; ++I) {
63 StringRef RuleName;
64
65 if (!S.checkStringLiteralArgumentAttr(A, I, RuleName, nullptr))
66 return nullptr;
67
68 // FIXME: Warn if the rule name is unknown. This is tricky because only
69 // clang-tidy knows about available rules.
70 DiagnosticIdentifiers.push_back(RuleName);
71 }
72
73 return ::new (S.Context) SuppressAttr(
74 A.getRange(), S.Context, DiagnosticIdentifiers.data(),
75 DiagnosticIdentifiers.size(), A.getAttributeSpellingListIndex());
76}
77
Erich Keanee891aa92018-07-13 15:07:47 +000078static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Eli Bendersky06a40422014-06-06 20:31:48 +000079 SourceRange) {
Mark Heffernanbd26f5e2014-07-21 18:08:34 +000080 IdentifierLoc *PragmaNameLoc = A.getArgAsIdent(0);
81 IdentifierLoc *OptionLoc = A.getArgAsIdent(1);
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +000082 IdentifierLoc *StateLoc = A.getArgAsIdent(2);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +000083 Expr *ValueExpr = A.getArgAsExpr(3);
84
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +000085 bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
86 bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
David Greenc8e39242018-08-01 14:36:12 +000087 bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == "unroll_and_jam";
88 bool PragmaNoUnrollAndJam =
89 PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
Eli Bendersky06a40422014-06-06 20:31:48 +000090 if (St->getStmtClass() != Stmt::DoStmtClass &&
91 St->getStmtClass() != Stmt::ForStmtClass &&
92 St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
93 St->getStmtClass() != Stmt::WhileStmtClass) {
Mark Heffernanc888e412014-07-24 18:09:38 +000094 const char *Pragma =
95 llvm::StringSwitch<const char *>(PragmaNameLoc->Ident->getName())
96 .Case("unroll", "#pragma unroll")
97 .Case("nounroll", "#pragma nounroll")
David Greenc8e39242018-08-01 14:36:12 +000098 .Case("unroll_and_jam", "#pragma unroll_and_jam")
99 .Case("nounroll_and_jam", "#pragma nounroll_and_jam")
Mark Heffernanc888e412014-07-24 18:09:38 +0000100 .Default("#pragma clang loop");
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000101 S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << Pragma;
Eli Bendersky06a40422014-06-06 20:31:48 +0000102 return nullptr;
103 }
104
Erich Keanebe89f4c52017-08-09 15:27:36 +0000105 LoopHintAttr::Spelling Spelling =
106 LoopHintAttr::Spelling(A.getAttributeSpellingListIndex());
Mark Heffernan397a98d2015-08-10 17:29:39 +0000107 LoopHintAttr::OptionType Option;
108 LoopHintAttr::LoopHintState State;
109 if (PragmaNoUnroll) {
110 // #pragma nounroll
Mark Heffernan397a98d2015-08-10 17:29:39 +0000111 Option = LoopHintAttr::Unroll;
112 State = LoopHintAttr::Disable;
113 } else if (PragmaUnroll) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000114 if (ValueExpr) {
115 // #pragma unroll N
116 Option = LoopHintAttr::UnrollCount;
117 State = LoopHintAttr::Numeric;
118 } else {
119 // #pragma unroll
120 Option = LoopHintAttr::Unroll;
121 State = LoopHintAttr::Enable;
122 }
David Greenc8e39242018-08-01 14:36:12 +0000123 } else if (PragmaNoUnrollAndJam) {
124 // #pragma nounroll_and_jam
125 Option = LoopHintAttr::UnrollAndJam;
126 State = LoopHintAttr::Disable;
127 } else if (PragmaUnrollAndJam) {
128 if (ValueExpr) {
129 // #pragma unroll_and_jam N
130 Option = LoopHintAttr::UnrollAndJamCount;
131 State = LoopHintAttr::Numeric;
132 } else {
133 // #pragma unroll_and_jam
134 Option = LoopHintAttr::UnrollAndJam;
135 State = LoopHintAttr::Enable;
136 }
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000137 } else {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000138 // #pragma clang loop ...
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000139 assert(OptionLoc && OptionLoc->Ident &&
140 "Attribute must have valid option info.");
Mark Heffernan397a98d2015-08-10 17:29:39 +0000141 Option = llvm::StringSwitch<LoopHintAttr::OptionType>(
142 OptionLoc->Ident->getName())
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000143 .Case("vectorize", LoopHintAttr::Vectorize)
144 .Case("vectorize_width", LoopHintAttr::VectorizeWidth)
145 .Case("interleave", LoopHintAttr::Interleave)
146 .Case("interleave_count", LoopHintAttr::InterleaveCount)
147 .Case("unroll", LoopHintAttr::Unroll)
148 .Case("unroll_count", LoopHintAttr::UnrollCount)
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000149 .Case("pipeline", LoopHintAttr::PipelineDisabled)
150 .Case("pipeline_initiation_interval",
151 LoopHintAttr::PipelineInitiationInterval)
Adam Nemet2de463e2016-06-14 12:04:26 +0000152 .Case("distribute", LoopHintAttr::Distribute)
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000153 .Default(LoopHintAttr::Vectorize);
Mark Heffernan397a98d2015-08-10 17:29:39 +0000154 if (Option == LoopHintAttr::VectorizeWidth ||
155 Option == LoopHintAttr::InterleaveCount ||
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000156 Option == LoopHintAttr::UnrollCount ||
157 Option == LoopHintAttr::PipelineInitiationInterval) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000158 assert(ValueExpr && "Attribute must have a valid value expression.");
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000159 if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc()))
Mark Heffernan397a98d2015-08-10 17:29:39 +0000160 return nullptr;
161 State = LoopHintAttr::Numeric;
162 } else if (Option == LoopHintAttr::Vectorize ||
163 Option == LoopHintAttr::Interleave ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000164 Option == LoopHintAttr::Unroll ||
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000165 Option == LoopHintAttr::Distribute ||
166 Option == LoopHintAttr::PipelineDisabled) {
Mark Heffernan397a98d2015-08-10 17:29:39 +0000167 assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument");
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000168 if (StateLoc->Ident->isStr("disable"))
169 State = LoopHintAttr::Disable;
Tyler Nowicki9d268e12015-06-11 23:23:17 +0000170 else if (StateLoc->Ident->isStr("assume_safety"))
171 State = LoopHintAttr::AssumeSafety;
Mark Heffernan397a98d2015-08-10 17:29:39 +0000172 else if (StateLoc->Ident->isStr("full"))
173 State = LoopHintAttr::Full;
174 else if (StateLoc->Ident->isStr("enable"))
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000175 State = LoopHintAttr::Enable;
Mark Heffernan397a98d2015-08-10 17:29:39 +0000176 else
177 llvm_unreachable("bad loop hint argument");
178 } else
179 llvm_unreachable("bad loop hint");
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000180 }
Eli Bendersky06a40422014-06-06 20:31:48 +0000181
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000182 return LoopHintAttr::CreateImplicit(S.Context, Spelling, Option, State,
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000183 ValueExpr, A.getRange());
Eli Bendersky06a40422014-06-06 20:31:48 +0000184}
185
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000186static void
187CheckForIncompatibleAttributes(Sema &S,
188 const SmallVectorImpl<const Attr *> &Attrs) {
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000189 // There are 6 categories of loop hints attributes: vectorize, interleave,
190 // unroll, unroll_and_jam, pipeline and distribute. Except for distribute they
191 // come in two variants: a state form and a numeric form. The state form
David Greenc8e39242018-08-01 14:36:12 +0000192 // selectively defaults/enables/disables the transformation for the loop
193 // (for unroll, default indicates full unrolling rather than enabling the
194 // transformation). The numeric form form provides an integer hint (for
195 // example, unroll count) to the transformer. The following array accumulates
196 // the hints encountered while iterating through the attributes to check for
197 // compatibility.
Eli Bendersky86483b32014-06-11 17:56:26 +0000198 struct {
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000199 const LoopHintAttr *StateAttr;
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000200 const LoopHintAttr *NumericAttr;
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000201 } HintAttrs[] = {{nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr},
202 {nullptr, nullptr}, {nullptr, nullptr}, {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();
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000212 enum {
213 Vectorize,
214 Interleave,
215 Unroll,
216 UnrollAndJam,
217 Distribute,
218 Pipeline
219 } Category;
Eli Bendersky06a40422014-06-06 20:31:48 +0000220 switch (Option) {
221 case LoopHintAttr::Vectorize:
222 case LoopHintAttr::VectorizeWidth:
Mark Heffernan450c2382014-07-23 17:31:31 +0000223 Category = Vectorize;
Eli Bendersky06a40422014-06-06 20:31:48 +0000224 break;
225 case LoopHintAttr::Interleave:
226 case LoopHintAttr::InterleaveCount:
Mark Heffernan450c2382014-07-23 17:31:31 +0000227 Category = Interleave;
Eli Bendersky06a40422014-06-06 20:31:48 +0000228 break;
Eli Bendersky86483b32014-06-11 17:56:26 +0000229 case LoopHintAttr::Unroll:
230 case LoopHintAttr::UnrollCount:
Mark Heffernan450c2382014-07-23 17:31:31 +0000231 Category = Unroll;
Eli Bendersky86483b32014-06-11 17:56:26 +0000232 break;
David Greenc8e39242018-08-01 14:36:12 +0000233 case LoopHintAttr::UnrollAndJam:
234 case LoopHintAttr::UnrollAndJamCount:
235 Category = UnrollAndJam;
236 break;
Adam Nemet2de463e2016-06-14 12:04:26 +0000237 case LoopHintAttr::Distribute:
238 // Perform the check for duplicated 'distribute' hints.
239 Category = Distribute;
240 break;
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000241 case LoopHintAttr::PipelineDisabled:
242 case LoopHintAttr::PipelineInitiationInterval:
243 Category = Pipeline;
244 break;
Eli Bendersky86483b32014-06-11 17:56:26 +0000245 };
Eli Bendersky06a40422014-06-06 20:31:48 +0000246
David Greenc8e39242018-08-01 14:36:12 +0000247 assert(Category < sizeof(HintAttrs) / sizeof(HintAttrs[0]));
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000248 auto &CategoryState = HintAttrs[Category];
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000249 const LoopHintAttr *PrevAttr;
Eli Bendersky86483b32014-06-11 17:56:26 +0000250 if (Option == LoopHintAttr::Vectorize ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000251 Option == LoopHintAttr::Interleave || Option == LoopHintAttr::Unroll ||
David Greenc8e39242018-08-01 14:36:12 +0000252 Option == LoopHintAttr::UnrollAndJam ||
Aaron Ballman9bdf5152019-01-04 17:20:00 +0000253 Option == LoopHintAttr::PipelineDisabled ||
Adam Nemet2de463e2016-06-14 12:04:26 +0000254 Option == LoopHintAttr::Distribute) {
Tyler Nowicki9d268e12015-06-11 23:23:17 +0000255 // Enable|Disable|AssumeSafety hint. For example, vectorize(enable).
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000256 PrevAttr = CategoryState.StateAttr;
257 CategoryState.StateAttr = LH;
Eli Bendersky06a40422014-06-06 20:31:48 +0000258 } else {
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000259 // Numeric hint. For example, vectorize_width(8).
260 PrevAttr = CategoryState.NumericAttr;
261 CategoryState.NumericAttr = LH;
Eli Bendersky06a40422014-06-06 20:31:48 +0000262 }
263
Tyler Nowicki884fc612014-07-29 17:21:32 +0000264 PrintingPolicy Policy(S.Context.getLangOpts());
265 SourceLocation OptionLoc = LH->getRange().getBegin();
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000266 if (PrevAttr)
267 // Cannot specify same type of attribute twice.
268 S.Diag(OptionLoc, diag::err_pragma_loop_compatibility)
Tyler Nowicki884fc612014-07-29 17:21:32 +0000269 << /*Duplicate=*/true << PrevAttr->getDiagnosticName(Policy)
270 << LH->getDiagnosticName(Policy);
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000271
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000272 if (CategoryState.StateAttr && CategoryState.NumericAttr &&
David Greenc8e39242018-08-01 14:36:12 +0000273 (Category == Unroll || Category == UnrollAndJam ||
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000274 CategoryState.StateAttr->getState() == LoopHintAttr::Disable)) {
Mark Heffernan450c2382014-07-23 17:31:31 +0000275 // Disable hints are not compatible with numeric hints of the same
276 // category. As a special case, numeric unroll hints are also not
Mark Heffernan397a98d2015-08-10 17:29:39 +0000277 // compatible with enable or full form of the unroll pragma because these
278 // directives indicate full unrolling.
Mark Heffernanbd26f5e2014-07-21 18:08:34 +0000279 S.Diag(OptionLoc, diag::err_pragma_loop_compatibility)
Eli Bendersky86483b32014-06-11 17:56:26 +0000280 << /*Duplicate=*/false
Tyler Nowicki0c9b34b2014-07-31 20:15:14 +0000281 << CategoryState.StateAttr->getDiagnosticName(Policy)
Tyler Nowicki884fc612014-07-29 17:21:32 +0000282 << CategoryState.NumericAttr->getDiagnosticName(Policy);
Eli Bendersky86483b32014-06-11 17:56:26 +0000283 }
Eli Bendersky06a40422014-06-06 20:31:48 +0000284 }
285}
286
Erich Keanee891aa92018-07-13 15:07:47 +0000287static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000288 SourceRange Range) {
Egor Churaev24939d42016-12-13 14:02:35 +0000289 // Although the feature was introduced only in OpenCL C v2.0 s6.11.5, it's
290 // useful for OpenCL 1.x too and doesn't require HW support.
291 // opencl_unroll_hint can have 0 arguments (compiler
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000292 // determines unrolling factor) or 1 argument (the unroll factor provided
293 // by the user).
294
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000295 unsigned NumArgs = A.getNumArgs();
296
297 if (NumArgs > 1) {
Erich Keane44bacdf2018-08-09 13:21:32 +0000298 S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << A << 1;
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000299 return nullptr;
300 }
301
302 unsigned UnrollFactor = 0;
303
304 if (NumArgs == 1) {
305 Expr *E = A.getArgAsExpr(0);
306 llvm::APSInt ArgVal(32);
307
308 if (!E->isIntegerConstantExpr(ArgVal, S.Context)) {
309 S.Diag(A.getLoc(), diag::err_attribute_argument_type)
Erich Keane44bacdf2018-08-09 13:21:32 +0000310 << A << AANT_ArgumentIntegerConstant << E->getSourceRange();
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000311 return nullptr;
312 }
313
314 int Val = ArgVal.getSExtValue();
315
316 if (Val <= 0) {
317 S.Diag(A.getRange().getBegin(),
318 diag::err_attribute_requires_positive_integer)
Andrew Savonichev1a5623482018-09-17 10:39:46 +0000319 << A << /* positive */ 0;
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000320 return nullptr;
321 }
322 UnrollFactor = Val;
323 }
324
325 return OpenCLUnrollHintAttr::CreateImplicit(S.Context, UnrollFactor);
326}
327
Erich Keanee891aa92018-07-13 15:07:47 +0000328static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
Eli Bendersky06a40422014-06-06 20:31:48 +0000329 SourceRange Range) {
330 switch (A.getKind()) {
Erich Keanee891aa92018-07-13 15:07:47 +0000331 case ParsedAttr::UnknownAttribute:
Simon Pilgrim6d2d96e2018-12-17 12:25:42 +0000332 S.Diag(A.getLoc(), A.isDeclspecAttribute()
333 ? (unsigned)diag::warn_unhandled_ms_attribute_ignored
334 : (unsigned)diag::warn_unknown_attribute_ignored)
335 << A.getName();
Eli Bendersky06a40422014-06-06 20:31:48 +0000336 return nullptr;
Erich Keanee891aa92018-07-13 15:07:47 +0000337 case ParsedAttr::AT_FallThrough:
Eli Bendersky06a40422014-06-06 20:31:48 +0000338 return handleFallThroughAttr(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000339 case ParsedAttr::AT_LoopHint:
Eli Bendersky06a40422014-06-06 20:31:48 +0000340 return handleLoopHintAttr(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000341 case ParsedAttr::AT_OpenCLUnrollHint:
Anastasia Stulova6bdbcbb2016-02-19 18:30:11 +0000342 return handleOpenCLUnrollHint(S, St, A, Range);
Erich Keanee891aa92018-07-13 15:07:47 +0000343 case ParsedAttr::AT_Suppress:
Matthias Gehre01a63382017-03-27 19:45:24 +0000344 return handleSuppressAttr(S, St, A, Range);
Eli Bendersky06a40422014-06-06 20:31:48 +0000345 default:
346 // if we're here, then we parsed a known attribute, but didn't recognize
347 // it as a statement attribute => it is declaration attribute
Richard Smith4f902c72016-03-08 00:32:55 +0000348 S.Diag(A.getRange().getBegin(), diag::err_decl_attribute_invalid_on_stmt)
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000349 << A.getName() << St->getBeginLoc();
Craig Topperc3ec1492014-05-26 06:22:03 +0000350 return nullptr;
Richard Smithc202b282012-04-14 00:33:13 +0000351 }
352}
353
Erich Keanec480f302018-07-12 21:09:05 +0000354StmtResult Sema::ProcessStmtAttributes(Stmt *S,
355 const ParsedAttributesView &AttrList,
Richard Smithc202b282012-04-14 00:33:13 +0000356 SourceRange Range) {
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000357 SmallVector<const Attr*, 8> Attrs;
Erich Keanee891aa92018-07-13 15:07:47 +0000358 for (const ParsedAttr &AL : AttrList) {
Erich Keanec480f302018-07-12 21:09:05 +0000359 if (Attr *a = ProcessStmtAttribute(*this, S, AL, Range))
Eli Bendersky06a40422014-06-06 20:31:48 +0000360 Attrs.push_back(a);
361 }
362
363 CheckForIncompatibleAttributes(*this, Attrs);
364
365 if (Attrs.empty())
366 return S;
367
Richard Smithc202b282012-04-14 00:33:13 +0000368 return ActOnAttributedStmt(Range.getBegin(), Attrs, S);
369}