35 #include "llvm/ADT/ArrayRef.h" 36 #include "llvm/ADT/DenseMap.h" 37 #include "llvm/ADT/STLExtras.h" 38 #include "llvm/ADT/SmallPtrSet.h" 39 #include "llvm/ADT/SmallString.h" 40 #include "llvm/ADT/SmallVector.h" 42 using namespace clang;
49 FE = ActOnFinishFullExpr(FE.
get(), FE.
get()->getExprLoc(), DiscardedValue);
63 DiscardCleanupsInEvaluationContext();
68 bool HasLeadingEmptyMacro) {
69 return new (Context)
NullStmt(SemiLoc, HasLeadingEmptyMacro);
79 return new (Context)
DeclStmt(DG, StartLoc, EndLoc);
109 if (getLangOpts().ObjCAutoRefCount) {
134 if (!Op->isComparisonOp())
137 if (Op->getOpcode() == BO_EQ)
139 else if (Op->getOpcode() == BO_NE)
141 else if (Op->getOpcode() == BO_Cmp)
144 assert(Op->isRelationalOp());
147 Loc = Op->getOperatorLoc();
148 CanAssign = Op->getLHS()->IgnoreParenImpCasts()->isLValue();
150 switch (Op->getOperator()) {
154 case OO_ExclaimEqual:
159 case OO_GreaterEqual:
170 Loc = Op->getOperatorLoc();
171 CanAssign = Op->getArg(0)->IgnoreParenImpCasts()->isLValue();
182 S.
Diag(Loc, diag::warn_unused_comparison)
188 if (Kind == Inequality)
189 S.
Diag(Loc, diag::note_inequality_comparison_to_or_assign)
192 S.
Diag(Loc, diag::note_equality_comparison_to_assign)
204 StringRef Msg = A->getMessage();
208 return S.
Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
209 return S.
Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
213 return S.
Diag(Loc, diag::warn_unused_constructor_msg) << A << Msg << R1
215 return S.
Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
220 return DiagnoseUnusedExprResult(
Label->getSubStmt());
222 const Expr *E = dyn_cast_or_null<Expr>(S);
228 if (isUnevaluatedContext())
237 bool ShouldSuppress =
238 SourceMgr.isMacroBodyExpansion(ExprLoc) ||
239 SourceMgr.isInSystemMacro(ExprLoc);
241 const Expr *WarnExpr;
244 if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context))
257 if (isa<ParenExpr>(E->IgnoreImpCasts()) && Loc.
isMacroID()) {
259 if (findMacroSpelling(SpellLoc,
"UNREFERENCED_PARAMETER"))
266 unsigned DiagID = diag::warn_unused_expr;
267 if (
const FullExpr *Temps = dyn_cast<FullExpr>(E))
268 E = Temps->getSubExpr();
270 E = TempExpr->getSubExpr();
276 if (
const auto *
Cast = dyn_cast<CastExpr>(E))
277 if (
Cast->getCastKind() == CK_NoOp ||
278 Cast->getCastKind() == CK_ConstructorConversion)
279 E =
Cast->getSubExpr()->IgnoreImpCasts();
281 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
282 if (E->getType()->isVoidType())
286 CE->getUnusedResultAttr(Context)),
294 if (
const Decl *FD = CE->getCalleeDecl()) {
297 if (FD->hasAttr<PureAttr>()) {
298 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"pure";
301 if (FD->hasAttr<ConstAttr>()) {
302 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"const";
306 }
else if (
const auto *CE = dyn_cast<CXXConstructExpr>(E)) {
308 const auto *A = Ctor->getAttr<WarnUnusedResultAttr>();
309 A = A ? A : Ctor->getParent()->getAttr<WarnUnusedResultAttr>();
313 }
else if (
const auto *ILE = dyn_cast<InitListExpr>(E)) {
314 if (
const TagDecl *TD = ILE->getType()->getAsTagDecl()) {
320 }
else if (ShouldSuppress)
325 if (getLangOpts().ObjCAutoRefCount && ME->isDelegateInitCall()) {
326 Diag(Loc, diag::err_arc_unused_init_message) << R1;
336 const Expr *Source = POE->getSyntacticForm();
337 if (isa<ObjCSubscriptRefExpr>(Source))
338 DiagID = diag::warn_unused_container_subscript_expr;
340 DiagID = diag::warn_unused_property_expr;
342 = dyn_cast<CXXFunctionalCastExpr>(E)) {
343 const Expr *E = FC->getSubExpr();
345 E = TE->getSubExpr();
346 if (isa<CXXTemporaryObjectExpr>(E))
349 if (
const CXXRecordDecl *RD = CE->getType()->getAsCXXRecordDecl())
350 if (!RD->getAttr<WarnUnusedAttr>())
354 else if (
const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E)) {
362 Diag(Loc, diag::warn_unused_voidptr)
368 if (E->isGLValue() && E->getType().isVolatileQualified()) {
369 Diag(Loc, diag::warn_unused_volatile) << R1 << R2;
373 DiagRuntimeBehavior(Loc,
nullptr, PDiag(DiagID) << R1 << R2);
377 PushCompoundScope(IsStmtExpr);
385 return getCurFunction()->CompoundScopes.back();
390 const unsigned NumElts = Elts.size();
398 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
402 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
406 Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
414 if (NumElts != 0 && !CurrentInstantiationScope &&
415 getCurCompoundScope().HasEmptyLoopBodies) {
416 for (
unsigned i = 0; i != NumElts - 1; ++i)
417 DiagnoseEmptyLoopBody(Elts[i], Elts[i + 1]);
428 if (DiagnoseUnexpandedParameterPack(Val.
get()))
433 if (getCurFunction()->SwitchStack.empty())
434 return ActOnFinishFullExpr(Val.
get(), Val.
get()->getExprLoc(),
false,
435 getLangOpts().CPlusPlus11);
438 getCurFunction()->SwitchStack.back().getPointer()->getCond();
443 auto CheckAndFinish = [&](
Expr *E) {
447 if (getLangOpts().CPlusPlus11) {
456 if (!E->isValueDependent())
457 ER = VerifyIntegerConstantExpression(E);
459 ER = DefaultLvalueConversion(ER.
get());
461 ER = ImpCastExprToType(ER.
get(), CondType, CK_IntegralCast);
463 ER = ActOnFinishFullExpr(ER.
get(), ER.
get()->getExprLoc(),
false);
467 ExprResult Converted = CorrectDelayedTyposInExpr(Val, CheckAndFinish);
468 if (Converted.
get() == Val.
get())
469 Converted = CheckAndFinish(Val.
get());
477 assert((LHSVal.
isInvalid() || LHSVal.
get()) &&
"missing LHS value");
480 "missing RHS value");
482 if (getCurFunction()->SwitchStack.empty()) {
483 Diag(CaseLoc, diag::err_case_not_in_switch);
488 getCurFunction()->SwitchStack.back().setInt(
true);
494 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(CS);
500 cast<CaseStmt>(S)->setSubStmt(SubStmt);
506 if (getCurFunction()->SwitchStack.empty()) {
507 Diag(DefaultLoc, diag::err_default_not_in_switch);
512 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(DS);
521 Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->
getDeclName();
553 CommaVisitor(
Sema &SemaRef) : Inherited(SemaRef.
Context), SemaRef(SemaRef) {}
575 Expr *CondExpr = Cond.
get().second;
578 !Diags.isIgnored(diag::warn_comma_operator, CondExpr->
getExprLoc()))
579 CommaVisitor(*this).Visit(CondExpr);
582 DiagnoseEmptyStmtBody(CondExpr->
getEndLoc(), thenStmt,
583 diag::warn_empty_if_body);
585 return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
596 if (IsConstexpr || isa<ObjCAvailabilityCheckExpr>(Cond.
get().second))
597 setFunctionHasBranchProtectedScope();
600 Cond.
get().second, thenStmt, ElseLoc, elseStmt);
604 struct CaseCompareFunctor {
605 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
607 return LHS.first < RHS;
609 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
610 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
611 return LHS.first < RHS.first;
614 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
615 return LHS < RHS.first;
622 static bool CmpCaseVals(
const std::pair<llvm::APSInt, CaseStmt*>& lhs,
623 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
624 if (lhs.first < rhs.first)
627 if (lhs.first == rhs.first &&
628 lhs.second->getCaseLoc().getRawEncoding()
629 < rhs.second->getCaseLoc().getRawEncoding())
636 static bool CmpEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
637 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
639 return lhs.first < rhs.first;
644 static bool EqEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
645 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
647 return lhs.first == rhs.first;
653 if (
const auto *FE = dyn_cast<FullExpr>(E))
654 E = FE->getSubExpr();
655 while (
const auto *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
656 if (ImpCast->getCastKind() != CK_IntegralCast)
break;
657 E = ImpCast->getSubExpr();
667 SwitchConvertDiagnoser(
Expr *Cond)
673 return S.
Diag(Loc, diag::err_typecheck_statement_requires_integer) << T;
678 return S.
Diag(Loc, diag::err_switch_incomplete_class_type)
684 return S.
Diag(Loc, diag::err_switch_explicit_conversion) << T << ConvTy;
695 return S.
Diag(Loc, diag::err_switch_multiple_conversions) << T;
706 llvm_unreachable(
"conversion functions are permitted");
708 } SwitchDiagnoser(Cond);
711 PerformContextualImplicitConversion(SwitchLoc, Cond, SwitchDiagnoser);
717 Cond = CondResult.
get();
723 return UsualUnaryConversions(Cond);
728 Expr *CondExpr = Cond.
get().second;
729 assert((Cond.
isInvalid() || CondExpr) &&
"switch with no condition");
737 "invalid condition type");
742 Diag(SwitchLoc, diag::warn_bool_switch_condition)
747 setFunctionHasBranchIntoScope();
750 getCurFunction()->SwitchStack.push_back(
756 Val = Val.extOrTrunc(BitWidth);
757 Val.setIsSigned(IsSigned);
763 unsigned UnpromotedWidth,
bool UnpromotedSign) {
771 if (UnpromotedWidth < Val.getBitWidth()) {
774 AdjustAPSInt(ConvVal, Val.getBitWidth(), Val.isSigned());
779 S.
Diag(Loc, diag::warn_case_value_overflow) << Val.toString(10)
780 << ConvVal.toString(10);
790 const Expr *CaseExpr,
791 EnumValsTy::iterator &EI,
792 EnumValsTy::iterator &EIEnd,
799 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
808 if (ED->
hasAttr<FlagEnumAttr>())
811 while (EI != EIEnd && EI->first < Val)
814 if (EI != EIEnd && EI->first == Val)
827 if (!CondEnumType || !CaseEnumType)
834 if (!CaseEnumType->getDecl()->getIdentifier() &&
835 !CaseEnumType->getDecl()->getTypedefNameForAnonDecl())
841 S.
Diag(Case->
getExprLoc(), diag::warn_comparison_of_mixed_enum_types_switch)
850 bool CaseListIsIncomplete = getCurFunction()->SwitchStack.back().getInt();
851 assert(SS == getCurFunction()->SwitchStack.back().getPointer() &&
852 "switch stack missing push/pop!");
854 getCurFunction()->SwitchStack.pop_back();
857 SS->
setBody(BodyStmt, SwitchLoc);
871 const Expr *CondExprBeforePromotion = CondExpr;
877 bool HasDependentValue
879 unsigned CondWidth = HasDependentValue ? 0 : Context.
getIntWidth(CondType);
886 unsigned CondWidthBeforePromotion
887 = HasDependentValue ? 0 : Context.
getIntWidth(CondTypeBeforePromotion);
888 bool CondIsSignedBeforePromotion
898 typedef std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRangesTy;
899 CaseRangesTy CaseRanges;
903 bool CaseListIsErroneous =
false;
909 if (TheDefaultStmt) {
910 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
917 CaseListIsErroneous =
true;
926 if (Lo->isValueDependent()) {
927 HasDependentValue =
true;
933 const Expr *LoBeforePromotion = Lo;
939 checkCaseValue(*
this, Lo->getBeginLoc(), LoVal, CondWidthBeforePromotion,
940 CondIsSignedBeforePromotion);
952 HasDependentValue =
true;
955 CaseRanges.push_back(std::make_pair(LoVal, CS));
957 CaseVals.push_back(std::make_pair(LoVal, CS));
961 if (!HasDependentValue) {
965 bool HasConstantCond =
false;
966 if (!TheDefaultStmt) {
972 assert(!HasConstantCond ||
973 (ConstantCondValue.getBitWidth() == CondWidth &&
974 ConstantCondValue.isSigned() == CondIsSigned));
976 bool ShouldCheckConstantCond = HasConstantCond;
981 if (!CaseVals.empty()) {
982 for (
unsigned i = 0, e = CaseVals.size(); i != e; ++i) {
983 if (ShouldCheckConstantCond &&
984 CaseVals[i].first == ConstantCondValue)
985 ShouldCheckConstantCond =
false;
987 if (i != 0 && CaseVals[i].first == CaseVals[i-1].first) {
990 StringRef PrevString, CurrString;
993 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(PrevCase)) {
994 PrevString = DeclRef->getDecl()->getName();
996 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(CurrCase)) {
997 CurrString = DeclRef->getDecl()->getName();
1000 CaseVals[i-1].first.toString(CaseValStr);
1002 if (PrevString == CurrString)
1003 Diag(CaseVals[i].second->getLHS()->getBeginLoc(),
1004 diag::err_duplicate_case)
1005 << (PrevString.empty() ? StringRef(CaseValStr) : PrevString);
1007 Diag(CaseVals[i].second->getLHS()->getBeginLoc(),
1008 diag::err_duplicate_case_differing_expr)
1009 << (PrevString.empty() ? StringRef(CaseValStr) : PrevString)
1010 << (CurrString.empty() ? StringRef(CaseValStr) : CurrString)
1013 Diag(CaseVals[i - 1].second->getLHS()->getBeginLoc(),
1014 diag::note_duplicate_case_prev);
1017 CaseListIsErroneous =
true;
1024 if (!CaseRanges.empty()) {
1027 llvm::stable_sort(CaseRanges);
1030 std::vector<llvm::APSInt> HiVals;
1031 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1033 CaseStmt *CR = CaseRanges[i].second;
1036 const Expr *HiBeforePromotion = Hi;
1043 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
1049 if (LoVal > HiVal) {
1052 CaseRanges.erase(CaseRanges.begin()+i);
1058 if (ShouldCheckConstantCond &&
1059 LoVal <= ConstantCondValue &&
1060 ConstantCondValue <= HiVal)
1061 ShouldCheckConstantCond =
false;
1063 HiVals.push_back(HiVal);
1069 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1072 CaseStmt *CR = CaseRanges[i].second;
1081 CaseValsTy::iterator I =
1082 llvm::lower_bound(CaseVals, CRLo, CaseCompareFunctor());
1083 if (I != CaseVals.end() && I->first < CRHi) {
1084 OverlapVal = I->first;
1085 OverlapStmt = I->second;
1089 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
1090 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
1091 OverlapVal = (I-1)->first;
1092 OverlapStmt = (I-1)->second;
1097 if (i && CRLo <= HiVals[i-1]) {
1098 OverlapVal = HiVals[i-1];
1099 OverlapStmt = CaseRanges[i-1].second;
1105 << OverlapVal.toString(10);
1107 diag::note_duplicate_case_prev);
1110 CaseListIsErroneous =
true;
1116 if (!CaseListIsErroneous && !CaseListIsIncomplete &&
1117 ShouldCheckConstantCond) {
1120 Diag(CondExpr->
getExprLoc(), diag::warn_missing_case_for_condition)
1121 << ConstantCondValue.toString(10)
1133 if (!CaseListIsErroneous && !CaseListIsIncomplete && !HasConstantCond &&
1143 EnumVals.push_back(std::make_pair(Val, EDI));
1146 auto EI = EnumVals.begin(), EIEnd =
1147 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1150 for (CaseValsTy::const_iterator CI = CaseVals.begin();
1151 CI != CaseVals.end(); CI++) {
1152 Expr *CaseExpr = CI->second->getLHS();
1156 << CondTypeBeforePromotion;
1160 EI = EnumVals.begin();
1161 for (CaseRangesTy::const_iterator RI = CaseRanges.begin();
1162 RI != CaseRanges.end(); RI++) {
1163 Expr *CaseExpr = RI->second->getLHS();
1167 << CondTypeBeforePromotion;
1170 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1173 CaseExpr = RI->second->getRHS();
1177 << CondTypeBeforePromotion;
1181 auto CI = CaseVals.begin();
1182 auto RI = CaseRanges.begin();
1183 bool hasCasesNotInSwitch =
false;
1187 for (EI = EnumVals.begin(); EI != EIEnd; EI++) {
1189 switch (EI->second->getAvailability()) {
1202 if (EI->second->hasAttr<UnusedAttr>())
1206 while (CI != CaseVals.end() && CI->first < EI->first)
1209 if (CI != CaseVals.end() && CI->first == EI->first)
1213 for (; RI != CaseRanges.end(); RI++) {
1215 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1217 if (EI->first <= Hi)
1221 if (RI == CaseRanges.end() || EI->first < RI->first) {
1222 hasCasesNotInSwitch =
true;
1223 UnhandledNames.push_back(EI->second->getDeclName());
1227 if (TheDefaultStmt && UnhandledNames.empty() && ED->
isClosedNonFlag())
1231 if (!UnhandledNames.empty()) {
1233 TheDefaultStmt ? diag::warn_def_missing_case
1234 : diag::warn_missing_case)
1235 << (
int)UnhandledNames.size();
1237 for (
size_t I = 0, E =
std::min(UnhandledNames.size(), (
size_t)3);
1239 DB << UnhandledNames[I];
1242 if (!hasCasesNotInSwitch)
1248 DiagnoseEmptyStmtBody(CondExpr->
getEndLoc(), BodyStmt,
1249 diag::warn_empty_switch_body);
1253 if (CaseListIsErroneous)
1262 if (Diags.isIgnored(diag::warn_not_in_enum_assignment, SrcExpr->
getExprLoc()))
1276 const EnumDecl *ED = ET->getDecl();
1281 if (ED->
hasAttr<FlagEnumAttr>()) {
1282 if (!IsValueInFlagEnum(ED, RhsVal,
true))
1288 EnumValsTy EnumVals;
1295 EnumVals.push_back(std::make_pair(Val, EDI));
1297 if (EnumVals.empty())
1300 EnumValsTy::iterator EIend =
1301 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1304 EnumValsTy::const_iterator EI = EnumVals.begin();
1305 while (EI != EIend && EI->first < RhsVal)
1307 if (EI == EIend || EI->first != RhsVal) {
1321 auto CondVal = Cond.
get();
1322 CheckBreakContinueBinding(CondVal.second);
1324 if (CondVal.second &&
1325 !Diags.isIgnored(diag::warn_comma_operator, CondVal.second->getExprLoc()))
1326 CommaVisitor(*this).Visit(CondVal.second);
1328 if (isa<NullStmt>(Body))
1329 getCurCompoundScope().setHasEmptyLoopBodies();
1339 assert(Cond &&
"ActOnDoStmt(): missing expression");
1341 CheckBreakContinueBinding(Cond);
1342 ExprResult CondResult = CheckBooleanCondition(DoLoc, Cond);
1345 Cond = CondResult.
get();
1347 CondResult = ActOnFinishFullExpr(Cond, DoLoc,
false);
1350 Cond = CondResult.
get();
1353 if (Cond && !getLangOpts().
C99 && !getLangOpts().
CPlusPlus &&
1354 !Diags.isIgnored(diag::warn_comma_operator, Cond->
getExprLoc()))
1355 CommaVisitor(*this).Visit(Cond);
1357 return new (Context)
DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen);
1362 using DeclSetVector =
1363 llvm::SetVector<VarDecl *, llvm::SmallVector<VarDecl *, 8>,
1364 llvm::SmallPtrSet<VarDecl *, 8>>;
1370 DeclSetVector &Decls;
1376 DeclExtractor(
Sema &S, DeclSetVector &Decls,
1383 bool isSimple() {
return Simple; }
1391 void VisitStmt(
Stmt *S) {
1452 DeclSetVector &Decls;
1458 DeclMatcher(
Sema &S, DeclSetVector &Decls,
Stmt *Statement) :
1459 Inherited(S.
Context), Decls(Decls), FoundDecl(
false) {
1460 if (!Statement)
return;
1484 void CheckLValueToRValueCast(
Expr *E) {
1487 if (isa<DeclRefExpr>(E)) {
1492 Visit(CO->getCond());
1493 CheckLValueToRValueCast(CO->getTrueExpr());
1494 CheckLValueToRValueCast(CO->getFalseExpr());
1499 dyn_cast<BinaryConditionalOperator>(E)) {
1500 CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr());
1501 CheckLValueToRValueCast(BCO->getFalseExpr());
1510 if (Decls.count(VD))
1518 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(S))
1520 Visit(OVE->getSourceExpr());
1526 bool FoundDeclInUse() {
return FoundDecl; }
1530 void CheckForLoopConditionalStatement(
Sema &S,
Expr *Second,
1533 if (!Second)
return;
1540 DeclSetVector Decls;
1542 DeclExtractor DE(S, Decls, Ranges);
1546 if (!DE.isSimple())
return;
1549 if (Decls.size() == 0)
return;
1552 for (
auto *VD : Decls)
1553 if (VD->getType().isVolatileQualified() || VD->hasGlobalStorage())
1556 if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
1557 DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
1558 DeclMatcher(S, Decls, Body).FoundDeclInUse())
1562 if (Decls.size() > 4) {
1565 PDiag << (unsigned)Decls.size();
1566 for (
auto *VD : Decls)
1567 PDiag << VD->getDeclName();
1570 for (
auto Range : Ranges)
1573 S.
Diag(Ranges.begin()->getBegin(), PDiag);
1578 bool ProcessIterationStmt(
Sema &S,
Stmt* Statement,
bool &Increment,
1580 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(Statement))
1581 if (!Cleanups->cleanupsHaveSideEffects())
1582 Statement = Cleanups->getSubExpr();
1584 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(Statement)) {
1585 switch (UO->getOpcode()) {
1586 default:
return false;
1604 default:
return false;
1624 bool InSwitch =
false;
1627 BreakContinueFinder(
Sema &S,
const Stmt* Body) :
1638 void VisitBreakStmt(
const BreakStmt* E) {
1658 void VisitForStmt(
const ForStmt *S) {
1665 void VisitWhileStmt(
const WhileStmt *) {
1670 void VisitDoStmt(
const DoStmt *) {
1697 bool ContinueFound() {
return ContinueLoc.
isValid(); }
1698 bool BreakFound() {
return BreakLoc.
isValid(); }
1709 void CheckForRedundantIteration(
Sema &S,
Expr *Third,
Stmt *Body) {
1711 if (!Body || !Third)
return;
1721 if (!LastStmt)
return;
1723 bool LoopIncrement, LastIncrement;
1726 if (!ProcessIterationStmt(S, Third, LoopIncrement, LoopDRE))
return;
1727 if (!ProcessIterationStmt(S, LastStmt, LastIncrement, LastDRE))
return;
1731 if (LoopIncrement != LastIncrement ||
1734 if (BreakContinueFinder(S, Body).ContinueFound())
return;
1737 << LastDRE->
getDecl() << LastIncrement;
1745 void Sema::CheckBreakContinueBinding(
Expr *E) {
1748 BreakContinueFinder BCFinder(*
this, E);
1750 if (BCFinder.BreakFound() && BreakParent) {
1752 Diag(BCFinder.GetBreakLoc(), diag::warn_break_binds_to_switch);
1754 Diag(BCFinder.GetBreakLoc(), diag::warn_loop_ctrl_binds_to_inner)
1757 }
else if (BCFinder.ContinueFound() && CurScope->getContinueParent()) {
1758 Diag(BCFinder.GetContinueLoc(), diag::warn_loop_ctrl_binds_to_inner)
1770 if (!getLangOpts().CPlusPlus) {
1771 if (
DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
1775 for (
auto *DI : DS->decls()) {
1780 Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
1781 DI->setInvalidDecl();
1787 CheckBreakContinueBinding(Second.
get().second);
1788 CheckBreakContinueBinding(third.
get());
1790 if (!Second.
get().first)
1791 CheckForLoopConditionalStatement(*
this, Second.
get().second, third.
get(),
1793 CheckForRedundantIteration(*
this, third.
get(), Body);
1795 if (Second.
get().second &&
1796 !Diags.isIgnored(diag::warn_comma_operator,
1797 Second.
get().second->getExprLoc()))
1798 CommaVisitor(*this).Visit(Second.
get().second);
1801 if (isa<NullStmt>(Body))
1802 getCurCompoundScope().setHasEmptyLoopBodies();
1804 return new (Context)
1805 ForStmt(Context, First, Second.
get().second, Second.
get().first, Third,
1806 Body, ForLoc, LParenLoc, RParenLoc);
1831 ExprResult result = CorrectDelayedTyposInExpr(collection);
1834 collection = result.
get();
1840 result = DefaultFunctionArrayLvalueConversion(collection);
1843 collection = result.
get();
1850 return Diag(forLoc, diag::err_collection_expr_type)
1861 (getLangOpts().ObjCAutoRefCount
1862 ? RequireCompleteType(forLoc,
QualType(objectType, 0),
1863 diag::err_arc_collection_forward, collection)
1864 : !isCompleteType(forLoc,
QualType(objectType, 0)))) {
1867 }
else if (iface || !objectType->
qual_empty()) {
1869 &Context.
Idents.
get(
"countByEnumeratingWithState"),
1885 method = LookupMethodInQualifiedType(selector, pointerType,
1890 Diag(forLoc, diag::warn_collection_expr_type)
1905 setFunctionHasBranchProtectedScope();
1908 CheckObjCForCollectionOperand(ForLoc, collection);
1912 if (
DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
1913 if (!DS->isSingleDecl())
1915 diag::err_toomany_element_decls));
1927 diag::err_non_local_variable_decl_in_for));
1933 Expr *DeducedInit = &OpaqueId;
1936 DiagnoseAutoDeductionFailure(D, DeducedInit);
1937 if (FirstType.
isNull()) {
1944 if (!inTemplateInstantiation()) {
1947 Diag(Loc, diag::warn_auto_var_is_id)
1953 Expr *FirstE = cast<Expr>(First);
1959 FirstType =
static_cast<Expr*
>(First)->getType();
1961 Diag(ForLoc, diag::err_selector_element_const_type)
1967 return StmtError(
Diag(ForLoc, diag::err_selector_element_type)
1974 CollectionExprResult =
1975 ActOnFinishFullExpr(CollectionExprResult.
get(),
false);
1980 nullptr, ForLoc, RParenLoc);
2034 void NoteForRangeBeginEndFunction(
Sema &SemaRef,
Expr *E,
2044 std::string Description;
2045 bool IsTemplate =
false;
2052 SemaRef.
Diag(Loc, diag::note_for_range_begin_end)
2053 << BEF << IsTemplate << Description << E->
getType();
2104 return Diag(InitStmt->
getBeginLoc(), diag::err_objc_for_range_init_stmt)
2106 return ActOnObjCForCollectionStmt(ForLoc, First, Range, RParenLoc);
2110 assert(DS &&
"first part of for range not a decl stmt");
2119 DiagnoseUnexpandedParameterPack(Range, UPPC_Expression)) {
2127 if (!ActOnCoroutineBodyStart(S, CoawaitLoc,
"co_await"))
2133 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2135 VarDecl *RangeVar = BuildForRangeVarDecl(*
this, RangeLoc,
2137 std::string(
"__range") + DepthStr);
2139 diag::err_for_range_deduction_failure)) {
2147 StmtResult RangeDecl = ActOnDeclStmt(RangeGroup, RangeLoc, RangeLoc);
2153 return BuildCXXForRangeStmt(
2154 ForLoc, CoawaitLoc, InitStmt, ColonLoc, RangeDecl.
get(),
2156 nullptr,
nullptr, DS, RParenLoc,
Kind);
2183 auto BuildBegin = [&] {
2187 BeginMemberLookup, CandidateSet,
2188 BeginRange, BeginExpr);
2193 << ColonLoc << BEF_begin << BeginRange->
getType();
2206 diag::err_for_range_iter_deduction_failure)) {
2207 NoteForRangeBeginEndFunction(SemaRef, BeginExpr->
get(), *BEF);
2213 auto BuildEnd = [&] {
2217 EndMemberLookup, CandidateSet,
2222 << ColonLoc << BEF_end << EndRange->
getType();
2226 diag::err_for_range_iter_deduction_failure)) {
2227 NoteForRangeBeginEndFunction(SemaRef, EndExpr->
get(), *BEF);
2240 if (BeginMemberLookup.isAmbiguous())
2247 if (BeginMemberLookup.empty() != EndMemberLookup.
empty()) {
2252 auto BuildNonmember = [&](
2254 llvm::function_ref<Sema::ForRangeStatus()> BuildFound,
2255 llvm::function_ref<Sema::ForRangeStatus()> BuildNotFound) {
2262 switch (BuildFound()) {
2269 SemaRef.
PDiag(diag::err_for_range_invalid)
2270 << BeginRange->
getType() << BEFFound),
2276 SemaRef.
Diag(D->getLocation(),
2277 diag::note_for_range_member_begin_end_ignored)
2278 << BeginRange->
getType() << BEFFound;
2282 llvm_unreachable(
"unexpected ForRangeStatus");
2284 if (BeginMemberLookup.empty())
2285 return BuildNonmember(BEF_end, EndMemberLookup, BuildEnd, BuildBegin);
2286 return BuildNonmember(BEF_begin, BeginMemberLookup, BuildBegin, BuildEnd);
2318 AdjustedRange = SemaRef.
BuildUnaryOp(S, RangeLoc, UO_Deref, Range);
2323 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2332 SemaRef.
Diag(RangeLoc, diag::err_for_range_dereference)
2335 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2341 struct InvalidateOnErrorScope {
2342 InvalidateOnErrorScope(
Sema &SemaRef,
Decl *D,
bool Enabled)
2343 : Trap(SemaRef.
Diags), D(D), Enabled(Enabled) {}
2344 ~InvalidateOnErrorScope() {
2345 if (Enabled && Trap.hasErrorOccurred())
2372 Scope *S = getCurScope();
2374 DeclStmt *RangeDS = cast<DeclStmt>(RangeDecl);
2376 QualType RangeVarType = RangeVar->getType();
2378 DeclStmt *LoopVarDS = cast<DeclStmt>(LoopVarDecl);
2383 InvalidateOnErrorScope Invalidate(*
this, LoopVar,
2384 LoopVar->getType()->isUndeducedType());
2390 if (RangeVarType->isDependentType()) {
2392 RangeVar->markUsed(Context);
2396 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2397 if (
auto *DD = dyn_cast<DecompositionDecl>(LoopVar))
2398 for (
auto *Binding : DD->bindings())
2400 LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.
DependentTy));
2402 }
else if (!BeginDeclStmt.get()) {
2407 ExprResult BeginRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2412 ExprResult EndRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2418 Expr *Range = RangeVar->getInit();
2423 if (RequireCompleteType(RangeLoc, RangeType,
2424 diag::err_for_range_incomplete_type))
2429 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2430 VarDecl *BeginVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2431 std::string(
"__begin") + DepthStr);
2432 VarDecl *EndVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2433 std::string(
"__end") + DepthStr);
2444 BeginExpr = BeginRangeRef;
2446 BeginExpr = ActOnCoawaitExpr(S, ColonLoc, BeginExpr.
get());
2451 diag::err_for_range_iter_deduction_failure)) {
2452 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2462 dyn_cast<VariableArrayType>(UnqAT)) {
2485 ExprResult SizeOfVLAExprR = ActOnUnaryExprOrTypeTraitExpr(
2489 VAT->desugar(), RangeLoc))
2495 ExprResult SizeOfEachElementExprR = ActOnUnaryExprOrTypeTraitExpr(
2498 CreateParsedType(VAT->desugar(),
2500 VAT->getElementType(), RangeLoc))
2508 SizeOfVLAExprR.
get(), SizeOfEachElementExprR.
get());
2515 llvm_unreachable(
"Unexpected array type in for-range");
2519 EndExpr = ActOnBinOp(S, ColonLoc, tok::plus, EndRangeRef.
get(),
2524 diag::err_for_range_iter_deduction_failure)) {
2525 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2533 *
this, BeginRangeRef.
get(), EndRangeRef.
get(), RangeType, BeginVar,
2534 EndVar,
ColonLoc, CoawaitLoc, &CandidateSet, &BeginExpr, &EndExpr,
2537 if (Kind == BFRK_Build && RangeStatus == FRS_NoViableFunction &&
2538 BEFFailure == BEF_begin) {
2541 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Range)) {
2542 if (
ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
2543 QualType ArrayTy = PVD->getOriginalType();
2544 QualType PointerTy = PVD->getType();
2547 << RangeLoc << PVD << ArrayTy << PointerTy;
2548 Diag(PVD->getLocation(), diag::note_declared_at);
2557 CoawaitLoc, InitStmt,
2558 LoopVarDecl, ColonLoc,
2566 if (RangeStatus == FRS_NoViableFunction) {
2567 Expr *Range = BEFFailure ? EndRangeRef.
get() : BeginRangeRef.
get();
2568 CandidateSet.NoteCandidates(
2570 PDiag(diag::err_for_range_invalid)
2571 << RangeLoc << Range->
getType()
2576 if (RangeStatus != FRS_Success)
2581 "invalid range expression in for loop");
2585 QualType BeginType = BeginVar->getType(), EndType = EndVar->
getType();
2588 ? diag::warn_for_range_begin_end_types_differ
2589 : diag::ext_for_range_begin_end_types_differ)
2590 << BeginType << EndType;
2591 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2592 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2596 ActOnDeclStmt(ConvertDeclToDeclGroup(BeginVar), ColonLoc, ColonLoc);
2598 ActOnDeclStmt(ConvertDeclToDeclGroup(EndVar), ColonLoc, ColonLoc);
2601 ExprResult BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2606 ExprResult EndRef = BuildDeclRefExpr(EndVar, EndType.getNonReferenceType(),
2612 NotEqExpr = ActOnBinOp(S, ColonLoc, tok::exclaimequal,
2613 BeginRef.
get(), EndRef.
get());
2615 NotEqExpr = CheckBooleanCondition(ColonLoc, NotEqExpr.
get());
2618 ActOnFinishFullExpr(NotEqExpr.
get(),
false);
2620 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2621 << RangeLoc << 0 << BeginRangeRef.
get()->getType();
2622 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2624 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2629 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2634 IncrExpr = ActOnUnaryOp(S, ColonLoc, tok::plusplus, BeginRef.
get());
2635 if (!IncrExpr.isInvalid() && CoawaitLoc.
isValid())
2639 IncrExpr = ActOnCoawaitExpr(S, CoawaitLoc, IncrExpr.get());
2640 if (!IncrExpr.isInvalid())
2641 IncrExpr = ActOnFinishFullExpr(IncrExpr.get(),
false);
2642 if (IncrExpr.isInvalid()) {
2643 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2644 << RangeLoc << 2 << BeginRangeRef.
get()->getType() ;
2645 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2650 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2655 ExprResult DerefExpr = ActOnUnaryOp(S, ColonLoc, tok::star, BeginRef.
get());
2657 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2658 << RangeLoc << 1 << BeginRangeRef.
get()->getType();
2659 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2665 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2666 AddInitializerToDecl(LoopVar, DerefExpr.
get(),
false);
2667 if (LoopVar->isInvalidDecl())
2668 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2674 if (Kind == BFRK_Check)
2679 if (getLangOpts().OpenMP >= 50 && BeginDeclStmt.isUsable())
2680 ActOnOpenMPLoopInitialization(ForLoc, BeginDeclStmt.get());
2683 InitStmt, RangeDS, cast_or_null<DeclStmt>(BeginDeclStmt.get()),
2684 cast_or_null<DeclStmt>(EndDeclStmt.
get()), NotEqExpr.
get(),
2685 IncrExpr.get(), LoopVarDS,
nullptr, ForLoc, CoawaitLoc,
2716 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(InitExpr))
2717 if (!Cleanups->cleanupsHaveSideEffects())
2718 InitExpr = Cleanups->getSubExpr();
2731 while (!isa<CXXOperatorCallExpr>(E) && !isa<UnaryOperator>(E)) {
2735 const MemberExpr *ME = cast<MemberExpr>(Call->getCallee());
2744 bool ReturnsReference =
false;
2745 if (isa<UnaryOperator>(E)) {
2746 ReturnsReference =
true;
2750 QualType ReturnType = FD->getReturnType();
2754 if (ReturnsReference) {
2758 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_const_reference_copy)
2759 << VD << VariableType << E->
getType();
2772 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_variable_always_copy)
2773 << VD << RangeInitType;
2786 return RD->hasAttr<TrivialABIAttr>();
2803 if (!CE->getConstructor()->isCopyConstructor())
2805 }
else if (
const CastExpr *CE = dyn_cast<CastExpr>(InitExpr)) {
2806 if (CE->getCastKind() != CK_LValueToRValue)
2824 << VD << VariableType << InitExpr->
getType();
2844 if (SemaRef.
Diags.
isIgnored(diag::warn_for_range_const_reference_copy,
2846 SemaRef.
Diags.
isIgnored(diag::warn_for_range_variable_always_copy,
2885 if (isa<ObjCForCollectionStmt>(S))
2886 return FinishObjCForCollectionStmt(S, B);
2892 diag::warn_empty_range_based_for_body);
2902 setFunctionHasBranchIntoScope();
2904 return new (Context)
GotoStmt(TheDecl, GotoLoc, LabelLoc);
2916 CheckSingleAssignmentConstraints(DestTy, ExprRes);
2920 if (DiagnoseAssignmentResult(ConvTy, StarLoc, DestTy, ETy, E, AA_Passing))
2924 ExprResult ExprRes = ActOnFinishFullExpr(E,
false);
2929 setFunctionHasIndirectGoto();
2935 const Scope &DestScope) {
2938 S.
Diag(Loc, diag::warn_jump_out_of_seh_finally);
2947 return StmtError(
Diag(ContinueLoc, diag::err_continue_not_in_loop));
2959 return StmtError(
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
2962 return StmtError(
Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt)
2966 return new (Context)
BreakStmt(BreakLoc);
2999 if (isCopyElisionCandidate(ReturnType, VD, CESK))
3014 if (!(CESK & CES_AllowDifferentTypes) && !VDType->
isDependentType() &&
3020 if (VD->
getKind() != Decl::Var &&
3021 !((CESK & CES_AllowParameters) && VD->
getKind() == Decl::ParmVar))
3032 if (VD->
hasAttr<BlocksAttr>())
return false;
3034 if (CESK & CES_AllowDifferentTypes)
3070 bool ConvertingConstructorsOnly,
3075 Expr *InitExpr = &AsRvalue;
3078 Value->getBeginLoc(), Value->getBeginLoc());
3091 if (ConvertingConstructorsOnly) {
3092 if (isa<CXXConstructorDecl>(FD)) {
3110 if (isa<CXXConstructorDecl>(FD)) {
3116 }
else if (isa<CXXMethodDecl>(FD)) {
3119 if (cast<CXXMethodDecl>(FD)->getRefQualifier() !=
RQ_RValue)
3133 Res = Seq.Perform(S, Entity, Kind, Value);
3161 bool AffectedByCWG1579 =
false;
3163 if (!NRVOCandidate) {
3164 NRVOCandidate = getCopyElisionCandidate(ResultType, Value, CES_Default);
3165 if (NRVOCandidate &&
3166 !getDiagnostics().isIgnored(diag::warn_return_std_move_in_cxx11,
3168 const VarDecl *NRVOCandidateInCXX11 =
3169 getCopyElisionCandidate(ResultType, Value, CES_FormerDefault);
3170 AffectedByCWG1579 = (!NRVOCandidateInCXX11);
3174 if (NRVOCandidate) {
3179 if (!Res.
isInvalid() && AffectedByCWG1579) {
3191 assert(!ResultType.
isNull());
3193 Str +=
"std::move(";
3198 << NRVOCandidate->
getDeclName() << ResultType << QT;
3203 !getDiagnostics().isIgnored(diag::warn_return_std_move,
3205 const VarDecl *FakeNRVOCandidate =
3206 getCopyElisionCandidate(
QualType(), Value, CES_AsIfByStdMove);
3207 if (FakeNRVOCandidate) {
3221 FakeValue,
false, FakeRes);
3226 Str +=
"std::move(";
3267 bool HasDeducedReturnType =
3270 if (ExprEvalContexts.back().Context ==
3271 ExpressionEvaluationContext::DiscardedStatement &&
3275 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3278 RetValExp = ER.
get();
3284 if (HasDeducedReturnType) {
3292 assert(AT &&
"lost auto type from lambda return type");
3293 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3303 if (RetValExp && !isa<InitListExpr>(RetValExp)) {
3304 ExprResult Result = DefaultFunctionArrayLvalueConversion(RetValExp);
3307 RetValExp = Result.
get();
3313 if (!CurContext->isDependentContext())
3322 Diag(ReturnLoc, diag::err_lambda_return_init_list)
3326 FnRetType = Context.
VoidTy;
3334 assert(!FnRetType.isNull());
3336 if (
auto *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
3338 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr);
3341 }
else if (
auto *CurRegion = dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
3342 Diag(ReturnLoc, diag::err_return_in_captured_stmt) << CurRegion->getRegionName();
3345 assert(CurLambda &&
"unknown kind of captured scope");
3348 ->getNoReturnAttr()) {
3349 Diag(ReturnLoc, diag::err_noreturn_lambda_has_return_expr);
3357 const VarDecl *NRVOCandidate =
nullptr;
3358 if (FnRetType->isDependentType()) {
3361 }
else if (FnRetType->isVoidType()) {
3362 if (RetValExp && !isa<InitListExpr>(RetValExp) &&
3363 !(getLangOpts().CPlusPlus &&
3366 if (!getLangOpts().CPlusPlus &&
3368 Diag(ReturnLoc, diag::ext_return_has_void_expr) <<
"literal" << 2;
3370 Diag(ReturnLoc, diag::err_return_block_has_expr);
3371 RetValExp =
nullptr;
3374 }
else if (!RetValExp) {
3375 return StmtError(
Diag(ReturnLoc, diag::err_block_return_missing_expr));
3385 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3388 NRVOCandidate !=
nullptr);
3389 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3390 FnRetType, RetValExp);
3395 RetValExp = Res.
get();
3396 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc);
3398 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3403 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3406 RetValExp = ER.
get();
3415 FunctionScopes.back()->Returns.push_back(Result);
3417 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3418 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3436 class LocalTypedefNameReferencer
3439 LocalTypedefNameReferencer(
Sema &S) : S(S) {}
3444 bool LocalTypedefNameReferencer::VisitRecordType(
const RecordType *RT) {
3446 if (!R || !R->isLocalClass() || !R->isLocalClass()->isExternallyVisible() ||
3447 R->isDependentType())
3449 for (
auto *TmpD : R->decls())
3450 if (
auto *T = dyn_cast<TypedefNameDecl>(TmpD))
3451 if (T->getAccess() !=
AS_private || R->hasFriends())
3476 TypeLoc OrigResultType = getReturnTypeLoc(FD);
3479 if (RetExpr && isa<InitListExpr>(RetExpr)) {
3483 getCurLambda() ? diag::err_lambda_return_init_list
3484 : diag::err_auto_fn_return_init_list)
3494 assert(AT->
isDeduced() &&
"should have deduced to dependent type");
3507 if (DAR != DAR_Succeeded)
3512 LocalTypedefNameReferencer Referencer(*
this);
3513 Referencer.TraverseType(RetExpr->
getType());
3521 Diag(ReturnLoc, diag::err_auto_fn_return_void_but_not_auto)
3526 Deduced = SubstAutoType(OrigResultType.
getType(), Context.
VoidTy);
3532 if (getLangOpts().CUDA)
3558 Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible)
3562 Diag(ReturnLoc, diag::err_auto_fn_different_deductions)
3581 ExprResult RetVal = CorrectDelayedTyposInExpr(RetValExp);
3585 if (R.
isInvalid() || ExprEvalContexts.back().Context ==
3586 ExpressionEvaluationContext::DiscardedStatement)
3590 const_cast<VarDecl*>(cast<ReturnStmt>(R.
get())->getNRVOCandidate())) {
3603 if (RetValExp && DiagnoseUnexpandedParameterPack(RetValExp))
3606 if (isa<CapturingScopeInfo>(getCurFunction()))
3607 return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp);
3611 const AttrVec *Attrs =
nullptr;
3612 bool isObjCMethod =
false;
3615 FnRetType = FD->getReturnType();
3617 Attrs = &FD->getAttrs();
3618 if (FD->isNoReturn())
3619 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
3620 << FD->getDeclName();
3621 if (FD->isMain() && RetValExp)
3622 if (isa<CXXBoolLiteralExpr>(RetValExp))
3623 Diag(ReturnLoc, diag::warn_main_returns_bool_literal)
3626 FnRetType = MD->getReturnType();
3627 isObjCMethod =
true;
3629 Attrs = &MD->getAttrs();
3630 if (MD->hasRelatedResultType() && MD->getClassInterface()) {
3642 if (ExprEvalContexts.back().Context ==
3643 ExpressionEvaluationContext::DiscardedStatement &&
3647 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3650 RetValExp = ER.
get();
3661 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3675 if (isa<InitListExpr>(RetValExp)) {
3679 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3680 int FunctionKind = 0;
3681 if (isa<ObjCMethodDecl>(CurDecl))
3683 else if (isa<CXXConstructorDecl>(CurDecl))
3685 else if (isa<CXXDestructorDecl>(CurDecl))
3688 Diag(ReturnLoc, diag::err_return_init_list)
3693 RetValExp =
nullptr;
3696 unsigned D = diag::ext_return_has_expr;
3698 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3699 if (isa<CXXConstructorDecl>(CurDecl) ||
3700 isa<CXXDestructorDecl>(CurDecl))
3701 D = diag::err_ctor_dtor_returns_void;
3703 D = diag::ext_return_has_void_expr;
3707 Result = IgnoredValueConversions(Result.
get());
3710 RetValExp = Result.
get();
3711 RetValExp = ImpCastExprToType(RetValExp,
3712 Context.
VoidTy, CK_ToVoid).get();
3715 if (D == diag::err_ctor_dtor_returns_void) {
3716 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3718 << CurDecl->
getDeclName() << isa<CXXDestructorDecl>(CurDecl)
3722 else if (D != diag::ext_return_has_void_expr ||
3724 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3726 int FunctionKind = 0;
3727 if (isa<ObjCMethodDecl>(CurDecl))
3729 else if (isa<CXXConstructorDecl>(CurDecl))
3731 else if (isa<CXXDestructorDecl>(CurDecl))
3742 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3745 RetValExp = ER.
get();
3751 }
else if (!RetValExp && !HasDependentReturnType) {
3757 DiagID = diag::err_constexpr_return_missing_expr;
3759 }
else if (getLangOpts().
C99) {
3761 DiagID = diag::ext_return_missing_expr;
3764 DiagID = diag::warn_return_missing_expr;
3768 Diag(ReturnLoc, DiagID)
3771 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1;
3776 assert(RetValExp || HasDependentReturnType);
3777 const VarDecl *NRVOCandidate =
nullptr;
3779 QualType RetType = RelatedRetType.
isNull() ? FnRetType : RelatedRetType;
3788 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3793 NRVOCandidate !=
nullptr);
3794 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3795 RetType, RetValExp);
3806 if (!RelatedRetType.
isNull()) {
3809 Res = PerformCopyInitialization(Entity, ReturnLoc, RetValExp);
3817 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc, isObjCMethod, Attrs,
3818 getCurFunctionDecl());
3823 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3826 RetValExp = ER.
get();
3834 FunctionScopes.back()->Returns.push_back(Result);
3836 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3837 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3846 VarDecl *Var = cast_or_null<VarDecl>(Parm);
3861 if (!getLangOpts().ObjCExceptions)
3862 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@try";
3864 setFunctionHasBranchProtectedScope();
3865 unsigned NumCatchStmts = CatchStmts.size();
3867 NumCatchStmts, Finally);
3872 ExprResult Result = DefaultLvalueConversion(Throw);
3876 Result = ActOnFinishFullExpr(Result.
get(),
false);
3879 Throw = Result.
get();
3887 return StmtError(
Diag(AtLoc, diag::err_objc_throw_expects_object)
3898 if (!getLangOpts().ObjCExceptions)
3899 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@throw";
3904 Scope *AtCatchParent = CurScope;
3906 AtCatchParent = AtCatchParent->
getParent();
3908 return StmtError(
Diag(AtLoc, diag::err_rethrow_used_outside_catch));
3910 return BuildObjCAtThrowStmt(AtLoc, Throw);
3915 ExprResult result = DefaultLvalueConversion(operand);
3918 operand = result.
get();
3926 if (getLangOpts().CPlusPlus) {
3927 if (RequireCompleteType(atLoc, type,
3928 diag::err_incomplete_receiver_type))
3929 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3932 ExprResult result = PerformContextuallyConvertToObjCPointer(operand);
3936 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3939 operand = result.
get();
3941 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3948 return ActOnFinishFullExpr(operand,
false);
3955 setFunctionHasBranchProtectedScope();
3963 Stmt *HandlerBlock) {
3965 return new (Context)
3966 CXXCatchStmt(CatchLoc, cast_or_null<VarDecl>(ExDecl), HandlerBlock);
3971 setFunctionHasBranchProtectedScope();
3976 class CatchHandlerType {
3978 unsigned IsPointer : 1;
3983 enum Unique { ForDenseMap };
3984 CatchHandlerType(
QualType QT, Unique) : QT(QT), IsPointer(
false) {}
3990 CatchHandlerType(
QualType Q) : QT(Q), IsPointer(
false) {
4002 CatchHandlerType(
QualType QT,
bool IsPointer)
4003 : QT(QT), IsPointer(IsPointer) {}
4005 QualType underlying()
const {
return QT; }
4006 bool isPointer()
const {
return IsPointer; }
4008 friend bool operator==(
const CatchHandlerType &LHS,
4009 const CatchHandlerType &RHS) {
4011 if (LHS.IsPointer != RHS.IsPointer)
4014 return LHS.QT == RHS.QT;
4023 CatchHandlerType::ForDenseMap);
4028 CatchHandlerType::ForDenseMap);
4036 const CatchHandlerType &RHS) {
4043 class CatchTypePublicBases {
4045 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &TypesToCheck;
4046 const bool CheckAgainstPointer;
4052 CatchTypePublicBases(
4054 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &T,
bool C)
4055 : Ctx(Ctx), TypesToCheck(T), CheckAgainstPointer(C),
4056 FoundHandler(
nullptr) {}
4058 CXXCatchStmt *getFoundHandler()
const {
return FoundHandler; }
4059 CanQualType getFoundHandlerType()
const {
return FoundHandlerType; }
4063 CatchHandlerType Check(S->
getType(), CheckAgainstPointer);
4064 const auto &M = TypesToCheck;
4065 auto I = M.find(Check);
4067 FoundHandler = I->second;
4082 if (!getLangOpts().CXXExceptions &&
4083 !getSourceManager().isInSystemHeader(TryLoc) && !getLangOpts().
CUDA) {
4085 targetDiag(TryLoc, diag::err_exceptions_disabled) <<
"try";
4089 if (getLangOpts().
CUDA)
4090 CUDADiagIfDeviceCode(TryLoc, diag::err_cuda_device_exceptions)
4091 <<
"try" << CurrentCUDATarget();
4093 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
4094 Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) <<
"try";
4100 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4104 const unsigned NumHandlers = Handlers.size();
4105 assert(!Handlers.empty() &&
4106 "The parser shouldn't call this if there are no handlers.");
4108 llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> HandledTypes;
4109 for (
unsigned i = 0; i < NumHandlers; ++i) {
4116 if (i < NumHandlers - 1)
4125 CatchHandlerType HandlerCHT =
4131 QualType Underlying = HandlerCHT.underlying();
4133 if (!RD->hasDefinition())
4142 CatchTypePublicBases CTPB(Context, HandledTypes, HandlerCHT.isPointer());
4143 if (RD->lookupInBases(CTPB, Paths)) {
4145 if (!Paths.
isAmbiguous(CTPB.getFoundHandlerType())) {
4147 diag::warn_exception_caught_by_earlier_handler)
4150 diag::note_previous_exception_handler)
4158 auto R = HandledTypes.insert(std::make_pair(H->
getCaughtType(), H));
4162 diag::warn_exception_caught_by_earlier_handler)
4165 diag::note_previous_exception_handler)
4177 assert(TryBlock && Handler);
4183 if (!getLangOpts().Borland) {
4185 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4201 Diag(TryLoc, diag::err_seh_try_outside_functions);
4205 Diag(TryLoc, diag::err_seh_try_unsupported);
4212 assert(FilterExpr && Block);
4216 Diag(FilterExpr->
getExprLoc(), diag::err_filter_expression_integral)
4223 CurrentSEHFinally.push_back(CurScope);
4227 CurrentSEHFinally.pop_back();
4232 CurrentSEHFinally.pop_back();
4238 Scope *SEHTryParent = CurScope;
4240 SEHTryParent = SEHTryParent->
getParent();
4242 return StmtError(
Diag(Loc, diag::err_ms___leave_not_in___try));
4255 QualifierLoc, NameInfo,
4256 cast<CompoundStmt>(Nested));
4265 return BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
4267 GetNameFromUnqualifiedId(Name),
4273 unsigned NumParams) {
4290 assert(NumParams > 0 &&
"CapturedStmt requires context parameter");
4333 CaptureInits.push_back(Init.
get());
4340 unsigned NumParams) {
4342 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, NumParams);
4356 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4359 PushDeclContext(CurScope, CD);
4363 PushExpressionEvaluationContext(
4364 ExpressionEvaluationContext::PotentiallyEvaluated);
4370 unsigned OpenMPCaptureLevel) {
4372 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, Params.size());
4376 bool ContextIsFound =
false;
4377 unsigned ParamNum = 0;
4380 I != E; ++I, ++ParamNum) {
4381 if (I->second.isNull()) {
4382 assert(!ContextIsFound &&
4383 "null type has been found already for '__context' parameter");
4393 ContextIsFound =
true;
4403 assert(ContextIsFound &&
"no null type for '__context' parameter");
4404 if (!ContextIsFound) {
4415 PushCapturedRegionScope(CurScope, CD, RD, Kind, OpenMPCaptureLevel);
4418 PushDeclContext(CurScope, CD);
4422 PushExpressionEvaluationContext(
4423 ExpressionEvaluationContext::PotentiallyEvaluated);
4427 DiscardCleanupsInEvaluationContext();
4428 PopExpressionEvaluationContext();
4437 ActOnFields(
nullptr, Record->getLocation(), Record, Fields,
4444 DiscardCleanupsInEvaluationContext();
4445 PopExpressionEvaluationContext();
4459 getASTContext(), S, static_cast<CapturedRegionKind>(RSI->
CapRegionKind),
4460 Captures, CaptureInits, CD, RD);
A call to an overloaded operator written using operator syntax.
Defines the clang::ASTContext interface.
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it's either not been deduced or was deduce...
QualType withConst() const
Retrieves a version of this type with const applied.
void setImplicit(bool I=true)
Represents a function declaration or definition.
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.
bool Cast(InterpState &S, CodePtr OpPC)
void setOrigin(CXXRecordDecl *Rec)
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Smart pointer class that efficiently represents Objective-C method names.
QualType getObjCIdType() const
Represents the Objective-CC id type.
PointerType - C99 6.7.5.1 - Pointer Declarators.
EvaluatedExprVisitor - This class visits 'Expr *'s.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isBlockPointerType() const
static void TryMoveInitialization(Sema &S, const InitializedEntity &Entity, const VarDecl *NRVOCandidate, QualType ResultType, Expr *&Value, bool ConvertingConstructorsOnly, ExprResult &Res)
Try to perform the initialization of a potentially-movable value, which is the operand to a return or...
bool isLambdaConversionOperator(CXXConversionDecl *C)
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
Instantiation or recovery rebuild of a for-range statement.
SourceLocation getExprLoc() const
static void AdjustAPSInt(llvm::APSInt &Val, unsigned BitWidth, bool IsSigned)
void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, CapturedRegionKind Kind, unsigned NumParams)
StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, Stmt *HandlerBlock)
ActOnCXXCatchBlock - Takes an exception declaration and a handler block and creates a proper catch ha...
bool operator==(CanQual< T > x, CanQual< U > y)
static unsigned getHashValue(const CatchHandlerType &Base)
static bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A, SourceLocation Loc, SourceRange R1, SourceRange R2, bool IsCtor)
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
Stmt - This represents one statement.
static StmtResult RebuildForRangeWithDereference(Sema &SemaRef, Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, Stmt *LoopVarDecl, SourceLocation ColonLoc, Expr *Range, SourceLocation RangeLoc, SourceLocation RParenLoc)
Speculatively attempt to dereference an invalid range expression.
VarDecl * getCopyElisionCandidate(QualType ReturnType, Expr *E, CopyElisionSemanticsKind CESK)
Determine whether the given expression is a candidate for copy elision in either a return statement o...
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt *> Elts, bool isStmtExpr)
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
void setParam(unsigned i, ImplicitParamDecl *P)
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isRecordType() const
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, Stmt *InitStmt, ConditionResult Cond)
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...
bool isDecltypeAuto() const
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
AssignConvertType
AssignConvertType - All of the 'assignment' semantic checks return this enum to indicate whether the ...
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Represents an attribute applied to a statement.
ParenExpr - This represents a parethesized expression, e.g.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
The base class of the type hierarchy.
Represents Objective-C's @throw statement.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a call to a C++ constructor.
SourceLocation getBeginLoc() const LLVM_READONLY
StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, Stmt *Body)
virtual void completeDefinition()
Note that the definition of this type is now complete.
QualType withConst() const
const TargetInfo & getTargetInfo() const
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
A container of type source information.
Wrapper for void* pointer.
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr *> Attrs, Stmt *SubStmt)
StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope)
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by...
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
Represents a C++ constructor within a class.
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Determining whether a for-range statement could be built.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
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)
This file provides some common utility functions for processing Lambda related AST Constructs...
enumerator_range enumerators() const
Represents a variable declaration or definition.
ActionResult< Stmt * > StmtResult
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization. ...
StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, MultiStmtArg Catch, Stmt *Finally)
QualType getReturnType() const
DiagnosticsEngine & Diags
bool isEnumeralType() const
const AstTypeMatcher< PointerType > pointerType
Matches pointer types, but does not match Objective-C object pointer types.
const T * getAs() const
Member-template getAs<specific type>'.
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl)
static bool ObjCEnumerationCollection(Expr *Collection)
SourceLocation getStarLoc() const
RAII class that determines when any errors have occurred between the time the instance was created an...
ObjCMethodDecl - Represents an instance or class method declaration.
bool isInvalidDecl() const
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.
EntityKind getKind() const
Determine the kind of initialization.
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement. ...
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input)
llvm::PointerIntPair< SwitchStmt *, 1, bool > SwitchInfo
A SwitchStmt, along with a flag indicating if its list of case statements is incomplete (because we d...
Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
static void checkCaseValue(Sema &S, SourceLocation Loc, const llvm::APSInt &Val, unsigned UnpromotedWidth, bool UnpromotedSign)
Check the specified case value is in range for the given unpromoted switch type.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Base wrapper for a particular "section" of type source info.
LabelStmt - Represents a label, which has a substatement.
Represents a struct/union/class.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
One of these records is kept for each identifier that is lexed.
bool isAtCatchScope() const
isAtCatchScope - Return true if this scope is @catch.
Expr * getFalseExpr() const
void DiagnoseUnusedExprResult(const Stmt *S)
DiagnoseUnusedExprResult - If the statement passed in is an expression whose result is unused...
StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue=true)
Represents a class type in Objective C.
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
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.
QualType getCaughtType() const
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
static bool hasTrivialABIAttr(QualType VariableType)
Determines whether the VariableType's declaration is a record with the clang::trivial_abi attribute...
FullExpr - Represents a "full-expression" node.
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a member of a struct/union/class.
StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, SourceLocation RParenLoc, BuildForRangeKind Kind)
ActOnCXXForRangeStmt - Check and build a C++11 for-range statement.
void setLocStart(SourceLocation L)
ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, Expr *collection)
void startDefinition()
Starts the definition of this tag declaration.
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
bool isReferenceType() const
StmtResult BuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt, ConditionResult Cond, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
std::pair< VarDecl *, Expr * > get() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by...
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
void ActOnAbortSEHFinallyBlock()
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
void setARCPseudoStrong(bool PS)
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr *> Attrs, Stmt *SubStmt)
static bool buildCapturedStmtCaptureList(Sema &S, CapturedRegionScopeInfo *RSI, SmallVectorImpl< CapturedStmt::Capture > &Captures, SmallVectorImpl< Expr *> &CaptureInits)
Represents Objective-C's @catch statement.
StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
IndirectGotoStmt - This represents an indirect goto.
static Sema::ForRangeStatus BuildNonArrayForRange(Sema &SemaRef, Expr *BeginRange, Expr *EndRange, QualType RangeType, VarDecl *BeginVar, VarDecl *EndVar, SourceLocation ColonLoc, SourceLocation CoawaitLoc, OverloadCandidateSet *CandidateSet, ExprResult *BeginExpr, ExprResult *EndExpr, BeginEndFunction *BEF)
Create the initialization, compare, and increment steps for the range-based for loop expression...
DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result, Optional< unsigned > DependentDeductionDepth=None, bool IgnoreConstraints=false)
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD)
bool isThisCapture() const
Represents a C++ unqualified-id that has been parsed.
An rvalue reference type, per C++11 [dcl.ref].
static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From, QualType T, APValue &Value, Sema::CCEKind CCE, bool RequireInt)
CheckConvertedConstantExpression - Check that the expression From is a converted constant expression ...
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Represents the results of name lookup.
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
This is a scope that corresponds to a switch statement.
APValue Val
Val - This is the value the expression can be folded to.
void ActOnStartSEHFinallyBlock()
AccessSpecifier getAccessSpecifier() const
Returns the access specifier for this base specifier.
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
Parameter for captured context.
SourceLocation getRParenLoc() const
An x-value expression is a reference to an object with independent storage but which can be "moved"...
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
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...
RecordDecl * CreateCapturedStmtRecordDecl(CapturedDecl *&CD, SourceLocation Loc, unsigned NumParams)
A builtin binary operation expression such as "x + y" or "x <= y".
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt *> Stmts, SourceLocation LB, SourceLocation RB)
StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope)
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
bool isRValueReferenceType() const
SmallVector< std::pair< llvm::APSInt, EnumConstantDecl * >, 64 > EnumValsTy
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Scope - A scope is a transient data structure that is used while parsing the program.
static void checkEnumTypesInSwitchStmt(Sema &S, const Expr *Cond, const Expr *Case)
CaseStmt - Represent a case statement.
SourceLocation getContinueLoc() const
bool isMacroBodyExpansion(SourceLocation Loc) const
Tests whether the given source location represents the expansion of a macro body. ...
Represents a C++ nested-name-specifier or a global scope specifier.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, bool AllowMask) const
IsValueInFlagEnum - Determine if a value is allowed as part of a flag enum.
ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond)
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)
const LangOptions & getLangOpts() const
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'.
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
static CatchHandlerType getTombstoneKey()
StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block)
StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope)
Perform initialization via a constructor.
Perform a user-defined conversion, either via a conversion function or via a constructor.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, SourceLocation RangeLoc, const DeclarationNameInfo &NameInfo, LookupResult &MemberLookup, OverloadCandidateSet *CandidateSet, Expr *Range, ExprResult *CallExpr)
Build a call to 'begin' or 'end' for a C++11 for-range statement.
Represents the body of a CapturedStmt, and serves as its DeclContext.
Represents an ObjC class declaration.
ExprResult BuildCaptureInit(const sema::Capture &Capture, SourceLocation ImplicitCaptureLoc, bool IsOpenMPMapping=false)
Initialize the given capture with a suitable expression.
Member name lookup, which finds the names of class/struct/union members.
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
SourceLocation getTypeSpecStartLoc() const
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, Scope *CurScope)
void setStmt(LabelStmt *T)
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
bool isSEHTrySupported() const
Whether the target supports SEH __try.
Contains information about the compound statement currently being parsed.
SourceLocation FirstCXXTryLoc
First C++ 'try' statement in the current function.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
unsigned getFlags() const
getFlags - Return the flags for this scope.
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
ConditionalOperator - The ?: ternary operator.
Sema - This implements semantic analysis and AST building for C.
A little helper class used to produce diagnostics.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
CompoundStmt - This represents a group of statements like { stmt stmt }.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represents a prototype with parameter type info, e.g.
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
Describes the capture of either a variable, or 'this', or variable-length array type.
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
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)
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getLocation() const
void ActOnFinishOfCompoundStmt()
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
QualType getAutoRRefDeductType() const
C++11 deduction pattern for 'auto &&' type.
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.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Scope * getCurScope() const
Retrieve the parser's current scope.
bool isVariableCapture() const
SourceLocation getBeginLoc() const
Get the begin source location.
Allows QualTypes to be sorted and hence used in maps and sets.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
This represents one expression.
QualType getPointeeType() const
Allow any unmodeled side effect.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
SourceLocation getDefaultLoc() const
TypeLoc getReturnTypeLoc(FunctionDecl *FD) const
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
const T * castAs() const
Member-template castAs<specific type>.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
VarDecl * getExceptionDecl() const
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
std::string getAsString() const
Retrieve the human-readable string for this name.
static void DiagnoseForRangeConstVariableCopies(Sema &SemaRef, const VarDecl *VD)
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
void setContextParam(unsigned i, ImplicitParamDecl *P)
bool isSEHTryScope() const
Determine whether this scope is a SEH '__try' block.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
Defines the clang::Preprocessor interface.
ObjCLifetime getObjCLifetime() const
bool isFileContext() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
The entity being initialized is an exception object that is being thrown.
Represents Objective-C's @synchronized statement.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Defines the clang::TypeLoc interface and its subclasses.
static DeclContext * castToDeclContext(const CapturedDecl *D)
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
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.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
An expression that sends a message to the given Objective-C object or class.
SwitchCase * getSwitchCaseList()
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
void setLocation(SourceLocation L)
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL)
Create a while statement.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
void setHasCXXTry(SourceLocation TryLoc)
Represents a C++ conversion function within a class.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
const Expr * getSubExpr() const
unsigned short CapRegionKind
The kind of captured region.
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr.cast]), which uses the syntax (Type)expr.
llvm::iterator_range< semantics_iterator > semantics()
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level)
Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.) for FD based on DSA for the...
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1...
SourceLocation getEndLoc() const LLVM_READONLY
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)
DoStmt - This represents a 'do/while' stmt.
bool isConstQualified() const
Determine whether this type is const-qualified.
RecordDecl * getDecl() const
static CatchHandlerType getEmptyKey()
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond)
Create a switch statement.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
SelectorTable & Selectors
Assigning into this object requires the old value to be released and the new value to be retained...
This captures a statement into a function.
static bool EqEnumVals(const std::pair< llvm::APSInt, EnumConstantDecl *> &lhs, const std::pair< llvm::APSInt, EnumConstantDecl *> &rhs)
EqEnumVals - Comparison preficate for uniqing enumeration values.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
SourceLocation getBeginLoc() const LLVM_READONLY
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
VarDecl * getVariable() const
void setHasSEHTry(SourceLocation TryLoc)
bool isOpenMPLoopScope() const
Determine whether this scope is a loop having OpenMP loop directive attached.
DeduceAutoResult
Result type of DeduceAutoType.
Encodes a location in the source.
QualType getReturnType() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Expr * getSubExpr() const
void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, Expr *SrcExpr)
DiagnoseAssignmentEnum - Warn if assignment to enum is a constant integer not in the range of enum va...
CastKind getCastKind() const
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Scope *CurScope)
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
Represents the declaration of a struct/union/class/enum.
StmtResult ActOnForEachLValueExpr(Expr *E)
In an Objective C collection iteration statement: for (x in y) x can be an arbitrary l-value expressi...
Represents a call to a member function that may be written either with member call syntax (e...
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
IdentifierTable & getIdentifierTable()
Represents the declaration of a label.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
StmtResult ActOnCapturedRegionEnd(Stmt *S)
void setAllEnumCasesCovered()
Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a switch over an enum value then ...
bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, SourceLocation ReturnLoc, Expr *&RetExpr, AutoType *AT)
Deduce the return type for a function from a returned expression, per C++1y [dcl.spec.auto]p6.
static QualType GetTypeBeforeIntegralPromotion(const Expr *&E)
GetTypeBeforeIntegralPromotion - Returns the pre-promotion type of potentially integral-promoted expr...
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt *> Handlers)
ActOnCXXTryBlock - Takes a try compound-statement and a number of handlers and creates a try statemen...
const ParmVarDecl * getParamDecl(unsigned i) const
bool isVLATypeCapture() const
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
Describes the kind of initialization being performed, along with location information for tokens rela...
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
bool isObjCObjectPointerType() const
SmallVector< Capture, 4 > Captures
Captures - The captures.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
bool isMSAsmLabel() const
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Stmt * getCapturedStmt()
Retrieve the statement being captured.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
sema::CompoundScopeInfo & getCurCompoundScope() const
Requests that all candidates be shown.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond, Stmt *Body)
EnumDecl * getDecl() const
An rvalue ref-qualifier was provided (&&).
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
static void DiagnoseForRangeReferenceVariableCopies(Sema &SemaRef, const VarDecl *VD, QualType RangeInitType)
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
LabelStmt * getStmt() const
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
QualType withRestrict() const
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
NullStmt - This is the null statement ";": C99 6.8.3p3.
bool isKnownToHaveBooleanValue(bool Semantic=true) const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
Dataflow Directional Tag Classes.
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
bool isValid() const
Return true if this is a valid SourceLocation object.
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
A single step in the initialization sequence.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
EvalResult is a struct with detailed info about an evaluated expression.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
QualType getType() const
Get the type for which this source info wrapper provides information.
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
void ActOnCapturedRegionError()
void addNRVOCandidate(VarDecl *VD)
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
StmtResult ActOnExprStmtError()
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
const Expr * getInit() const
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
bool isSingleDecl() const
static void DiagnoseForRangeVariableCopies(Sema &SemaRef, const CXXForRangeStmt *ForStmt)
DiagnoseForRangeVariableCopies - Diagnose three cases and fixes for them.
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
const Decl * getSingleDecl() const
bool isAmbiguous(CanQualType BaseType)
Determine whether the path from the most-derived type to the given base type is ambiguous (i...
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
ConstEvaluatedExprVisitor - This class visits 'const Expr *'s.
unsigned short OpenMPLevel
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl. ...
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Represents a __leave statement.
Represents a pointer to an Objective C object.
SwitchStmt - This represents a 'switch' stmt.
StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, CXXScopeSpec &SS, UnqualifiedId &Name, Stmt *Nested)
unsigned getIntWidth(QualType T) const
RecordDecl * TheRecordDecl
The captured record type.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, BuildForRangeKind Kind)
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
Represents Objective-C's collection statement.
ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E)
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
bool isReferenceCapture() const
static bool ShouldDiagnoseSwitchCaseNotInEnum(const Sema &S, const EnumDecl *ED, const Expr *CaseExpr, EnumValsTy::iterator &EI, EnumValsTy::iterator &EIEnd, const llvm::APSInt &Val)
Returns true if we should emit a diagnostic about this case expression not being a part of the enum u...
TypeSourceInfo * getTypeSourceInfo() const
void setUsesSEHTry(bool UST)
static bool CmpEnumVals(const std::pair< llvm::APSInt, EnumConstantDecl *> &lhs, const std::pair< llvm::APSInt, EnumConstantDecl *> &rhs)
CmpEnumVals - Comparison predicate for sorting enumeration values.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
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.
Represents a base class of a C++ class.
static bool DiagnoseUnusedComparison(Sema &S, const Expr *E)
Diagnose unused comparisons, both builtin and overloaded operators.
void ActOnStartOfCompoundStmt(bool IsStmtExpr)
void NoteCandidates(PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr *> Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
When overload resolution fails, prints diagnostic messages containing the candidates in the candidate...
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
DeclStmt * getRangeStmt()
FieldDecl * BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture)
Build a FieldDecl suitable to hold the given capture.
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
GotoStmt - This represents a direct goto.
bool isLValueReferenceType() const
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
static bool CmpCaseVals(const std::pair< llvm::APSInt, CaseStmt *> &lhs, const std::pair< llvm::APSInt, CaseStmt *> &rhs)
CmpCaseVals - Comparison predicate for sorting case values.
const SwitchCase * getNextSwitchCase() const
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
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...
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
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...
ActionResult< Expr * > ExprResult
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
TypedefNameDecl * getTypedefNameForAnonDecl() const
StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp)
ActOnCapScopeReturnStmt - Utility routine to type-check return statements for capturing scopes...
Represents a C++ struct/union/class.
ContinueStmt - This represents a continue.
Expr * getTrueExpr() const
static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init, SourceLocation Loc, int DiagID)
Finish building a variable declaration for a for-range statement.
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef< Stmt *> handlers)
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
CXXCatchStmt - This represents a C++ catch block.
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.
WhileStmt - This represents a 'while' stmt.
std::unique_ptr< sema::FunctionScopeInfo, PoppedFunctionScopeDeleter > PoppedFunctionScopePtr
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
SourceLocation getBreakLoc() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
__DEVICE__ int min(int __a, int __b)
void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc)
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool HasImplicitReturnType
SourceLocation getTypeSpecEndLoc() const
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
A reference to a declared variable, function, enum, etc.
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
bool isPointerType() const
BreakStmt - This represents a break.
SourceManager & SourceMgr
CapturedRegionKind
The different kinds of captured statement.
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD, CopyElisionSemanticsKind CESK)
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
An l-value expression is a reference to an object with independent storage.
bool empty() const
Return true if no decls were found.
static bool hasDeducedReturnType(FunctionDecl *FD)
Determine whether the declared return type of the specified function contains 'auto'.
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
A boolean literal, per ([C++ lex.bool] Boolean literals).
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Represents a C array with a specified size that is not an integer-constant-expression.
DeclStmt * getBeginStmt()
Describes an entity that is being initialized.
void setType(QualType newType)
Wrapper for source info for pointers.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
StmtResult ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt, ConditionResult Cond, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
SourceLocation ColonLoc
Location of ':'.
Represents Objective-C's @autoreleasepool Statement.
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
Represents the canonical version of C arrays with a specified constant size.
Declaration of a template function.
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
SourceLocation getLocation() const
QualType getType() const
Return the type wrapped by this type source info.
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
Skip past any parentheses which might surround this expression until reaching a fixed point...
QualType getType() const
Retrieves the type of the base class.