34 #include "llvm/ADT/ArrayRef.h"
35 #include "llvm/ADT/DenseMap.h"
36 #include "llvm/ADT/STLExtras.h"
37 #include "llvm/ADT/SmallPtrSet.h"
38 #include "llvm/ADT/SmallString.h"
39 #include "llvm/ADT/SmallVector.h"
40 using namespace clang;
62 DiscardCleanupsInEvaluationContext();
67 bool HasLeadingEmptyMacro) {
108 if (getLangOpts().ObjCAutoRefCount) {
129 bool IsNotEqual, CanAssign, IsRelational;
132 if (!Op->isComparisonOp())
135 IsRelational = Op->isRelationalOp();
136 Loc = Op->getOperatorLoc();
137 IsNotEqual = Op->getOpcode() ==
BO_NE;
138 CanAssign = Op->getLHS()->IgnoreParenImpCasts()->isLValue();
140 switch (Op->getOperator()) {
144 case OO_ExclaimEqual:
145 IsRelational =
false;
149 case OO_GreaterEqual:
155 Loc = Op->getOperatorLoc();
156 IsNotEqual = Op->getOperator() == OO_ExclaimEqual;
157 CanAssign = Op->getArg(0)->IgnoreParenImpCasts()->isLValue();
168 S.
Diag(Loc, diag::warn_unused_comparison)
169 << (
unsigned)IsRelational << (
unsigned)IsNotEqual << E->getSourceRange();
173 if (!IsRelational && CanAssign) {
175 S.
Diag(Loc, diag::note_inequality_comparison_to_or_assign)
178 S.
Diag(Loc, diag::note_equality_comparison_to_assign)
186 if (
const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
187 return DiagnoseUnusedExprResult(Label->getSubStmt());
189 const Expr *E = dyn_cast_or_null<Expr>(
S);
195 if (isUnevaluatedContext())
204 bool ShouldSuppress =
208 const Expr *WarnExpr;
211 if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2,
Context))
224 unsigned DiagID = diag::warn_unused_expr;
226 E = Temps->getSubExpr();
228 E = TempExpr->getSubExpr();
234 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
235 if (E->getType()->isVoidType())
242 if (
const Decl *FD = CE->getCalleeDecl()) {
245 : FD->hasAttr<WarnUnusedResultAttr>()) {
246 Diag(Loc, diag::warn_unused_result) << R1 << R2;
251 if (FD->hasAttr<PureAttr>()) {
252 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"pure";
255 if (FD->hasAttr<ConstAttr>()) {
256 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"const";
260 }
else if (ShouldSuppress)
264 if (getLangOpts().ObjCAutoRefCount && ME->isDelegateInitCall()) {
265 Diag(Loc, diag::err_arc_unused_init_message) << R1;
270 if (MD->
hasAttr<WarnUnusedResultAttr>()) {
271 Diag(Loc, diag::warn_unused_result) << R1 << R2;
276 const Expr *Source = POE->getSyntacticForm();
277 if (isa<ObjCSubscriptRefExpr>(Source))
278 DiagID = diag::warn_unused_container_subscript_expr;
280 DiagID = diag::warn_unused_property_expr;
282 = dyn_cast<CXXFunctionalCastExpr>(E)) {
283 if (isa<CXXConstructExpr>(FC->getSubExpr()) ||
284 isa<CXXTemporaryObjectExpr>(FC->getSubExpr()))
288 else if (
const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E)) {
296 Diag(Loc, diag::warn_unused_voidptr)
302 if (E->isGLValue() && E->getType().isVolatileQualified()) {
303 Diag(Loc, diag::warn_unused_volatile) << R1 << R2;
307 DiagRuntimeBehavior(Loc,
nullptr, PDiag(DiagID) << R1 << R2);
319 return getCurFunction()->CompoundScopes.back();
324 const unsigned NumElts = Elts.size();
332 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
336 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
340 Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
345 for (
unsigned i = 0; i != NumElts; ++i) {
347 if (isStmtExpr && i == NumElts - 1)
350 DiagnoseUnusedExprResult(Elts[i]);
356 if (NumElts != 0 && !CurrentInstantiationScope &&
357 getCurCompoundScope().HasEmptyLoopBodies) {
358 for (
unsigned i = 0; i != NumElts - 1; ++i)
359 DiagnoseEmptyLoopBody(Elts[i], Elts[i + 1]);
369 assert(LHSVal &&
"missing expression in case statement");
371 if (getCurFunction()->SwitchStack.empty()) {
372 Diag(CaseLoc, diag::err_case_not_in_switch);
377 CorrectDelayedTyposInExpr(LHSVal, [
this](
class Expr *E) {
379 return VerifyIntegerConstantExpression(E);
381 getCurFunction()->SwitchStack.back()->getCond()) {
382 QualType CondType = CondExpr->getType();
383 llvm::APSInt TempVal;
397 LHSVal = VerifyIntegerConstantExpression(LHSVal).get();
405 RHSVal = VerifyIntegerConstantExpression(RHSVal).get();
410 LHS = ActOnFinishFullExpr(LHSVal, LHSVal->
getExprLoc(),
false,
411 getLangOpts().CPlusPlus11);
415 auto RHS = RHSVal ? ActOnFinishFullExpr(RHSVal, RHSVal->
getExprLoc(),
false,
416 getLangOpts().CPlusPlus11)
423 getCurFunction()->SwitchStack.back()->addSwitchCase(CS);
429 DiagnoseUnusedExprResult(SubStmt);
438 DiagnoseUnusedExprResult(SubStmt);
440 if (getCurFunction()->SwitchStack.empty()) {
441 Diag(DefaultLoc, diag::err_default_not_in_switch);
446 getCurFunction()->SwitchStack.back()->addSwitchCase(DS);
455 Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->
getDeclName();
488 if (!CondVal.
get() && !CondVar) {
489 getCurFunction()->setHasDroppedStmt();
495 VarDecl *ConditionVar =
nullptr;
497 ConditionVar = cast<VarDecl>(CondVar);
498 CondResult = CheckConditionVariable(ConditionVar, IfLoc,
true);
499 CondResult = ActOnFinishFullExpr(CondResult.get(), IfLoc);
500 if (CondResult.isInvalid())
503 Expr *ConditionExpr = CondResult.getAs<
Expr>();
507 DiagnoseUnusedExprResult(thenStmt);
510 DiagnoseEmptyStmtBody(ConditionExpr->getLocEnd(), thenStmt,
511 diag::warn_empty_if_body);
514 DiagnoseUnusedExprResult(elseStmt);
517 thenStmt, ElseLoc, elseStmt);
521 struct CaseCompareFunctor {
522 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
523 const llvm::APSInt &RHS) {
524 return LHS.first < RHS;
526 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
527 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
528 return LHS.first < RHS.first;
530 bool operator()(
const llvm::APSInt &LHS,
531 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
532 return LHS < RHS.first;
539 static bool CmpCaseVals(
const std::pair<llvm::APSInt, CaseStmt*>& lhs,
540 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
541 if (lhs.first < rhs.first)
544 if (lhs.first == rhs.first &&
545 lhs.second->getCaseLoc().getRawEncoding()
546 < rhs.second->getCaseLoc().getRawEncoding())
553 static bool CmpEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
554 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
556 return lhs.first < rhs.first;
561 static bool EqEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
562 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
564 return lhs.first == rhs.first;
571 expr = cleanups->getSubExpr();
574 expr = impcast->getSubExpr();
584 VarDecl *ConditionVar =
nullptr;
586 ConditionVar = cast<VarDecl>(CondVar);
587 CondResult = CheckConditionVariable(ConditionVar,
SourceLocation(),
false);
588 if (CondResult.isInvalid())
591 Cond = CondResult.get();
601 SwitchConvertDiagnoser(
Expr *Cond)
607 return S.
Diag(Loc, diag::err_typecheck_statement_requires_integer) << T;
612 return S.
Diag(Loc, diag::err_switch_incomplete_class_type)
613 << T << Cond->getSourceRange();
618 return S.
Diag(Loc, diag::err_switch_explicit_conversion) << T << ConvTy;
629 return S.
Diag(Loc, diag::err_switch_multiple_conversions) << T;
640 llvm_unreachable(
"conversion functions are permitted");
642 } SwitchDiagnoser(Cond);
645 PerformContextualImplicitConversion(SwitchLoc, Cond, SwitchDiagnoser);
647 Cond = CondResult.
get();
650 CondResult = UsualUnaryConversions(Cond);
652 Cond = CondResult.
get();
654 CondResult = ActOnFinishFullExpr(Cond, SwitchLoc);
657 Cond = CondResult.
get();
659 getCurFunction()->setHasBranchIntoScope();
662 getCurFunction()->SwitchStack.push_back(SS);
666 static void AdjustAPSInt(llvm::APSInt &Val,
unsigned BitWidth,
bool IsSigned) {
667 Val = Val.extOrTrunc(BitWidth);
668 Val.setIsSigned(IsSigned);
674 unsigned UnpromotedWidth,
bool UnpromotedSign) {
678 if (UnpromotedWidth < Val.getBitWidth()) {
679 llvm::APSInt ConvVal(Val);
681 AdjustAPSInt(ConvVal, Val.getBitWidth(), Val.isSigned());
686 S.
Diag(Loc, diag::warn_case_value_overflow) << Val.toString(10)
687 << ConvVal.toString(10);
697 const Expr *CaseExpr,
698 EnumValsTy::iterator &EI,
699 EnumValsTy::iterator &EIEnd,
700 const llvm::APSInt &Val) {
701 bool FlagType = ED->
hasAttr<FlagEnumAttr>();
705 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
717 while (EI != EIEnd && EI->first < Val)
720 if (EI != EIEnd && EI->first == Val)
731 assert(SS == getCurFunction()->SwitchStack.back() &&
732 "switch stack missing push/pop!");
734 getCurFunction()->SwitchStack.pop_back();
737 SS->
setBody(BodyStmt, SwitchLoc);
744 Expr *CondExprBeforePromotion = CondExpr;
766 Diag(SwitchLoc, diag::warn_bool_switch_condition)
767 << CondExpr->getSourceRange();
773 bool HasDependentValue
782 unsigned CondWidthBeforePromotion
784 bool CondIsSignedBeforePromotion
794 typedef std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRangesTy;
795 CaseRangesTy CaseRanges;
799 bool CaseListIsErroneous =
false;
805 if (TheDefaultStmt) {
806 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
813 CaseListIsErroneous =
true;
822 if (Lo->isTypeDependent() || Lo->isValueDependent()) {
823 HasDependentValue =
true;
829 if (getLangOpts().CPlusPlus11) {
835 CaseListIsErroneous =
true;
846 Lo = DefaultLvalueConversion(Lo).get();
853 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
864 HasDependentValue =
true;
867 CaseRanges.push_back(std::make_pair(LoVal, CS));
869 CaseVals.push_back(std::make_pair(LoVal, CS));
873 if (!HasDependentValue) {
876 llvm::APSInt ConstantCondValue;
877 bool HasConstantCond =
false;
878 if (!HasDependentValue && !TheDefaultStmt) {
881 assert(!HasConstantCond ||
882 (ConstantCondValue.getBitWidth() == CondWidth &&
883 ConstantCondValue.isSigned() == CondIsSigned));
885 bool ShouldCheckConstantCond = HasConstantCond;
888 std::stable_sort(CaseVals.begin(), CaseVals.end(),
CmpCaseVals);
890 if (!CaseVals.empty()) {
891 for (
unsigned i = 0, e = CaseVals.size(); i != e; ++i) {
892 if (ShouldCheckConstantCond &&
893 CaseVals[i].first == ConstantCondValue)
894 ShouldCheckConstantCond =
false;
896 if (i != 0 && CaseVals[i].first == CaseVals[i-1].first) {
899 StringRef PrevString, CurrString;
902 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(PrevCase)) {
903 PrevString = DeclRef->getDecl()->getName();
905 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(CurrCase)) {
906 CurrString = DeclRef->getDecl()->getName();
909 CaseVals[i-1].first.toString(CaseValStr);
911 if (PrevString == CurrString)
912 Diag(CaseVals[i].second->getLHS()->getLocStart(),
913 diag::err_duplicate_case) <<
914 (PrevString.empty() ? StringRef(CaseValStr) : PrevString);
916 Diag(CaseVals[i].second->getLHS()->getLocStart(),
917 diag::err_duplicate_case_differing_expr) <<
918 (PrevString.empty() ? StringRef(CaseValStr) : PrevString) <<
919 (CurrString.empty() ? StringRef(CaseValStr) : CurrString) <<
922 Diag(CaseVals[i-1].second->getLHS()->getLocStart(),
923 diag::note_duplicate_case_prev);
926 CaseListIsErroneous =
true;
933 if (!CaseRanges.empty()) {
936 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
939 std::vector<llvm::APSInt> HiVals;
940 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
941 llvm::APSInt &LoVal = CaseRanges[i].first;
942 CaseStmt *CR = CaseRanges[i].second;
953 CaseListIsErroneous =
true;
962 Hi = DefaultLvalueConversion(Hi).get();
969 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
978 Diag(CR->
getLHS()->getLocStart(), diag::warn_case_empty_range)
981 CaseRanges.erase(CaseRanges.begin()+i);
986 if (ShouldCheckConstantCond &&
987 LoVal <= ConstantCondValue &&
988 ConstantCondValue <= HiVal)
989 ShouldCheckConstantCond =
false;
991 HiVals.push_back(HiVal);
997 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
998 llvm::APSInt &CRLo = CaseRanges[i].first;
999 llvm::APSInt &CRHi = HiVals[i];
1000 CaseStmt *CR = CaseRanges[i].second;
1005 llvm::APSInt OverlapVal(32);
1009 CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(),
1010 CaseVals.end(), CRLo,
1011 CaseCompareFunctor());
1012 if (I != CaseVals.end() && I->first < CRHi) {
1013 OverlapVal = I->first;
1014 OverlapStmt = I->second;
1018 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
1019 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
1020 OverlapVal = (I-1)->first;
1021 OverlapStmt = (I-1)->second;
1026 if (i && CRLo <= HiVals[i-1]) {
1027 OverlapVal = HiVals[i-1];
1028 OverlapStmt = CaseRanges[i-1].second;
1033 Diag(CR->
getLHS()->getLocStart(), diag::err_duplicate_case)
1034 << OverlapVal.toString(10);
1036 diag::note_duplicate_case_prev);
1039 CaseListIsErroneous =
true;
1045 if (!CaseListIsErroneous && ShouldCheckConstantCond) {
1048 Diag(CondExpr->
getExprLoc(), diag::warn_missing_case_for_condition)
1049 << ConstantCondValue.toString(10)
1050 << CondExpr->getSourceRange();
1061 if (!CaseListIsErroneous && !HasConstantCond && ET) {
1068 llvm::APSInt Val = EDI->getInitVal();
1070 EnumVals.push_back(std::make_pair(Val, EDI));
1072 std::stable_sort(EnumVals.begin(), EnumVals.end(),
CmpEnumVals);
1073 auto EI = EnumVals.begin(), EIEnd =
1074 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1077 for (CaseValsTy::const_iterator CI = CaseVals.begin();
1078 CI != CaseVals.end(); CI++) {
1079 Expr *CaseExpr = CI->second->getLHS();
1083 << CondTypeBeforePromotion;
1087 EI = EnumVals.begin();
1088 for (CaseRangesTy::const_iterator RI = CaseRanges.begin();
1089 RI != CaseRanges.end(); RI++) {
1090 Expr *CaseExpr = RI->second->getLHS();
1094 << CondTypeBeforePromotion;
1097 RI->second->getRHS()->EvaluateKnownConstInt(
Context);
1100 CaseExpr = RI->second->getRHS();
1104 << CondTypeBeforePromotion;
1108 auto CI = CaseVals.begin();
1109 auto RI = CaseRanges.begin();
1110 bool hasCasesNotInSwitch =
false;
1114 for (EI = EnumVals.begin(); EI != EIEnd; EI++){
1116 while (CI != CaseVals.end() && CI->first < EI->first)
1119 if (CI != CaseVals.end() && CI->first == EI->first)
1123 for (; RI != CaseRanges.end(); RI++) {
1125 RI->second->getRHS()->EvaluateKnownConstInt(
Context);
1127 if (EI->first <= Hi)
1131 if (RI == CaseRanges.end() || EI->first < RI->first) {
1132 hasCasesNotInSwitch =
true;
1133 UnhandledNames.push_back(EI->second->getDeclName());
1137 if (TheDefaultStmt && UnhandledNames.empty())
1141 if (!UnhandledNames.empty()) {
1143 TheDefaultStmt ? diag::warn_def_missing_case
1144 : diag::warn_missing_case)
1145 << (
int)UnhandledNames.size();
1147 for (
size_t I = 0, E = std::min(UnhandledNames.size(), (
size_t)3);
1149 DB << UnhandledNames[I];
1152 if (!hasCasesNotInSwitch)
1158 DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), BodyStmt,
1159 diag::warn_empty_switch_body);
1163 if (CaseListIsErroneous)
1172 if (Diags.isIgnored(diag::warn_not_in_enum_assignment, SrcExpr->
getExprLoc()))
1186 const EnumDecl *ED = ET->getDecl();
1188 if (ED->
hasAttr<FlagEnumAttr>()) {
1189 if (!IsValueInFlagEnum(ED, RhsVal,
true))
1195 EnumValsTy EnumVals;
1200 llvm::APSInt Val = EDI->getInitVal();
1202 EnumVals.push_back(std::make_pair(Val, EDI));
1204 if (EnumVals.empty())
1206 std::stable_sort(EnumVals.begin(), EnumVals.end(),
CmpEnumVals);
1207 EnumValsTy::iterator EIend =
1208 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1211 EnumValsTy::const_iterator EI = EnumVals.begin();
1212 while (EI != EIend && EI->first < RhsVal)
1214 if (EI == EIend || EI->first != RhsVal) {
1228 VarDecl *ConditionVar =
nullptr;
1230 ConditionVar = cast<VarDecl>(CondVar);
1231 CondResult = CheckConditionVariable(ConditionVar, WhileLoc,
true);
1232 CondResult = ActOnFinishFullExpr(CondResult.get(), WhileLoc);
1233 if (CondResult.isInvalid())
1236 Expr *ConditionExpr = CondResult.get();
1239 CheckBreakContinueBinding(ConditionExpr);
1241 DiagnoseUnusedExprResult(Body);
1243 if (isa<NullStmt>(Body))
1244 getCurCompoundScope().setHasEmptyLoopBodies();
1254 assert(Cond &&
"ActOnDoStmt(): missing expression");
1256 CheckBreakContinueBinding(Cond);
1257 ExprResult CondResult = CheckBooleanCondition(Cond, DoLoc);
1260 Cond = CondResult.
get();
1262 CondResult = ActOnFinishFullExpr(Cond, DoLoc);
1265 Cond = CondResult.
get();
1267 DiagnoseUnusedExprResult(Body);
1269 return new (
Context)
DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen);
1277 llvm::SmallPtrSetImpl<VarDecl*> &Decls;
1283 DeclExtractor(
Sema &
S, llvm::SmallPtrSetImpl<VarDecl*> &Decls,
1290 bool isSimple() {
return Simple; }
1298 void VisitStmt(
Stmt *
S) {
1345 Ranges.push_back(E->getSourceRange());
1355 llvm::SmallPtrSetImpl<VarDecl*> &Decls;
1361 DeclMatcher(
Sema &
S, llvm::SmallPtrSetImpl<VarDecl*> &Decls,
1364 if (!Statement)
return;
1388 void CheckLValueToRValueCast(
Expr *E) {
1391 if (isa<DeclRefExpr>(E)) {
1396 Visit(CO->getCond());
1397 CheckLValueToRValueCast(CO->getTrueExpr());
1398 CheckLValueToRValueCast(CO->getFalseExpr());
1403 dyn_cast<BinaryConditionalOperator>(E)) {
1404 CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr());
1405 CheckLValueToRValueCast(BCO->getFalseExpr());
1414 if (Decls.count(VD))
1418 bool FoundDeclInUse() {
return FoundDecl; }
1422 void CheckForLoopConditionalStatement(
Sema &S,
Expr *Second,
1425 if (!Second)
return;
1428 Second->getLocStart()))
1432 llvm::SmallPtrSet<VarDecl*, 8> Decls;
1434 DeclExtractor DE(S, Decls, Ranges);
1438 if (!DE.isSimple())
return;
1441 if (Decls.size() == 0)
return;
1444 for (llvm::SmallPtrSetImpl<VarDecl*>::iterator I = Decls.begin(),
1447 if ((*I)->getType().isVolatileQualified() ||
1448 (*I)->hasGlobalStorage())
return;
1450 if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
1451 DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
1452 DeclMatcher(S, Decls, Body).FoundDeclInUse())
1456 if (Decls.size() > 4)
1459 PDiag << Decls.size();
1460 for (llvm::SmallPtrSetImpl<VarDecl*>::iterator I = Decls.begin(),
1463 PDiag << (*I)->getDeclName();
1474 PDiag << Second->getSourceRange();
1476 S.
Diag(Ranges.begin()->getBegin(), PDiag);
1481 bool ProcessIterationStmt(
Sema &S,
Stmt* Statement,
bool &Increment,
1483 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(Statement)) {
1484 switch (UO->getOpcode()) {
1485 default:
return false;
1503 default:
return false;
1524 BreakContinueFinder(
Sema &S,
Stmt* Body) :
1539 bool ContinueFound() {
return ContinueLoc.
isValid(); }
1540 bool BreakFound() {
return BreakLoc.isValid(); }
1551 void CheckForRedundantIteration(
Sema &S,
Expr *Third,
Stmt *Body) {
1553 if (!Body || !Third)
return;
1556 Third->getLocStart()))
1563 if (!LastStmt)
return;
1565 bool LoopIncrement, LastIncrement;
1568 if (!ProcessIterationStmt(S, Third, LoopIncrement, LoopDRE))
return;
1569 if (!ProcessIterationStmt(S, LastStmt, LastIncrement, LastDRE))
return;
1573 if (LoopIncrement != LastIncrement ||
1576 if (BreakContinueFinder(S, Body).ContinueFound())
return;
1579 << LastDRE->
getDecl() << LastIncrement;
1587 void Sema::CheckBreakContinueBinding(
Expr *E) {
1590 BreakContinueFinder BCFinder(*
this, E);
1592 if (BCFinder.BreakFound() && BreakParent) {
1594 Diag(BCFinder.GetBreakLoc(), diag::warn_break_binds_to_switch);
1596 Diag(BCFinder.GetBreakLoc(), diag::warn_loop_ctrl_binds_to_inner)
1599 }
else if (BCFinder.ContinueFound() && CurScope->getContinueParent()) {
1600 Diag(BCFinder.GetContinueLoc(), diag::warn_loop_ctrl_binds_to_inner)
1611 if (
DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
1615 for (
auto *DI : DS->decls()) {
1620 Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
1621 DI->setInvalidDecl();
1627 CheckBreakContinueBinding(second.
get());
1628 CheckBreakContinueBinding(third.
get());
1630 CheckForLoopConditionalStatement(*
this, second.
get(), third.
get(), Body);
1631 CheckForRedundantIteration(*
this, third.
get(), Body);
1634 VarDecl *ConditionVar =
nullptr;
1636 ConditionVar = cast<VarDecl>(secondVar);
1637 SecondResult = CheckConditionVariable(ConditionVar, ForLoc,
true);
1638 SecondResult = ActOnFinishFullExpr(SecondResult.get(), ForLoc);
1639 if (SecondResult.isInvalid())
1645 DiagnoseUnusedExprResult(First);
1646 DiagnoseUnusedExprResult(Third);
1647 DiagnoseUnusedExprResult(Body);
1649 if (isa<NullStmt>(Body))
1650 getCurCompoundScope().setHasEmptyLoopBodies();
1653 Third, Body, ForLoc, LParenLoc, RParenLoc);
1667 ExprResult FullExpr = ActOnFinishFullExpr(E);
1678 ExprResult result = CorrectDelayedTyposInExpr(collection);
1681 collection = result.
get();
1687 result = DefaultFunctionArrayLvalueConversion(collection);
1690 collection = result.
get();
1697 return Diag(forLoc, diag::err_collection_expr_type)
1698 << collection->
getType() << collection->getSourceRange();
1708 RequireCompleteType(forLoc,
QualType(objectType, 0),
1709 getLangOpts().ObjCAutoRefCount
1710 ? diag::err_arc_collection_forward
1715 }
else if (iface || !objectType->
qual_empty()) {
1733 method = LookupMethodInQualifiedType(selector, pointerType,
1738 Diag(forLoc, diag::warn_collection_expr_type)
1739 << collection->
getType() << selector << collection->getSourceRange();
1755 CheckObjCForCollectionOperand(ForLoc, collection);
1759 if (
DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
1760 if (!DS->isSingleDecl())
1762 diag::err_toomany_element_decls));
1774 diag::err_non_local_variable_decl_in_for));
1780 Expr *DeducedInit = &OpaqueId;
1783 DiagnoseAutoDeductionFailure(D, DeducedInit);
1784 if (FirstType.
isNull()) {
1791 if (ActiveTemplateInstantiations.empty()) {
1794 Diag(Loc, diag::warn_auto_var_is_id)
1800 Expr *FirstE = cast<Expr>(First);
1803 diag::err_selector_element_not_lvalue)
1804 << First->getSourceRange());
1806 FirstType =
static_cast<Expr*
>(First)->getType();
1808 Diag(ForLoc, diag::err_selector_element_const_type)
1809 << FirstType << First->getSourceRange();
1814 return StmtError(
Diag(ForLoc, diag::err_selector_element_type)
1815 << FirstType << First->getSourceRange());
1821 CollectionExprResult = ActOnFinishFullExpr(CollectionExprResult.
get());
1826 nullptr, ForLoc, RParenLoc);
1875 void NoteForRangeBeginEndFunction(
Sema &SemaRef,
Expr *E,
1885 std::string Description;
1886 bool IsTemplate =
false;
1893 SemaRef.
Diag(Loc, diag::note_for_range_begin_end)
1894 << BEF << IsTemplate << Description << E->
getType();
1942 return ActOnObjCForCollectionStmt(ForLoc, First, Range, RParenLoc);
1945 assert(DS &&
"first part of for range not a decl stmt");
1954 DiagnoseUnexpandedParameterPack(Range, UPPC_Expression)) {
1961 VarDecl *RangeVar = BuildForRangeVarDecl(*
this, RangeLoc,
1965 diag::err_for_range_deduction_failure)) {
1974 StmtResult RangeDecl = ActOnDeclStmt(RangeGroup, RangeLoc, RangeLoc);
1980 return BuildCXXForRangeStmt(ForLoc, ColonLoc, RangeDecl.
get(),
1982 nullptr, DS, RParenLoc,
Kind);
2022 if (BeginMemberLookup.empty() != EndMemberLookup.
empty()) {
2026 SemaRef.
Diag(RangeLoc, diag::err_for_range_member_begin_end_mismatch)
2027 << RangeLoc << BeginRange->
getType() << *BEF;
2042 BeginMemberLookup, CandidateSet,
2043 BeginRange, BeginExpr);
2048 diag::err_for_range_iter_deduction_failure)) {
2049 NoteForRangeBeginEndFunction(SemaRef, BeginExpr->
get(), *BEF);
2057 EndMemberLookup, CandidateSet,
2062 diag::err_for_range_iter_deduction_failure)) {
2063 NoteForRangeBeginEndFunction(SemaRef, EndExpr->
get(), *BEF);
2091 AdjustedRange.
get(), RParenLoc,
2100 SemaRef.
Diag(RangeLoc, diag::err_for_range_dereference)
2103 AdjustedRange.
get(), RParenLoc,
2109 struct InvalidateOnErrorScope {
2110 InvalidateOnErrorScope(
Sema &SemaRef,
Decl *D,
bool Enabled)
2111 : Trap(SemaRef.Diags), D(D), Enabled(Enabled) {}
2112 ~InvalidateOnErrorScope() {
2113 if (Enabled && Trap.hasErrorOccurred())
2129 Scope *S = getCurScope();
2131 DeclStmt *RangeDS = cast<DeclStmt>(RangeDecl);
2133 QualType RangeVarType = RangeVar->getType();
2135 DeclStmt *LoopVarDS = cast<DeclStmt>(LoopVarDecl);
2140 InvalidateOnErrorScope Invalidate(*
this, LoopVar,
2141 LoopVar->getType()->isUndeducedType());
2146 if (RangeVarType->isDependentType()) {
2152 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check)
2154 }
else if (!BeginEndDecl.get()) {
2159 ExprResult BeginRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2164 ExprResult EndRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2170 Expr *Range = RangeVar->getInit();
2175 if (RequireCompleteType(RangeLoc, RangeType,
2176 diag::err_for_range_incomplete_type))
2180 VarDecl *BeginVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2182 VarDecl *EndVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2194 BeginExpr = BeginRangeRef;
2196 diag::err_for_range_iter_deduction_failure)) {
2197 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2207 dyn_cast<VariableArrayType>(UnqAT))
2208 BoundExpr = VAT->getSizeExpr();
2212 llvm_unreachable(
"Unexpected array type in for-range");
2216 EndExpr = ActOnBinOp(S, ColonLoc, tok::plus, EndRangeRef.
get(),
2221 diag::err_for_range_iter_deduction_failure)) {
2222 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2231 EndRangeRef.
get(), RangeType,
2232 BeginVar, EndVar,
ColonLoc, &CandidateSet,
2233 &BeginExpr, &EndExpr, &BEFFailure);
2235 if (Kind == BFRK_Build && RangeStatus == FRS_NoViableFunction &&
2236 BEFFailure == BEF_begin) {
2239 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Range)) {
2241 QualType ArrayTy = PVD->getOriginalType();
2242 QualType PointerTy = PVD->getType();
2244 Diag(Range->getLocStart(), diag::err_range_on_array_parameter)
2245 << RangeLoc << PVD << ArrayTy << PointerTy;
2246 Diag(PVD->getLocation(), diag::note_declared_at);
2255 LoopVarDecl, ColonLoc,
2263 if (RangeStatus == FRS_NoViableFunction) {
2264 Expr *Range = BEFFailure ? EndRangeRef.
get() : BeginRangeRef.
get();
2265 Diag(Range->getLocStart(), diag::err_for_range_invalid)
2266 << RangeLoc << Range->
getType() << BEFFailure;
2270 if (RangeStatus != FRS_Success)
2275 "invalid range expression in for loop");
2280 Diag(RangeLoc, diag::err_for_range_begin_end_types_differ)
2281 << BeginType << EndType;
2282 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2283 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2286 Decl *BeginEndDecls[] = { BeginVar, EndVar };
2291 BeginEndDecl = ActOnDeclStmt(BeginEndGroup, ColonLoc, ColonLoc);
2294 ExprResult BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2299 ExprResult EndRef = BuildDeclRefExpr(EndVar, EndType.getNonReferenceType(),
2305 NotEqExpr = ActOnBinOp(S, ColonLoc, tok::exclaimequal,
2306 BeginRef.
get(), EndRef.
get());
2307 NotEqExpr = ActOnBooleanCondition(S, ColonLoc, NotEqExpr.get());
2308 NotEqExpr = ActOnFinishFullExpr(NotEqExpr.get());
2309 if (NotEqExpr.isInvalid()) {
2310 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2311 << RangeLoc << 0 << BeginRangeRef.
get()->
getType();
2312 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2314 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2319 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2324 IncrExpr = ActOnUnaryOp(S, ColonLoc, tok::plusplus, BeginRef.
get());
2325 IncrExpr = ActOnFinishFullExpr(IncrExpr.get());
2326 if (IncrExpr.isInvalid()) {
2327 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2328 << RangeLoc << 2 << BeginRangeRef.
get()->
getType() ;
2329 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2334 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2339 ExprResult DerefExpr = ActOnUnaryOp(S, ColonLoc, tok::star, BeginRef.
get());
2341 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2342 << RangeLoc << 1 << BeginRangeRef.
get()->
getType();
2343 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2349 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2350 AddInitializerToDecl(LoopVar, DerefExpr.
get(),
false,
2352 if (LoopVar->isInvalidDecl())
2353 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2359 if (Kind == BFRK_Check)
2363 RangeDS, cast_or_null<DeclStmt>(BeginEndDecl.get()), NotEqExpr.
get(),
2364 IncrExpr.get(), LoopVarDS,
nullptr, ForLoc,
ColonLoc, RParenLoc);
2405 while (!isa<CXXOperatorCallExpr>(E) && !isa<UnaryOperator>(E)) {
2409 const MemberExpr *ME = cast<MemberExpr>(Call->getCallee());
2418 bool ReturnsReference =
false;
2419 if (isa<UnaryOperator>(E)) {
2420 ReturnsReference =
true;
2424 QualType ReturnType = FD->getReturnType();
2428 if (ReturnsReference) {
2432 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_const_reference_copy)
2433 << VD << VariableType << E->
getType();
2443 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_variable_always_copy)
2444 << VD << RangeInitType;
2464 if (!CE->getConstructor()->isCopyConstructor())
2466 }
else if (
const CastExpr *CE = dyn_cast<CastExpr>(InitExpr)) {
2482 << VD << VariableType << InitExpr->
getType();
2498 if (SemaRef.
Diags.
isIgnored(diag::warn_for_range_const_reference_copy,
2500 SemaRef.
Diags.
isIgnored(diag::warn_for_range_variable_always_copy,
2536 if (isa<ObjCForCollectionStmt>(S))
2537 return FinishObjCForCollectionStmt(S, B);
2543 diag::warn_empty_range_based_for_body);
2553 getCurFunction()->setHasBranchIntoScope();
2567 CheckSingleAssignmentConstraints(DestTy, ExprRes);
2571 if (DiagnoseAssignmentResult(ConvTy, StarLoc, DestTy, ETy, E, AA_Passing))
2580 getCurFunction()->setHasIndirectGoto();
2586 const Scope &DestScope) {
2589 S.
Diag(Loc, diag::warn_jump_out_of_seh_finally);
2598 return StmtError(
Diag(ContinueLoc, diag::err_continue_not_in_loop));
2610 return StmtError(
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
2613 return StmtError(
Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt)
2640 bool AllowFunctionParameter) {
2653 if (isCopyElisionCandidate(ReturnType, VD, AllowFunctionParameter))
2659 bool AllowFunctionParameter) {
2673 if (VD->
getKind() != Decl::Var &&
2674 !(AllowFunctionParameter && VD->
getKind() == Decl::ParmVar))
2685 if (VD->
hasAttr<BlocksAttr>())
return false;
2716 (NRVOCandidate || getCopyElisionCandidate(ResultType, Value,
true))) {
2720 Expr *InitExpr = &AsRvalue;
2723 Value->getLocStart());
2732 StepEnd = Seq.step_end();
2738 = cast<CXXConstructorDecl>(
Step->Function.Function);
2757 Res = Seq.Perform(*
this, Entity, Kind, Value);
2798 assert(AT &&
"lost auto type from lambda return type");
2799 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
2809 if (RetValExp && !isa<InitListExpr>(RetValExp)) {
2813 RetValExp = Result.
get();
2819 if (!CurContext->isDependentContext())
2828 Diag(ReturnLoc, diag::err_lambda_return_init_list)
2829 << RetValExp->getSourceRange();
2840 assert(!FnRetType.isNull());
2842 if (
BlockScopeInfo *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
2844 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr);
2848 dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
2849 Diag(ReturnLoc, diag::err_return_in_captured_stmt) << CurRegion->getRegionName();
2852 assert(CurLambda &&
"unknown kind of captured scope");
2854 ->getNoReturnAttr()) {
2855 Diag(ReturnLoc, diag::err_noreturn_lambda_has_return_expr);
2863 const VarDecl *NRVOCandidate =
nullptr;
2864 if (FnRetType->isDependentType()) {
2867 }
else if (FnRetType->isVoidType()) {
2868 if (RetValExp && !isa<InitListExpr>(RetValExp) &&
2869 !(getLangOpts().CPlusPlus &&
2872 if (!getLangOpts().CPlusPlus &&
2874 Diag(ReturnLoc, diag::ext_return_has_void_expr) <<
"literal" << 2;
2876 Diag(ReturnLoc, diag::err_return_block_has_expr);
2877 RetValExp =
nullptr;
2880 }
else if (!RetValExp) {
2881 return StmtError(
Diag(ReturnLoc, diag::err_block_return_missing_expr));
2891 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp,
false);
2894 NRVOCandidate !=
nullptr);
2895 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
2896 FnRetType, RetValExp);
2901 RetValExp = Res.
get();
2902 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc);
2904 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp,
false);
2908 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
2911 RetValExp = ER.
get();
2920 FunctionScopes.back()->Returns.push_back(Result);
2938 class LocalTypedefNameReferencer
2941 LocalTypedefNameReferencer(
Sema &S) : S(S) {}
2946 bool LocalTypedefNameReferencer::VisitRecordType(
const RecordType *RT) {
2948 if (!R || !R->isLocalClass() || !R->isLocalClass()->isExternallyVisible() ||
2949 R->isDependentType())
2951 for (
auto *TmpD : R->decls())
2952 if (
auto *T = dyn_cast<TypedefNameDecl>(TmpD))
2953 if (T->getAccess() !=
AS_private || R->hasFriends())
2972 TypeLoc OrigResultType = getReturnTypeLoc(FD);
2975 if (RetExpr && isa<InitListExpr>(RetExpr)) {
2979 getCurLambda() ? diag::err_lambda_return_init_list
2980 : diag::err_auto_fn_return_init_list)
2981 << RetExpr->getSourceRange();
2990 assert(AT->
isDeduced() &&
"should have deduced to dependent type");
2992 }
else if (RetExpr) {
2995 if (isa<InitListExpr>(RetExpr)) {
3008 if (DAR != DAR_Succeeded)
3013 LocalTypedefNameReferencer Referencer(*
this);
3014 Referencer.TraverseType(RetExpr->
getType());
3022 Diag(ReturnLoc, diag::err_auto_fn_return_void_but_not_auto)
3042 Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible)
3046 Diag(ReturnLoc, diag::err_auto_fn_different_deductions)
3063 StmtResult R = BuildReturnStmt(ReturnLoc, RetValExp);
3069 const_cast<VarDecl*>(cast<ReturnStmt>(R.
get())->getNRVOCandidate())) {
3082 if (RetValExp && DiagnoseUnexpandedParameterPack(RetValExp))
3085 if (isa<CapturingScopeInfo>(getCurFunction()))
3086 return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp);
3090 const AttrVec *Attrs =
nullptr;
3091 bool isObjCMethod =
false;
3098 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
3101 FnRetType = MD->getReturnType();
3102 isObjCMethod =
true;
3104 Attrs = &MD->getAttrs();
3105 if (MD->hasRelatedResultType() && MD->getClassInterface()) {
3120 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3134 if (isa<InitListExpr>(RetValExp)) {
3138 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3139 int FunctionKind = 0;
3140 if (isa<ObjCMethodDecl>(CurDecl))
3142 else if (isa<CXXConstructorDecl>(CurDecl))
3144 else if (isa<CXXDestructorDecl>(CurDecl))
3147 Diag(ReturnLoc, diag::err_return_init_list)
3149 << RetValExp->getSourceRange();
3152 RetValExp =
nullptr;
3155 unsigned D = diag::ext_return_has_expr;
3157 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3158 if (isa<CXXConstructorDecl>(CurDecl) ||
3159 isa<CXXDestructorDecl>(CurDecl))
3160 D = diag::err_ctor_dtor_returns_void;
3162 D = diag::ext_return_has_void_expr;
3166 Result = IgnoredValueConversions(Result.
get());
3169 RetValExp = Result.
get();
3170 RetValExp = ImpCastExprToType(RetValExp,
3174 if (D == diag::err_ctor_dtor_returns_void) {
3175 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3177 << CurDecl->
getDeclName() << isa<CXXDestructorDecl>(CurDecl)
3178 << RetValExp->getSourceRange();
3181 else if (D != diag::ext_return_has_void_expr ||
3183 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3185 int FunctionKind = 0;
3186 if (isa<ObjCMethodDecl>(CurDecl))
3188 else if (isa<CXXConstructorDecl>(CurDecl))
3190 else if (isa<CXXDestructorDecl>(CurDecl))
3195 << RetValExp->getSourceRange();
3200 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3203 RetValExp = ER.
get();
3208 }
else if (!RetValExp && !HasDependentReturnType) {
3214 DiagID = diag::err_constexpr_return_missing_expr;
3216 }
else if (getLangOpts().
C99) {
3218 DiagID = diag::ext_return_missing_expr;
3221 DiagID = diag::warn_return_missing_expr;
3227 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1;
3231 assert(RetValExp || HasDependentReturnType);
3232 const VarDecl *NRVOCandidate =
nullptr;
3234 QualType RetType = RelatedRetType.
isNull() ? FnRetType : RelatedRetType;
3243 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp,
false);
3248 NRVOCandidate !=
nullptr);
3249 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3250 RetType, RetValExp);
3261 if (!RelatedRetType.
isNull()) {
3264 Res = PerformCopyInitialization(Entity, ReturnLoc, RetValExp);
3272 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc, isObjCMethod, Attrs,
3273 getCurFunctionDecl());
3277 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3280 RetValExp = ER.
get();
3288 FunctionScopes.back()->Returns.push_back(Result);
3297 VarDecl *Var = cast_or_null<VarDecl>(Parm);
3312 if (!getLangOpts().ObjCExceptions)
3313 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@try";
3315 getCurFunction()->setHasBranchProtectedScope();
3316 unsigned NumCatchStmts = CatchStmts.size();
3318 NumCatchStmts, Finally);
3327 Result = ActOnFinishFullExpr(Result.
get());
3330 Throw = Result.
get();
3338 return StmtError(
Diag(AtLoc, diag::error_objc_throw_expects_object)
3339 << Throw->
getType() << Throw->getSourceRange());
3349 if (!getLangOpts().ObjCExceptions)
3350 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@throw";
3355 Scope *AtCatchParent = CurScope;
3357 AtCatchParent = AtCatchParent->
getParent();
3359 return StmtError(
Diag(AtLoc, diag::error_rethrow_used_outside_catch));
3361 return BuildObjCAtThrowStmt(AtLoc, Throw);
3366 ExprResult result = DefaultLvalueConversion(operand);
3369 operand = result.
get();
3377 if (getLangOpts().CPlusPlus) {
3378 if (RequireCompleteType(atLoc, type,
3379 diag::err_incomplete_receiver_type))
3380 return Diag(atLoc, diag::error_objc_synchronized_expects_object)
3381 << type << operand->getSourceRange();
3383 ExprResult result = PerformContextuallyConvertToObjCPointer(operand);
3385 return Diag(atLoc, diag::error_objc_synchronized_expects_object)
3386 << type << operand->getSourceRange();
3388 operand = result.
get();
3390 return Diag(atLoc, diag::error_objc_synchronized_expects_object)
3391 << type << operand->getSourceRange();
3397 return ActOnFinishFullExpr(operand);
3404 getCurFunction()->setHasBranchProtectedScope();
3412 Stmt *HandlerBlock) {
3415 CXXCatchStmt(CatchLoc, cast_or_null<VarDecl>(ExDecl), HandlerBlock);
3420 getCurFunction()->setHasBranchProtectedScope();
3425 class CatchHandlerType {
3427 unsigned IsPointer : 1;
3432 enum Unique { ForDenseMap };
3433 CatchHandlerType(
QualType QT, Unique) : QT(QT), IsPointer(
false) {}
3440 if (QT->isPointerType())
3443 if (IsPointer || QT->isReferenceType())
3444 QT = QT->getPointeeType();
3445 QT = QT.getUnqualifiedType();
3451 CatchHandlerType(
QualType QT,
bool IsPointer)
3452 : QT(QT), IsPointer(IsPointer) {}
3454 QualType underlying()
const {
return QT; }
3455 bool isPointer()
const {
return IsPointer; }
3457 friend bool operator==(
const CatchHandlerType &LHS,
3458 const CatchHandlerType &RHS) {
3460 if (LHS.IsPointer != RHS.IsPointer)
3463 return LHS.QT == RHS.QT;
3472 CatchHandlerType::ForDenseMap);
3477 CatchHandlerType::ForDenseMap);
3485 const CatchHandlerType &RHS) {
3492 static const bool value =
true;
3497 class CatchTypePublicBases {
3499 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &TypesToCheck;
3500 const bool CheckAgainstPointer;
3506 CatchTypePublicBases(
3508 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &T,
bool C)
3509 : Ctx(Ctx), TypesToCheck(T), CheckAgainstPointer(C),
3510 FoundHandler(
nullptr) {}
3512 CXXCatchStmt *getFoundHandler()
const {
return FoundHandler; }
3513 CanQualType getFoundHandlerType()
const {
return FoundHandlerType; }
3517 auto &PBOT = *
reinterpret_cast<CatchTypePublicBases *
>(User);
3519 CatchHandlerType Check(S->
getType(), PBOT.CheckAgainstPointer);
3520 auto M = PBOT.TypesToCheck;
3521 auto I = M.find(Check);
3523 PBOT.FoundHandler = I->second;
3524 PBOT.FoundHandlerType = PBOT.Ctx.getCanonicalType(S->
getType());
3538 if (!getLangOpts().CXXExceptions &&
3539 !getSourceManager().isInSystemHeader(TryLoc))
3540 Diag(TryLoc, diag::err_exceptions_disabled) <<
"try";
3542 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
3543 Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) <<
"try";
3549 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
3553 const unsigned NumHandlers = Handlers.size();
3554 assert(!Handlers.empty() &&
3555 "The parser shouldn't call this if there are no handlers.");
3557 llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> HandledTypes;
3558 for (
unsigned i = 0; i < NumHandlers; ++i) {
3565 if (i < NumHandlers - 1)
3574 CatchHandlerType HandlerCHT =
3580 QualType Underlying = HandlerCHT.underlying();
3582 if (!RD->hasDefinition())
3591 CatchTypePublicBases CTPB(
Context, HandledTypes, HandlerCHT.isPointer());
3592 if (RD->lookupInBases(CatchTypePublicBases::FindPublicBasesOfType, &CTPB,
3595 if (!Paths.
isAmbiguous(CTPB.getFoundHandlerType())) {
3597 diag::warn_exception_caught_by_earlier_handler)
3600 diag::note_previous_exception_handler)
3608 auto R = HandledTypes.insert(std::make_pair(H->
getCaughtType(), H));
3612 diag::warn_exception_caught_by_earlier_handler)
3615 diag::note_previous_exception_handler)
3627 assert(TryBlock && Handler);
3633 if (!getLangOpts().Borland) {
3635 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
3651 Diag(TryLoc, diag::err_seh_try_outside_functions);
3655 Diag(TryLoc, diag::err_seh_try_unsupported);
3664 assert(FilterExpr && Block);
3668 diag::err_filter_expression_integral)
3676 CurrentSEHFinally.push_back(CurScope);
3680 CurrentSEHFinally.pop_back();
3685 CurrentSEHFinally.pop_back();
3691 Scope *SEHTryParent = CurScope;
3693 SEHTryParent = SEHTryParent->
getParent();
3695 return StmtError(
Diag(Loc, diag::err_ms___leave_not_in___try));
3708 QualifierLoc, NameInfo,
3709 cast<CompoundStmt>(Nested));
3718 return BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
3720 GetNameFromUnqualifiedId(Name),
3726 unsigned NumParams) {
3743 assert(NumParams > 0 &&
"CapturedStmt requires context parameter");
3755 for (CaptureIter Cap = Candidates.begin(); Cap != Candidates.end(); ++Cap) {
3757 if (Cap->isThisCapture()) {
3760 CaptureInits.push_back(Cap->getInitExpr());
3762 }
else if (Cap->isVLATypeCapture()) {
3765 CaptureInits.push_back(
nullptr);
3769 assert(Cap->isReferenceCapture() &&
3770 "non-reference capture not yet implemented");
3774 Cap->getVariable()));
3775 CaptureInits.push_back(Cap->getInitExpr());
3781 unsigned NumParams) {
3783 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, NumParams);
3796 PushCapturedRegionScope(CurScope, CD, RD, Kind);
3799 PushDeclContext(CurScope, CD);
3803 PushExpressionEvaluationContext(PotentiallyEvaluated);
3810 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, Params.size());
3814 bool ContextIsFound =
false;
3815 unsigned ParamNum = 0;
3818 I != E; ++I, ++ParamNum) {
3819 if (I->second.isNull()) {
3820 assert(!ContextIsFound &&
3821 "null type has been found already for '__context' parameter");
3828 ContextIsFound =
true;
3837 assert(ContextIsFound &&
"no null type for '__context' parameter");
3838 if (!ContextIsFound) {
3848 PushCapturedRegionScope(CurScope, CD, RD, Kind);
3851 PushDeclContext(CurScope, CD);
3855 PushExpressionEvaluationContext(PotentiallyEvaluated);
3859 DiscardCleanupsInEvaluationContext();
3860 PopExpressionEvaluationContext();
3867 ActOnFields(
nullptr, Record->
getLocation(), Record, Fields,
3871 PopFunctionScopeInfo();
3886 CaptureInits, CD, RD);
3891 DiscardCleanupsInEvaluationContext();
3892 PopExpressionEvaluationContext();
3895 PopFunctionScopeInfo();
unsigned getFlags() const
A call to an overloaded operator written using operator syntax.
Defines the clang::ASTContext interface.
const SwitchCase * getNextSwitchCase() const
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
CastKind getCastKind() const
void setImplicit(bool I=true)
SourceLocation getLocStart() const LLVM_READONLY
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
void setOrigin(CXXRecordDecl *Rec)
Smart pointer class that efficiently represents Objective-C method names.
EvaluatedExprVisitor - This class visits 'Expr *'s.
static void AdjustAPSInt(llvm::APSInt &Val, unsigned BitWidth, bool IsSigned)
void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, CapturedRegionKind Kind, unsigned NumParams)
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
QualType getType() const
Retrieves the type of the base class.
StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, Stmt *HandlerBlock)
bool operator==(CanQual< T > x, CanQual< U > y)
static unsigned getHashValue(const CatchHandlerType &Base)
bool hasUnusedResultAttr() const
Returns true if this function or its return type has the warn_unused_result attribute. If the return type has the attribute and this function is a method of the return type's class, then false will be returned to avoid spurious warnings on member methods such as assignment operators.
IdentifierInfo * getIdentifier() const
const LangOptions & getLangOpts() const
const Scope * getFnParent() const
SmallVectorImpl< Step >::const_iterator step_iterator
unsigned getIntWidth(QualType T) const
StmtResult ActOnExprStmt(ExprResult Arg)
const Scope * getParent() const
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
void setParam(unsigned i, ImplicitParamDecl *P)
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
ActionResult< Expr * > ExprResult
SmallVector< Scope *, 2 > CurrentSEHFinally
Stack of active SEH __finally scopes. Can be empty.
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments...
TypeLoc getReturnTypeLoc(FunctionDecl *FD) const
bool isRecordType() const
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
Represents a C++11 auto or C++1y decltype(auto) type.
Represents an attribute applied to a statement.
bool isEnumeralType() const
bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD, bool AllowFunctionParameters)
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr * > CaptureInits, CapturedDecl *CD, RecordDecl *RD)
Represents Objective-C's @throw statement.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
const Expr * getInit() const
const ObjCObjectType * getObjectType() const
Represents a call to a C++ constructor.
StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, Stmt *Body)
virtual void completeDefinition()
bool isDecltypeAuto() const
A container of type source information.
Wrapper for void* pointer.
StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope)
bool isBlockPointerType() const
Scope * getContinueParent()
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
bool isInSystemMacro(SourceLocation loc)
Returns whether Loc is expanded from a macro in a system header.
Represents a C++ constructor within a class.
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Retains information about a function, method, or block that is currently being parsed.
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, MultiStmtArg Catch, Stmt *Finally)
DiagnosticsEngine & Diags
ObjCLifetime getObjCLifetime() const
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl)
SourceLocation getLocStart() const LLVM_READONLY
static bool ObjCEnumerationCollection(Expr *Collection)
RAII class that determines when any errors have occurred between the time the instance was created an...
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
Defines the Objective-C statement AST node classes.
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input)
ParmVarDecl - Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
SourceLocation getDefaultLoc() const
SourceLocation getLocation() const
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
QualType withConst() const
Retrieves a version of this type with const applied. Note that this does not always yield a canonical...
static void checkCaseValue(Sema &S, SourceLocation Loc, const llvm::APSInt &Val, unsigned UnpromotedWidth, bool UnpromotedSign)
Base wrapper for a particular "section" of type source info.
Expr * IgnoreImpCasts() LLVM_READONLY
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool OdrUse)
Perform marking for a reference to an arbitrary declaration. It marks the declaration referenced...
const internal::VariadicDynCastAllOfMatcher< Stmt, CaseStmt > caseStmt
Matches case statements inside switch statements.
void DiagnoseUnusedExprResult(const Stmt *S)
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
VarDecl * getCopyElisionCandidate(QualType ReturnType, Expr *E, bool AllowFunctionParameters)
Determine whether the given expression is a candidate for copy elision in either a return statement o...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A C++ nested-name-specifier augmented with source location information.
bool isReferenceType() const
QualType getReturnType() const
static bool CmpCaseVals(const std::pair< llvm::APSInt, CaseStmt * > &lhs, const std::pair< llvm::APSInt, CaseStmt * > &rhs)
void setLocStart(SourceLocation L)
ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, Expr *collection)
bool isSEHTryScope() const
Determine whether this scope is a SEH '__try' block.
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, FullExprArg Second, Decl *SecondVar, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
void startDefinition()
Starts the definition of this tag declaration.
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
void ActOnAbortSEHFinallyBlock()
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Represents Objective-C's @catch statement.
StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization. ...
SourceLocation getBeginLoc() const
Get the begin source location.
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Represents a C++ unqualified-id that has been parsed.
static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From, QualType T, APValue &Value, Sema::CCEKind CCE, bool RequireInt)
Represents the results of name lookup.
const TargetInfo & getTargetInfo() const
This is a scope that corresponds to a switch statement.
void ActOnStartSEHFinallyBlock()
QualType getReturnType() const
const CXXRecordDecl * getParent() const
An x-value expression is a reference to an object with independent storage but which can be "moved"...
field_range fields() const
RecordDecl * CreateCapturedStmtRecordDecl(CapturedDecl *&CD, SourceLocation Loc, unsigned NumParams)
bool isMacroBodyExpansion(SourceLocation Loc) const
Tests whether the given source location represents the expansion of a macro body. ...
A builtin binary operation expression such as "x + y" or "x <= y".
bool isValueDependent() const
RecordDecl * getDecl() const
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef< Stmt * > handlers)
ObjCInterfaceDecl * getInterface() const
StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope)
SmallVector< std::pair< llvm::APSInt, EnumConstantDecl * >, 64 > EnumValsTy
bool isOverloadedOperator() const
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
LabelStmt * getStmt() const
Expr * IgnoreParenCasts() LLVM_READONLY
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *BeginEndDecl, Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, BuildForRangeKind Kind)
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
Represents a C++ nested-name-specifier or a global scope specifier.
bool isOpenMPLoopScope() const
Determine whether this scope is a loop having OpenMP loop directive attached.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Def If non-NULL, and the type refers to some kind of declaration that can be completed (such as a C s...
Represents binding an expression to a temporary.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
static CatchHandlerType getTombstoneKey()
StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block)
StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope)
Perform initialization via a constructor.
A class that does preorder depth-first traversal on the entire Clang AST and visits each node...
This represents the body of a CapturedStmt, and serves as its DeclContext.
Represents an ObjC class declaration.
StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, Scope *CurScope)
void setStmt(LabelStmt *T)
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
Contains information about the compound statement currently being parsed.
SourceLocation FirstCXXTryLoc
First C++ 'try' statement in the current function.
const ArrayType * getAsArrayTypeUnsafe() const
QualType getAutoRRefDeductType() const
C++11 deduction pattern for 'auto &&' type.
EnumDecl * getDecl() const
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
static Sema::ForRangeStatus BuildNonArrayForRange(Sema &SemaRef, Scope *S, Expr *BeginRange, Expr *EndRange, QualType RangeType, VarDecl *BeginVar, VarDecl *EndVar, SourceLocation ColonLoc, OverloadCandidateSet *CandidateSet, ExprResult *BeginExpr, ExprResult *EndExpr, Sema::BeginEndFunction *BEF)
Create the initialization, compare, and increment steps for the range-based for loop expression...
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
Sema - This implements semantic analysis and AST building for C.
Expr * getFalseExpr() const
A little helper class used to produce diagnostics.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit, bool TypeMayContainAuto)
Describes the capture of either a variable, or 'this', or variable-length array type.
Retains information about a captured region.
bool inferObjCARCLifetime(ValueDecl *decl)
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp)
StmtResult ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
SourceLocation getTypeSpecStartLoc() const
void ActOnFinishOfCompoundStmt()
StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
bool isSignedIntegerOrEnumerationType() const
Allows QualTypes to be sorted and hence used in maps and sets.
Retains information about a block that is currently being parsed.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Type source information for an attributed type.
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
bool isAtCatchScope() const
isAtCatchScope - Return true if this scope is @catch.
bool isKnownToHaveBooleanValue() const
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
static void buildCapturedStmtCaptureList(SmallVectorImpl< CapturedStmt::Capture > &Captures, SmallVectorImpl< Expr * > &CaptureInits, ArrayRef< CapturingScopeInfo::Capture > Candidates)
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
void setInvalidDecl(bool Invalid=true)
static void DiagnoseForRangeConstVariableCopies(Sema &SemaRef, const VarDecl *VD)
void setContextParam(unsigned i, ImplicitParamDecl *P)
Defines the clang::Preprocessor interface.
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
const ParmVarDecl * getParamDecl(unsigned i) const
Represents Objective-C's @synchronized statement.
bool isMSAsmLabel() const
Defines the clang::TypeLoc interface and its subclasses.
static DeclContext * castToDeclContext(const CapturedDecl *D)
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, Expr *Cond, Decl *CondVar)
const SwitchCase * getSwitchCaseList() const
QualType getType() const
Get the type for which this source info wrapper provides information.
Expr * getSubExpr() const
bool isDependentType() const
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
bool isFunctionOrMethod() const
static CapturedDecl * Create(ASTContext &C, DeclContext *DC, unsigned NumParams)
static bool isEqual(const CatchHandlerType &LHS, const CatchHandlerType &RHS)
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
QualType getObjCIdType() const
Represents the Objective-CC id type.
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
An expression that sends a message to the given Objective-C object or class.
void setLocation(SourceLocation L)
DeclarationName getDeclName() const
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
void setHasCXXTry(SourceLocation TryLoc)
Represents a C++ conversion function within a class.
The result type of a method or function.
TypeSourceInfo * getTypeSourceInfo() const
Expr * getTrueExpr() const
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr, bool DelayTypeCreation=false)
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
static CatchHandlerType getEmptyKey()
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute. The C++11 [[noreturn]] attr...
void ActOnStartOfCompoundStmt()
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
static QualType GetTypeBeforeIntegralPromotion(Expr *&expr)
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
SelectorTable & Selectors
This captures a statement into a function. For example, the following pragma annotated compound state...
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
void setHasSEHTry(SourceLocation TryLoc)
bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, bool AllowMask) const
DeduceAutoResult
Result type of DeduceAutoType.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
enumerator_range enumerators() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Expr * getSourceExpr() const
void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, Expr *SrcExpr)
void FinalizeDeclaration(Decl *D)
StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Scope *CurScope)
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isSingleDecl() const
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
bool isSEHTrySupported() const
Whether the target supports SEH __try.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
StmtResult ActOnForEachLValueExpr(Expr *E)
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
bool isLocalVarDecl() const
IdentifierTable & getIdentifierTable()
const Expr * getCond() const
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
QualType withConst() const
StmtResult ActOnCapturedRegionEnd(Stmt *S)
void setAllEnumCasesCovered()
bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, SourceLocation ReturnLoc, Expr *&RetExpr, AutoType *AT)
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
static bool CmpEnumVals(const std::pair< llvm::APSInt, EnumConstantDecl * > &lhs, const std::pair< llvm::APSInt, EnumConstantDecl * > &rhs)
Describes the kind of initialization being performed, along with location information for tokens rela...
SourceLocation getContinueLoc() const
SmallVector< Capture, 4 > Captures
Captures - The captures.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Stmt * getCapturedStmt()
Retrieve the statement being captured.
bool isTypeDependent() const
bool isFileContext() const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
QualType getType() const
Return the type wrapped by this type source info.
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name...
const Decl * getSingleDecl() const
SourceLocation getExprLoc() const LLVM_READONLY
static void DiagnoseForRangeReferenceVariableCopies(Sema &SemaRef, const VarDecl *VD, QualType RangeInitType)
QualType getPointeeType() const
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
AccessSpecifier getAccessSpecifier() const
Returns the access specifier for this base specifier.
CapturedRegionKind CapRegionKind
The kind of captured region.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
void ActOnCapturedRegionError()
void addNRVOCandidate(VarDecl *VD)
bool isInvalidDecl() const
void setARCPseudoStrong(bool ps)
StmtResult ActOnExprStmtError()
TypeLoc IgnoreParens() const
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getCaughtType() const
static void DiagnoseForRangeVariableCopies(Sema &SemaRef, const CXXForRangeStmt *ForStmt)
SourceLocation getLocStart() const LLVM_READONLY
bool isAmbiguous(CanQualType BaseType)
Determine whether the path from the most-derived type to the given base type is ambiguous (i...
sema::CompoundScopeInfo & getCurCompoundScope() const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Expr * IgnoreParenImpCasts() LLVM_READONLY
QualType getNonReferenceType() const
StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, CXXScopeSpec &SS, UnqualifiedId &Name, Stmt *Nested)
bool empty() const
Return true if no decls were found.
RecordDecl * TheRecordDecl
The captured record type.
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, Expr *LHSVal, SourceLocation DotDotDotLoc, Expr *RHSVal, SourceLocation ColonLoc)
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>. Pointer - pointer requires t...
static StmtResult RebuildForRangeWithDereference(Sema &SemaRef, Scope *S, SourceLocation ForLoc, Stmt *LoopVarDecl, SourceLocation ColonLoc, Expr *Range, SourceLocation RangeLoc, SourceLocation RParenLoc)
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T)
Represents Objective-C's collection statement.
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
static bool ShouldDiagnoseSwitchCaseNotInEnum(const Sema &S, const EnumDecl *ED, const Expr *CaseExpr, EnumValsTy::iterator &EI, EnumValsTy::iterator &EIEnd, const llvm::APSInt &Val)
void setUsesSEHTry(bool UST)
ActionResult< Stmt * > StmtResult
ForRangeStatus BuildForRangeBeginEndCall(Scope *S, SourceLocation Loc, SourceLocation RangeLoc, VarDecl *Decl, BeginEndFunction BEF, const DeclarationNameInfo &NameInfo, LookupResult &MemberLookup, OverloadCandidateSet *CandidateSet, Expr *Range, ExprResult *CallExpr)
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represents Objective-C's @finally statement.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
void addDecl(Decl *D)
Add the declaration D into this context.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
Represents a base class of a C++ class.
static bool DiagnoseUnusedComparison(Sema &S, const Expr *E)
Diagnose unused comparisons, both builtin and overloaded operators. For '==' and '!=', suggest fixits for '=' or '|='.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
bool isPODType(ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, const VarDecl *NRVOCandidate, QualType ResultType, Expr *Value, bool AllowNRVO=true)
Perform the initialization of a potentially-movable value, which is the result of return value...
const Expr * getSubExpr() const
static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD, QualType Type)
Create the initialization entity for a related result.
Describes the sequence of initializations required to initialize a given object or reference with a s...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp)
Represents a C++ struct/union/class.
bool isObjCObjectPointerType() const
static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init, SourceLocation Loc, int DiagID)
SourceLocation getBreakLoc() const
VarDecl * getLoopVariable()
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr.type.conv]).
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
StmtResult ActOnCXXForRangeStmt(SourceLocation ForLoc, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, SourceLocation RParenLoc, BuildForRangeKind Kind)
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult{return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Defines the clang::TargetInfo interface.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
bool HasImplicitReturnType
Whether the target type of return statements in this context is deduced (e.g. a lambda or block with ...
static bool EqEnumVals(const std::pair< llvm::APSInt, EnumConstantDecl * > &lhs, const std::pair< llvm::APSInt, EnumConstantDecl * > &rhs)
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
VarDecl * getExceptionDecl() const
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
SourceLocation getStarLoc() const
SourceManager & SourceMgr
CapturedRegionKind
The different kinds of captured statement.
DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result)
An l-value expression is a reference to an object with independent storage.
static bool hasDeducedReturnType(FunctionDecl *FD)
Determine whether the declared return type of the specified function contains 'auto'.
SourceLocation getRParenLoc() const
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
A boolean literal, per ([C++ lex.bool] Boolean literals).
SourceLocation getStartLoc() const
bool isConstQualified() const
Determine whether this type is const-qualified.
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
Describes an entity that is being initialized.
void setType(QualType newType)
Wrapper for source info for pointers.
SourceLocation ColonLoc
Location of ':'.
bool isSingleDecl() const
Represents Objective-C's @autoreleasepool Statement.
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
Declaration of a template function.
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
bool isIntegerType() const
bool hasLocalStorage() const
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
static void CheckJumpOutOfSEHFinally(Sema &S, SourceLocation Loc, const Scope &DestScope)
Helper class that creates diagnostics with optional template instantiation stacks.
Expr * IgnoreParens() LLVM_READONLY
bool isPointerType() const
OverloadedOperatorKind getOverloadedOperator() const
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, Decl *CondVar, Stmt *Body)
QualType getDeducedType() const
Get the type deduced for this auto type, or null if it's either not been deduced or was deduced to a ...