1534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith//===--- SemaStmtAttr.cpp - Statement Attribute Handling ------------------===// 2534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// 3534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// The LLVM Compiler Infrastructure 4534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// 5534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// This file is distributed under the University of Illinois Open Source 6534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// License. See LICENSE.TXT for details. 7534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// 8534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith//===----------------------------------------------------------------------===// 9534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// 10534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// This file implements stmt-related attribute processing. 11534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith// 12534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith//===----------------------------------------------------------------------===// 13534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 14534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith#include "clang/Sema/SemaInternal.h" 15534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith#include "clang/AST/ASTContext.h" 16534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith#include "clang/Basic/SourceManager.h" 17534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith#include "clang/Sema/DelayedDiagnostic.h" 18534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith#include "clang/Sema/Lookup.h" 19c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines#include "clang/Sema/LoopHint.h" 20e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith#include "clang/Sema/ScopeInfo.h" 21534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith#include "llvm/ADT/StringExtras.h" 22e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith 23534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithusing namespace clang; 24534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithusing namespace sema; 25534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 26e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smithstatic Attr *handleFallThroughAttr(Sema &S, Stmt *St, const AttributeList &A, 27e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith SourceRange Range) { 28e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith if (!isa<NullStmt>(St)) { 29e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_wrong_target) 30e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith << St->getLocStart(); 31e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith if (isa<SwitchCase>(St)) { 326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines SourceLocation L = S.getLocForEndOfToken(Range.getEnd()); 33e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith S.Diag(L, diag::note_fallthrough_insert_semi_fixit) 34e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith << FixItHint::CreateInsertion(L, ";"); 35e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith } 366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 37e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith } 38e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith if (S.getCurFunction()->SwitchStack.empty()) { 39e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith S.Diag(A.getRange().getBegin(), diag::err_fallthrough_attr_outside_switch); 406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 41e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith } 42651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines return ::new (S.Context) FallThroughAttr(A.getRange(), S.Context, 43651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines A.getAttributeSpellingListIndex()); 44e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith} 45e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith 46c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hinesstatic Attr *handleLoopHintAttr(Sema &S, Stmt *St, const AttributeList &A, 47c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines SourceRange) { 48176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines IdentifierLoc *PragmaNameLoc = A.getArgAsIdent(0); 49176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines IdentifierLoc *OptionLoc = A.getArgAsIdent(1); 50176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines IdentifierLoc *StateLoc = A.getArgAsIdent(2); 51176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines Expr *ValueExpr = A.getArgAsExpr(3); 52176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 53176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll"; 54176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll"; 55c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines if (St->getStmtClass() != Stmt::DoStmtClass && 56c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines St->getStmtClass() != Stmt::ForStmtClass && 57c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines St->getStmtClass() != Stmt::CXXForRangeStmtClass && 58c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines St->getStmtClass() != Stmt::WhileStmtClass) { 59176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const char *Pragma = 60176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::StringSwitch<const char *>(PragmaNameLoc->Ident->getName()) 61176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Case("unroll", "#pragma unroll") 62176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Case("nounroll", "#pragma nounroll") 63176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Default("#pragma clang loop"); 64176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines S.Diag(St->getLocStart(), diag::err_pragma_loop_precedes_nonloop) << Pragma; 65c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines return nullptr; 66c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines } 67c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 68176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines LoopHintAttr::Spelling Spelling; 69a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar LoopHintAttr::OptionType Option; 70a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar LoopHintAttr::LoopHintState State; 71a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar if (PragmaNoUnroll) { 72a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar // #pragma nounroll 73176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines Spelling = LoopHintAttr::Pragma_nounroll; 74a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Option = LoopHintAttr::Unroll; 75a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar State = LoopHintAttr::Disable; 76a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar } else if (PragmaUnroll) { 77a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Spelling = LoopHintAttr::Pragma_unroll; 78a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar if (ValueExpr) { 79a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar // #pragma unroll N 80a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Option = LoopHintAttr::UnrollCount; 81a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar State = LoopHintAttr::Numeric; 82a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar } else { 83a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar // #pragma unroll 84a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Option = LoopHintAttr::Unroll; 85a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar State = LoopHintAttr::Enable; 86a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar } 87176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } else { 88a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar // #pragma clang loop ... 89a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Spelling = LoopHintAttr::Pragma_clang_loop; 90176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines assert(OptionLoc && OptionLoc->Ident && 91176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines "Attribute must have valid option info."); 92a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Option = llvm::StringSwitch<LoopHintAttr::OptionType>( 93a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar OptionLoc->Ident->getName()) 94176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Case("vectorize", LoopHintAttr::Vectorize) 95176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Case("vectorize_width", LoopHintAttr::VectorizeWidth) 96176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Case("interleave", LoopHintAttr::Interleave) 97176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Case("interleave_count", LoopHintAttr::InterleaveCount) 98176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Case("unroll", LoopHintAttr::Unroll) 99176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Case("unroll_count", LoopHintAttr::UnrollCount) 100176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines .Default(LoopHintAttr::Vectorize); 101a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar if (Option == LoopHintAttr::VectorizeWidth || 102a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Option == LoopHintAttr::InterleaveCount || 103a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Option == LoopHintAttr::UnrollCount) { 104a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar assert(ValueExpr && "Attribute must have a valid value expression."); 105a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar if (S.CheckLoopHintExpr(ValueExpr, St->getLocStart())) 106a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar return nullptr; 107a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar State = LoopHintAttr::Numeric; 108a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar } else if (Option == LoopHintAttr::Vectorize || 109a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Option == LoopHintAttr::Interleave || 110a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar Option == LoopHintAttr::Unroll) { 111a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument"); 112176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (StateLoc->Ident->isStr("disable")) 113176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines State = LoopHintAttr::Disable; 114b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar else if (StateLoc->Ident->isStr("assume_safety")) 115b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar State = LoopHintAttr::AssumeSafety; 116a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar else if (StateLoc->Ident->isStr("full")) 117a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar State = LoopHintAttr::Full; 118a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar else if (StateLoc->Ident->isStr("enable")) 119176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines State = LoopHintAttr::Enable; 120a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar else 121a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar llvm_unreachable("bad loop hint argument"); 122a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar } else 123a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar llvm_unreachable("bad loop hint"); 124176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 125c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 126176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return LoopHintAttr::CreateImplicit(S.Context, Spelling, Option, State, 127176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ValueExpr, A.getRange()); 128c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines} 129c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 130c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hinesstatic void 131176edba5311f6eff0cad2631449885ddf4fbc9eaStephen HinesCheckForIncompatibleAttributes(Sema &S, 132176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const SmallVectorImpl<const Attr *> &Attrs) { 133176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // There are 3 categories of loop hints attributes: vectorize, interleave, 134176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // and unroll. Each comes in two variants: a state form and a numeric form. 135176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // The state form selectively defaults/enables/disables the transformation 136176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // for the loop (for unroll, default indicates full unrolling rather than 137176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // enabling the transformation). The numeric form form provides an integer 138176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // hint (for example, unroll count) to the transformer. The following array 139176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // accumulates the hints encountered while iterating through the attributes 140176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // to check for compatibility. 141c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines struct { 142176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const LoopHintAttr *StateAttr; 143176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const LoopHintAttr *NumericAttr; 144176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } HintAttrs[] = {{nullptr, nullptr}, {nullptr, nullptr}, {nullptr, nullptr}}; 145c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 146c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines for (const auto *I : Attrs) { 147c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines const LoopHintAttr *LH = dyn_cast<LoopHintAttr>(I); 148c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 149c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines // Skip non loop hint attributes 150c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines if (!LH) 151c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines continue; 152c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 153c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines int Option = LH->getOption(); 154c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines int Category; 155176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines enum { Vectorize, Interleave, Unroll }; 156c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines switch (Option) { 157c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines case LoopHintAttr::Vectorize: 158c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines case LoopHintAttr::VectorizeWidth: 159176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines Category = Vectorize; 160c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines break; 161c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines case LoopHintAttr::Interleave: 162c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines case LoopHintAttr::InterleaveCount: 163176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines Category = Interleave; 164c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines break; 165c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines case LoopHintAttr::Unroll: 166c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines case LoopHintAttr::UnrollCount: 167176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines Category = Unroll; 168c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines break; 169c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines }; 170c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 171176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines auto &CategoryState = HintAttrs[Category]; 172176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const LoopHintAttr *PrevAttr; 173c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines if (Option == LoopHintAttr::Vectorize || 174c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines Option == LoopHintAttr::Interleave || Option == LoopHintAttr::Unroll) { 175b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar // Enable|Disable|AssumeSafety hint. For example, vectorize(enable). 176176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines PrevAttr = CategoryState.StateAttr; 177176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines CategoryState.StateAttr = LH; 178c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines } else { 179176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // Numeric hint. For example, vectorize_width(8). 180176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines PrevAttr = CategoryState.NumericAttr; 181176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines CategoryState.NumericAttr = LH; 182c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines } 183c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 184176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines PrintingPolicy Policy(S.Context.getLangOpts()); 185176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines SourceLocation OptionLoc = LH->getRange().getBegin(); 186176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (PrevAttr) 187176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // Cannot specify same type of attribute twice. 188176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines S.Diag(OptionLoc, diag::err_pragma_loop_compatibility) 189176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines << /*Duplicate=*/true << PrevAttr->getDiagnosticName(Policy) 190176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines << LH->getDiagnosticName(Policy); 191176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 192176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines if (CategoryState.StateAttr && CategoryState.NumericAttr && 193176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines (Category == Unroll || 194176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines CategoryState.StateAttr->getState() == LoopHintAttr::Disable)) { 195176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // Disable hints are not compatible with numeric hints of the same 196176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // category. As a special case, numeric unroll hints are also not 197a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar // compatible with enable or full form of the unroll pragma because these 198a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar // directives indicate full unrolling. 199176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines S.Diag(OptionLoc, diag::err_pragma_loop_compatibility) 200c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines << /*Duplicate=*/false 201176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines << CategoryState.StateAttr->getDiagnosticName(Policy) 202176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines << CategoryState.NumericAttr->getDiagnosticName(Policy); 203c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines } 204c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines } 205c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines} 206534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 207e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smithstatic Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const AttributeList &A, 208e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith SourceRange Range) { 209534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith switch (A.getKind()) { 2106880f492365cc4fa4c941aa83688635003ee7498Michael Han case AttributeList::UnknownAttribute: 2116880f492365cc4fa4c941aa83688635003ee7498Michael Han S.Diag(A.getLoc(), A.isDeclspecAttribute() ? 2126880f492365cc4fa4c941aa83688635003ee7498Michael Han diag::warn_unhandled_ms_attribute_ignored : 2136880f492365cc4fa4c941aa83688635003ee7498Michael Han diag::warn_unknown_attribute_ignored) << A.getName(); 2146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 2158e083e71d48f7f4d6ef40c00531c2e14df745486Sean Hunt case AttributeList::AT_FallThrough: 216e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith return handleFallThroughAttr(S, St, A, Range); 217c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines case AttributeList::AT_LoopHint: 218c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines return handleLoopHintAttr(S, St, A, Range); 219534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith default: 2206880f492365cc4fa4c941aa83688635003ee7498Michael Han // if we're here, then we parsed a known attribute, but didn't recognize 2216880f492365cc4fa4c941aa83688635003ee7498Michael Han // it as a statement attribute => it is declaration attribute 222053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith S.Diag(A.getRange().getBegin(), diag::err_attribute_invalid_on_stmt) 223053214013990ad8ec096dafc64aa7c0ad2b05bc0Richard Smith << A.getName() << St->getLocStart(); 2246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines return nullptr; 225534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 226534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith} 227534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 228534986f2b21e6050bf00163cd6423fd92155a6edRichard SmithStmtResult Sema::ProcessStmtAttributes(Stmt *S, AttributeList *AttrList, 229534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SourceRange Range) { 2304990890fc9428f98bef90ba349203a648c592778Alexander Kornienko SmallVector<const Attr*, 8> Attrs; 231534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith for (const AttributeList* l = AttrList; l; l = l->getNext()) { 232e0d3b4cd2b66f1cef26cacbed5820ab7c22ad5b3Richard Smith if (Attr *a = ProcessStmtAttribute(*this, S, *l, Range)) 233534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Attrs.push_back(a); 234534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 235534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 236c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines CheckForIncompatibleAttributes(*this, Attrs); 237c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 238534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith if (Attrs.empty()) 239534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return S; 240534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 241534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return ActOnAttributedStmt(Range.getBegin(), Attrs, S); 242534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith} 243