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(),
64 DiscardCleanupsInEvaluationContext();
69 bool HasLeadingEmptyMacro) {
70 return new (Context)
NullStmt(SemiLoc, HasLeadingEmptyMacro);
80 return new (Context)
DeclStmt(DG, StartLoc, EndLoc);
110 if (getLangOpts().ObjCAutoRefCount) {
135 if (!Op->isComparisonOp())
138 if (Op->getOpcode() == BO_EQ)
140 else if (Op->getOpcode() == BO_NE)
142 else if (Op->getOpcode() == BO_Cmp)
145 assert(Op->isRelationalOp());
148 Loc = Op->getOperatorLoc();
149 CanAssign = Op->getLHS()->IgnoreParenImpCasts()->isLValue();
151 switch (Op->getOperator()) {
155 case OO_ExclaimEqual:
160 case OO_GreaterEqual:
171 Loc = Op->getOperatorLoc();
172 CanAssign = Op->getArg(0)->IgnoreParenImpCasts()->isLValue();
183 S.
Diag(Loc, diag::warn_unused_comparison)
189 if (Kind == Inequality)
190 S.
Diag(Loc, diag::note_inequality_comparison_to_or_assign)
193 S.
Diag(Loc, diag::note_equality_comparison_to_assign)
202 return DiagnoseUnusedExprResult(
Label->getSubStmt());
204 const Expr *E = dyn_cast_or_null<Expr>(S);
210 if (isUnevaluatedContext())
219 bool ShouldSuppress =
220 SourceMgr.isMacroBodyExpansion(ExprLoc) ||
221 SourceMgr.isInSystemMacro(ExprLoc);
223 const Expr *WarnExpr;
226 if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context))
239 if (isa<ParenExpr>(E->IgnoreImpCasts()) && Loc.
isMacroID()) {
241 if (findMacroSpelling(SpellLoc,
"UNREFERENCED_PARAMETER"))
248 unsigned DiagID = diag::warn_unused_expr;
249 if (
const FullExpr *Temps = dyn_cast<FullExpr>(E))
250 E = Temps->getSubExpr();
252 E = TempExpr->getSubExpr();
258 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
259 if (E->getType()->isVoidType())
262 if (
const Attr *A = CE->getUnusedResultAttr(Context)) {
263 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
271 if (
const Decl *FD = CE->getCalleeDecl()) {
274 if (FD->hasAttr<PureAttr>()) {
275 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"pure";
278 if (FD->hasAttr<ConstAttr>()) {
279 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"const";
283 }
else if (ShouldSuppress)
287 if (getLangOpts().ObjCAutoRefCount && ME->isDelegateInitCall()) {
288 Diag(Loc, diag::err_arc_unused_init_message) << R1;
293 if (
const auto *A = MD->
getAttr<WarnUnusedResultAttr>()) {
294 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
299 const Expr *Source = POE->getSyntacticForm();
300 if (isa<ObjCSubscriptRefExpr>(Source))
301 DiagID = diag::warn_unused_container_subscript_expr;
303 DiagID = diag::warn_unused_property_expr;
305 = dyn_cast<CXXFunctionalCastExpr>(E)) {
306 const Expr *E = FC->getSubExpr();
308 E = TE->getSubExpr();
309 if (isa<CXXTemporaryObjectExpr>(E))
312 if (
const CXXRecordDecl *RD = CE->getType()->getAsCXXRecordDecl())
313 if (!RD->getAttr<WarnUnusedAttr>())
317 else if (
const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E)) {
325 Diag(Loc, diag::warn_unused_voidptr)
331 if (E->isGLValue() && E->getType().isVolatileQualified()) {
332 Diag(Loc, diag::warn_unused_volatile) << R1 << R2;
336 DiagRuntimeBehavior(Loc,
nullptr, PDiag(DiagID) << R1 << R2);
340 PushCompoundScope(IsStmtExpr);
348 return getCurFunction()->CompoundScopes.back();
353 const unsigned NumElts = Elts.size();
361 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
365 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
369 Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
374 for (
unsigned i = 0; i != NumElts; ++i) {
376 if (isStmtExpr && i == NumElts - 1)
379 DiagnoseUnusedExprResult(Elts[i]);
385 if (NumElts != 0 && !CurrentInstantiationScope &&
386 getCurCompoundScope().HasEmptyLoopBodies) {
387 for (
unsigned i = 0; i != NumElts - 1; ++i)
388 DiagnoseEmptyLoopBody(Elts[i], Elts[i + 1]);
399 if (DiagnoseUnexpandedParameterPack(Val.
get()))
404 if (!getCurFunction()->SwitchStack.empty()) {
406 getCurFunction()->SwitchStack.back().getPointer()->getCond();
411 auto CheckAndFinish = [&](
Expr *E) {
415 if (getLangOpts().CPlusPlus11) {
418 llvm::APSInt TempVal;
424 if (!E->isValueDependent())
425 ER = VerifyIntegerConstantExpression(E);
427 ER = DefaultLvalueConversion(ER.
get());
429 ER = ImpCastExprToType(ER.
get(), CondType, CK_IntegralCast);
433 ExprResult Converted = CorrectDelayedTyposInExpr(Val, CheckAndFinish);
434 if (Converted.
get() == Val.
get())
435 Converted = CheckAndFinish(Val.
get());
441 return ActOnFinishFullExpr(Val.
get(), Val.
get()->getExprLoc(),
false,
442 getLangOpts().CPlusPlus11);
449 assert((LHSVal.
isInvalid() || LHSVal.
get()) &&
"missing LHS value");
452 "missing RHS value");
454 if (getCurFunction()->SwitchStack.empty()) {
455 Diag(CaseLoc, diag::err_case_not_in_switch);
460 getCurFunction()->SwitchStack.back().setInt(
true);
466 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(CS);
472 DiagnoseUnusedExprResult(SubStmt);
473 cast<CaseStmt>(S)->setSubStmt(SubStmt);
479 DiagnoseUnusedExprResult(SubStmt);
481 if (getCurFunction()->SwitchStack.empty()) {
482 Diag(DefaultLoc, diag::err_default_not_in_switch);
487 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(DS);
496 Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->
getDeclName();
528 CommaVisitor(
Sema &SemaRef) : Inherited(SemaRef.
Context), SemaRef(SemaRef) {}
550 Expr *CondExpr = Cond.
get().second;
553 !Diags.isIgnored(diag::warn_comma_operator, CondExpr->
getExprLoc()))
554 CommaVisitor(*this).Visit(CondExpr);
557 DiagnoseEmptyStmtBody(CondExpr->
getEndLoc(), thenStmt,
558 diag::warn_empty_if_body);
560 return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
571 if (IsConstexpr || isa<ObjCAvailabilityCheckExpr>(Cond.
get().second))
572 setFunctionHasBranchProtectedScope();
574 DiagnoseUnusedExprResult(thenStmt);
575 DiagnoseUnusedExprResult(elseStmt);
578 Cond.
get().second, thenStmt, ElseLoc, elseStmt);
582 struct CaseCompareFunctor {
583 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
584 const llvm::APSInt &RHS) {
585 return LHS.first < RHS;
587 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
588 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
589 return LHS.first < RHS.first;
591 bool operator()(
const llvm::APSInt &LHS,
592 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
593 return LHS < RHS.first;
600 static bool CmpCaseVals(
const std::pair<llvm::APSInt, CaseStmt*>& lhs,
601 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
602 if (lhs.first < rhs.first)
605 if (lhs.first == rhs.first &&
606 lhs.second->getCaseLoc().getRawEncoding()
607 < rhs.second->getCaseLoc().getRawEncoding())
614 static bool CmpEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
615 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
617 return lhs.first < rhs.first;
622 static bool EqEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
623 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
625 return lhs.first == rhs.first;
631 if (
const auto *FE = dyn_cast<FullExpr>(E))
632 E = FE->getSubExpr();
633 while (
const auto *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
634 if (ImpCast->getCastKind() != CK_IntegralCast)
break;
635 E = ImpCast->getSubExpr();
645 SwitchConvertDiagnoser(
Expr *Cond)
651 return S.
Diag(Loc, diag::err_typecheck_statement_requires_integer) << T;
656 return S.
Diag(Loc, diag::err_switch_incomplete_class_type)
662 return S.
Diag(Loc, diag::err_switch_explicit_conversion) << T << ConvTy;
673 return S.
Diag(Loc, diag::err_switch_multiple_conversions) << T;
684 llvm_unreachable(
"conversion functions are permitted");
686 } SwitchDiagnoser(Cond);
689 PerformContextualImplicitConversion(SwitchLoc, Cond, SwitchDiagnoser);
695 Cond = CondResult.
get();
701 return UsualUnaryConversions(Cond);
706 Expr *CondExpr = Cond.
get().second;
707 assert((Cond.
isInvalid() || CondExpr) &&
"switch with no condition");
715 "invalid condition type");
720 Diag(SwitchLoc, diag::warn_bool_switch_condition)
725 setFunctionHasBranchIntoScope();
728 getCurFunction()->SwitchStack.push_back(
733 static void AdjustAPSInt(llvm::APSInt &Val,
unsigned BitWidth,
bool IsSigned) {
734 Val = Val.extOrTrunc(BitWidth);
735 Val.setIsSigned(IsSigned);
741 unsigned UnpromotedWidth,
bool UnpromotedSign) {
749 if (UnpromotedWidth < Val.getBitWidth()) {
750 llvm::APSInt ConvVal(Val);
752 AdjustAPSInt(ConvVal, Val.getBitWidth(), Val.isSigned());
757 S.
Diag(Loc, diag::warn_case_value_overflow) << Val.toString(10)
758 << ConvVal.toString(10);
768 const Expr *CaseExpr,
769 EnumValsTy::iterator &EI,
770 EnumValsTy::iterator &EIEnd,
771 const llvm::APSInt &Val) {
777 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
786 if (ED->
hasAttr<FlagEnumAttr>())
789 while (EI != EIEnd && EI->first < Val)
792 if (EI != EIEnd && EI->first == Val)
805 if (!CondEnumType || !CaseEnumType)
812 if (!CaseEnumType->getDecl()->getIdentifier() &&
813 !CaseEnumType->getDecl()->getTypedefNameForAnonDecl())
819 S.
Diag(Case->
getExprLoc(), diag::warn_comparison_of_mixed_enum_types_switch)
828 bool CaseListIsIncomplete = getCurFunction()->SwitchStack.back().getInt();
829 assert(SS == getCurFunction()->SwitchStack.back().getPointer() &&
830 "switch stack missing push/pop!");
832 getCurFunction()->SwitchStack.pop_back();
835 SS->
setBody(BodyStmt, SwitchLoc);
849 const Expr *CondExprBeforePromotion = CondExpr;
855 bool HasDependentValue
857 unsigned CondWidth = HasDependentValue ? 0 : Context.
getIntWidth(CondType);
864 unsigned CondWidthBeforePromotion
865 = HasDependentValue ? 0 : Context.
getIntWidth(CondTypeBeforePromotion);
866 bool CondIsSignedBeforePromotion
876 typedef std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRangesTy;
877 CaseRangesTy CaseRanges;
881 bool CaseListIsErroneous =
false;
887 if (TheDefaultStmt) {
888 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
895 CaseListIsErroneous =
true;
904 if (Lo->isValueDependent()) {
905 HasDependentValue =
true;
911 const Expr *LoBeforePromotion = Lo;
917 checkCaseValue(*
this, Lo->getBeginLoc(), LoVal, CondWidthBeforePromotion,
918 CondIsSignedBeforePromotion);
930 HasDependentValue =
true;
933 CaseRanges.push_back(std::make_pair(LoVal, CS));
935 CaseVals.push_back(std::make_pair(LoVal, CS));
939 if (!HasDependentValue) {
942 llvm::APSInt ConstantCondValue;
943 bool HasConstantCond =
false;
944 if (!HasDependentValue && !TheDefaultStmt) {
950 assert(!HasConstantCond ||
951 (ConstantCondValue.getBitWidth() == CondWidth &&
952 ConstantCondValue.isSigned() == CondIsSigned));
954 bool ShouldCheckConstantCond = HasConstantCond;
957 std::stable_sort(CaseVals.begin(), CaseVals.end(),
CmpCaseVals);
959 if (!CaseVals.empty()) {
960 for (
unsigned i = 0, e = CaseVals.size(); i != e; ++i) {
961 if (ShouldCheckConstantCond &&
962 CaseVals[i].first == ConstantCondValue)
963 ShouldCheckConstantCond =
false;
965 if (i != 0 && CaseVals[i].first == CaseVals[i-1].first) {
968 StringRef PrevString, CurrString;
971 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(PrevCase)) {
972 PrevString = DeclRef->getDecl()->getName();
974 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(CurrCase)) {
975 CurrString = DeclRef->getDecl()->getName();
978 CaseVals[i-1].first.toString(CaseValStr);
980 if (PrevString == CurrString)
981 Diag(CaseVals[i].second->getLHS()->getBeginLoc(),
982 diag::err_duplicate_case)
983 << (PrevString.empty() ? StringRef(CaseValStr) : PrevString);
985 Diag(CaseVals[i].second->getLHS()->getBeginLoc(),
986 diag::err_duplicate_case_differing_expr)
987 << (PrevString.empty() ? StringRef(CaseValStr) : PrevString)
988 << (CurrString.empty() ? StringRef(CaseValStr) : CurrString)
991 Diag(CaseVals[i - 1].second->getLHS()->getBeginLoc(),
992 diag::note_duplicate_case_prev);
995 CaseListIsErroneous =
true;
1002 if (!CaseRanges.empty()) {
1005 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
1008 std::vector<llvm::APSInt> HiVals;
1009 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1010 llvm::APSInt &LoVal = CaseRanges[i].first;
1011 CaseStmt *CR = CaseRanges[i].second;
1014 const Expr *HiBeforePromotion = Hi;
1021 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
1027 if (LoVal > HiVal) {
1030 CaseRanges.erase(CaseRanges.begin()+i);
1036 if (ShouldCheckConstantCond &&
1037 LoVal <= ConstantCondValue &&
1038 ConstantCondValue <= HiVal)
1039 ShouldCheckConstantCond =
false;
1041 HiVals.push_back(HiVal);
1047 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1048 llvm::APSInt &CRLo = CaseRanges[i].first;
1049 llvm::APSInt &CRHi = HiVals[i];
1050 CaseStmt *CR = CaseRanges[i].second;
1055 llvm::APSInt OverlapVal(32);
1059 CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(),
1060 CaseVals.end(), CRLo,
1061 CaseCompareFunctor());
1062 if (I != CaseVals.end() && I->first < CRHi) {
1063 OverlapVal = I->first;
1064 OverlapStmt = I->second;
1068 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
1069 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
1070 OverlapVal = (I-1)->first;
1071 OverlapStmt = (I-1)->second;
1076 if (i && CRLo <= HiVals[i-1]) {
1077 OverlapVal = HiVals[i-1];
1078 OverlapStmt = CaseRanges[i-1].second;
1084 << OverlapVal.toString(10);
1086 diag::note_duplicate_case_prev);
1089 CaseListIsErroneous =
true;
1095 if (!CaseListIsErroneous && !CaseListIsIncomplete &&
1096 ShouldCheckConstantCond) {
1099 Diag(CondExpr->
getExprLoc(), diag::warn_missing_case_for_condition)
1100 << ConstantCondValue.toString(10)
1112 if (!CaseListIsErroneous && !CaseListIsIncomplete && !HasConstantCond &&
1120 llvm::APSInt Val = EDI->getInitVal();
1122 EnumVals.push_back(std::make_pair(Val, EDI));
1124 std::stable_sort(EnumVals.begin(), EnumVals.end(),
CmpEnumVals);
1125 auto EI = EnumVals.begin(), EIEnd =
1126 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1129 for (CaseValsTy::const_iterator CI = CaseVals.begin();
1130 CI != CaseVals.end(); CI++) {
1131 Expr *CaseExpr = CI->second->getLHS();
1135 << CondTypeBeforePromotion;
1139 EI = EnumVals.begin();
1140 for (CaseRangesTy::const_iterator RI = CaseRanges.begin();
1141 RI != CaseRanges.end(); RI++) {
1142 Expr *CaseExpr = RI->second->getLHS();
1146 << CondTypeBeforePromotion;
1149 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1152 CaseExpr = RI->second->getRHS();
1156 << CondTypeBeforePromotion;
1160 auto CI = CaseVals.begin();
1161 auto RI = CaseRanges.begin();
1162 bool hasCasesNotInSwitch =
false;
1166 for (EI = EnumVals.begin(); EI != EIEnd; EI++) {
1168 switch (EI->second->getAvailability()) {
1182 while (CI != CaseVals.end() && CI->first < EI->first)
1185 if (CI != CaseVals.end() && CI->first == EI->first)
1189 for (; RI != CaseRanges.end(); RI++) {
1191 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1193 if (EI->first <= Hi)
1197 if (RI == CaseRanges.end() || EI->first < RI->first) {
1198 hasCasesNotInSwitch =
true;
1199 UnhandledNames.push_back(EI->second->getDeclName());
1203 if (TheDefaultStmt && UnhandledNames.empty() && ED->
isClosedNonFlag())
1207 if (!UnhandledNames.empty()) {
1209 TheDefaultStmt ? diag::warn_def_missing_case
1210 : diag::warn_missing_case)
1211 << (
int)UnhandledNames.size();
1213 for (
size_t I = 0, E =
std::min(UnhandledNames.size(), (
size_t)3);
1215 DB << UnhandledNames[I];
1218 if (!hasCasesNotInSwitch)
1224 DiagnoseEmptyStmtBody(CondExpr->
getEndLoc(), BodyStmt,
1225 diag::warn_empty_switch_body);
1229 if (CaseListIsErroneous)
1238 if (Diags.isIgnored(diag::warn_not_in_enum_assignment, SrcExpr->
getExprLoc()))
1252 const EnumDecl *ED = ET->getDecl();
1257 if (ED->
hasAttr<FlagEnumAttr>()) {
1258 if (!IsValueInFlagEnum(ED, RhsVal,
true))
1264 EnumValsTy EnumVals;
1269 llvm::APSInt Val = EDI->getInitVal();
1271 EnumVals.push_back(std::make_pair(Val, EDI));
1273 if (EnumVals.empty())
1275 std::stable_sort(EnumVals.begin(), EnumVals.end(),
CmpEnumVals);
1276 EnumValsTy::iterator EIend =
1277 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1280 EnumValsTy::const_iterator EI = EnumVals.begin();
1281 while (EI != EIend && EI->first < RhsVal)
1283 if (EI == EIend || EI->first != RhsVal) {
1297 auto CondVal = Cond.
get();
1298 CheckBreakContinueBinding(CondVal.second);
1300 if (CondVal.second &&
1301 !Diags.isIgnored(diag::warn_comma_operator, CondVal.second->getExprLoc()))
1302 CommaVisitor(*this).Visit(CondVal.second);
1304 DiagnoseUnusedExprResult(Body);
1306 if (isa<NullStmt>(Body))
1307 getCurCompoundScope().setHasEmptyLoopBodies();
1317 assert(Cond &&
"ActOnDoStmt(): missing expression");
1319 CheckBreakContinueBinding(Cond);
1320 ExprResult CondResult = CheckBooleanCondition(DoLoc, Cond);
1323 Cond = CondResult.
get();
1325 CondResult = ActOnFinishFullExpr(Cond, DoLoc);
1328 Cond = CondResult.
get();
1331 if (Cond && !getLangOpts().
C99 && !getLangOpts().
CPlusPlus &&
1332 !Diags.isIgnored(diag::warn_comma_operator, Cond->
getExprLoc()))
1333 CommaVisitor(*this).Visit(Cond);
1335 DiagnoseUnusedExprResult(Body);
1337 return new (Context)
DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen);
1342 using DeclSetVector =
1343 llvm::SetVector<VarDecl *, llvm::SmallVector<VarDecl *, 8>,
1344 llvm::SmallPtrSet<VarDecl *, 8>>;
1350 DeclSetVector &Decls;
1356 DeclExtractor(
Sema &S, DeclSetVector &Decls,
1363 bool isSimple() {
return Simple; }
1371 void VisitStmt(
Stmt *S) {
1432 DeclSetVector &Decls;
1438 DeclMatcher(
Sema &S, DeclSetVector &Decls,
Stmt *Statement) :
1439 Inherited(S.
Context), Decls(Decls), FoundDecl(
false) {
1440 if (!Statement)
return;
1464 void CheckLValueToRValueCast(
Expr *E) {
1467 if (isa<DeclRefExpr>(E)) {
1472 Visit(CO->getCond());
1473 CheckLValueToRValueCast(CO->getTrueExpr());
1474 CheckLValueToRValueCast(CO->getFalseExpr());
1479 dyn_cast<BinaryConditionalOperator>(E)) {
1480 CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr());
1481 CheckLValueToRValueCast(BCO->getFalseExpr());
1490 if (Decls.count(VD))
1498 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(S))
1500 Visit(OVE->getSourceExpr());
1506 bool FoundDeclInUse() {
return FoundDecl; }
1510 void CheckForLoopConditionalStatement(
Sema &S,
Expr *Second,
1513 if (!Second)
return;
1520 DeclSetVector Decls;
1522 DeclExtractor DE(S, Decls, Ranges);
1526 if (!DE.isSimple())
return;
1529 if (Decls.size() == 0)
return;
1532 for (
auto *VD : Decls)
1533 if (VD->getType().isVolatileQualified() || VD->hasGlobalStorage())
1536 if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
1537 DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
1538 DeclMatcher(S, Decls, Body).FoundDeclInUse())
1542 if (Decls.size() > 4) {
1545 PDiag << (unsigned)Decls.size();
1546 for (
auto *VD : Decls)
1547 PDiag << VD->getDeclName();
1550 for (
auto Range : Ranges)
1553 S.
Diag(Ranges.begin()->getBegin(), PDiag);
1558 bool ProcessIterationStmt(
Sema &S,
Stmt* Statement,
bool &Increment,
1560 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(Statement))
1561 if (!Cleanups->cleanupsHaveSideEffects())
1562 Statement = Cleanups->getSubExpr();
1564 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(Statement)) {
1565 switch (UO->getOpcode()) {
1566 default:
return false;
1584 default:
return false;
1604 bool InSwitch =
false;
1607 BreakContinueFinder(
Sema &S,
const Stmt* Body) :
1618 void VisitBreakStmt(
const BreakStmt* E) {
1638 void VisitForStmt(
const ForStmt *S) {
1645 void VisitWhileStmt(
const WhileStmt *) {
1650 void VisitDoStmt(
const DoStmt *) {
1677 bool ContinueFound() {
return ContinueLoc.
isValid(); }
1678 bool BreakFound() {
return BreakLoc.
isValid(); }
1689 void CheckForRedundantIteration(
Sema &S,
Expr *Third,
Stmt *Body) {
1691 if (!Body || !Third)
return;
1701 if (!LastStmt)
return;
1703 bool LoopIncrement, LastIncrement;
1706 if (!ProcessIterationStmt(S, Third, LoopIncrement, LoopDRE))
return;
1707 if (!ProcessIterationStmt(S, LastStmt, LastIncrement, LastDRE))
return;
1711 if (LoopIncrement != LastIncrement ||
1714 if (BreakContinueFinder(S, Body).ContinueFound())
return;
1717 << LastDRE->
getDecl() << LastIncrement;
1725 void Sema::CheckBreakContinueBinding(
Expr *E) {
1728 BreakContinueFinder BCFinder(*
this, E);
1730 if (BCFinder.BreakFound() && BreakParent) {
1732 Diag(BCFinder.GetBreakLoc(), diag::warn_break_binds_to_switch);
1734 Diag(BCFinder.GetBreakLoc(), diag::warn_loop_ctrl_binds_to_inner)
1737 }
else if (BCFinder.ContinueFound() && CurScope->getContinueParent()) {
1738 Diag(BCFinder.GetContinueLoc(), diag::warn_loop_ctrl_binds_to_inner)
1750 if (!getLangOpts().CPlusPlus) {
1751 if (
DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
1755 for (
auto *DI : DS->decls()) {
1760 Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
1761 DI->setInvalidDecl();
1767 CheckBreakContinueBinding(Second.
get().second);
1768 CheckBreakContinueBinding(third.
get());
1770 if (!Second.
get().first)
1771 CheckForLoopConditionalStatement(*
this, Second.
get().second, third.
get(),
1773 CheckForRedundantIteration(*
this, third.
get(), Body);
1775 if (Second.
get().second &&
1776 !Diags.isIgnored(diag::warn_comma_operator,
1777 Second.
get().second->getExprLoc()))
1778 CommaVisitor(*this).Visit(Second.
get().second);
1782 DiagnoseUnusedExprResult(First);
1783 DiagnoseUnusedExprResult(Third);
1784 DiagnoseUnusedExprResult(Body);
1786 if (isa<NullStmt>(Body))
1787 getCurCompoundScope().setHasEmptyLoopBodies();
1789 return new (Context)
1790 ForStmt(Context, First, Second.
get().second, Second.
get().first, Third,
1791 Body, ForLoc, LParenLoc, RParenLoc);
1816 ExprResult result = CorrectDelayedTyposInExpr(collection);
1819 collection = result.
get();
1825 result = DefaultFunctionArrayLvalueConversion(collection);
1828 collection = result.
get();
1835 return Diag(forLoc, diag::err_collection_expr_type)
1846 (getLangOpts().ObjCAutoRefCount
1847 ? RequireCompleteType(forLoc,
QualType(objectType, 0),
1848 diag::err_arc_collection_forward, collection)
1849 : !isCompleteType(forLoc,
QualType(objectType, 0)))) {
1852 }
else if (iface || !objectType->
qual_empty()) {
1854 &Context.
Idents.
get(
"countByEnumeratingWithState"),
1870 method = LookupMethodInQualifiedType(selector, pointerType,
1875 Diag(forLoc, diag::warn_collection_expr_type)
1890 setFunctionHasBranchProtectedScope();
1893 CheckObjCForCollectionOperand(ForLoc, collection);
1897 if (
DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
1898 if (!DS->isSingleDecl())
1900 diag::err_toomany_element_decls));
1912 diag::err_non_local_variable_decl_in_for));
1918 Expr *DeducedInit = &OpaqueId;
1921 DiagnoseAutoDeductionFailure(D, DeducedInit);
1922 if (FirstType.
isNull()) {
1929 if (!inTemplateInstantiation()) {
1932 Diag(Loc, diag::warn_auto_var_is_id)
1938 Expr *FirstE = cast<Expr>(First);
1944 FirstType =
static_cast<Expr*
>(First)->getType();
1946 Diag(ForLoc, diag::err_selector_element_const_type)
1952 return StmtError(
Diag(ForLoc, diag::err_selector_element_type)
1959 CollectionExprResult = ActOnFinishFullExpr(CollectionExprResult.
get());
1964 nullptr, ForLoc, RParenLoc);
2018 void NoteForRangeBeginEndFunction(
Sema &SemaRef,
Expr *E,
2028 std::string Description;
2029 bool IsTemplate =
false;
2036 SemaRef.
Diag(Loc, diag::note_for_range_begin_end)
2037 << BEF << IsTemplate << Description << E->
getType();
2088 return Diag(InitStmt->
getBeginLoc(), diag::err_objc_for_range_init_stmt)
2090 return ActOnObjCForCollectionStmt(ForLoc, First, Range, RParenLoc);
2094 assert(DS &&
"first part of for range not a decl stmt");
2103 DiagnoseUnexpandedParameterPack(Range, UPPC_Expression)) {
2111 if (!ActOnCoroutineBodyStart(S, CoawaitLoc,
"co_await"))
2117 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2119 VarDecl *RangeVar = BuildForRangeVarDecl(*
this, RangeLoc,
2121 std::string(
"__range") + DepthStr);
2123 diag::err_for_range_deduction_failure)) {
2131 StmtResult RangeDecl = ActOnDeclStmt(RangeGroup, RangeLoc, RangeLoc);
2137 return BuildCXXForRangeStmt(
2138 ForLoc, CoawaitLoc, InitStmt, ColonLoc, RangeDecl.
get(),
2140 nullptr,
nullptr, DS, RParenLoc,
Kind);
2167 auto BuildBegin = [&] {
2171 BeginMemberLookup, CandidateSet,
2172 BeginRange, BeginExpr);
2177 << ColonLoc << BEF_begin << BeginRange->
getType();
2190 diag::err_for_range_iter_deduction_failure)) {
2191 NoteForRangeBeginEndFunction(SemaRef, BeginExpr->
get(), *BEF);
2197 auto BuildEnd = [&] {
2201 EndMemberLookup, CandidateSet,
2206 << ColonLoc << BEF_end << EndRange->
getType();
2210 diag::err_for_range_iter_deduction_failure)) {
2211 NoteForRangeBeginEndFunction(SemaRef, EndExpr->
get(), *BEF);
2224 if (BeginMemberLookup.isAmbiguous())
2231 if (BeginMemberLookup.empty() != EndMemberLookup.
empty()) {
2236 auto BuildNonmember = [&](
2238 llvm::function_ref<Sema::ForRangeStatus()> BuildFound,
2239 llvm::function_ref<Sema::ForRangeStatus()> BuildNotFound) {
2246 switch (BuildFound()) {
2252 << BeginRange->
getType() << BEFFound;
2258 SemaRef.
Diag(D->getLocation(),
2259 diag::note_for_range_member_begin_end_ignored)
2260 << BeginRange->
getType() << BEFFound;
2264 llvm_unreachable(
"unexpected ForRangeStatus");
2266 if (BeginMemberLookup.empty())
2267 return BuildNonmember(BEF_end, EndMemberLookup, BuildEnd, BuildBegin);
2268 return BuildNonmember(BEF_begin, BeginMemberLookup, BuildBegin, BuildEnd);
2300 AdjustedRange = SemaRef.
BuildUnaryOp(S, RangeLoc, UO_Deref, Range);
2305 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2314 SemaRef.
Diag(RangeLoc, diag::err_for_range_dereference)
2317 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2323 struct InvalidateOnErrorScope {
2324 InvalidateOnErrorScope(
Sema &SemaRef,
Decl *D,
bool Enabled)
2325 : Trap(SemaRef.
Diags), D(D), Enabled(Enabled) {}
2326 ~InvalidateOnErrorScope() {
2327 if (Enabled && Trap.hasErrorOccurred())
2354 Scope *S = getCurScope();
2356 DeclStmt *RangeDS = cast<DeclStmt>(RangeDecl);
2358 QualType RangeVarType = RangeVar->getType();
2360 DeclStmt *LoopVarDS = cast<DeclStmt>(LoopVarDecl);
2365 InvalidateOnErrorScope Invalidate(*
this, LoopVar,
2366 LoopVar->getType()->isUndeducedType());
2372 if (RangeVarType->isDependentType()) {
2374 RangeVar->markUsed(Context);
2378 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2379 if (
auto *DD = dyn_cast<DecompositionDecl>(LoopVar))
2380 for (
auto *Binding : DD->bindings())
2382 LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.
DependentTy));
2384 }
else if (!BeginDeclStmt.get()) {
2389 ExprResult BeginRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2394 ExprResult EndRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2400 Expr *Range = RangeVar->getInit();
2405 if (RequireCompleteType(RangeLoc, RangeType,
2406 diag::err_for_range_incomplete_type))
2411 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2412 VarDecl *BeginVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2413 std::string(
"__begin") + DepthStr);
2414 VarDecl *EndVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2415 std::string(
"__end") + DepthStr);
2426 BeginExpr = BeginRangeRef;
2428 BeginExpr = ActOnCoawaitExpr(S, ColonLoc, BeginExpr.
get());
2433 diag::err_for_range_iter_deduction_failure)) {
2434 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2444 dyn_cast<VariableArrayType>(UnqAT)) {
2467 ExprResult SizeOfVLAExprR = ActOnUnaryExprOrTypeTraitExpr(
2471 VAT->desugar(), RangeLoc))
2477 ExprResult SizeOfEachElementExprR = ActOnUnaryExprOrTypeTraitExpr(
2480 CreateParsedType(VAT->desugar(),
2482 VAT->getElementType(), RangeLoc))
2490 SizeOfVLAExprR.
get(), SizeOfEachElementExprR.
get());
2497 llvm_unreachable(
"Unexpected array type in for-range");
2501 EndExpr = ActOnBinOp(S, ColonLoc, tok::plus, EndRangeRef.
get(),
2506 diag::err_for_range_iter_deduction_failure)) {
2507 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2515 *
this, BeginRangeRef.
get(), EndRangeRef.
get(), RangeType, BeginVar,
2516 EndVar,
ColonLoc, CoawaitLoc, &CandidateSet, &BeginExpr, &EndExpr,
2519 if (Kind == BFRK_Build && RangeStatus == FRS_NoViableFunction &&
2520 BEFFailure == BEF_begin) {
2523 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Range)) {
2524 if (
ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
2525 QualType ArrayTy = PVD->getOriginalType();
2526 QualType PointerTy = PVD->getType();
2529 << RangeLoc << PVD << ArrayTy << PointerTy;
2530 Diag(PVD->getLocation(), diag::note_declared_at);
2539 CoawaitLoc, InitStmt,
2540 LoopVarDecl, ColonLoc,
2548 if (RangeStatus == FRS_NoViableFunction) {
2549 Expr *Range = BEFFailure ? EndRangeRef.
get() : BeginRangeRef.
get();
2551 << RangeLoc << Range->
getType() << BEFFailure;
2555 if (RangeStatus != FRS_Success)
2560 "invalid range expression in for loop");
2564 QualType BeginType = BeginVar->getType(), EndType = EndVar->
getType();
2567 ? diag::warn_for_range_begin_end_types_differ
2568 : diag::ext_for_range_begin_end_types_differ)
2569 << BeginType << EndType;
2570 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2571 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2575 ActOnDeclStmt(ConvertDeclToDeclGroup(BeginVar), ColonLoc, ColonLoc);
2577 ActOnDeclStmt(ConvertDeclToDeclGroup(EndVar), ColonLoc, ColonLoc);
2580 ExprResult BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2585 ExprResult EndRef = BuildDeclRefExpr(EndVar, EndType.getNonReferenceType(),
2591 NotEqExpr = ActOnBinOp(S, ColonLoc, tok::exclaimequal,
2592 BeginRef.
get(), EndRef.
get());
2594 NotEqExpr = CheckBooleanCondition(ColonLoc, NotEqExpr.
get());
2596 NotEqExpr = ActOnFinishFullExpr(NotEqExpr.
get());
2598 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2599 << RangeLoc << 0 << BeginRangeRef.
get()->getType();
2600 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2602 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2607 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2612 IncrExpr = ActOnUnaryOp(S, ColonLoc, tok::plusplus, BeginRef.
get());
2613 if (!IncrExpr.isInvalid() && CoawaitLoc.
isValid())
2617 IncrExpr = ActOnCoawaitExpr(S, CoawaitLoc, IncrExpr.get());
2618 if (!IncrExpr.isInvalid())
2619 IncrExpr = ActOnFinishFullExpr(IncrExpr.get());
2620 if (IncrExpr.isInvalid()) {
2621 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2622 << RangeLoc << 2 << BeginRangeRef.
get()->getType() ;
2623 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2628 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2633 ExprResult DerefExpr = ActOnUnaryOp(S, ColonLoc, tok::star, BeginRef.
get());
2635 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2636 << RangeLoc << 1 << BeginRangeRef.
get()->getType();
2637 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2643 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2644 AddInitializerToDecl(LoopVar, DerefExpr.
get(),
false);
2645 if (LoopVar->isInvalidDecl())
2646 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2652 if (Kind == BFRK_Check)
2656 InitStmt, RangeDS, cast_or_null<DeclStmt>(BeginDeclStmt.get()),
2657 cast_or_null<DeclStmt>(EndDeclStmt.
get()), NotEqExpr.
get(),
2658 IncrExpr.get(), LoopVarDS,
nullptr, ForLoc, CoawaitLoc,
2689 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(InitExpr))
2690 if (!Cleanups->cleanupsHaveSideEffects())
2691 InitExpr = Cleanups->getSubExpr();
2704 while (!isa<CXXOperatorCallExpr>(E) && !isa<UnaryOperator>(E)) {
2708 const MemberExpr *ME = cast<MemberExpr>(Call->getCallee());
2717 bool ReturnsReference =
false;
2718 if (isa<UnaryOperator>(E)) {
2719 ReturnsReference =
true;
2723 QualType ReturnType = FD->getReturnType();
2727 if (ReturnsReference) {
2731 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_const_reference_copy)
2732 << VD << VariableType << E->
getType();
2742 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_variable_always_copy)
2743 << VD << RangeInitType;
2763 if (!CE->getConstructor()->isCopyConstructor())
2765 }
else if (
const CastExpr *CE = dyn_cast<CastExpr>(InitExpr)) {
2766 if (CE->getCastKind() != CK_LValueToRValue)
2781 << VD << VariableType << InitExpr->
getType();
2797 if (SemaRef.
Diags.
isIgnored(diag::warn_for_range_const_reference_copy,
2799 SemaRef.
Diags.
isIgnored(diag::warn_for_range_variable_always_copy,
2835 if (isa<ObjCForCollectionStmt>(S))
2836 return FinishObjCForCollectionStmt(S, B);
2842 diag::warn_empty_range_based_for_body);
2852 setFunctionHasBranchIntoScope();
2854 return new (Context)
GotoStmt(TheDecl, GotoLoc, LabelLoc);
2866 CheckSingleAssignmentConstraints(DestTy, ExprRes);
2870 if (DiagnoseAssignmentResult(ConvTy, StarLoc, DestTy, ETy, E, AA_Passing))
2879 setFunctionHasIndirectGoto();
2885 const Scope &DestScope) {
2888 S.
Diag(Loc, diag::warn_jump_out_of_seh_finally);
2897 return StmtError(
Diag(ContinueLoc, diag::err_continue_not_in_loop));
2909 return StmtError(
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
2912 return StmtError(
Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt)
2916 return new (Context)
BreakStmt(BreakLoc);
2949 if (isCopyElisionCandidate(ReturnType, VD, CESK))
2964 if (!(CESK & CES_AllowDifferentTypes) && !VDType->
isDependentType() &&
2970 if (VD->
getKind() != Decl::Var &&
2971 !((CESK & CES_AllowParameters) && VD->
getKind() == Decl::ParmVar))
2982 if (VD->
hasAttr<BlocksAttr>())
return false;
2984 if (CESK & CES_AllowDifferentTypes)
3020 bool ConvertingConstructorsOnly,
3025 Expr *InitExpr = &AsRvalue;
3028 Value->getBeginLoc(), Value->getBeginLoc());
3041 if (ConvertingConstructorsOnly) {
3042 if (isa<CXXConstructorDecl>(FD)) {
3060 if (isa<CXXConstructorDecl>(FD)) {
3066 }
else if (isa<CXXMethodDecl>(FD)) {
3069 if (cast<CXXMethodDecl>(FD)->getRefQualifier() !=
RQ_RValue)
3083 Res = Seq.Perform(S, Entity, Kind, Value);
3111 bool AffectedByCWG1579 =
false;
3113 if (!NRVOCandidate) {
3114 NRVOCandidate = getCopyElisionCandidate(ResultType, Value, CES_Default);
3115 if (NRVOCandidate &&
3116 !getDiagnostics().isIgnored(diag::warn_return_std_move_in_cxx11,
3118 const VarDecl *NRVOCandidateInCXX11 =
3119 getCopyElisionCandidate(ResultType, Value, CES_FormerDefault);
3120 AffectedByCWG1579 = (!NRVOCandidateInCXX11);
3124 if (NRVOCandidate) {
3129 if (!Res.
isInvalid() && AffectedByCWG1579) {
3141 assert(!ResultType.
isNull());
3143 Str +=
"std::move(";
3148 << NRVOCandidate->
getDeclName() << ResultType << QT;
3153 !getDiagnostics().isIgnored(diag::warn_return_std_move,
3155 const VarDecl *FakeNRVOCandidate =
3156 getCopyElisionCandidate(
QualType(), Value, CES_AsIfByStdMove);
3157 if (FakeNRVOCandidate) {
3171 FakeValue,
false, FakeRes);
3176 Str +=
"std::move(";
3217 bool HasDeducedReturnType =
3220 if (ExprEvalContexts.back().Context ==
3221 ExpressionEvaluationContext::DiscardedStatement &&
3224 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3227 RetValExp = ER.
get();
3233 if (HasDeducedReturnType) {
3241 assert(AT &&
"lost auto type from lambda return type");
3242 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3252 if (RetValExp && !isa<InitListExpr>(RetValExp)) {
3253 ExprResult Result = DefaultFunctionArrayLvalueConversion(RetValExp);
3256 RetValExp = Result.
get();
3262 if (!CurContext->isDependentContext())
3271 Diag(ReturnLoc, diag::err_lambda_return_init_list)
3275 FnRetType = Context.
VoidTy;
3283 assert(!FnRetType.isNull());
3285 if (
BlockScopeInfo *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
3287 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr);
3291 dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
3292 Diag(ReturnLoc, diag::err_return_in_captured_stmt) << CurRegion->getRegionName();
3295 assert(CurLambda &&
"unknown kind of captured scope");
3297 ->getNoReturnAttr()) {
3298 Diag(ReturnLoc, diag::err_noreturn_lambda_has_return_expr);
3306 const VarDecl *NRVOCandidate =
nullptr;
3307 if (FnRetType->isDependentType()) {
3310 }
else if (FnRetType->isVoidType()) {
3311 if (RetValExp && !isa<InitListExpr>(RetValExp) &&
3312 !(getLangOpts().CPlusPlus &&
3315 if (!getLangOpts().CPlusPlus &&
3317 Diag(ReturnLoc, diag::ext_return_has_void_expr) <<
"literal" << 2;
3319 Diag(ReturnLoc, diag::err_return_block_has_expr);
3320 RetValExp =
nullptr;
3323 }
else if (!RetValExp) {
3324 return StmtError(
Diag(ReturnLoc, diag::err_block_return_missing_expr));
3334 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3337 NRVOCandidate !=
nullptr);
3338 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3339 FnRetType, RetValExp);
3344 RetValExp = Res.
get();
3345 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc);
3347 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3351 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3354 RetValExp = ER.
get();
3363 FunctionScopes.back()->Returns.push_back(Result);
3365 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3366 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3384 class LocalTypedefNameReferencer
3387 LocalTypedefNameReferencer(
Sema &S) : S(S) {}
3392 bool LocalTypedefNameReferencer::VisitRecordType(
const RecordType *RT) {
3394 if (!R || !R->isLocalClass() || !R->isLocalClass()->isExternallyVisible() ||
3395 R->isDependentType())
3397 for (
auto *TmpD : R->decls())
3398 if (
auto *T = dyn_cast<TypedefNameDecl>(TmpD))
3399 if (T->getAccess() !=
AS_private || R->hasFriends())
3424 TypeLoc OrigResultType = getReturnTypeLoc(FD);
3427 if (RetExpr && isa<InitListExpr>(RetExpr)) {
3431 getCurLambda() ? diag::err_lambda_return_init_list
3432 : diag::err_auto_fn_return_init_list)
3442 assert(AT->
isDeduced() &&
"should have deduced to dependent type");
3455 if (DAR != DAR_Succeeded)
3460 LocalTypedefNameReferencer Referencer(*
this);
3461 Referencer.TraverseType(RetExpr->
getType());
3469 Diag(ReturnLoc, diag::err_auto_fn_return_void_but_not_auto)
3474 Deduced = SubstAutoType(OrigResultType.
getType(), Context.
VoidTy);
3498 Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible)
3502 Diag(ReturnLoc, diag::err_auto_fn_different_deductions)
3519 StmtResult R = BuildReturnStmt(ReturnLoc, RetValExp);
3520 if (R.
isInvalid() || ExprEvalContexts.back().Context ==
3521 ExpressionEvaluationContext::DiscardedStatement)
3525 const_cast<VarDecl*>(cast<ReturnStmt>(R.
get())->getNRVOCandidate())) {
3538 if (RetValExp && DiagnoseUnexpandedParameterPack(RetValExp))
3541 if (isa<CapturingScopeInfo>(getCurFunction()))
3542 return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp);
3546 const AttrVec *Attrs =
nullptr;
3547 bool isObjCMethod =
false;
3550 FnRetType = FD->getReturnType();
3552 Attrs = &FD->getAttrs();
3553 if (FD->isNoReturn())
3554 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
3555 << FD->getDeclName();
3556 if (FD->isMain() && RetValExp)
3557 if (isa<CXXBoolLiteralExpr>(RetValExp))
3558 Diag(ReturnLoc, diag::warn_main_returns_bool_literal)
3561 FnRetType = MD->getReturnType();
3562 isObjCMethod =
true;
3564 Attrs = &MD->getAttrs();
3565 if (MD->hasRelatedResultType() && MD->getClassInterface()) {
3577 if (ExprEvalContexts.back().Context ==
3578 ExpressionEvaluationContext::DiscardedStatement &&
3581 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3584 RetValExp = ER.
get();
3595 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3609 if (isa<InitListExpr>(RetValExp)) {
3613 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3614 int FunctionKind = 0;
3615 if (isa<ObjCMethodDecl>(CurDecl))
3617 else if (isa<CXXConstructorDecl>(CurDecl))
3619 else if (isa<CXXDestructorDecl>(CurDecl))
3622 Diag(ReturnLoc, diag::err_return_init_list)
3627 RetValExp =
nullptr;
3630 unsigned D = diag::ext_return_has_expr;
3632 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3633 if (isa<CXXConstructorDecl>(CurDecl) ||
3634 isa<CXXDestructorDecl>(CurDecl))
3635 D = diag::err_ctor_dtor_returns_void;
3637 D = diag::ext_return_has_void_expr;
3641 Result = IgnoredValueConversions(Result.
get());
3644 RetValExp = Result.
get();
3645 RetValExp = ImpCastExprToType(RetValExp,
3646 Context.
VoidTy, CK_ToVoid).get();
3649 if (D == diag::err_ctor_dtor_returns_void) {
3650 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3652 << CurDecl->
getDeclName() << isa<CXXDestructorDecl>(CurDecl)
3656 else if (D != diag::ext_return_has_void_expr ||
3658 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3660 int FunctionKind = 0;
3661 if (isa<ObjCMethodDecl>(CurDecl))
3663 else if (isa<CXXConstructorDecl>(CurDecl))
3665 else if (isa<CXXDestructorDecl>(CurDecl))
3675 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3678 RetValExp = ER.
get();
3684 }
else if (!RetValExp && !HasDependentReturnType) {
3690 DiagID = diag::err_constexpr_return_missing_expr;
3692 }
else if (getLangOpts().
C99) {
3694 DiagID = diag::ext_return_missing_expr;
3697 DiagID = diag::warn_return_missing_expr;
3703 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1;
3708 assert(RetValExp || HasDependentReturnType);
3709 const VarDecl *NRVOCandidate =
nullptr;
3711 QualType RetType = RelatedRetType.
isNull() ? FnRetType : RelatedRetType;
3720 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3725 NRVOCandidate !=
nullptr);
3726 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3727 RetType, RetValExp);
3738 if (!RelatedRetType.
isNull()) {
3741 Res = PerformCopyInitialization(Entity, ReturnLoc, RetValExp);
3749 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc, isObjCMethod, Attrs,
3750 getCurFunctionDecl());
3754 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3757 RetValExp = ER.
get();
3765 FunctionScopes.back()->Returns.push_back(Result);
3767 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3768 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3777 VarDecl *Var = cast_or_null<VarDecl>(Parm);
3792 if (!getLangOpts().ObjCExceptions)
3793 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@try";
3795 setFunctionHasBranchProtectedScope();
3796 unsigned NumCatchStmts = CatchStmts.size();
3798 NumCatchStmts, Finally);
3803 ExprResult Result = DefaultLvalueConversion(Throw);
3807 Result = ActOnFinishFullExpr(Result.
get());
3810 Throw = Result.
get();
3818 return StmtError(
Diag(AtLoc, diag::err_objc_throw_expects_object)
3829 if (!getLangOpts().ObjCExceptions)
3830 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@throw";
3835 Scope *AtCatchParent = CurScope;
3837 AtCatchParent = AtCatchParent->
getParent();
3839 return StmtError(
Diag(AtLoc, diag::err_rethrow_used_outside_catch));
3841 return BuildObjCAtThrowStmt(AtLoc, Throw);
3846 ExprResult result = DefaultLvalueConversion(operand);
3849 operand = result.
get();
3857 if (getLangOpts().CPlusPlus) {
3858 if (RequireCompleteType(atLoc, type,
3859 diag::err_incomplete_receiver_type))
3860 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3863 ExprResult result = PerformContextuallyConvertToObjCPointer(operand);
3867 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3870 operand = result.
get();
3872 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3879 return ActOnFinishFullExpr(operand);
3886 setFunctionHasBranchProtectedScope();
3894 Stmt *HandlerBlock) {
3896 return new (Context)
3897 CXXCatchStmt(CatchLoc, cast_or_null<VarDecl>(ExDecl), HandlerBlock);
3902 setFunctionHasBranchProtectedScope();
3907 class CatchHandlerType {
3909 unsigned IsPointer : 1;
3914 enum Unique { ForDenseMap };
3915 CatchHandlerType(
QualType QT, Unique) : QT(QT), IsPointer(
false) {}
3921 CatchHandlerType(
QualType Q) : QT(Q), IsPointer(
false) {
3933 CatchHandlerType(
QualType QT,
bool IsPointer)
3934 : QT(QT), IsPointer(IsPointer) {}
3936 QualType underlying()
const {
return QT; }
3937 bool isPointer()
const {
return IsPointer; }
3939 friend bool operator==(
const CatchHandlerType &LHS,
3940 const CatchHandlerType &RHS) {
3942 if (LHS.IsPointer != RHS.IsPointer)
3945 return LHS.QT == RHS.QT;
3954 CatchHandlerType::ForDenseMap);
3959 CatchHandlerType::ForDenseMap);
3967 const CatchHandlerType &RHS) {
3974 class CatchTypePublicBases {
3976 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &TypesToCheck;
3977 const bool CheckAgainstPointer;
3983 CatchTypePublicBases(
3985 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &T,
bool C)
3986 : Ctx(Ctx), TypesToCheck(T), CheckAgainstPointer(C),
3987 FoundHandler(
nullptr) {}
3989 CXXCatchStmt *getFoundHandler()
const {
return FoundHandler; }
3990 CanQualType getFoundHandlerType()
const {
return FoundHandlerType; }
3994 CatchHandlerType Check(S->
getType(), CheckAgainstPointer);
3995 const auto &M = TypesToCheck;
3996 auto I = M.find(Check);
3998 FoundHandler = I->second;
4013 if (!getLangOpts().CXXExceptions &&
4014 !getSourceManager().isInSystemHeader(TryLoc) &&
4015 (!getLangOpts().OpenMPIsDevice ||
4016 !getLangOpts().OpenMPHostCXXExceptions ||
4017 isInOpenMPTargetExecutionDirective() ||
4018 isInOpenMPDeclareTargetContext()))
4019 Diag(TryLoc, diag::err_exceptions_disabled) <<
"try";
4022 if (getLangOpts().CUDA)
4023 CUDADiagIfDeviceCode(TryLoc, diag::err_cuda_device_exceptions)
4024 <<
"try" << CurrentCUDATarget();
4026 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
4027 Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) <<
"try";
4033 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4037 const unsigned NumHandlers = Handlers.size();
4038 assert(!Handlers.empty() &&
4039 "The parser shouldn't call this if there are no handlers.");
4041 llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> HandledTypes;
4042 for (
unsigned i = 0; i < NumHandlers; ++i) {
4049 if (i < NumHandlers - 1)
4058 CatchHandlerType HandlerCHT =
4064 QualType Underlying = HandlerCHT.underlying();
4066 if (!RD->hasDefinition())
4075 CatchTypePublicBases CTPB(Context, HandledTypes, HandlerCHT.isPointer());
4076 if (RD->lookupInBases(CTPB, Paths)) {
4078 if (!Paths.
isAmbiguous(CTPB.getFoundHandlerType())) {
4080 diag::warn_exception_caught_by_earlier_handler)
4083 diag::note_previous_exception_handler)
4091 auto R = HandledTypes.insert(std::make_pair(H->
getCaughtType(), H));
4095 diag::warn_exception_caught_by_earlier_handler)
4098 diag::note_previous_exception_handler)
4110 assert(TryBlock && Handler);
4116 if (!getLangOpts().Borland) {
4118 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4134 Diag(TryLoc, diag::err_seh_try_outside_functions);
4138 Diag(TryLoc, diag::err_seh_try_unsupported);
4147 assert(FilterExpr && Block);
4151 diag::err_filter_expression_integral)
4159 CurrentSEHFinally.push_back(CurScope);
4163 CurrentSEHFinally.pop_back();
4168 CurrentSEHFinally.pop_back();
4174 Scope *SEHTryParent = CurScope;
4176 SEHTryParent = SEHTryParent->
getParent();
4178 return StmtError(
Diag(Loc, diag::err_ms___leave_not_in___try));
4191 QualifierLoc, NameInfo,
4192 cast<CompoundStmt>(Nested));
4201 return BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
4203 GetNameFromUnqualifiedId(Name),
4209 unsigned NumParams) {
4226 assert(NumParams > 0 &&
"CapturedStmt requires context parameter");
4237 if (Cap.isThisCapture()) {
4240 CaptureInits.push_back(Cap.getInitExpr());
4242 }
else if (Cap.isVLATypeCapture()) {
4245 CaptureInits.push_back(
nullptr);
4250 Cap.isReferenceCapture()
4253 Cap.getVariable()));
4254 CaptureInits.push_back(Cap.getInitExpr());
4260 unsigned NumParams) {
4262 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, NumParams);
4276 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4279 PushDeclContext(CurScope, CD);
4283 PushExpressionEvaluationContext(
4284 ExpressionEvaluationContext::PotentiallyEvaluated);
4291 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, Params.size());
4295 bool ContextIsFound =
false;
4296 unsigned ParamNum = 0;
4299 I != E; ++I, ++ParamNum) {
4300 if (I->second.isNull()) {
4301 assert(!ContextIsFound &&
4302 "null type has been found already for '__context' parameter");
4312 ContextIsFound =
true;
4322 assert(ContextIsFound &&
"no null type for '__context' parameter");
4323 if (!ContextIsFound) {
4334 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4337 PushDeclContext(CurScope, CD);
4341 PushExpressionEvaluationContext(
4342 ExpressionEvaluationContext::PotentiallyEvaluated);
4346 DiscardCleanupsInEvaluationContext();
4347 PopExpressionEvaluationContext();
4354 ActOnFields(
nullptr, Record->
getLocation(), Record, Fields,
4358 PopFunctionScopeInfo();
4372 getASTContext(), S, static_cast<CapturedRegionKind>(RSI->
CapRegionKind),
4373 Captures, CaptureInits, CD, RD);
4378 DiscardCleanupsInEvaluationContext();
4379 PopExpressionEvaluationContext();
4382 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.
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.
StmtResult ActOnExprStmt(ExprResult Arg)
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...
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.