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)
201 return DiagnoseUnusedExprResult(
Label->getSubStmt());
203 const Expr *E = dyn_cast_or_null<Expr>(S);
209 if (isUnevaluatedContext())
218 bool ShouldSuppress =
219 SourceMgr.isMacroBodyExpansion(ExprLoc) ||
220 SourceMgr.isInSystemMacro(ExprLoc);
222 const Expr *WarnExpr;
225 if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context))
238 if (isa<ParenExpr>(E->IgnoreImpCasts()) && Loc.
isMacroID()) {
240 if (findMacroSpelling(SpellLoc,
"UNREFERENCED_PARAMETER"))
247 unsigned DiagID = diag::warn_unused_expr;
248 if (
const FullExpr *Temps = dyn_cast<FullExpr>(E))
249 E = Temps->getSubExpr();
251 E = TempExpr->getSubExpr();
257 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
258 if (E->getType()->isVoidType())
261 if (
const Attr *A = CE->getUnusedResultAttr(Context)) {
262 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
270 if (
const Decl *FD = CE->getCalleeDecl()) {
273 if (FD->hasAttr<PureAttr>()) {
274 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"pure";
277 if (FD->hasAttr<ConstAttr>()) {
278 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"const";
282 }
else if (ShouldSuppress)
286 if (getLangOpts().ObjCAutoRefCount && ME->isDelegateInitCall()) {
287 Diag(Loc, diag::err_arc_unused_init_message) << R1;
292 if (
const auto *A = MD->
getAttr<WarnUnusedResultAttr>()) {
293 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
298 const Expr *Source = POE->getSyntacticForm();
299 if (isa<ObjCSubscriptRefExpr>(Source))
300 DiagID = diag::warn_unused_container_subscript_expr;
302 DiagID = diag::warn_unused_property_expr;
304 = dyn_cast<CXXFunctionalCastExpr>(E)) {
305 const Expr *E = FC->getSubExpr();
307 E = TE->getSubExpr();
308 if (isa<CXXTemporaryObjectExpr>(E))
311 if (
const CXXRecordDecl *RD = CE->getType()->getAsCXXRecordDecl())
312 if (!RD->getAttr<WarnUnusedAttr>())
316 else if (
const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E)) {
324 Diag(Loc, diag::warn_unused_voidptr)
330 if (E->isGLValue() && E->getType().isVolatileQualified()) {
331 Diag(Loc, diag::warn_unused_volatile) << R1 << R2;
335 DiagRuntimeBehavior(Loc,
nullptr, PDiag(DiagID) << R1 << R2);
339 PushCompoundScope(IsStmtExpr);
347 return getCurFunction()->CompoundScopes.back();
351 return getCurCompoundScope().IsStmtExpr;
356 const unsigned NumElts = Elts.size();
364 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
368 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
372 Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
380 if (NumElts != 0 && !CurrentInstantiationScope &&
381 getCurCompoundScope().HasEmptyLoopBodies) {
382 for (
unsigned i = 0; i != NumElts - 1; ++i)
383 DiagnoseEmptyLoopBody(Elts[i], Elts[i + 1]);
394 if (DiagnoseUnexpandedParameterPack(Val.
get()))
399 if (!getCurFunction()->SwitchStack.empty()) {
401 getCurFunction()->SwitchStack.back().getPointer()->getCond();
406 auto CheckAndFinish = [&](
Expr *E) {
410 if (getLangOpts().CPlusPlus11) {
413 llvm::APSInt TempVal;
419 if (!E->isValueDependent())
420 ER = VerifyIntegerConstantExpression(E);
422 ER = DefaultLvalueConversion(ER.
get());
424 ER = ImpCastExprToType(ER.
get(), CondType, CK_IntegralCast);
428 ExprResult Converted = CorrectDelayedTyposInExpr(Val, CheckAndFinish);
429 if (Converted.
get() == Val.
get())
430 Converted = CheckAndFinish(Val.
get());
436 return ActOnFinishFullExpr(Val.
get(), Val.
get()->getExprLoc(),
false,
437 getLangOpts().CPlusPlus11);
444 assert((LHSVal.
isInvalid() || LHSVal.
get()) &&
"missing LHS value");
447 "missing RHS value");
449 if (getCurFunction()->SwitchStack.empty()) {
450 Diag(CaseLoc, diag::err_case_not_in_switch);
455 getCurFunction()->SwitchStack.back().setInt(
true);
461 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(CS);
467 cast<CaseStmt>(S)->setSubStmt(SubStmt);
473 if (getCurFunction()->SwitchStack.empty()) {
474 Diag(DefaultLoc, diag::err_default_not_in_switch);
479 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(DS);
488 Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->
getDeclName();
520 CommaVisitor(
Sema &SemaRef) : Inherited(SemaRef.
Context), SemaRef(SemaRef) {}
542 Expr *CondExpr = Cond.
get().second;
545 !Diags.isIgnored(diag::warn_comma_operator, CondExpr->
getExprLoc()))
546 CommaVisitor(*this).Visit(CondExpr);
549 DiagnoseEmptyStmtBody(CondExpr->
getEndLoc(), thenStmt,
550 diag::warn_empty_if_body);
552 return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
563 if (IsConstexpr || isa<ObjCAvailabilityCheckExpr>(Cond.
get().second))
564 setFunctionHasBranchProtectedScope();
567 Cond.
get().second, thenStmt, ElseLoc, elseStmt);
571 struct CaseCompareFunctor {
572 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
573 const llvm::APSInt &RHS) {
574 return LHS.first < RHS;
576 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
577 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
578 return LHS.first < RHS.first;
580 bool operator()(
const llvm::APSInt &LHS,
581 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
582 return LHS < RHS.first;
589 static bool CmpCaseVals(
const std::pair<llvm::APSInt, CaseStmt*>& lhs,
590 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
591 if (lhs.first < rhs.first)
594 if (lhs.first == rhs.first &&
595 lhs.second->getCaseLoc().getRawEncoding()
596 < rhs.second->getCaseLoc().getRawEncoding())
603 static bool CmpEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
604 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
606 return lhs.first < rhs.first;
611 static bool EqEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
612 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
614 return lhs.first == rhs.first;
620 if (
const auto *FE = dyn_cast<FullExpr>(E))
621 E = FE->getSubExpr();
622 while (
const auto *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
623 if (ImpCast->getCastKind() != CK_IntegralCast)
break;
624 E = ImpCast->getSubExpr();
634 SwitchConvertDiagnoser(
Expr *Cond)
640 return S.
Diag(Loc, diag::err_typecheck_statement_requires_integer) << T;
645 return S.
Diag(Loc, diag::err_switch_incomplete_class_type)
651 return S.
Diag(Loc, diag::err_switch_explicit_conversion) << T << ConvTy;
662 return S.
Diag(Loc, diag::err_switch_multiple_conversions) << T;
673 llvm_unreachable(
"conversion functions are permitted");
675 } SwitchDiagnoser(Cond);
678 PerformContextualImplicitConversion(SwitchLoc, Cond, SwitchDiagnoser);
684 Cond = CondResult.
get();
690 return UsualUnaryConversions(Cond);
695 Expr *CondExpr = Cond.
get().second;
696 assert((Cond.
isInvalid() || CondExpr) &&
"switch with no condition");
704 "invalid condition type");
709 Diag(SwitchLoc, diag::warn_bool_switch_condition)
714 setFunctionHasBranchIntoScope();
717 getCurFunction()->SwitchStack.push_back(
722 static void AdjustAPSInt(llvm::APSInt &Val,
unsigned BitWidth,
bool IsSigned) {
723 Val = Val.extOrTrunc(BitWidth);
724 Val.setIsSigned(IsSigned);
730 unsigned UnpromotedWidth,
bool UnpromotedSign) {
738 if (UnpromotedWidth < Val.getBitWidth()) {
739 llvm::APSInt ConvVal(Val);
741 AdjustAPSInt(ConvVal, Val.getBitWidth(), Val.isSigned());
746 S.
Diag(Loc, diag::warn_case_value_overflow) << Val.toString(10)
747 << ConvVal.toString(10);
757 const Expr *CaseExpr,
758 EnumValsTy::iterator &EI,
759 EnumValsTy::iterator &EIEnd,
760 const llvm::APSInt &Val) {
766 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
775 if (ED->
hasAttr<FlagEnumAttr>())
778 while (EI != EIEnd && EI->first < Val)
781 if (EI != EIEnd && EI->first == Val)
794 if (!CondEnumType || !CaseEnumType)
801 if (!CaseEnumType->getDecl()->getIdentifier() &&
802 !CaseEnumType->getDecl()->getTypedefNameForAnonDecl())
808 S.
Diag(Case->
getExprLoc(), diag::warn_comparison_of_mixed_enum_types_switch)
817 bool CaseListIsIncomplete = getCurFunction()->SwitchStack.back().getInt();
818 assert(SS == getCurFunction()->SwitchStack.back().getPointer() &&
819 "switch stack missing push/pop!");
821 getCurFunction()->SwitchStack.pop_back();
824 SS->
setBody(BodyStmt, SwitchLoc);
838 const Expr *CondExprBeforePromotion = CondExpr;
844 bool HasDependentValue
846 unsigned CondWidth = HasDependentValue ? 0 : Context.
getIntWidth(CondType);
853 unsigned CondWidthBeforePromotion
854 = HasDependentValue ? 0 : Context.
getIntWidth(CondTypeBeforePromotion);
855 bool CondIsSignedBeforePromotion
865 typedef std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRangesTy;
866 CaseRangesTy CaseRanges;
870 bool CaseListIsErroneous =
false;
876 if (TheDefaultStmt) {
877 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
884 CaseListIsErroneous =
true;
893 if (Lo->isValueDependent()) {
894 HasDependentValue =
true;
900 const Expr *LoBeforePromotion = Lo;
906 checkCaseValue(*
this, Lo->getBeginLoc(), LoVal, CondWidthBeforePromotion,
907 CondIsSignedBeforePromotion);
919 HasDependentValue =
true;
922 CaseRanges.push_back(std::make_pair(LoVal, CS));
924 CaseVals.push_back(std::make_pair(LoVal, CS));
928 if (!HasDependentValue) {
931 llvm::APSInt ConstantCondValue;
932 bool HasConstantCond =
false;
933 if (!HasDependentValue && !TheDefaultStmt) {
939 assert(!HasConstantCond ||
940 (ConstantCondValue.getBitWidth() == CondWidth &&
941 ConstantCondValue.isSigned() == CondIsSigned));
943 bool ShouldCheckConstantCond = HasConstantCond;
946 std::stable_sort(CaseVals.begin(), CaseVals.end(),
CmpCaseVals);
948 if (!CaseVals.empty()) {
949 for (
unsigned i = 0, e = CaseVals.size(); i != e; ++i) {
950 if (ShouldCheckConstantCond &&
951 CaseVals[i].first == ConstantCondValue)
952 ShouldCheckConstantCond =
false;
954 if (i != 0 && CaseVals[i].first == CaseVals[i-1].first) {
957 StringRef PrevString, CurrString;
960 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(PrevCase)) {
961 PrevString = DeclRef->getDecl()->getName();
963 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(CurrCase)) {
964 CurrString = DeclRef->getDecl()->getName();
967 CaseVals[i-1].first.toString(CaseValStr);
969 if (PrevString == CurrString)
970 Diag(CaseVals[i].second->getLHS()->getBeginLoc(),
971 diag::err_duplicate_case)
972 << (PrevString.empty() ? StringRef(CaseValStr) : PrevString);
974 Diag(CaseVals[i].second->getLHS()->getBeginLoc(),
975 diag::err_duplicate_case_differing_expr)
976 << (PrevString.empty() ? StringRef(CaseValStr) : PrevString)
977 << (CurrString.empty() ? StringRef(CaseValStr) : CurrString)
980 Diag(CaseVals[i - 1].second->getLHS()->getBeginLoc(),
981 diag::note_duplicate_case_prev);
984 CaseListIsErroneous =
true;
991 if (!CaseRanges.empty()) {
994 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
997 std::vector<llvm::APSInt> HiVals;
998 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
999 llvm::APSInt &LoVal = CaseRanges[i].first;
1000 CaseStmt *CR = CaseRanges[i].second;
1003 const Expr *HiBeforePromotion = Hi;
1010 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
1016 if (LoVal > HiVal) {
1019 CaseRanges.erase(CaseRanges.begin()+i);
1025 if (ShouldCheckConstantCond &&
1026 LoVal <= ConstantCondValue &&
1027 ConstantCondValue <= HiVal)
1028 ShouldCheckConstantCond =
false;
1030 HiVals.push_back(HiVal);
1036 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1037 llvm::APSInt &CRLo = CaseRanges[i].first;
1038 llvm::APSInt &CRHi = HiVals[i];
1039 CaseStmt *CR = CaseRanges[i].second;
1044 llvm::APSInt OverlapVal(32);
1048 CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(),
1049 CaseVals.end(), CRLo,
1050 CaseCompareFunctor());
1051 if (I != CaseVals.end() && I->first < CRHi) {
1052 OverlapVal = I->first;
1053 OverlapStmt = I->second;
1057 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
1058 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
1059 OverlapVal = (I-1)->first;
1060 OverlapStmt = (I-1)->second;
1065 if (i && CRLo <= HiVals[i-1]) {
1066 OverlapVal = HiVals[i-1];
1067 OverlapStmt = CaseRanges[i-1].second;
1073 << OverlapVal.toString(10);
1075 diag::note_duplicate_case_prev);
1078 CaseListIsErroneous =
true;
1084 if (!CaseListIsErroneous && !CaseListIsIncomplete &&
1085 ShouldCheckConstantCond) {
1088 Diag(CondExpr->
getExprLoc(), diag::warn_missing_case_for_condition)
1089 << ConstantCondValue.toString(10)
1101 if (!CaseListIsErroneous && !CaseListIsIncomplete && !HasConstantCond &&
1109 llvm::APSInt Val = EDI->getInitVal();
1111 EnumVals.push_back(std::make_pair(Val, EDI));
1113 std::stable_sort(EnumVals.begin(), EnumVals.end(),
CmpEnumVals);
1114 auto EI = EnumVals.begin(), EIEnd =
1115 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1118 for (CaseValsTy::const_iterator CI = CaseVals.begin();
1119 CI != CaseVals.end(); CI++) {
1120 Expr *CaseExpr = CI->second->getLHS();
1124 << CondTypeBeforePromotion;
1128 EI = EnumVals.begin();
1129 for (CaseRangesTy::const_iterator RI = CaseRanges.begin();
1130 RI != CaseRanges.end(); RI++) {
1131 Expr *CaseExpr = RI->second->getLHS();
1135 << CondTypeBeforePromotion;
1138 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1141 CaseExpr = RI->second->getRHS();
1145 << CondTypeBeforePromotion;
1149 auto CI = CaseVals.begin();
1150 auto RI = CaseRanges.begin();
1151 bool hasCasesNotInSwitch =
false;
1155 for (EI = EnumVals.begin(); EI != EIEnd; EI++) {
1157 switch (EI->second->getAvailability()) {
1171 while (CI != CaseVals.end() && CI->first < EI->first)
1174 if (CI != CaseVals.end() && CI->first == EI->first)
1178 for (; RI != CaseRanges.end(); RI++) {
1180 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1182 if (EI->first <= Hi)
1186 if (RI == CaseRanges.end() || EI->first < RI->first) {
1187 hasCasesNotInSwitch =
true;
1188 UnhandledNames.push_back(EI->second->getDeclName());
1192 if (TheDefaultStmt && UnhandledNames.empty() && ED->
isClosedNonFlag())
1196 if (!UnhandledNames.empty()) {
1198 TheDefaultStmt ? diag::warn_def_missing_case
1199 : diag::warn_missing_case)
1200 << (
int)UnhandledNames.size();
1202 for (
size_t I = 0, E =
std::min(UnhandledNames.size(), (
size_t)3);
1204 DB << UnhandledNames[I];
1207 if (!hasCasesNotInSwitch)
1213 DiagnoseEmptyStmtBody(CondExpr->
getEndLoc(), BodyStmt,
1214 diag::warn_empty_switch_body);
1218 if (CaseListIsErroneous)
1227 if (Diags.isIgnored(diag::warn_not_in_enum_assignment, SrcExpr->
getExprLoc()))
1241 const EnumDecl *ED = ET->getDecl();
1246 if (ED->
hasAttr<FlagEnumAttr>()) {
1247 if (!IsValueInFlagEnum(ED, RhsVal,
true))
1253 EnumValsTy EnumVals;
1258 llvm::APSInt Val = EDI->getInitVal();
1260 EnumVals.push_back(std::make_pair(Val, EDI));
1262 if (EnumVals.empty())
1264 std::stable_sort(EnumVals.begin(), EnumVals.end(),
CmpEnumVals);
1265 EnumValsTy::iterator EIend =
1266 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1269 EnumValsTy::const_iterator EI = EnumVals.begin();
1270 while (EI != EIend && EI->first < RhsVal)
1272 if (EI == EIend || EI->first != RhsVal) {
1286 auto CondVal = Cond.
get();
1287 CheckBreakContinueBinding(CondVal.second);
1289 if (CondVal.second &&
1290 !Diags.isIgnored(diag::warn_comma_operator, CondVal.second->getExprLoc()))
1291 CommaVisitor(*this).Visit(CondVal.second);
1293 if (isa<NullStmt>(Body))
1294 getCurCompoundScope().setHasEmptyLoopBodies();
1304 assert(Cond &&
"ActOnDoStmt(): missing expression");
1306 CheckBreakContinueBinding(Cond);
1307 ExprResult CondResult = CheckBooleanCondition(DoLoc, Cond);
1310 Cond = CondResult.
get();
1312 CondResult = ActOnFinishFullExpr(Cond, DoLoc,
false);
1315 Cond = CondResult.
get();
1318 if (Cond && !getLangOpts().
C99 && !getLangOpts().
CPlusPlus &&
1319 !Diags.isIgnored(diag::warn_comma_operator, Cond->
getExprLoc()))
1320 CommaVisitor(*this).Visit(Cond);
1322 return new (Context)
DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen);
1327 using DeclSetVector =
1328 llvm::SetVector<VarDecl *, llvm::SmallVector<VarDecl *, 8>,
1329 llvm::SmallPtrSet<VarDecl *, 8>>;
1335 DeclSetVector &Decls;
1341 DeclExtractor(
Sema &S, DeclSetVector &Decls,
1348 bool isSimple() {
return Simple; }
1356 void VisitStmt(
Stmt *S) {
1417 DeclSetVector &Decls;
1423 DeclMatcher(
Sema &S, DeclSetVector &Decls,
Stmt *Statement) :
1424 Inherited(S.
Context), Decls(Decls), FoundDecl(
false) {
1425 if (!Statement)
return;
1449 void CheckLValueToRValueCast(
Expr *E) {
1452 if (isa<DeclRefExpr>(E)) {
1457 Visit(CO->getCond());
1458 CheckLValueToRValueCast(CO->getTrueExpr());
1459 CheckLValueToRValueCast(CO->getFalseExpr());
1464 dyn_cast<BinaryConditionalOperator>(E)) {
1465 CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr());
1466 CheckLValueToRValueCast(BCO->getFalseExpr());
1475 if (Decls.count(VD))
1483 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(S))
1485 Visit(OVE->getSourceExpr());
1491 bool FoundDeclInUse() {
return FoundDecl; }
1495 void CheckForLoopConditionalStatement(
Sema &S,
Expr *Second,
1498 if (!Second)
return;
1505 DeclSetVector Decls;
1507 DeclExtractor DE(S, Decls, Ranges);
1511 if (!DE.isSimple())
return;
1514 if (Decls.size() == 0)
return;
1517 for (
auto *VD : Decls)
1518 if (VD->getType().isVolatileQualified() || VD->hasGlobalStorage())
1521 if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
1522 DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
1523 DeclMatcher(S, Decls, Body).FoundDeclInUse())
1527 if (Decls.size() > 4) {
1530 PDiag << (unsigned)Decls.size();
1531 for (
auto *VD : Decls)
1532 PDiag << VD->getDeclName();
1535 for (
auto Range : Ranges)
1538 S.
Diag(Ranges.begin()->getBegin(), PDiag);
1543 bool ProcessIterationStmt(
Sema &S,
Stmt* Statement,
bool &Increment,
1545 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(Statement))
1546 if (!Cleanups->cleanupsHaveSideEffects())
1547 Statement = Cleanups->getSubExpr();
1549 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(Statement)) {
1550 switch (UO->getOpcode()) {
1551 default:
return false;
1569 default:
return false;
1589 bool InSwitch =
false;
1592 BreakContinueFinder(
Sema &S,
const Stmt* Body) :
1603 void VisitBreakStmt(
const BreakStmt* E) {
1623 void VisitForStmt(
const ForStmt *S) {
1630 void VisitWhileStmt(
const WhileStmt *) {
1635 void VisitDoStmt(
const DoStmt *) {
1662 bool ContinueFound() {
return ContinueLoc.
isValid(); }
1663 bool BreakFound() {
return BreakLoc.
isValid(); }
1674 void CheckForRedundantIteration(
Sema &S,
Expr *Third,
Stmt *Body) {
1676 if (!Body || !Third)
return;
1686 if (!LastStmt)
return;
1688 bool LoopIncrement, LastIncrement;
1691 if (!ProcessIterationStmt(S, Third, LoopIncrement, LoopDRE))
return;
1692 if (!ProcessIterationStmt(S, LastStmt, LastIncrement, LastDRE))
return;
1696 if (LoopIncrement != LastIncrement ||
1699 if (BreakContinueFinder(S, Body).ContinueFound())
return;
1702 << LastDRE->
getDecl() << LastIncrement;
1710 void Sema::CheckBreakContinueBinding(
Expr *E) {
1713 BreakContinueFinder BCFinder(*
this, E);
1715 if (BCFinder.BreakFound() && BreakParent) {
1717 Diag(BCFinder.GetBreakLoc(), diag::warn_break_binds_to_switch);
1719 Diag(BCFinder.GetBreakLoc(), diag::warn_loop_ctrl_binds_to_inner)
1722 }
else if (BCFinder.ContinueFound() && CurScope->getContinueParent()) {
1723 Diag(BCFinder.GetContinueLoc(), diag::warn_loop_ctrl_binds_to_inner)
1735 if (!getLangOpts().CPlusPlus) {
1736 if (
DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
1740 for (
auto *DI : DS->decls()) {
1745 Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
1746 DI->setInvalidDecl();
1752 CheckBreakContinueBinding(Second.
get().second);
1753 CheckBreakContinueBinding(third.
get());
1755 if (!Second.
get().first)
1756 CheckForLoopConditionalStatement(*
this, Second.
get().second, third.
get(),
1758 CheckForRedundantIteration(*
this, third.
get(), Body);
1760 if (Second.
get().second &&
1761 !Diags.isIgnored(diag::warn_comma_operator,
1762 Second.
get().second->getExprLoc()))
1763 CommaVisitor(*this).Visit(Second.
get().second);
1766 if (isa<NullStmt>(Body))
1767 getCurCompoundScope().setHasEmptyLoopBodies();
1769 return new (Context)
1770 ForStmt(Context, First, Second.
get().second, Second.
get().first, Third,
1771 Body, ForLoc, LParenLoc, RParenLoc);
1796 ExprResult result = CorrectDelayedTyposInExpr(collection);
1799 collection = result.
get();
1805 result = DefaultFunctionArrayLvalueConversion(collection);
1808 collection = result.
get();
1815 return Diag(forLoc, diag::err_collection_expr_type)
1826 (getLangOpts().ObjCAutoRefCount
1827 ? RequireCompleteType(forLoc,
QualType(objectType, 0),
1828 diag::err_arc_collection_forward, collection)
1829 : !isCompleteType(forLoc,
QualType(objectType, 0)))) {
1832 }
else if (iface || !objectType->
qual_empty()) {
1834 &Context.
Idents.
get(
"countByEnumeratingWithState"),
1850 method = LookupMethodInQualifiedType(selector, pointerType,
1855 Diag(forLoc, diag::warn_collection_expr_type)
1870 setFunctionHasBranchProtectedScope();
1873 CheckObjCForCollectionOperand(ForLoc, collection);
1877 if (
DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
1878 if (!DS->isSingleDecl())
1880 diag::err_toomany_element_decls));
1892 diag::err_non_local_variable_decl_in_for));
1898 Expr *DeducedInit = &OpaqueId;
1901 DiagnoseAutoDeductionFailure(D, DeducedInit);
1902 if (FirstType.
isNull()) {
1909 if (!inTemplateInstantiation()) {
1912 Diag(Loc, diag::warn_auto_var_is_id)
1918 Expr *FirstE = cast<Expr>(First);
1924 FirstType =
static_cast<Expr*
>(First)->getType();
1926 Diag(ForLoc, diag::err_selector_element_const_type)
1932 return StmtError(
Diag(ForLoc, diag::err_selector_element_type)
1939 CollectionExprResult =
1940 ActOnFinishFullExpr(CollectionExprResult.
get(),
false);
1945 nullptr, ForLoc, RParenLoc);
1999 void NoteForRangeBeginEndFunction(
Sema &SemaRef,
Expr *E,
2009 std::string Description;
2010 bool IsTemplate =
false;
2017 SemaRef.
Diag(Loc, diag::note_for_range_begin_end)
2018 << BEF << IsTemplate << Description << E->
getType();
2069 return Diag(InitStmt->
getBeginLoc(), diag::err_objc_for_range_init_stmt)
2071 return ActOnObjCForCollectionStmt(ForLoc, First, Range, RParenLoc);
2075 assert(DS &&
"first part of for range not a decl stmt");
2084 DiagnoseUnexpandedParameterPack(Range, UPPC_Expression)) {
2092 if (!ActOnCoroutineBodyStart(S, CoawaitLoc,
"co_await"))
2098 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2100 VarDecl *RangeVar = BuildForRangeVarDecl(*
this, RangeLoc,
2102 std::string(
"__range") + DepthStr);
2104 diag::err_for_range_deduction_failure)) {
2112 StmtResult RangeDecl = ActOnDeclStmt(RangeGroup, RangeLoc, RangeLoc);
2118 return BuildCXXForRangeStmt(
2119 ForLoc, CoawaitLoc, InitStmt, ColonLoc, RangeDecl.
get(),
2121 nullptr,
nullptr, DS, RParenLoc,
Kind);
2148 auto BuildBegin = [&] {
2152 BeginMemberLookup, CandidateSet,
2153 BeginRange, BeginExpr);
2158 << ColonLoc << BEF_begin << BeginRange->
getType();
2171 diag::err_for_range_iter_deduction_failure)) {
2172 NoteForRangeBeginEndFunction(SemaRef, BeginExpr->
get(), *BEF);
2178 auto BuildEnd = [&] {
2182 EndMemberLookup, CandidateSet,
2187 << ColonLoc << BEF_end << EndRange->
getType();
2191 diag::err_for_range_iter_deduction_failure)) {
2192 NoteForRangeBeginEndFunction(SemaRef, EndExpr->
get(), *BEF);
2205 if (BeginMemberLookup.isAmbiguous())
2212 if (BeginMemberLookup.empty() != EndMemberLookup.
empty()) {
2217 auto BuildNonmember = [&](
2219 llvm::function_ref<Sema::ForRangeStatus()> BuildFound,
2220 llvm::function_ref<Sema::ForRangeStatus()> BuildNotFound) {
2227 switch (BuildFound()) {
2233 << BeginRange->
getType() << BEFFound;
2239 SemaRef.
Diag(D->getLocation(),
2240 diag::note_for_range_member_begin_end_ignored)
2241 << BeginRange->
getType() << BEFFound;
2245 llvm_unreachable(
"unexpected ForRangeStatus");
2247 if (BeginMemberLookup.empty())
2248 return BuildNonmember(BEF_end, EndMemberLookup, BuildEnd, BuildBegin);
2249 return BuildNonmember(BEF_begin, BeginMemberLookup, BuildBegin, BuildEnd);
2281 AdjustedRange = SemaRef.
BuildUnaryOp(S, RangeLoc, UO_Deref, Range);
2286 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2295 SemaRef.
Diag(RangeLoc, diag::err_for_range_dereference)
2298 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2304 struct InvalidateOnErrorScope {
2305 InvalidateOnErrorScope(
Sema &SemaRef,
Decl *D,
bool Enabled)
2306 : Trap(SemaRef.
Diags), D(D), Enabled(Enabled) {}
2307 ~InvalidateOnErrorScope() {
2308 if (Enabled && Trap.hasErrorOccurred())
2335 Scope *S = getCurScope();
2337 DeclStmt *RangeDS = cast<DeclStmt>(RangeDecl);
2339 QualType RangeVarType = RangeVar->getType();
2341 DeclStmt *LoopVarDS = cast<DeclStmt>(LoopVarDecl);
2346 InvalidateOnErrorScope Invalidate(*
this, LoopVar,
2347 LoopVar->getType()->isUndeducedType());
2353 if (RangeVarType->isDependentType()) {
2355 RangeVar->markUsed(Context);
2359 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2360 if (
auto *DD = dyn_cast<DecompositionDecl>(LoopVar))
2361 for (
auto *Binding : DD->bindings())
2363 LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.
DependentTy));
2365 }
else if (!BeginDeclStmt.get()) {
2370 ExprResult BeginRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2375 ExprResult EndRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2381 Expr *Range = RangeVar->getInit();
2386 if (RequireCompleteType(RangeLoc, RangeType,
2387 diag::err_for_range_incomplete_type))
2392 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2393 VarDecl *BeginVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2394 std::string(
"__begin") + DepthStr);
2395 VarDecl *EndVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2396 std::string(
"__end") + DepthStr);
2407 BeginExpr = BeginRangeRef;
2409 BeginExpr = ActOnCoawaitExpr(S, ColonLoc, BeginExpr.
get());
2414 diag::err_for_range_iter_deduction_failure)) {
2415 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2425 dyn_cast<VariableArrayType>(UnqAT)) {
2448 ExprResult SizeOfVLAExprR = ActOnUnaryExprOrTypeTraitExpr(
2452 VAT->desugar(), RangeLoc))
2458 ExprResult SizeOfEachElementExprR = ActOnUnaryExprOrTypeTraitExpr(
2461 CreateParsedType(VAT->desugar(),
2463 VAT->getElementType(), RangeLoc))
2471 SizeOfVLAExprR.
get(), SizeOfEachElementExprR.
get());
2478 llvm_unreachable(
"Unexpected array type in for-range");
2482 EndExpr = ActOnBinOp(S, ColonLoc, tok::plus, EndRangeRef.
get(),
2487 diag::err_for_range_iter_deduction_failure)) {
2488 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2496 *
this, BeginRangeRef.
get(), EndRangeRef.
get(), RangeType, BeginVar,
2497 EndVar,
ColonLoc, CoawaitLoc, &CandidateSet, &BeginExpr, &EndExpr,
2500 if (Kind == BFRK_Build && RangeStatus == FRS_NoViableFunction &&
2501 BEFFailure == BEF_begin) {
2504 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Range)) {
2505 if (
ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
2506 QualType ArrayTy = PVD->getOriginalType();
2507 QualType PointerTy = PVD->getType();
2510 << RangeLoc << PVD << ArrayTy << PointerTy;
2511 Diag(PVD->getLocation(), diag::note_declared_at);
2520 CoawaitLoc, InitStmt,
2521 LoopVarDecl, ColonLoc,
2529 if (RangeStatus == FRS_NoViableFunction) {
2530 Expr *Range = BEFFailure ? EndRangeRef.
get() : BeginRangeRef.
get();
2532 << RangeLoc << Range->
getType() << BEFFailure;
2536 if (RangeStatus != FRS_Success)
2541 "invalid range expression in for loop");
2545 QualType BeginType = BeginVar->getType(), EndType = EndVar->
getType();
2548 ? diag::warn_for_range_begin_end_types_differ
2549 : diag::ext_for_range_begin_end_types_differ)
2550 << BeginType << EndType;
2551 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2552 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2556 ActOnDeclStmt(ConvertDeclToDeclGroup(BeginVar), ColonLoc, ColonLoc);
2558 ActOnDeclStmt(ConvertDeclToDeclGroup(EndVar), ColonLoc, ColonLoc);
2561 ExprResult BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2566 ExprResult EndRef = BuildDeclRefExpr(EndVar, EndType.getNonReferenceType(),
2572 NotEqExpr = ActOnBinOp(S, ColonLoc, tok::exclaimequal,
2573 BeginRef.
get(), EndRef.
get());
2575 NotEqExpr = CheckBooleanCondition(ColonLoc, NotEqExpr.
get());
2578 ActOnFinishFullExpr(NotEqExpr.
get(),
false);
2580 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2581 << RangeLoc << 0 << BeginRangeRef.
get()->getType();
2582 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2584 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2589 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2594 IncrExpr = ActOnUnaryOp(S, ColonLoc, tok::plusplus, BeginRef.
get());
2595 if (!IncrExpr.isInvalid() && CoawaitLoc.
isValid())
2599 IncrExpr = ActOnCoawaitExpr(S, CoawaitLoc, IncrExpr.get());
2600 if (!IncrExpr.isInvalid())
2601 IncrExpr = ActOnFinishFullExpr(IncrExpr.get(),
false);
2602 if (IncrExpr.isInvalid()) {
2603 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2604 << RangeLoc << 2 << BeginRangeRef.
get()->getType() ;
2605 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2610 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2615 ExprResult DerefExpr = ActOnUnaryOp(S, ColonLoc, tok::star, BeginRef.
get());
2617 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2618 << RangeLoc << 1 << BeginRangeRef.
get()->getType();
2619 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2625 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2626 AddInitializerToDecl(LoopVar, DerefExpr.
get(),
false);
2627 if (LoopVar->isInvalidDecl())
2628 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2634 if (Kind == BFRK_Check)
2638 InitStmt, RangeDS, cast_or_null<DeclStmt>(BeginDeclStmt.get()),
2639 cast_or_null<DeclStmt>(EndDeclStmt.
get()), NotEqExpr.
get(),
2640 IncrExpr.get(), LoopVarDS,
nullptr, ForLoc, CoawaitLoc,
2671 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(InitExpr))
2672 if (!Cleanups->cleanupsHaveSideEffects())
2673 InitExpr = Cleanups->getSubExpr();
2686 while (!isa<CXXOperatorCallExpr>(E) && !isa<UnaryOperator>(E)) {
2690 const MemberExpr *ME = cast<MemberExpr>(Call->getCallee());
2699 bool ReturnsReference =
false;
2700 if (isa<UnaryOperator>(E)) {
2701 ReturnsReference =
true;
2705 QualType ReturnType = FD->getReturnType();
2709 if (ReturnsReference) {
2713 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_const_reference_copy)
2714 << VD << VariableType << E->
getType();
2724 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_variable_always_copy)
2725 << VD << RangeInitType;
2745 if (!CE->getConstructor()->isCopyConstructor())
2747 }
else if (
const CastExpr *CE = dyn_cast<CastExpr>(InitExpr)) {
2748 if (CE->getCastKind() != CK_LValueToRValue)
2763 << VD << VariableType << InitExpr->
getType();
2779 if (SemaRef.
Diags.
isIgnored(diag::warn_for_range_const_reference_copy,
2781 SemaRef.
Diags.
isIgnored(diag::warn_for_range_variable_always_copy,
2817 if (isa<ObjCForCollectionStmt>(S))
2818 return FinishObjCForCollectionStmt(S, B);
2824 diag::warn_empty_range_based_for_body);
2834 setFunctionHasBranchIntoScope();
2836 return new (Context)
GotoStmt(TheDecl, GotoLoc, LabelLoc);
2848 CheckSingleAssignmentConstraints(DestTy, ExprRes);
2852 if (DiagnoseAssignmentResult(ConvTy, StarLoc, DestTy, ETy, E, AA_Passing))
2856 ExprResult ExprRes = ActOnFinishFullExpr(E,
false);
2861 setFunctionHasIndirectGoto();
2867 const Scope &DestScope) {
2870 S.
Diag(Loc, diag::warn_jump_out_of_seh_finally);
2879 return StmtError(
Diag(ContinueLoc, diag::err_continue_not_in_loop));
2891 return StmtError(
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
2894 return StmtError(
Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt)
2898 return new (Context)
BreakStmt(BreakLoc);
2931 if (isCopyElisionCandidate(ReturnType, VD, CESK))
2946 if (!(CESK & CES_AllowDifferentTypes) && !VDType->
isDependentType() &&
2952 if (VD->
getKind() != Decl::Var &&
2953 !((CESK & CES_AllowParameters) && VD->
getKind() == Decl::ParmVar))
2964 if (VD->
hasAttr<BlocksAttr>())
return false;
2966 if (CESK & CES_AllowDifferentTypes)
3002 bool ConvertingConstructorsOnly,
3007 Expr *InitExpr = &AsRvalue;
3010 Value->getBeginLoc(), Value->getBeginLoc());
3023 if (ConvertingConstructorsOnly) {
3024 if (isa<CXXConstructorDecl>(FD)) {
3042 if (isa<CXXConstructorDecl>(FD)) {
3048 }
else if (isa<CXXMethodDecl>(FD)) {
3051 if (cast<CXXMethodDecl>(FD)->getRefQualifier() !=
RQ_RValue)
3065 Res = Seq.Perform(S, Entity, Kind, Value);
3093 bool AffectedByCWG1579 =
false;
3095 if (!NRVOCandidate) {
3096 NRVOCandidate = getCopyElisionCandidate(ResultType, Value, CES_Default);
3097 if (NRVOCandidate &&
3098 !getDiagnostics().isIgnored(diag::warn_return_std_move_in_cxx11,
3100 const VarDecl *NRVOCandidateInCXX11 =
3101 getCopyElisionCandidate(ResultType, Value, CES_FormerDefault);
3102 AffectedByCWG1579 = (!NRVOCandidateInCXX11);
3106 if (NRVOCandidate) {
3111 if (!Res.
isInvalid() && AffectedByCWG1579) {
3123 assert(!ResultType.
isNull());
3125 Str +=
"std::move(";
3130 << NRVOCandidate->
getDeclName() << ResultType << QT;
3135 !getDiagnostics().isIgnored(diag::warn_return_std_move,
3137 const VarDecl *FakeNRVOCandidate =
3138 getCopyElisionCandidate(
QualType(), Value, CES_AsIfByStdMove);
3139 if (FakeNRVOCandidate) {
3153 FakeValue,
false, FakeRes);
3158 Str +=
"std::move(";
3199 bool HasDeducedReturnType =
3202 if (ExprEvalContexts.back().Context ==
3203 ExpressionEvaluationContext::DiscardedStatement &&
3207 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3210 RetValExp = ER.
get();
3216 if (HasDeducedReturnType) {
3224 assert(AT &&
"lost auto type from lambda return type");
3225 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3235 if (RetValExp && !isa<InitListExpr>(RetValExp)) {
3236 ExprResult Result = DefaultFunctionArrayLvalueConversion(RetValExp);
3239 RetValExp = Result.
get();
3245 if (!CurContext->isDependentContext())
3254 Diag(ReturnLoc, diag::err_lambda_return_init_list)
3258 FnRetType = Context.
VoidTy;
3266 assert(!FnRetType.isNull());
3268 if (
BlockScopeInfo *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
3270 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr);
3274 dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
3275 Diag(ReturnLoc, diag::err_return_in_captured_stmt) << CurRegion->getRegionName();
3278 assert(CurLambda &&
"unknown kind of captured scope");
3280 ->getNoReturnAttr()) {
3281 Diag(ReturnLoc, diag::err_noreturn_lambda_has_return_expr);
3289 const VarDecl *NRVOCandidate =
nullptr;
3290 if (FnRetType->isDependentType()) {
3293 }
else if (FnRetType->isVoidType()) {
3294 if (RetValExp && !isa<InitListExpr>(RetValExp) &&
3295 !(getLangOpts().CPlusPlus &&
3298 if (!getLangOpts().CPlusPlus &&
3300 Diag(ReturnLoc, diag::ext_return_has_void_expr) <<
"literal" << 2;
3302 Diag(ReturnLoc, diag::err_return_block_has_expr);
3303 RetValExp =
nullptr;
3306 }
else if (!RetValExp) {
3307 return StmtError(
Diag(ReturnLoc, diag::err_block_return_missing_expr));
3317 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3320 NRVOCandidate !=
nullptr);
3321 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3322 FnRetType, RetValExp);
3327 RetValExp = Res.
get();
3328 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc);
3330 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3335 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3338 RetValExp = ER.
get();
3347 FunctionScopes.back()->Returns.push_back(Result);
3349 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3350 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3368 class LocalTypedefNameReferencer
3371 LocalTypedefNameReferencer(
Sema &S) : S(S) {}
3376 bool LocalTypedefNameReferencer::VisitRecordType(
const RecordType *RT) {
3378 if (!R || !R->isLocalClass() || !R->isLocalClass()->isExternallyVisible() ||
3379 R->isDependentType())
3381 for (
auto *TmpD : R->decls())
3382 if (
auto *T = dyn_cast<TypedefNameDecl>(TmpD))
3383 if (T->getAccess() !=
AS_private || R->hasFriends())
3408 TypeLoc OrigResultType = getReturnTypeLoc(FD);
3411 if (RetExpr && isa<InitListExpr>(RetExpr)) {
3415 getCurLambda() ? diag::err_lambda_return_init_list
3416 : diag::err_auto_fn_return_init_list)
3426 assert(AT->
isDeduced() &&
"should have deduced to dependent type");
3439 if (DAR != DAR_Succeeded)
3444 LocalTypedefNameReferencer Referencer(*
this);
3445 Referencer.TraverseType(RetExpr->
getType());
3453 Diag(ReturnLoc, diag::err_auto_fn_return_void_but_not_auto)
3458 Deduced = SubstAutoType(OrigResultType.
getType(), Context.
VoidTy);
3482 Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible)
3486 Diag(ReturnLoc, diag::err_auto_fn_different_deductions)
3503 StmtResult R = BuildReturnStmt(ReturnLoc, RetValExp);
3504 if (R.
isInvalid() || ExprEvalContexts.back().Context ==
3505 ExpressionEvaluationContext::DiscardedStatement)
3509 const_cast<VarDecl*>(cast<ReturnStmt>(R.
get())->getNRVOCandidate())) {
3522 if (RetValExp && DiagnoseUnexpandedParameterPack(RetValExp))
3525 if (isa<CapturingScopeInfo>(getCurFunction()))
3526 return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp);
3530 const AttrVec *Attrs =
nullptr;
3531 bool isObjCMethod =
false;
3534 FnRetType = FD->getReturnType();
3536 Attrs = &FD->getAttrs();
3537 if (FD->isNoReturn())
3538 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
3539 << FD->getDeclName();
3540 if (FD->isMain() && RetValExp)
3541 if (isa<CXXBoolLiteralExpr>(RetValExp))
3542 Diag(ReturnLoc, diag::warn_main_returns_bool_literal)
3545 FnRetType = MD->getReturnType();
3546 isObjCMethod =
true;
3548 Attrs = &MD->getAttrs();
3549 if (MD->hasRelatedResultType() && MD->getClassInterface()) {
3561 if (ExprEvalContexts.back().Context ==
3562 ExpressionEvaluationContext::DiscardedStatement &&
3566 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3569 RetValExp = ER.
get();
3580 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3594 if (isa<InitListExpr>(RetValExp)) {
3598 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3599 int FunctionKind = 0;
3600 if (isa<ObjCMethodDecl>(CurDecl))
3602 else if (isa<CXXConstructorDecl>(CurDecl))
3604 else if (isa<CXXDestructorDecl>(CurDecl))
3607 Diag(ReturnLoc, diag::err_return_init_list)
3612 RetValExp =
nullptr;
3615 unsigned D = diag::ext_return_has_expr;
3617 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3618 if (isa<CXXConstructorDecl>(CurDecl) ||
3619 isa<CXXDestructorDecl>(CurDecl))
3620 D = diag::err_ctor_dtor_returns_void;
3622 D = diag::ext_return_has_void_expr;
3626 Result = IgnoredValueConversions(Result.
get());
3629 RetValExp = Result.
get();
3630 RetValExp = ImpCastExprToType(RetValExp,
3631 Context.
VoidTy, CK_ToVoid).get();
3634 if (D == diag::err_ctor_dtor_returns_void) {
3635 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3637 << CurDecl->
getDeclName() << isa<CXXDestructorDecl>(CurDecl)
3641 else if (D != diag::ext_return_has_void_expr ||
3643 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3645 int FunctionKind = 0;
3646 if (isa<ObjCMethodDecl>(CurDecl))
3648 else if (isa<CXXConstructorDecl>(CurDecl))
3650 else if (isa<CXXDestructorDecl>(CurDecl))
3661 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3664 RetValExp = ER.
get();
3670 }
else if (!RetValExp && !HasDependentReturnType) {
3676 DiagID = diag::err_constexpr_return_missing_expr;
3678 }
else if (getLangOpts().
C99) {
3680 DiagID = diag::ext_return_missing_expr;
3683 DiagID = diag::warn_return_missing_expr;
3689 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1;
3694 assert(RetValExp || HasDependentReturnType);
3695 const VarDecl *NRVOCandidate =
nullptr;
3697 QualType RetType = RelatedRetType.
isNull() ? FnRetType : RelatedRetType;
3706 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3711 NRVOCandidate !=
nullptr);
3712 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3713 RetType, RetValExp);
3724 if (!RelatedRetType.
isNull()) {
3727 Res = PerformCopyInitialization(Entity, ReturnLoc, RetValExp);
3735 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc, isObjCMethod, Attrs,
3736 getCurFunctionDecl());
3741 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3744 RetValExp = ER.
get();
3752 FunctionScopes.back()->Returns.push_back(Result);
3754 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3755 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3764 VarDecl *Var = cast_or_null<VarDecl>(Parm);
3779 if (!getLangOpts().ObjCExceptions)
3780 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@try";
3782 setFunctionHasBranchProtectedScope();
3783 unsigned NumCatchStmts = CatchStmts.size();
3785 NumCatchStmts, Finally);
3790 ExprResult Result = DefaultLvalueConversion(Throw);
3794 Result = ActOnFinishFullExpr(Result.
get(),
false);
3797 Throw = Result.
get();
3805 return StmtError(
Diag(AtLoc, diag::err_objc_throw_expects_object)
3816 if (!getLangOpts().ObjCExceptions)
3817 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@throw";
3822 Scope *AtCatchParent = CurScope;
3824 AtCatchParent = AtCatchParent->
getParent();
3826 return StmtError(
Diag(AtLoc, diag::err_rethrow_used_outside_catch));
3828 return BuildObjCAtThrowStmt(AtLoc, Throw);
3833 ExprResult result = DefaultLvalueConversion(operand);
3836 operand = result.
get();
3844 if (getLangOpts().CPlusPlus) {
3845 if (RequireCompleteType(atLoc, type,
3846 diag::err_incomplete_receiver_type))
3847 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3850 ExprResult result = PerformContextuallyConvertToObjCPointer(operand);
3854 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3857 operand = result.
get();
3859 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3866 return ActOnFinishFullExpr(operand,
false);
3873 setFunctionHasBranchProtectedScope();
3881 Stmt *HandlerBlock) {
3883 return new (Context)
3884 CXXCatchStmt(CatchLoc, cast_or_null<VarDecl>(ExDecl), HandlerBlock);
3889 setFunctionHasBranchProtectedScope();
3894 class CatchHandlerType {
3896 unsigned IsPointer : 1;
3901 enum Unique { ForDenseMap };
3902 CatchHandlerType(
QualType QT, Unique) : QT(QT), IsPointer(
false) {}
3908 CatchHandlerType(
QualType Q) : QT(Q), IsPointer(
false) {
3920 CatchHandlerType(
QualType QT,
bool IsPointer)
3921 : QT(QT), IsPointer(IsPointer) {}
3923 QualType underlying()
const {
return QT; }
3924 bool isPointer()
const {
return IsPointer; }
3926 friend bool operator==(
const CatchHandlerType &LHS,
3927 const CatchHandlerType &RHS) {
3929 if (LHS.IsPointer != RHS.IsPointer)
3932 return LHS.QT == RHS.QT;
3941 CatchHandlerType::ForDenseMap);
3946 CatchHandlerType::ForDenseMap);
3954 const CatchHandlerType &RHS) {
3961 class CatchTypePublicBases {
3963 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &TypesToCheck;
3964 const bool CheckAgainstPointer;
3970 CatchTypePublicBases(
3972 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &T,
bool C)
3973 : Ctx(Ctx), TypesToCheck(T), CheckAgainstPointer(C),
3974 FoundHandler(
nullptr) {}
3976 CXXCatchStmt *getFoundHandler()
const {
return FoundHandler; }
3977 CanQualType getFoundHandlerType()
const {
return FoundHandlerType; }
3981 CatchHandlerType Check(S->
getType(), CheckAgainstPointer);
3982 const auto &M = TypesToCheck;
3983 auto I = M.find(Check);
3985 FoundHandler = I->second;
4000 if (!getLangOpts().CXXExceptions &&
4001 !getSourceManager().isInSystemHeader(TryLoc) &&
4002 (!getLangOpts().OpenMPIsDevice ||
4003 !getLangOpts().OpenMPHostCXXExceptions ||
4004 isInOpenMPTargetExecutionDirective() ||
4005 isInOpenMPDeclareTargetContext()))
4006 Diag(TryLoc, diag::err_exceptions_disabled) <<
"try";
4009 if (getLangOpts().CUDA)
4010 CUDADiagIfDeviceCode(TryLoc, diag::err_cuda_device_exceptions)
4011 <<
"try" << CurrentCUDATarget();
4013 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
4014 Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) <<
"try";
4020 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4024 const unsigned NumHandlers = Handlers.size();
4025 assert(!Handlers.empty() &&
4026 "The parser shouldn't call this if there are no handlers.");
4028 llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> HandledTypes;
4029 for (
unsigned i = 0; i < NumHandlers; ++i) {
4036 if (i < NumHandlers - 1)
4045 CatchHandlerType HandlerCHT =
4051 QualType Underlying = HandlerCHT.underlying();
4053 if (!RD->hasDefinition())
4062 CatchTypePublicBases CTPB(Context, HandledTypes, HandlerCHT.isPointer());
4063 if (RD->lookupInBases(CTPB, Paths)) {
4065 if (!Paths.
isAmbiguous(CTPB.getFoundHandlerType())) {
4067 diag::warn_exception_caught_by_earlier_handler)
4070 diag::note_previous_exception_handler)
4078 auto R = HandledTypes.insert(std::make_pair(H->
getCaughtType(), H));
4082 diag::warn_exception_caught_by_earlier_handler)
4085 diag::note_previous_exception_handler)
4097 assert(TryBlock && Handler);
4103 if (!getLangOpts().Borland) {
4105 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4121 Diag(TryLoc, diag::err_seh_try_outside_functions);
4125 Diag(TryLoc, diag::err_seh_try_unsupported);
4134 assert(FilterExpr && Block);
4138 diag::err_filter_expression_integral)
4146 CurrentSEHFinally.push_back(CurScope);
4150 CurrentSEHFinally.pop_back();
4155 CurrentSEHFinally.pop_back();
4161 Scope *SEHTryParent = CurScope;
4163 SEHTryParent = SEHTryParent->
getParent();
4165 return StmtError(
Diag(Loc, diag::err_ms___leave_not_in___try));
4178 QualifierLoc, NameInfo,
4179 cast<CompoundStmt>(Nested));
4188 return BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
4190 GetNameFromUnqualifiedId(Name),
4196 unsigned NumParams) {
4213 assert(NumParams > 0 &&
"CapturedStmt requires context parameter");
4224 if (Cap.isThisCapture()) {
4227 CaptureInits.push_back(Cap.getInitExpr());
4229 }
else if (Cap.isVLATypeCapture()) {
4232 CaptureInits.push_back(
nullptr);
4237 Cap.isReferenceCapture()
4240 Cap.getVariable()));
4241 CaptureInits.push_back(Cap.getInitExpr());
4247 unsigned NumParams) {
4249 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, NumParams);
4263 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4266 PushDeclContext(CurScope, CD);
4270 PushExpressionEvaluationContext(
4271 ExpressionEvaluationContext::PotentiallyEvaluated);
4278 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, Params.size());
4282 bool ContextIsFound =
false;
4283 unsigned ParamNum = 0;
4286 I != E; ++I, ++ParamNum) {
4287 if (I->second.isNull()) {
4288 assert(!ContextIsFound &&
4289 "null type has been found already for '__context' parameter");
4299 ContextIsFound =
true;
4309 assert(ContextIsFound &&
"no null type for '__context' parameter");
4310 if (!ContextIsFound) {
4321 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4324 PushDeclContext(CurScope, CD);
4328 PushExpressionEvaluationContext(
4329 ExpressionEvaluationContext::PotentiallyEvaluated);
4333 DiscardCleanupsInEvaluationContext();
4334 PopExpressionEvaluationContext();
4341 ActOnFields(
nullptr, Record->
getLocation(), Record, Fields,
4345 PopFunctionScopeInfo();
4359 getASTContext(), S, static_cast<CapturedRegionKind>(RSI->
CapRegionKind),
4360 Captures, CaptureInits, CD, RD);
4365 DiscardCleanupsInEvaluationContext();
4366 PopExpressionEvaluationContext();
4369 PopFunctionScopeInfo();
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 isCurCompoundStmtAStmtExpr() const
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 isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
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)
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
static unsigned getHashValue(const CatchHandlerType &Base)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
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.
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 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.
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
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 * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
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
FullExpr - Represents a "full-expression" node.
field_range fields() const
SourceLocation getBeginLoc() const LLVM_READONLY
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)
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)
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...
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD)
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...
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
IgnoreParenCasts - Ignore parentheses and casts.
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.
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)
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.
SourceLocation getBeginLoc() const
Get the begin source location.
Allows QualTypes to be sorted and hence used in maps and sets.
Retains information about a block that is currently being parsed.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Type source information for an attributed type.
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>.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
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.
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.
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 void buildCapturedStmtCaptureList(SmallVectorImpl< CapturedStmt::Capture > &Captures, SmallVectorImpl< Expr *> &CaptureInits, ArrayRef< sema::Capture > Candidates)
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.
TypeLoc IgnoreParens() const
SourceLocation getBeginLoc() const LLVM_READONLY
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
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)
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.
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
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 isKnownToHaveBooleanValue() const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
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.
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.
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
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
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.
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.
DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result, Optional< unsigned > DependentDeductionDepth=None)
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 markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
DeclStmt * getRangeStmt()
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
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.
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...
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.
bool HasImplicitReturnType
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.
__DEVICE__ int min(int __a, int __b)
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.
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)
void NoteCandidates(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...
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)
Attr - This represents one attribute.
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
IgnoreParens - Ignore parentheses.
QualType getType() const
Retrieves the type of the base class.