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;
250 E = Temps->getSubExpr();
252 E = TempExpr->getSubExpr();
258 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
259 if (E->getType()->isVoidType())
266 if (
const Decl *FD = CE->getCalleeDecl()) {
267 if (
const Attr *A = isa<FunctionDecl>(FD)
268 ? cast<FunctionDecl>(FD)->getUnusedResultAttr()
269 : FD->getAttr<WarnUnusedResultAttr>()) {
270 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
275 if (FD->hasAttr<PureAttr>()) {
276 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"pure";
279 if (FD->hasAttr<ConstAttr>()) {
280 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"const";
284 }
else if (ShouldSuppress)
288 if (getLangOpts().ObjCAutoRefCount && ME->isDelegateInitCall()) {
289 Diag(Loc, diag::err_arc_unused_init_message) << R1;
294 if (
const auto *A = MD->
getAttr<WarnUnusedResultAttr>()) {
295 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
300 const Expr *Source = POE->getSyntacticForm();
301 if (isa<ObjCSubscriptRefExpr>(Source))
302 DiagID = diag::warn_unused_container_subscript_expr;
304 DiagID = diag::warn_unused_property_expr;
306 = dyn_cast<CXXFunctionalCastExpr>(E)) {
307 const Expr *E = FC->getSubExpr();
309 E = TE->getSubExpr();
310 if (isa<CXXTemporaryObjectExpr>(E))
313 if (
const CXXRecordDecl *RD = CE->getType()->getAsCXXRecordDecl())
314 if (!RD->getAttr<WarnUnusedAttr>())
318 else if (
const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E)) {
326 Diag(Loc, diag::warn_unused_voidptr)
332 if (E->isGLValue() && E->getType().isVolatileQualified()) {
333 Diag(Loc, diag::warn_unused_volatile) << R1 << R2;
337 DiagRuntimeBehavior(Loc,
nullptr, PDiag(DiagID) << R1 << R2);
341 PushCompoundScope(IsStmtExpr);
349 return getCurFunction()->CompoundScopes.back();
354 const unsigned NumElts = Elts.size();
362 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
366 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
370 Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
375 for (
unsigned i = 0; i != NumElts; ++i) {
377 if (isStmtExpr && i == NumElts - 1)
380 DiagnoseUnusedExprResult(Elts[i]);
386 if (NumElts != 0 && !CurrentInstantiationScope &&
387 getCurCompoundScope().HasEmptyLoopBodies) {
388 for (
unsigned i = 0; i != NumElts - 1; ++i)
389 DiagnoseEmptyLoopBody(Elts[i], Elts[i + 1]);
400 if (DiagnoseUnexpandedParameterPack(Val.
get()))
405 if (!getCurFunction()->SwitchStack.empty()) {
407 getCurFunction()->SwitchStack.back().getPointer()->getCond();
412 auto CheckAndFinish = [&](
Expr *E) {
416 if (getLangOpts().CPlusPlus11) {
419 llvm::APSInt TempVal;
425 if (!E->isValueDependent())
426 ER = VerifyIntegerConstantExpression(E);
428 ER = DefaultLvalueConversion(ER.
get());
430 ER = ImpCastExprToType(ER.
get(), CondType, CK_IntegralCast);
434 ExprResult Converted = CorrectDelayedTyposInExpr(Val, CheckAndFinish);
435 if (Converted.
get() == Val.
get())
436 Converted = CheckAndFinish(Val.
get());
442 return ActOnFinishFullExpr(Val.
get(), Val.
get()->getExprLoc(),
false,
443 getLangOpts().CPlusPlus11);
450 assert((LHSVal.
isInvalid() || LHSVal.
get()) &&
"missing LHS value");
453 "missing RHS value");
455 if (getCurFunction()->SwitchStack.empty()) {
456 Diag(CaseLoc, diag::err_case_not_in_switch);
461 getCurFunction()->SwitchStack.back().setInt(
true);
467 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(CS);
473 DiagnoseUnusedExprResult(SubStmt);
482 DiagnoseUnusedExprResult(SubStmt);
484 if (getCurFunction()->SwitchStack.empty()) {
485 Diag(DefaultLoc, diag::err_default_not_in_switch);
490 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(DS);
499 Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->
getDeclName();
531 CommaVisitor(
Sema &SemaRef) : Inherited(SemaRef.
Context), SemaRef(SemaRef) {}
553 Expr *CondExpr = Cond.
get().second;
554 if (!Diags.isIgnored(diag::warn_comma_operator,
556 CommaVisitor(*this).Visit(CondExpr);
559 DiagnoseEmptyStmtBody(CondExpr->
getLocEnd(), thenStmt,
560 diag::warn_empty_if_body);
562 return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
573 if (IsConstexpr || isa<ObjCAvailabilityCheckExpr>(Cond.
get().second))
574 setFunctionHasBranchProtectedScope();
576 DiagnoseUnusedExprResult(thenStmt);
577 DiagnoseUnusedExprResult(elseStmt);
580 IfStmt(Context, IfLoc, IsConstexpr, InitStmt, Cond.
get().first,
581 Cond.
get().second, thenStmt, ElseLoc, elseStmt);
585 struct CaseCompareFunctor {
586 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
587 const llvm::APSInt &RHS) {
588 return LHS.first < RHS;
590 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
591 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
592 return LHS.first < RHS.first;
594 bool operator()(
const llvm::APSInt &LHS,
595 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
596 return LHS < RHS.first;
603 static bool CmpCaseVals(
const std::pair<llvm::APSInt, CaseStmt*>& lhs,
604 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
605 if (lhs.first < rhs.first)
608 if (lhs.first == rhs.first &&
609 lhs.second->getCaseLoc().getRawEncoding()
610 < rhs.second->getCaseLoc().getRawEncoding())
617 static bool CmpEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
618 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
620 return lhs.first < rhs.first;
625 static bool EqEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
626 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
628 return lhs.first == rhs.first;
634 if (
const auto *CleanUps = dyn_cast<ExprWithCleanups>(E))
635 E = CleanUps->getSubExpr();
636 while (
const auto *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
637 if (ImpCast->getCastKind() != CK_IntegralCast)
break;
638 E = ImpCast->getSubExpr();
648 SwitchConvertDiagnoser(
Expr *Cond)
654 return S.
Diag(Loc, diag::err_typecheck_statement_requires_integer) << T;
659 return S.
Diag(Loc, diag::err_switch_incomplete_class_type)
665 return S.
Diag(Loc, diag::err_switch_explicit_conversion) << T << ConvTy;
676 return S.
Diag(Loc, diag::err_switch_multiple_conversions) << T;
687 llvm_unreachable(
"conversion functions are permitted");
689 } SwitchDiagnoser(Cond);
692 PerformContextualImplicitConversion(SwitchLoc, Cond, SwitchDiagnoser);
698 Cond = CondResult.
get();
704 return UsualUnaryConversions(Cond);
709 Expr *CondExpr = Cond.
get().second;
710 assert((Cond.
isInvalid() || CondExpr) &&
"switch with no condition");
718 "invalid condition type");
723 Diag(SwitchLoc, diag::warn_bool_switch_condition)
728 setFunctionHasBranchIntoScope();
732 getCurFunction()->SwitchStack.push_back(
737 static void AdjustAPSInt(llvm::APSInt &Val,
unsigned BitWidth,
bool IsSigned) {
738 Val = Val.extOrTrunc(BitWidth);
739 Val.setIsSigned(IsSigned);
745 unsigned UnpromotedWidth,
bool UnpromotedSign) {
753 if (UnpromotedWidth < Val.getBitWidth()) {
754 llvm::APSInt ConvVal(Val);
756 AdjustAPSInt(ConvVal, Val.getBitWidth(), Val.isSigned());
761 S.
Diag(Loc, diag::warn_case_value_overflow) << Val.toString(10)
762 << ConvVal.toString(10);
772 const Expr *CaseExpr,
773 EnumValsTy::iterator &EI,
774 EnumValsTy::iterator &EIEnd,
775 const llvm::APSInt &Val) {
781 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
790 if (ED->
hasAttr<FlagEnumAttr>())
793 while (EI != EIEnd && EI->first < Val)
796 if (EI != EIEnd && EI->first == Val)
809 if (!CondEnumType || !CaseEnumType)
816 if (!CaseEnumType->getDecl()->getIdentifier() &&
817 !CaseEnumType->getDecl()->getTypedefNameForAnonDecl())
823 S.
Diag(Case->
getExprLoc(), diag::warn_comparison_of_mixed_enum_types_switch)
832 bool CaseListIsIncomplete = getCurFunction()->SwitchStack.back().getInt();
833 assert(SS == getCurFunction()->SwitchStack.back().getPointer() &&
834 "switch stack missing push/pop!");
836 getCurFunction()->SwitchStack.pop_back();
839 SS->
setBody(BodyStmt, SwitchLoc);
853 const Expr *CondExprBeforePromotion = CondExpr;
859 bool HasDependentValue
861 unsigned CondWidth = HasDependentValue ? 0 : Context.
getIntWidth(CondType);
868 unsigned CondWidthBeforePromotion
869 = HasDependentValue ? 0 : Context.
getIntWidth(CondTypeBeforePromotion);
870 bool CondIsSignedBeforePromotion
880 typedef std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRangesTy;
881 CaseRangesTy CaseRanges;
885 bool CaseListIsErroneous =
false;
891 if (TheDefaultStmt) {
892 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
899 CaseListIsErroneous =
true;
908 if (Lo->isValueDependent()) {
909 HasDependentValue =
true;
915 const Expr *LoBeforePromotion = Lo;
922 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
934 HasDependentValue =
true;
937 CaseRanges.push_back(std::make_pair(LoVal, CS));
939 CaseVals.push_back(std::make_pair(LoVal, CS));
943 if (!HasDependentValue) {
946 llvm::APSInt ConstantCondValue;
947 bool HasConstantCond =
false;
948 if (!HasDependentValue && !TheDefaultStmt) {
949 HasConstantCond = CondExpr->
EvaluateAsInt(ConstantCondValue, Context,
951 assert(!HasConstantCond ||
952 (ConstantCondValue.getBitWidth() == CondWidth &&
953 ConstantCondValue.isSigned() == CondIsSigned));
955 bool ShouldCheckConstantCond = HasConstantCond;
958 std::stable_sort(CaseVals.begin(), CaseVals.end(),
CmpCaseVals);
960 if (!CaseVals.empty()) {
961 for (
unsigned i = 0, e = CaseVals.size(); i != e; ++i) {
962 if (ShouldCheckConstantCond &&
963 CaseVals[i].first == ConstantCondValue)
964 ShouldCheckConstantCond =
false;
966 if (i != 0 && CaseVals[i].first == CaseVals[i-1].first) {
969 StringRef PrevString, CurrString;
972 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(PrevCase)) {
973 PrevString = DeclRef->getDecl()->getName();
975 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(CurrCase)) {
976 CurrString = DeclRef->getDecl()->getName();
979 CaseVals[i-1].first.toString(CaseValStr);
981 if (PrevString == CurrString)
982 Diag(CaseVals[i].second->getLHS()->getLocStart(),
983 diag::err_duplicate_case) <<
984 (PrevString.empty() ? StringRef(CaseValStr) : PrevString);
986 Diag(CaseVals[i].second->getLHS()->getLocStart(),
987 diag::err_duplicate_case_differing_expr) <<
988 (PrevString.empty() ? StringRef(CaseValStr) : PrevString) <<
989 (CurrString.empty() ? StringRef(CaseValStr) : CurrString) <<
992 Diag(CaseVals[i-1].second->getLHS()->getLocStart(),
993 diag::note_duplicate_case_prev);
996 CaseListIsErroneous =
true;
1003 if (!CaseRanges.empty()) {
1006 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
1009 std::vector<llvm::APSInt> HiVals;
1010 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1011 llvm::APSInt &LoVal = CaseRanges[i].first;
1012 CaseStmt *CR = CaseRanges[i].second;
1015 const Expr *HiBeforePromotion = Hi;
1022 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
1028 if (LoVal > HiVal) {
1032 CaseRanges.erase(CaseRanges.begin()+i);
1038 if (ShouldCheckConstantCond &&
1039 LoVal <= ConstantCondValue &&
1040 ConstantCondValue <= HiVal)
1041 ShouldCheckConstantCond =
false;
1043 HiVals.push_back(HiVal);
1049 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1050 llvm::APSInt &CRLo = CaseRanges[i].first;
1051 llvm::APSInt &CRHi = HiVals[i];
1052 CaseStmt *CR = CaseRanges[i].second;
1057 llvm::APSInt OverlapVal(32);
1061 CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(),
1062 CaseVals.end(), CRLo,
1063 CaseCompareFunctor());
1064 if (I != CaseVals.end() && I->first < CRHi) {
1065 OverlapVal = I->first;
1066 OverlapStmt = I->second;
1070 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
1071 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
1072 OverlapVal = (I-1)->first;
1073 OverlapStmt = (I-1)->second;
1078 if (i && CRLo <= HiVals[i-1]) {
1079 OverlapVal = HiVals[i-1];
1080 OverlapStmt = CaseRanges[i-1].second;
1086 << OverlapVal.toString(10);
1088 diag::note_duplicate_case_prev);
1091 CaseListIsErroneous =
true;
1097 if (!CaseListIsErroneous && !CaseListIsIncomplete &&
1098 ShouldCheckConstantCond) {
1101 Diag(CondExpr->
getExprLoc(), diag::warn_missing_case_for_condition)
1102 << ConstantCondValue.toString(10)
1114 if (!CaseListIsErroneous && !CaseListIsIncomplete && !HasConstantCond &&
1122 llvm::APSInt Val = EDI->getInitVal();
1124 EnumVals.push_back(std::make_pair(Val, EDI));
1126 std::stable_sort(EnumVals.begin(), EnumVals.end(),
CmpEnumVals);
1127 auto EI = EnumVals.begin(), EIEnd =
1128 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1131 for (CaseValsTy::const_iterator CI = CaseVals.begin();
1132 CI != CaseVals.end(); CI++) {
1133 Expr *CaseExpr = CI->second->getLHS();
1137 << CondTypeBeforePromotion;
1141 EI = EnumVals.begin();
1142 for (CaseRangesTy::const_iterator RI = CaseRanges.begin();
1143 RI != CaseRanges.end(); RI++) {
1144 Expr *CaseExpr = RI->second->getLHS();
1148 << CondTypeBeforePromotion;
1151 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1154 CaseExpr = RI->second->getRHS();
1158 << CondTypeBeforePromotion;
1162 auto CI = CaseVals.begin();
1163 auto RI = CaseRanges.begin();
1164 bool hasCasesNotInSwitch =
false;
1168 for (EI = EnumVals.begin(); EI != EIEnd; EI++){
1170 while (CI != CaseVals.end() && CI->first < EI->first)
1173 if (CI != CaseVals.end() && CI->first == EI->first)
1177 for (; RI != CaseRanges.end(); RI++) {
1179 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1181 if (EI->first <= Hi)
1185 if (RI == CaseRanges.end() || EI->first < RI->first) {
1186 hasCasesNotInSwitch =
true;
1187 UnhandledNames.push_back(EI->second->getDeclName());
1191 if (TheDefaultStmt && UnhandledNames.empty() && ED->
isClosedNonFlag())
1195 if (!UnhandledNames.empty()) {
1197 TheDefaultStmt ? diag::warn_def_missing_case
1198 : diag::warn_missing_case)
1199 << (
int)UnhandledNames.size();
1201 for (
size_t I = 0, E =
std::min(UnhandledNames.size(), (
size_t)3);
1203 DB << UnhandledNames[I];
1206 if (!hasCasesNotInSwitch)
1212 DiagnoseEmptyStmtBody(CondExpr->
getLocEnd(), BodyStmt,
1213 diag::warn_empty_switch_body);
1217 if (CaseListIsErroneous)
1226 if (Diags.isIgnored(diag::warn_not_in_enum_assignment, SrcExpr->
getExprLoc()))
1240 const EnumDecl *ED = ET->getDecl();
1245 if (ED->
hasAttr<FlagEnumAttr>()) {
1246 if (!IsValueInFlagEnum(ED, RhsVal,
true))
1252 EnumValsTy EnumVals;
1257 llvm::APSInt Val = EDI->getInitVal();
1259 EnumVals.push_back(std::make_pair(Val, EDI));
1261 if (EnumVals.empty())
1263 std::stable_sort(EnumVals.begin(), EnumVals.end(),
CmpEnumVals);
1264 EnumValsTy::iterator EIend =
1265 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1268 EnumValsTy::const_iterator EI = EnumVals.begin();
1269 while (EI != EIend && EI->first < RhsVal)
1271 if (EI == EIend || EI->first != RhsVal) {
1285 auto CondVal = Cond.
get();
1286 CheckBreakContinueBinding(CondVal.second);
1288 if (CondVal.second &&
1289 !Diags.isIgnored(diag::warn_comma_operator, CondVal.second->getExprLoc()))
1290 CommaVisitor(*this).Visit(CondVal.second);
1292 DiagnoseUnusedExprResult(Body);
1294 if (isa<NullStmt>(Body))
1295 getCurCompoundScope().setHasEmptyLoopBodies();
1297 return new (Context)
1298 WhileStmt(Context, CondVal.first, CondVal.second, Body, WhileLoc);
1305 assert(Cond &&
"ActOnDoStmt(): missing expression");
1307 CheckBreakContinueBinding(Cond);
1308 ExprResult CondResult = CheckBooleanCondition(DoLoc, Cond);
1311 Cond = CondResult.
get();
1313 CondResult = ActOnFinishFullExpr(Cond, DoLoc);
1316 Cond = CondResult.
get();
1318 DiagnoseUnusedExprResult(Body);
1320 return new (Context)
DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen);
1325 using DeclSetVector =
1326 llvm::SetVector<VarDecl *, llvm::SmallVector<VarDecl *, 8>,
1327 llvm::SmallPtrSet<VarDecl *, 8>>;
1333 DeclSetVector &Decls;
1339 DeclExtractor(
Sema &S, DeclSetVector &Decls,
1346 bool isSimple() {
return Simple; }
1354 void VisitStmt(
Stmt *S) {
1411 DeclSetVector &Decls;
1417 DeclMatcher(
Sema &S, DeclSetVector &Decls,
Stmt *Statement) :
1418 Inherited(S.
Context), Decls(Decls), FoundDecl(
false) {
1419 if (!Statement)
return;
1443 void CheckLValueToRValueCast(
Expr *E) {
1446 if (isa<DeclRefExpr>(E)) {
1451 Visit(CO->getCond());
1452 CheckLValueToRValueCast(CO->getTrueExpr());
1453 CheckLValueToRValueCast(CO->getFalseExpr());
1458 dyn_cast<BinaryConditionalOperator>(E)) {
1459 CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr());
1460 CheckLValueToRValueCast(BCO->getFalseExpr());
1469 if (Decls.count(VD))
1477 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(S))
1479 Visit(OVE->getSourceExpr());
1485 bool FoundDeclInUse() {
return FoundDecl; }
1489 void CheckForLoopConditionalStatement(
Sema &S,
Expr *Second,
1492 if (!Second)
return;
1499 DeclSetVector Decls;
1501 DeclExtractor DE(S, Decls, Ranges);
1505 if (!DE.isSimple())
return;
1508 if (Decls.size() == 0)
return;
1511 for (
auto *VD : Decls)
1512 if (VD->getType().isVolatileQualified() || VD->hasGlobalStorage())
1515 if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
1516 DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
1517 DeclMatcher(S, Decls, Body).FoundDeclInUse())
1521 if (Decls.size() > 4) {
1524 PDiag << (unsigned)Decls.size();
1525 for (
auto *VD : Decls)
1526 PDiag << VD->getDeclName();
1529 for (
auto Range : Ranges)
1532 S.
Diag(Ranges.begin()->getBegin(), PDiag);
1537 bool ProcessIterationStmt(
Sema &S,
Stmt* Statement,
bool &Increment,
1539 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(Statement))
1540 if (!Cleanups->cleanupsHaveSideEffects())
1541 Statement = Cleanups->getSubExpr();
1543 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(Statement)) {
1544 switch (UO->getOpcode()) {
1545 default:
return false;
1563 default:
return false;
1583 bool InSwitch =
false;
1586 BreakContinueFinder(
Sema &S,
const Stmt* Body) :
1597 void VisitBreakStmt(
const BreakStmt* E) {
1617 void VisitForStmt(
const ForStmt *S) {
1624 void VisitWhileStmt(
const WhileStmt *) {
1629 void VisitDoStmt(
const DoStmt *) {
1654 bool ContinueFound() {
return ContinueLoc.
isValid(); }
1655 bool BreakFound() {
return BreakLoc.
isValid(); }
1666 void CheckForRedundantIteration(
Sema &S,
Expr *Third,
Stmt *Body) {
1668 if (!Body || !Third)
return;
1678 if (!LastStmt)
return;
1680 bool LoopIncrement, LastIncrement;
1683 if (!ProcessIterationStmt(S, Third, LoopIncrement, LoopDRE))
return;
1684 if (!ProcessIterationStmt(S, LastStmt, LastIncrement, LastDRE))
return;
1688 if (LoopIncrement != LastIncrement ||
1691 if (BreakContinueFinder(S, Body).ContinueFound())
return;
1694 << LastDRE->
getDecl() << LastIncrement;
1702 void Sema::CheckBreakContinueBinding(
Expr *E) {
1705 BreakContinueFinder BCFinder(*
this, E);
1707 if (BCFinder.BreakFound() && BreakParent) {
1709 Diag(BCFinder.GetBreakLoc(), diag::warn_break_binds_to_switch);
1711 Diag(BCFinder.GetBreakLoc(), diag::warn_loop_ctrl_binds_to_inner)
1714 }
else if (BCFinder.ContinueFound() && CurScope->getContinueParent()) {
1715 Diag(BCFinder.GetContinueLoc(), diag::warn_loop_ctrl_binds_to_inner)
1727 if (!getLangOpts().CPlusPlus) {
1728 if (
DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
1732 for (
auto *DI : DS->decls()) {
1737 Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
1738 DI->setInvalidDecl();
1744 CheckBreakContinueBinding(Second.
get().second);
1745 CheckBreakContinueBinding(third.
get());
1747 if (!Second.
get().first)
1748 CheckForLoopConditionalStatement(*
this, Second.
get().second, third.
get(),
1750 CheckForRedundantIteration(*
this, third.
get(), Body);
1752 if (Second.
get().second &&
1753 !Diags.isIgnored(diag::warn_comma_operator,
1754 Second.
get().second->getExprLoc()))
1755 CommaVisitor(*this).Visit(Second.
get().second);
1759 DiagnoseUnusedExprResult(First);
1760 DiagnoseUnusedExprResult(Third);
1761 DiagnoseUnusedExprResult(Body);
1763 if (isa<NullStmt>(Body))
1764 getCurCompoundScope().setHasEmptyLoopBodies();
1766 return new (Context)
1767 ForStmt(Context, First, Second.
get().second, Second.
get().first, Third,
1768 Body, ForLoc, LParenLoc, RParenLoc);
1782 ExprResult FullExpr = ActOnFinishFullExpr(E);
1793 ExprResult result = CorrectDelayedTyposInExpr(collection);
1796 collection = result.
get();
1802 result = DefaultFunctionArrayLvalueConversion(collection);
1805 collection = result.
get();
1812 return Diag(forLoc, diag::err_collection_expr_type)
1823 (getLangOpts().ObjCAutoRefCount
1824 ? RequireCompleteType(forLoc,
QualType(objectType, 0),
1825 diag::err_arc_collection_forward, collection)
1826 : !isCompleteType(forLoc,
QualType(objectType, 0)))) {
1829 }
else if (iface || !objectType->
qual_empty()) {
1831 &Context.
Idents.
get(
"countByEnumeratingWithState"),
1847 method = LookupMethodInQualifiedType(selector, pointerType,
1852 Diag(forLoc, diag::warn_collection_expr_type)
1867 setFunctionHasBranchProtectedScope();
1870 CheckObjCForCollectionOperand(ForLoc, collection);
1874 if (
DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
1875 if (!DS->isSingleDecl())
1877 diag::err_toomany_element_decls));
1889 diag::err_non_local_variable_decl_in_for));
1895 Expr *DeducedInit = &OpaqueId;
1898 DiagnoseAutoDeductionFailure(D, DeducedInit);
1899 if (FirstType.
isNull()) {
1906 if (!inTemplateInstantiation()) {
1909 Diag(Loc, diag::warn_auto_var_is_id)
1915 Expr *FirstE = cast<Expr>(First);
1918 diag::err_selector_element_not_lvalue)
1921 FirstType =
static_cast<Expr*
>(First)->getType();
1923 Diag(ForLoc, diag::err_selector_element_const_type)
1929 return StmtError(
Diag(ForLoc, diag::err_selector_element_type)
1936 CollectionExprResult = ActOnFinishFullExpr(CollectionExprResult.
get());
1941 nullptr, ForLoc, RParenLoc);
1995 void NoteForRangeBeginEndFunction(
Sema &SemaRef,
Expr *E,
2005 std::string Description;
2006 bool IsTemplate =
false;
2013 SemaRef.
Diag(Loc, diag::note_for_range_begin_end)
2014 << BEF << IsTemplate << Description << E->
getType();
2063 return ActOnObjCForCollectionStmt(ForLoc, First, Range, RParenLoc);
2066 assert(DS &&
"first part of for range not a decl stmt");
2075 DiagnoseUnexpandedParameterPack(Range, UPPC_Expression)) {
2083 if (!ActOnCoroutineBodyStart(S, CoawaitLoc,
"co_await"))
2089 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2091 VarDecl *RangeVar = BuildForRangeVarDecl(*
this, RangeLoc,
2093 std::string(
"__range") + DepthStr);
2095 diag::err_for_range_deduction_failure)) {
2103 StmtResult RangeDecl = ActOnDeclStmt(RangeGroup, RangeLoc, RangeLoc);
2109 return BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc, RangeDecl.
get(),
2112 DS, RParenLoc,
Kind);
2148 if (BeginMemberLookup.empty() != EndMemberLookup.
empty()) {
2150 *BEF = BeginMemberLookup.empty() ? BEF_end : BEF_begin;
2152 SemaRef.
Diag(RangeLoc, diag::err_for_range_member_begin_end_mismatch)
2153 << RangeLoc << BeginRange->
getType() << *BEF;
2167 BeginMemberLookup, CandidateSet,
2168 BeginRange, BeginExpr);
2173 << ColonLoc << BEF_begin << BeginRange->
getType();
2186 diag::err_for_range_iter_deduction_failure)) {
2187 NoteForRangeBeginEndFunction(SemaRef, BeginExpr->
get(), *BEF);
2194 EndMemberLookup, CandidateSet,
2199 << ColonLoc << BEF_end << EndRange->
getType();
2203 diag::err_for_range_iter_deduction_failure)) {
2204 NoteForRangeBeginEndFunction(SemaRef, EndExpr->
get(), *BEF);
2227 AdjustedRange = SemaRef.
BuildUnaryOp(S, RangeLoc, UO_Deref, Range);
2232 S, ForLoc, CoawaitLoc, LoopVarDecl, ColonLoc, AdjustedRange.
get(),
2241 SemaRef.
Diag(RangeLoc, diag::err_for_range_dereference)
2244 ColonLoc, AdjustedRange.
get(), RParenLoc,
2250 struct InvalidateOnErrorScope {
2251 InvalidateOnErrorScope(
Sema &SemaRef,
Decl *D,
bool Enabled)
2252 : Trap(SemaRef.
Diags), D(D), Enabled(Enabled) {}
2253 ~InvalidateOnErrorScope() {
2254 if (Enabled && Trap.hasErrorOccurred())
2280 Scope *S = getCurScope();
2282 DeclStmt *RangeDS = cast<DeclStmt>(RangeDecl);
2284 QualType RangeVarType = RangeVar->getType();
2286 DeclStmt *LoopVarDS = cast<DeclStmt>(LoopVarDecl);
2291 InvalidateOnErrorScope Invalidate(*
this, LoopVar,
2292 LoopVar->getType()->isUndeducedType());
2298 if (RangeVarType->isDependentType()) {
2300 RangeVar->markUsed(Context);
2304 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2305 if (
auto *DD = dyn_cast<DecompositionDecl>(LoopVar))
2306 for (
auto *Binding : DD->bindings())
2308 LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.
DependentTy));
2310 }
else if (!BeginDeclStmt.get()) {
2315 ExprResult BeginRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2320 ExprResult EndRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2326 Expr *Range = RangeVar->getInit();
2331 if (RequireCompleteType(RangeLoc, RangeType,
2332 diag::err_for_range_incomplete_type))
2337 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2338 VarDecl *BeginVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2339 std::string(
"__begin") + DepthStr);
2340 VarDecl *EndVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2341 std::string(
"__end") + DepthStr);
2352 BeginExpr = BeginRangeRef;
2354 BeginExpr = ActOnCoawaitExpr(S, ColonLoc, BeginExpr.
get());
2359 diag::err_for_range_iter_deduction_failure)) {
2360 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2370 dyn_cast<VariableArrayType>(UnqAT)) {
2393 ExprResult SizeOfVLAExprR = ActOnUnaryExprOrTypeTraitExpr(
2397 VAT->desugar(), RangeLoc))
2403 ExprResult SizeOfEachElementExprR = ActOnUnaryExprOrTypeTraitExpr(
2406 CreateParsedType(VAT->desugar(),
2408 VAT->getElementType(), RangeLoc))
2416 SizeOfVLAExprR.
get(), SizeOfEachElementExprR.
get());
2423 llvm_unreachable(
"Unexpected array type in for-range");
2427 EndExpr = ActOnBinOp(S, ColonLoc, tok::plus, EndRangeRef.
get(),
2432 diag::err_for_range_iter_deduction_failure)) {
2433 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2441 *
this, BeginRangeRef.
get(), EndRangeRef.
get(), RangeType, BeginVar,
2442 EndVar,
ColonLoc, CoawaitLoc, &CandidateSet, &BeginExpr, &EndExpr,
2445 if (Kind == BFRK_Build && RangeStatus == FRS_NoViableFunction &&
2446 BEFFailure == BEF_begin) {
2449 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Range)) {
2450 if (
ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
2451 QualType ArrayTy = PVD->getOriginalType();
2452 QualType PointerTy = PVD->getType();
2455 << RangeLoc << PVD << ArrayTy << PointerTy;
2456 Diag(PVD->getLocation(), diag::note_declared_at);
2466 LoopVarDecl, ColonLoc,
2474 if (RangeStatus == FRS_NoViableFunction) {
2475 Expr *Range = BEFFailure ? EndRangeRef.
get() : BeginRangeRef.
get();
2477 << RangeLoc << Range->
getType() << BEFFailure;
2481 if (RangeStatus != FRS_Success)
2486 "invalid range expression in for loop");
2490 QualType BeginType = BeginVar->getType(), EndType = EndVar->
getType();
2493 ? diag::warn_for_range_begin_end_types_differ
2494 : diag::ext_for_range_begin_end_types_differ)
2495 << BeginType << EndType;
2496 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2497 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2501 ActOnDeclStmt(ConvertDeclToDeclGroup(BeginVar), ColonLoc, ColonLoc);
2503 ActOnDeclStmt(ConvertDeclToDeclGroup(EndVar), ColonLoc, ColonLoc);
2506 ExprResult BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2511 ExprResult EndRef = BuildDeclRefExpr(EndVar, EndType.getNonReferenceType(),
2517 NotEqExpr = ActOnBinOp(S, ColonLoc, tok::exclaimequal,
2518 BeginRef.
get(), EndRef.
get());
2520 NotEqExpr = CheckBooleanCondition(ColonLoc, NotEqExpr.
get());
2522 NotEqExpr = ActOnFinishFullExpr(NotEqExpr.
get());
2524 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2525 << RangeLoc << 0 << BeginRangeRef.
get()->getType();
2526 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2528 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2533 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2538 IncrExpr = ActOnUnaryOp(S, ColonLoc, tok::plusplus, BeginRef.
get());
2539 if (!IncrExpr.isInvalid() && CoawaitLoc.
isValid())
2543 IncrExpr = ActOnCoawaitExpr(S, CoawaitLoc, IncrExpr.get());
2544 if (!IncrExpr.isInvalid())
2545 IncrExpr = ActOnFinishFullExpr(IncrExpr.get());
2546 if (IncrExpr.isInvalid()) {
2547 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2548 << RangeLoc << 2 << BeginRangeRef.
get()->getType() ;
2549 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2554 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2559 ExprResult DerefExpr = ActOnUnaryOp(S, ColonLoc, tok::star, BeginRef.
get());
2561 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2562 << RangeLoc << 1 << BeginRangeRef.
get()->getType();
2563 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2569 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2570 AddInitializerToDecl(LoopVar, DerefExpr.
get(),
false);
2571 if (LoopVar->isInvalidDecl())
2572 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2578 if (Kind == BFRK_Check)
2582 RangeDS, cast_or_null<DeclStmt>(BeginDeclStmt.get()),
2583 cast_or_null<DeclStmt>(EndDeclStmt.
get()), NotEqExpr.
get(),
2584 IncrExpr.get(), LoopVarDS,
nullptr, ForLoc, CoawaitLoc,
2615 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(InitExpr))
2616 if (!Cleanups->cleanupsHaveSideEffects())
2617 InitExpr = Cleanups->getSubExpr();
2630 while (!isa<CXXOperatorCallExpr>(E) && !isa<UnaryOperator>(E)) {
2634 const MemberExpr *ME = cast<MemberExpr>(Call->getCallee());
2643 bool ReturnsReference =
false;
2644 if (isa<UnaryOperator>(E)) {
2645 ReturnsReference =
true;
2649 QualType ReturnType = FD->getReturnType();
2653 if (ReturnsReference) {
2657 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_const_reference_copy)
2658 << VD << VariableType << E->
getType();
2668 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_variable_always_copy)
2669 << VD << RangeInitType;
2689 if (!CE->getConstructor()->isCopyConstructor())
2691 }
else if (
const CastExpr *CE = dyn_cast<CastExpr>(InitExpr)) {
2692 if (CE->getCastKind() != CK_LValueToRValue)
2707 << VD << VariableType << InitExpr->
getType();
2723 if (SemaRef.
Diags.
isIgnored(diag::warn_for_range_const_reference_copy,
2725 SemaRef.
Diags.
isIgnored(diag::warn_for_range_variable_always_copy,
2761 if (isa<ObjCForCollectionStmt>(S))
2762 return FinishObjCForCollectionStmt(S, B);
2768 diag::warn_empty_range_based_for_body);
2778 setFunctionHasBranchIntoScope();
2780 return new (Context)
GotoStmt(TheDecl, GotoLoc, LabelLoc);
2792 CheckSingleAssignmentConstraints(DestTy, ExprRes);
2796 if (DiagnoseAssignmentResult(ConvTy, StarLoc, DestTy, ETy, E, AA_Passing))
2805 setFunctionHasIndirectGoto();
2811 const Scope &DestScope) {
2814 S.
Diag(Loc, diag::warn_jump_out_of_seh_finally);
2823 return StmtError(
Diag(ContinueLoc, diag::err_continue_not_in_loop));
2835 return StmtError(
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
2838 return StmtError(
Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt)
2842 return new (Context)
BreakStmt(BreakLoc);
2875 if (isCopyElisionCandidate(ReturnType, VD, CESK))
2890 if (!(CESK & CES_AllowDifferentTypes) && !VDType->
isDependentType() &&
2896 if (VD->
getKind() != Decl::Var &&
2897 !((CESK & CES_AllowParameters) && VD->
getKind() == Decl::ParmVar))
2908 if (VD->
hasAttr<BlocksAttr>())
return false;
2910 if (CESK & CES_AllowDifferentTypes)
2946 bool ConvertingConstructorsOnly,
2951 Expr *InitExpr = &AsRvalue;
2954 Value->getLocStart(), Value->getLocStart());
2967 if (ConvertingConstructorsOnly) {
2968 if (isa<CXXConstructorDecl>(FD)) {
2986 if (isa<CXXConstructorDecl>(FD)) {
2992 }
else if (isa<CXXMethodDecl>(FD)) {
2995 if (cast<CXXMethodDecl>(FD)->getRefQualifier() !=
RQ_RValue)
3009 Res = Seq.Perform(S, Entity, Kind, Value);
3037 bool AffectedByCWG1579 =
false;
3039 if (!NRVOCandidate) {
3040 NRVOCandidate = getCopyElisionCandidate(ResultType, Value, CES_Default);
3041 if (NRVOCandidate &&
3042 !getDiagnostics().isIgnored(diag::warn_return_std_move_in_cxx11,
3044 const VarDecl *NRVOCandidateInCXX11 =
3045 getCopyElisionCandidate(ResultType, Value, CES_FormerDefault);
3046 AffectedByCWG1579 = (!NRVOCandidateInCXX11);
3050 if (NRVOCandidate) {
3055 if (!Res.
isInvalid() && AffectedByCWG1579) {
3067 assert(!ResultType.
isNull());
3069 Str +=
"std::move(";
3074 << NRVOCandidate->
getDeclName() << ResultType << QT;
3079 !getDiagnostics().isIgnored(diag::warn_return_std_move,
3081 const VarDecl *FakeNRVOCandidate =
3082 getCopyElisionCandidate(
QualType(), Value, CES_AsIfByStdMove);
3083 if (FakeNRVOCandidate) {
3097 FakeValue,
false, FakeRes);
3102 Str +=
"std::move(";
3143 bool HasDeducedReturnType =
3146 if (ExprEvalContexts.back().Context ==
3147 ExpressionEvaluationContext::DiscardedStatement &&
3150 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3153 RetValExp = ER.
get();
3155 return new (Context)
ReturnStmt(ReturnLoc, RetValExp,
nullptr);
3158 if (HasDeducedReturnType) {
3166 assert(AT &&
"lost auto type from lambda return type");
3167 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3177 if (RetValExp && !isa<InitListExpr>(RetValExp)) {
3178 ExprResult Result = DefaultFunctionArrayLvalueConversion(RetValExp);
3181 RetValExp = Result.
get();
3187 if (!CurContext->isDependentContext())
3196 Diag(ReturnLoc, diag::err_lambda_return_init_list)
3200 FnRetType = Context.
VoidTy;
3208 assert(!FnRetType.isNull());
3210 if (
BlockScopeInfo *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
3212 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr);
3216 dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
3217 Diag(ReturnLoc, diag::err_return_in_captured_stmt) << CurRegion->getRegionName();
3220 assert(CurLambda &&
"unknown kind of captured scope");
3222 ->getNoReturnAttr()) {
3223 Diag(ReturnLoc, diag::err_noreturn_lambda_has_return_expr);
3231 const VarDecl *NRVOCandidate =
nullptr;
3232 if (FnRetType->isDependentType()) {
3235 }
else if (FnRetType->isVoidType()) {
3236 if (RetValExp && !isa<InitListExpr>(RetValExp) &&
3237 !(getLangOpts().CPlusPlus &&
3240 if (!getLangOpts().CPlusPlus &&
3242 Diag(ReturnLoc, diag::ext_return_has_void_expr) <<
"literal" << 2;
3244 Diag(ReturnLoc, diag::err_return_block_has_expr);
3245 RetValExp =
nullptr;
3248 }
else if (!RetValExp) {
3249 return StmtError(
Diag(ReturnLoc, diag::err_block_return_missing_expr));
3259 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3262 NRVOCandidate !=
nullptr);
3263 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3264 FnRetType, RetValExp);
3269 RetValExp = Res.
get();
3270 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc);
3272 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3276 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3279 RetValExp = ER.
get();
3288 FunctionScopes.back()->Returns.push_back(Result);
3290 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3291 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3309 class LocalTypedefNameReferencer
3312 LocalTypedefNameReferencer(
Sema &S) : S(S) {}
3317 bool LocalTypedefNameReferencer::VisitRecordType(
const RecordType *RT) {
3319 if (!R || !R->isLocalClass() || !R->isLocalClass()->isExternallyVisible() ||
3320 R->isDependentType())
3322 for (
auto *TmpD : R->decls())
3323 if (
auto *T = dyn_cast<TypedefNameDecl>(TmpD))
3324 if (T->getAccess() !=
AS_private || R->hasFriends())
3349 TypeLoc OrigResultType = getReturnTypeLoc(FD);
3352 if (RetExpr && isa<InitListExpr>(RetExpr)) {
3356 getCurLambda() ? diag::err_lambda_return_init_list
3357 : diag::err_auto_fn_return_init_list)
3367 assert(AT->
isDeduced() &&
"should have deduced to dependent type");
3380 if (DAR != DAR_Succeeded)
3385 LocalTypedefNameReferencer Referencer(*
this);
3386 Referencer.TraverseType(RetExpr->
getType());
3394 Diag(ReturnLoc, diag::err_auto_fn_return_void_but_not_auto)
3399 Deduced = SubstAutoType(OrigResultType.
getType(), Context.
VoidTy);
3423 Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible)
3427 Diag(ReturnLoc, diag::err_auto_fn_different_deductions)
3444 StmtResult R = BuildReturnStmt(ReturnLoc, RetValExp);
3445 if (R.
isInvalid() || ExprEvalContexts.back().Context ==
3446 ExpressionEvaluationContext::DiscardedStatement)
3450 const_cast<VarDecl*>(cast<ReturnStmt>(R.
get())->getNRVOCandidate())) {
3463 if (RetValExp && DiagnoseUnexpandedParameterPack(RetValExp))
3466 if (isa<CapturingScopeInfo>(getCurFunction()))
3467 return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp);
3471 const AttrVec *Attrs =
nullptr;
3472 bool isObjCMethod =
false;
3475 FnRetType = FD->getReturnType();
3477 Attrs = &FD->getAttrs();
3478 if (FD->isNoReturn())
3479 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
3480 << FD->getDeclName();
3481 if (FD->isMain() && RetValExp)
3482 if (isa<CXXBoolLiteralExpr>(RetValExp))
3483 Diag(ReturnLoc, diag::warn_main_returns_bool_literal)
3486 FnRetType = MD->getReturnType();
3487 isObjCMethod =
true;
3489 Attrs = &MD->getAttrs();
3490 if (MD->hasRelatedResultType() && MD->getClassInterface()) {
3502 if (ExprEvalContexts.back().Context ==
3503 ExpressionEvaluationContext::DiscardedStatement &&
3506 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3509 RetValExp = ER.
get();
3511 return new (Context)
ReturnStmt(ReturnLoc, RetValExp,
nullptr);
3516 if (getLangOpts().CPlusPlus14) {
3519 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3533 if (isa<InitListExpr>(RetValExp)) {
3537 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3538 int FunctionKind = 0;
3539 if (isa<ObjCMethodDecl>(CurDecl))
3541 else if (isa<CXXConstructorDecl>(CurDecl))
3543 else if (isa<CXXDestructorDecl>(CurDecl))
3546 Diag(ReturnLoc, diag::err_return_init_list)
3551 RetValExp =
nullptr;
3554 unsigned D = diag::ext_return_has_expr;
3556 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3557 if (isa<CXXConstructorDecl>(CurDecl) ||
3558 isa<CXXDestructorDecl>(CurDecl))
3559 D = diag::err_ctor_dtor_returns_void;
3561 D = diag::ext_return_has_void_expr;
3565 Result = IgnoredValueConversions(Result.
get());
3568 RetValExp = Result.
get();
3569 RetValExp = ImpCastExprToType(RetValExp,
3570 Context.
VoidTy, CK_ToVoid).get();
3573 if (D == diag::err_ctor_dtor_returns_void) {
3574 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3576 << CurDecl->
getDeclName() << isa<CXXDestructorDecl>(CurDecl)
3580 else if (D != diag::ext_return_has_void_expr ||
3582 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3584 int FunctionKind = 0;
3585 if (isa<ObjCMethodDecl>(CurDecl))
3587 else if (isa<CXXConstructorDecl>(CurDecl))
3589 else if (isa<CXXDestructorDecl>(CurDecl))
3599 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3602 RetValExp = ER.
get();
3606 Result =
new (Context)
ReturnStmt(ReturnLoc, RetValExp,
nullptr);
3607 }
else if (!RetValExp && !HasDependentReturnType) {
3613 DiagID = diag::err_constexpr_return_missing_expr;
3615 }
else if (getLangOpts().
C99) {
3617 DiagID = diag::ext_return_missing_expr;
3620 DiagID = diag::warn_return_missing_expr;
3626 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1;
3628 Result =
new (Context)
ReturnStmt(ReturnLoc);
3630 assert(RetValExp || HasDependentReturnType);
3631 const VarDecl *NRVOCandidate =
nullptr;
3633 QualType RetType = RelatedRetType.
isNull() ? FnRetType : RelatedRetType;
3642 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3647 NRVOCandidate !=
nullptr);
3648 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3649 RetType, RetValExp);
3660 if (!RelatedRetType.
isNull()) {
3663 Res = PerformCopyInitialization(Entity, ReturnLoc, RetValExp);
3671 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc, isObjCMethod, Attrs,
3672 getCurFunctionDecl());
3676 ExprResult ER = ActOnFinishFullExpr(RetValExp, ReturnLoc);
3679 RetValExp = ER.
get();
3681 Result =
new (Context)
ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate);
3687 FunctionScopes.back()->Returns.push_back(Result);
3689 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3690 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3699 VarDecl *Var = cast_or_null<VarDecl>(Parm);
3714 if (!getLangOpts().ObjCExceptions)
3715 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@try";
3717 setFunctionHasBranchProtectedScope();
3718 unsigned NumCatchStmts = CatchStmts.size();
3720 NumCatchStmts, Finally);
3725 ExprResult Result = DefaultLvalueConversion(Throw);
3729 Result = ActOnFinishFullExpr(Result.
get());
3732 Throw = Result.
get();
3740 return StmtError(
Diag(AtLoc, diag::err_objc_throw_expects_object)
3751 if (!getLangOpts().ObjCExceptions)
3752 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@throw";
3757 Scope *AtCatchParent = CurScope;
3759 AtCatchParent = AtCatchParent->
getParent();
3761 return StmtError(
Diag(AtLoc, diag::err_rethrow_used_outside_catch));
3763 return BuildObjCAtThrowStmt(AtLoc, Throw);
3768 ExprResult result = DefaultLvalueConversion(operand);
3771 operand = result.
get();
3779 if (getLangOpts().CPlusPlus) {
3780 if (RequireCompleteType(atLoc, type,
3781 diag::err_incomplete_receiver_type))
3782 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3785 ExprResult result = PerformContextuallyConvertToObjCPointer(operand);
3789 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3792 operand = result.
get();
3794 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3801 return ActOnFinishFullExpr(operand);
3808 setFunctionHasBranchProtectedScope();
3816 Stmt *HandlerBlock) {
3818 return new (Context)
3819 CXXCatchStmt(CatchLoc, cast_or_null<VarDecl>(ExDecl), HandlerBlock);
3824 setFunctionHasBranchProtectedScope();
3829 class CatchHandlerType {
3831 unsigned IsPointer : 1;
3836 enum Unique { ForDenseMap };
3837 CatchHandlerType(
QualType QT, Unique) : QT(QT), IsPointer(
false) {}
3843 CatchHandlerType(
QualType Q) : QT(Q), IsPointer(
false) {
3855 CatchHandlerType(
QualType QT,
bool IsPointer)
3856 : QT(QT), IsPointer(IsPointer) {}
3858 QualType underlying()
const {
return QT; }
3859 bool isPointer()
const {
return IsPointer; }
3861 friend bool operator==(
const CatchHandlerType &LHS,
3862 const CatchHandlerType &RHS) {
3864 if (LHS.IsPointer != RHS.IsPointer)
3867 return LHS.QT == RHS.QT;
3876 CatchHandlerType::ForDenseMap);
3881 CatchHandlerType::ForDenseMap);
3889 const CatchHandlerType &RHS) {
3896 class CatchTypePublicBases {
3898 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &TypesToCheck;
3899 const bool CheckAgainstPointer;
3905 CatchTypePublicBases(
3907 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &T,
bool C)
3908 : Ctx(Ctx), TypesToCheck(T), CheckAgainstPointer(C),
3909 FoundHandler(
nullptr) {}
3911 CXXCatchStmt *getFoundHandler()
const {
return FoundHandler; }
3912 CanQualType getFoundHandlerType()
const {
return FoundHandlerType; }
3916 CatchHandlerType Check(S->
getType(), CheckAgainstPointer);
3917 const auto &M = TypesToCheck;
3918 auto I = M.find(Check);
3920 FoundHandler = I->second;
3935 if (!getLangOpts().CXXExceptions &&
3936 !getSourceManager().isInSystemHeader(TryLoc) &&
3937 (!getLangOpts().OpenMPIsDevice ||
3938 !getLangOpts().OpenMPHostCXXExceptions ||
3939 isInOpenMPTargetExecutionDirective() ||
3940 isInOpenMPDeclareTargetContext()))
3941 Diag(TryLoc, diag::err_exceptions_disabled) <<
"try";
3944 if (getLangOpts().CUDA)
3945 CUDADiagIfDeviceCode(TryLoc, diag::err_cuda_device_exceptions)
3946 <<
"try" << CurrentCUDATarget();
3948 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
3949 Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) <<
"try";
3955 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
3959 const unsigned NumHandlers = Handlers.size();
3960 assert(!Handlers.empty() &&
3961 "The parser shouldn't call this if there are no handlers.");
3963 llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> HandledTypes;
3964 for (
unsigned i = 0; i < NumHandlers; ++i) {
3971 if (i < NumHandlers - 1)
3980 CatchHandlerType HandlerCHT =
3986 QualType Underlying = HandlerCHT.underlying();
3988 if (!RD->hasDefinition())
3997 CatchTypePublicBases CTPB(Context, HandledTypes, HandlerCHT.isPointer());
3998 if (RD->lookupInBases(CTPB, Paths)) {
4000 if (!Paths.
isAmbiguous(CTPB.getFoundHandlerType())) {
4002 diag::warn_exception_caught_by_earlier_handler)
4005 diag::note_previous_exception_handler)
4013 auto R = HandledTypes.insert(std::make_pair(H->
getCaughtType(), H));
4017 diag::warn_exception_caught_by_earlier_handler)
4020 diag::note_previous_exception_handler)
4032 assert(TryBlock && Handler);
4038 if (!getLangOpts().Borland) {
4040 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4056 Diag(TryLoc, diag::err_seh_try_outside_functions);
4060 Diag(TryLoc, diag::err_seh_try_unsupported);
4069 assert(FilterExpr && Block);
4073 diag::err_filter_expression_integral)
4081 CurrentSEHFinally.push_back(CurScope);
4085 CurrentSEHFinally.pop_back();
4090 CurrentSEHFinally.pop_back();
4096 Scope *SEHTryParent = CurScope;
4098 SEHTryParent = SEHTryParent->
getParent();
4100 return StmtError(
Diag(Loc, diag::err_ms___leave_not_in___try));
4113 QualifierLoc, NameInfo,
4114 cast<CompoundStmt>(Nested));
4123 return BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
4125 GetNameFromUnqualifiedId(Name),
4131 unsigned NumParams) {
4148 assert(NumParams > 0 &&
"CapturedStmt requires context parameter");
4159 if (Cap.isThisCapture()) {
4162 CaptureInits.push_back(Cap.getInitExpr());
4164 }
else if (Cap.isVLATypeCapture()) {
4167 CaptureInits.push_back(
nullptr);
4172 Cap.isReferenceCapture()
4175 Cap.getVariable()));
4176 CaptureInits.push_back(Cap.getInitExpr());
4182 unsigned NumParams) {
4184 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, NumParams);
4198 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4201 PushDeclContext(CurScope, CD);
4205 PushExpressionEvaluationContext(
4206 ExpressionEvaluationContext::PotentiallyEvaluated);
4213 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, Params.size());
4217 bool ContextIsFound =
false;
4218 unsigned ParamNum = 0;
4221 I != E; ++I, ++ParamNum) {
4222 if (I->second.isNull()) {
4223 assert(!ContextIsFound &&
4224 "null type has been found already for '__context' parameter");
4234 ContextIsFound =
true;
4244 assert(ContextIsFound &&
"no null type for '__context' parameter");
4245 if (!ContextIsFound) {
4256 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4259 PushDeclContext(CurScope, CD);
4263 PushExpressionEvaluationContext(
4264 ExpressionEvaluationContext::PotentiallyEvaluated);
4268 DiscardCleanupsInEvaluationContext();
4269 PopExpressionEvaluationContext();
4276 ActOnFields(
nullptr, Record->
getLocation(), Record, Fields,
4280 PopFunctionScopeInfo();
4294 getASTContext(), S, static_cast<CapturedRegionKind>(RSI->
CapRegionKind),
4295 Captures, CaptureInits, CD, RD);
4300 DiscardCleanupsInEvaluationContext();
4301 PopExpressionEvaluationContext();
4304 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.
SourceLocation getLocStart() const LLVM_READONLY
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.
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>.
Stmt - This represents one statement.
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.
IfStmt - This represents an if/then/else.
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.
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...
bool EvaluateAsInt(llvm::APSInt &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...
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)
SourceLocation getLocStart() const LLVM_READONLY
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 an expression – generally a full-expression – that introduces cleanups to be run at the ...
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)
static StmtResult RebuildForRangeWithDereference(Sema &SemaRef, Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *LoopVarDecl, SourceLocation ColonLoc, Expr *Range, SourceLocation RangeLoc, SourceLocation RParenLoc)
Speculatively attempt to dereference an invalid range expression.
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
field_range fields() const
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
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...
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.
This is a scope that corresponds to a switch statement.
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"...
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)
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
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, 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.
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.
StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, SourceLocation RParenLoc, BuildForRangeKind Kind)
ActOnCXXForRangeStmt - Check and build a C++11 for-range statement.
const internal::VariadicDynCastAllOfMatcher< Stmt, CaseStmt > caseStmt
Matches case statements inside switch statements.
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 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.
Expr - 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
getNameAsString - 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.
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.
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)
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...
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()
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
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...
const SwitchCase * getSwitchCaseList() const
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...
SourceLocation getLocStart() const LLVM_READONLY
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.
SourceLocation getLocEnd() const LLVM_READONLY
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...
SourceLocation getStartLoc() const LLVM_READONLY
const Scope * getParent() const
getParent - Return the scope that this is nested in.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
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)
void setARCPseudoStrong(bool ps)
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.
SourceLocation getLocStart() const LLVM_READONLY
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.
const Stmt * getBody() const
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...
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.
SourceLocation getExprLoc() const LLVM_READONLY
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.
const Expr * getCond() const
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)
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.
const DeclStmt * getConditionVariableDeclStmt() const
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
QualType getType() const
Retrieves the type of the base class.