35 #include "llvm/ADT/ArrayRef.h" 36 #include "llvm/ADT/DenseMap.h" 37 #include "llvm/ADT/STLExtras.h" 38 #include "llvm/ADT/SmallPtrSet.h" 39 #include "llvm/ADT/SmallString.h" 40 #include "llvm/ADT/SmallVector.h" 42 using namespace clang;
49 FE = ActOnFinishFullExpr(FE.
get(), FE.
get()->getExprLoc(), DiscardedValue);
63 DiscardCleanupsInEvaluationContext();
68 bool HasLeadingEmptyMacro) {
69 return new (Context)
NullStmt(SemiLoc, HasLeadingEmptyMacro);
79 return new (Context)
DeclStmt(DG, StartLoc, EndLoc);
109 if (getLangOpts().ObjCAutoRefCount) {
134 if (!Op->isComparisonOp())
137 if (Op->getOpcode() == BO_EQ)
139 else if (Op->getOpcode() == BO_NE)
141 else if (Op->getOpcode() == BO_Cmp)
144 assert(Op->isRelationalOp());
147 Loc = Op->getOperatorLoc();
148 CanAssign = Op->getLHS()->IgnoreParenImpCasts()->isLValue();
150 switch (Op->getOperator()) {
154 case OO_ExclaimEqual:
159 case OO_GreaterEqual:
170 Loc = Op->getOperatorLoc();
171 CanAssign = Op->getArg(0)->IgnoreParenImpCasts()->isLValue();
182 S.
Diag(Loc, diag::warn_unused_comparison)
188 if (Kind == Inequality)
189 S.
Diag(Loc, diag::note_inequality_comparison_to_or_assign)
192 S.
Diag(Loc, diag::note_equality_comparison_to_assign)
201 return DiagnoseUnusedExprResult(
Label->getSubStmt());
203 const Expr *E = dyn_cast_or_null<Expr>(S);
209 if (isUnevaluatedContext())
218 bool ShouldSuppress =
219 SourceMgr.isMacroBodyExpansion(ExprLoc) ||
220 SourceMgr.isInSystemMacro(ExprLoc);
222 const Expr *WarnExpr;
225 if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context))
238 if (isa<ParenExpr>(E->IgnoreImpCasts()) && Loc.
isMacroID()) {
240 if (findMacroSpelling(SpellLoc,
"UNREFERENCED_PARAMETER"))
247 unsigned DiagID = diag::warn_unused_expr;
248 if (
const FullExpr *Temps = dyn_cast<FullExpr>(E))
249 E = Temps->getSubExpr();
251 E = TempExpr->getSubExpr();
257 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
258 if (E->getType()->isVoidType())
261 if (
const Attr *A = CE->getUnusedResultAttr(Context)) {
262 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
270 if (
const Decl *FD = CE->getCalleeDecl()) {
273 if (FD->hasAttr<PureAttr>()) {
274 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"pure";
277 if (FD->hasAttr<ConstAttr>()) {
278 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"const";
282 }
else if (ShouldSuppress)
286 if (getLangOpts().ObjCAutoRefCount && ME->isDelegateInitCall()) {
287 Diag(Loc, diag::err_arc_unused_init_message) << R1;
292 if (
const auto *A = MD->
getAttr<WarnUnusedResultAttr>()) {
293 Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
298 const Expr *Source = POE->getSyntacticForm();
299 if (isa<ObjCSubscriptRefExpr>(Source))
300 DiagID = diag::warn_unused_container_subscript_expr;
302 DiagID = diag::warn_unused_property_expr;
304 = dyn_cast<CXXFunctionalCastExpr>(E)) {
305 const Expr *E = FC->getSubExpr();
307 E = TE->getSubExpr();
308 if (isa<CXXTemporaryObjectExpr>(E))
311 if (
const CXXRecordDecl *RD = CE->getType()->getAsCXXRecordDecl())
312 if (!RD->getAttr<WarnUnusedAttr>())
316 else if (
const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E)) {
324 Diag(Loc, diag::warn_unused_voidptr)
330 if (E->isGLValue() && E->getType().isVolatileQualified()) {
331 Diag(Loc, diag::warn_unused_volatile) << R1 << R2;
335 DiagRuntimeBehavior(Loc,
nullptr, PDiag(DiagID) << R1 << R2);
339 PushCompoundScope(IsStmtExpr);
347 return getCurFunction()->CompoundScopes.back();
352 const unsigned NumElts = Elts.size();
360 for (; i != NumElts && isa<DeclStmt>(Elts[
i]); ++
i)
364 for (; i != NumElts && !isa<DeclStmt>(Elts[
i]); ++
i)
368 Decl *D = *cast<DeclStmt>(Elts[
i])->decl_begin();
376 if (NumElts != 0 && !CurrentInstantiationScope &&
377 getCurCompoundScope().HasEmptyLoopBodies) {
378 for (
unsigned i = 0;
i != NumElts - 1; ++
i)
379 DiagnoseEmptyLoopBody(Elts[
i], Elts[i + 1]);
390 if (DiagnoseUnexpandedParameterPack(Val.
get()))
395 if (!getCurFunction()->SwitchStack.empty()) {
397 getCurFunction()->SwitchStack.back().getPointer()->getCond();
402 auto CheckAndFinish = [&](
Expr *E) {
406 if (getLangOpts().CPlusPlus11) {
409 llvm::APSInt TempVal;
415 if (!E->isValueDependent())
416 ER = VerifyIntegerConstantExpression(E);
418 ER = DefaultLvalueConversion(ER.
get());
420 ER = ImpCastExprToType(ER.
get(), CondType, CK_IntegralCast);
424 ExprResult Converted = CorrectDelayedTyposInExpr(Val, CheckAndFinish);
425 if (Converted.
get() == Val.
get())
426 Converted = CheckAndFinish(Val.
get());
432 return ActOnFinishFullExpr(Val.
get(), Val.
get()->getExprLoc(),
false,
433 getLangOpts().CPlusPlus11);
440 assert((LHSVal.
isInvalid() || LHSVal.
get()) &&
"missing LHS value");
443 "missing RHS value");
445 if (getCurFunction()->SwitchStack.empty()) {
446 Diag(CaseLoc, diag::err_case_not_in_switch);
451 getCurFunction()->SwitchStack.back().setInt(
true);
457 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(CS);
463 cast<CaseStmt>(S)->setSubStmt(SubStmt);
469 if (getCurFunction()->SwitchStack.empty()) {
470 Diag(DefaultLoc, diag::err_default_not_in_switch);
475 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(DS);
484 Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->
getDeclName();
516 CommaVisitor(
Sema &SemaRef) : Inherited(SemaRef.
Context), SemaRef(SemaRef) {}
538 Expr *CondExpr = Cond.
get().second;
541 !Diags.isIgnored(diag::warn_comma_operator, CondExpr->
getExprLoc()))
542 CommaVisitor(*this).Visit(CondExpr);
545 DiagnoseEmptyStmtBody(CondExpr->
getEndLoc(), thenStmt,
546 diag::warn_empty_if_body);
548 return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
559 if (IsConstexpr || isa<ObjCAvailabilityCheckExpr>(Cond.
get().second))
560 setFunctionHasBranchProtectedScope();
563 Cond.
get().second, thenStmt, ElseLoc, elseStmt);
567 struct CaseCompareFunctor {
568 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
569 const llvm::APSInt &RHS) {
570 return LHS.first < RHS;
572 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
573 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
574 return LHS.first < RHS.first;
576 bool operator()(
const llvm::APSInt &LHS,
577 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
578 return LHS < RHS.first;
585 static bool CmpCaseVals(
const std::pair<llvm::APSInt, CaseStmt*>& lhs,
586 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
587 if (lhs.first < rhs.first)
590 if (lhs.first == rhs.first &&
591 lhs.second->getCaseLoc().getRawEncoding()
592 < rhs.second->getCaseLoc().getRawEncoding())
599 static bool CmpEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
600 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
602 return lhs.first < rhs.first;
607 static bool EqEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
608 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
610 return lhs.first == rhs.first;
616 if (
const auto *FE = dyn_cast<FullExpr>(E))
617 E = FE->getSubExpr();
618 while (
const auto *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
619 if (ImpCast->getCastKind() != CK_IntegralCast)
break;
620 E = ImpCast->getSubExpr();
630 SwitchConvertDiagnoser(
Expr *Cond)
636 return S.
Diag(Loc, diag::err_typecheck_statement_requires_integer) << T;
641 return S.
Diag(Loc, diag::err_switch_incomplete_class_type)
647 return S.
Diag(Loc, diag::err_switch_explicit_conversion) << T << ConvTy;
658 return S.
Diag(Loc, diag::err_switch_multiple_conversions) << T;
669 llvm_unreachable(
"conversion functions are permitted");
671 } SwitchDiagnoser(Cond);
674 PerformContextualImplicitConversion(SwitchLoc, Cond, SwitchDiagnoser);
680 Cond = CondResult.
get();
686 return UsualUnaryConversions(Cond);
691 Expr *CondExpr = Cond.
get().second;
692 assert((Cond.
isInvalid() || CondExpr) &&
"switch with no condition");
700 "invalid condition type");
705 Diag(SwitchLoc, diag::warn_bool_switch_condition)
710 setFunctionHasBranchIntoScope();
713 getCurFunction()->SwitchStack.push_back(
718 static void AdjustAPSInt(llvm::APSInt &Val,
unsigned BitWidth,
bool IsSigned) {
719 Val = Val.extOrTrunc(BitWidth);
720 Val.setIsSigned(IsSigned);
726 unsigned UnpromotedWidth,
bool UnpromotedSign) {
734 if (UnpromotedWidth < Val.getBitWidth()) {
735 llvm::APSInt ConvVal(Val);
737 AdjustAPSInt(ConvVal, Val.getBitWidth(), Val.isSigned());
742 S.
Diag(Loc, diag::warn_case_value_overflow) << Val.toString(10)
743 << ConvVal.toString(10);
753 const Expr *CaseExpr,
754 EnumValsTy::iterator &EI,
755 EnumValsTy::iterator &EIEnd,
756 const llvm::APSInt &Val) {
762 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
771 if (ED->
hasAttr<FlagEnumAttr>())
774 while (EI != EIEnd && EI->first < Val)
777 if (EI != EIEnd && EI->first == Val)
790 if (!CondEnumType || !CaseEnumType)
797 if (!CaseEnumType->getDecl()->getIdentifier() &&
798 !CaseEnumType->getDecl()->getTypedefNameForAnonDecl())
804 S.
Diag(Case->
getExprLoc(), diag::warn_comparison_of_mixed_enum_types_switch)
813 bool CaseListIsIncomplete = getCurFunction()->SwitchStack.back().getInt();
814 assert(SS == getCurFunction()->SwitchStack.back().getPointer() &&
815 "switch stack missing push/pop!");
817 getCurFunction()->SwitchStack.pop_back();
820 SS->
setBody(BodyStmt, SwitchLoc);
834 const Expr *CondExprBeforePromotion = CondExpr;
840 bool HasDependentValue
842 unsigned CondWidth = HasDependentValue ? 0 : Context.
getIntWidth(CondType);
849 unsigned CondWidthBeforePromotion
850 = HasDependentValue ? 0 : Context.
getIntWidth(CondTypeBeforePromotion);
851 bool CondIsSignedBeforePromotion
861 typedef std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRangesTy;
862 CaseRangesTy CaseRanges;
866 bool CaseListIsErroneous =
false;
872 if (TheDefaultStmt) {
873 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
880 CaseListIsErroneous =
true;
889 if (Lo->isValueDependent()) {
890 HasDependentValue =
true;
896 const Expr *LoBeforePromotion = Lo;
902 checkCaseValue(*
this, Lo->getBeginLoc(), LoVal, CondWidthBeforePromotion,
903 CondIsSignedBeforePromotion);
915 HasDependentValue =
true;
918 CaseRanges.push_back(std::make_pair(LoVal, CS));
920 CaseVals.push_back(std::make_pair(LoVal, CS));
924 if (!HasDependentValue) {
927 llvm::APSInt ConstantCondValue;
928 bool HasConstantCond =
false;
929 if (!HasDependentValue && !TheDefaultStmt) {
935 assert(!HasConstantCond ||
936 (ConstantCondValue.getBitWidth() == CondWidth &&
937 ConstantCondValue.isSigned() == CondIsSigned));
939 bool ShouldCheckConstantCond = HasConstantCond;
944 if (!CaseVals.empty()) {
945 for (
unsigned i = 0, e = CaseVals.size();
i != e; ++
i) {
946 if (ShouldCheckConstantCond &&
947 CaseVals[
i].first == ConstantCondValue)
948 ShouldCheckConstantCond =
false;
950 if (
i != 0 && CaseVals[
i].first == CaseVals[
i-1].first) {
953 StringRef PrevString, CurrString;
956 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(PrevCase)) {
957 PrevString = DeclRef->getDecl()->getName();
959 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(CurrCase)) {
960 CurrString = DeclRef->getDecl()->getName();
963 CaseVals[
i-1].first.toString(CaseValStr);
965 if (PrevString == CurrString)
966 Diag(CaseVals[
i].second->getLHS()->getBeginLoc(),
967 diag::err_duplicate_case)
968 << (PrevString.empty() ? StringRef(CaseValStr) : PrevString);
970 Diag(CaseVals[
i].second->getLHS()->getBeginLoc(),
971 diag::err_duplicate_case_differing_expr)
972 << (PrevString.empty() ? StringRef(CaseValStr) : PrevString)
973 << (CurrString.empty() ? StringRef(CaseValStr) : CurrString)
976 Diag(CaseVals[
i - 1].second->getLHS()->getBeginLoc(),
977 diag::note_duplicate_case_prev);
980 CaseListIsErroneous =
true;
987 if (!CaseRanges.empty()) {
990 llvm::stable_sort(CaseRanges);
993 std::vector<llvm::APSInt> HiVals;
994 for (
unsigned i = 0, e = CaseRanges.size();
i != e; ++
i) {
995 llvm::APSInt &LoVal = CaseRanges[
i].first;
999 const Expr *HiBeforePromotion = Hi;
1006 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
1012 if (LoVal > HiVal) {
1015 CaseRanges.erase(CaseRanges.begin()+
i);
1021 if (ShouldCheckConstantCond &&
1022 LoVal <= ConstantCondValue &&
1023 ConstantCondValue <= HiVal)
1024 ShouldCheckConstantCond =
false;
1026 HiVals.push_back(HiVal);
1032 for (
unsigned i = 0, e = CaseRanges.size();
i != e; ++
i) {
1033 llvm::APSInt &CRLo = CaseRanges[
i].first;
1034 llvm::APSInt &CRHi = HiVals[
i];
1040 llvm::APSInt OverlapVal(32);
1044 CaseValsTy::iterator I =
1045 llvm::lower_bound(CaseVals, CRLo, CaseCompareFunctor());
1046 if (I != CaseVals.end() && I->first < CRHi) {
1047 OverlapVal = I->first;
1048 OverlapStmt = I->second;
1052 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
1053 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
1054 OverlapVal = (I-1)->first;
1055 OverlapStmt = (I-1)->second;
1060 if (
i && CRLo <= HiVals[
i-1]) {
1061 OverlapVal = HiVals[
i-1];
1062 OverlapStmt = CaseRanges[
i-1].second;
1068 << OverlapVal.toString(10);
1070 diag::note_duplicate_case_prev);
1073 CaseListIsErroneous =
true;
1079 if (!CaseListIsErroneous && !CaseListIsIncomplete &&
1080 ShouldCheckConstantCond) {
1083 Diag(CondExpr->
getExprLoc(), diag::warn_missing_case_for_condition)
1084 << ConstantCondValue.toString(10)
1096 if (!CaseListIsErroneous && !CaseListIsIncomplete && !HasConstantCond &&
1104 llvm::APSInt Val = EDI->getInitVal();
1106 EnumVals.push_back(std::make_pair(Val, EDI));
1109 auto EI = EnumVals.begin(), EIEnd =
1110 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1113 for (CaseValsTy::const_iterator CI = CaseVals.begin();
1114 CI != CaseVals.end(); CI++) {
1115 Expr *CaseExpr = CI->second->getLHS();
1119 << CondTypeBeforePromotion;
1123 EI = EnumVals.begin();
1124 for (CaseRangesTy::const_iterator RI = CaseRanges.begin();
1125 RI != CaseRanges.end(); RI++) {
1126 Expr *CaseExpr = RI->second->getLHS();
1130 << CondTypeBeforePromotion;
1133 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1136 CaseExpr = RI->second->getRHS();
1140 << CondTypeBeforePromotion;
1144 auto CI = CaseVals.begin();
1145 auto RI = CaseRanges.begin();
1146 bool hasCasesNotInSwitch =
false;
1150 for (EI = EnumVals.begin(); EI != EIEnd; EI++) {
1152 switch (EI->second->getAvailability()) {
1165 if (EI->second->hasAttr<UnusedAttr>())
1169 while (CI != CaseVals.end() && CI->first < EI->first)
1172 if (CI != CaseVals.end() && CI->first == EI->first)
1176 for (; RI != CaseRanges.end(); RI++) {
1178 RI->second->getRHS()->EvaluateKnownConstInt(Context);
1180 if (EI->first <= Hi)
1184 if (RI == CaseRanges.end() || EI->first < RI->first) {
1185 hasCasesNotInSwitch =
true;
1186 UnhandledNames.push_back(EI->second->getDeclName());
1190 if (TheDefaultStmt && UnhandledNames.empty() && ED->
isClosedNonFlag())
1194 if (!UnhandledNames.empty()) {
1196 TheDefaultStmt ? diag::warn_def_missing_case
1197 : diag::warn_missing_case)
1198 << (
int)UnhandledNames.size();
1200 for (
size_t I = 0, E =
std::min(UnhandledNames.size(), (
size_t)3);
1202 DB << UnhandledNames[I];
1205 if (!hasCasesNotInSwitch)
1211 DiagnoseEmptyStmtBody(CondExpr->
getEndLoc(), BodyStmt,
1212 diag::warn_empty_switch_body);
1216 if (CaseListIsErroneous)
1225 if (Diags.isIgnored(diag::warn_not_in_enum_assignment, SrcExpr->
getExprLoc()))
1239 const EnumDecl *ED = ET->getDecl();
1244 if (ED->
hasAttr<FlagEnumAttr>()) {
1245 if (!IsValueInFlagEnum(ED, RhsVal,
true))
1251 EnumValsTy EnumVals;
1256 llvm::APSInt Val = EDI->getInitVal();
1258 EnumVals.push_back(std::make_pair(Val, EDI));
1260 if (EnumVals.empty())
1263 EnumValsTy::iterator EIend =
1264 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1267 EnumValsTy::const_iterator EI = EnumVals.begin();
1268 while (EI != EIend && EI->first < RhsVal)
1270 if (EI == EIend || EI->first != RhsVal) {
1284 auto CondVal = Cond.
get();
1285 CheckBreakContinueBinding(CondVal.second);
1287 if (CondVal.second &&
1288 !Diags.isIgnored(diag::warn_comma_operator, CondVal.second->getExprLoc()))
1289 CommaVisitor(*this).Visit(CondVal.second);
1291 if (isa<NullStmt>(Body))
1292 getCurCompoundScope().setHasEmptyLoopBodies();
1302 assert(Cond &&
"ActOnDoStmt(): missing expression");
1304 CheckBreakContinueBinding(Cond);
1305 ExprResult CondResult = CheckBooleanCondition(DoLoc, Cond);
1308 Cond = CondResult.
get();
1310 CondResult = ActOnFinishFullExpr(Cond, DoLoc,
false);
1313 Cond = CondResult.
get();
1316 if (Cond && !getLangOpts().
C99 && !getLangOpts().
CPlusPlus &&
1317 !Diags.isIgnored(diag::warn_comma_operator, Cond->
getExprLoc()))
1318 CommaVisitor(*this).Visit(Cond);
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) {
1415 DeclSetVector &Decls;
1421 DeclMatcher(
Sema &S, DeclSetVector &Decls,
Stmt *Statement) :
1422 Inherited(S.
Context), Decls(Decls), FoundDecl(
false) {
1423 if (!Statement)
return;
1447 void CheckLValueToRValueCast(
Expr *E) {
1450 if (isa<DeclRefExpr>(E)) {
1455 Visit(CO->getCond());
1456 CheckLValueToRValueCast(CO->getTrueExpr());
1457 CheckLValueToRValueCast(CO->getFalseExpr());
1462 dyn_cast<BinaryConditionalOperator>(E)) {
1463 CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr());
1464 CheckLValueToRValueCast(BCO->getFalseExpr());
1473 if (Decls.count(VD))
1481 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(S))
1483 Visit(OVE->getSourceExpr());
1489 bool FoundDeclInUse() {
return FoundDecl; }
1493 void CheckForLoopConditionalStatement(
Sema &S,
Expr *Second,
1496 if (!Second)
return;
1503 DeclSetVector Decls;
1505 DeclExtractor DE(S, Decls, Ranges);
1509 if (!DE.isSimple())
return;
1512 if (Decls.size() == 0)
return;
1515 for (
auto *VD : Decls)
1516 if (VD->getType().isVolatileQualified() || VD->hasGlobalStorage())
1519 if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
1520 DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
1521 DeclMatcher(S, Decls, Body).FoundDeclInUse())
1525 if (Decls.size() > 4) {
1528 PDiag << (unsigned)Decls.size();
1529 for (
auto *VD : Decls)
1530 PDiag << VD->getDeclName();
1533 for (
auto Range : Ranges)
1536 S.
Diag(Ranges.begin()->getBegin(), PDiag);
1541 bool ProcessIterationStmt(
Sema &S,
Stmt* Statement,
bool &Increment,
1543 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(Statement))
1544 if (!Cleanups->cleanupsHaveSideEffects())
1545 Statement = Cleanups->getSubExpr();
1547 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(Statement)) {
1548 switch (UO->getOpcode()) {
1549 default:
return false;
1567 default:
return false;
1587 bool InSwitch =
false;
1590 BreakContinueFinder(
Sema &S,
const Stmt* Body) :
1601 void VisitBreakStmt(
const BreakStmt* E) {
1621 void VisitForStmt(
const ForStmt *S) {
1628 void VisitWhileStmt(
const WhileStmt *) {
1633 void VisitDoStmt(
const DoStmt *) {
1660 bool ContinueFound() {
return ContinueLoc.
isValid(); }
1661 bool BreakFound() {
return BreakLoc.
isValid(); }
1672 void CheckForRedundantIteration(
Sema &S,
Expr *Third,
Stmt *Body) {
1674 if (!Body || !Third)
return;
1684 if (!LastStmt)
return;
1686 bool LoopIncrement, LastIncrement;
1689 if (!ProcessIterationStmt(S, Third, LoopIncrement, LoopDRE))
return;
1690 if (!ProcessIterationStmt(S, LastStmt, LastIncrement, LastDRE))
return;
1694 if (LoopIncrement != LastIncrement ||
1697 if (BreakContinueFinder(S, Body).ContinueFound())
return;
1700 << LastDRE->
getDecl() << LastIncrement;
1708 void Sema::CheckBreakContinueBinding(
Expr *E) {
1711 BreakContinueFinder BCFinder(*
this, E);
1713 if (BCFinder.BreakFound() && BreakParent) {
1715 Diag(BCFinder.GetBreakLoc(), diag::warn_break_binds_to_switch);
1717 Diag(BCFinder.GetBreakLoc(), diag::warn_loop_ctrl_binds_to_inner)
1720 }
else if (BCFinder.ContinueFound() && CurScope->getContinueParent()) {
1721 Diag(BCFinder.GetContinueLoc(), diag::warn_loop_ctrl_binds_to_inner)
1733 if (!getLangOpts().CPlusPlus) {
1734 if (
DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
1738 for (
auto *DI : DS->decls()) {
1743 Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
1744 DI->setInvalidDecl();
1750 CheckBreakContinueBinding(Second.
get().second);
1751 CheckBreakContinueBinding(third.
get());
1753 if (!Second.
get().first)
1754 CheckForLoopConditionalStatement(*
this, Second.
get().second, third.
get(),
1756 CheckForRedundantIteration(*
this, third.
get(), Body);
1758 if (Second.
get().second &&
1759 !Diags.isIgnored(diag::warn_comma_operator,
1760 Second.
get().second->getExprLoc()))
1761 CommaVisitor(*this).Visit(Second.
get().second);
1764 if (isa<NullStmt>(Body))
1765 getCurCompoundScope().setHasEmptyLoopBodies();
1767 return new (Context)
1768 ForStmt(Context, First, Second.
get().second, Second.
get().first, Third,
1769 Body, ForLoc, LParenLoc, RParenLoc);
1797 collection = result.
get();
1803 result = DefaultFunctionArrayLvalueConversion(collection);
1806 collection = result.
get();
1813 return Diag(forLoc, diag::err_collection_expr_type)
1824 (getLangOpts().ObjCAutoRefCount
1825 ? RequireCompleteType(forLoc,
QualType(objectType, 0),
1826 diag::err_arc_collection_forward, collection)
1827 : !isCompleteType(forLoc,
QualType(objectType, 0)))) {
1830 }
else if (iface || !objectType->
qual_empty()) {
1832 &Context.
Idents.
get(
"countByEnumeratingWithState"),
1848 method = LookupMethodInQualifiedType(selector, pointerType,
1853 Diag(forLoc, diag::warn_collection_expr_type)
1868 setFunctionHasBranchProtectedScope();
1871 CheckObjCForCollectionOperand(ForLoc, collection);
1875 if (
DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
1876 if (!DS->isSingleDecl())
1878 diag::err_toomany_element_decls));
1890 diag::err_non_local_variable_decl_in_for));
1896 Expr *DeducedInit = &OpaqueId;
1899 DiagnoseAutoDeductionFailure(D, DeducedInit);
1900 if (FirstType.
isNull()) {
1907 if (!inTemplateInstantiation()) {
1910 Diag(Loc, diag::warn_auto_var_is_id)
1916 Expr *FirstE = cast<Expr>(First);
1922 FirstType =
static_cast<Expr*
>(First)->getType();
1924 Diag(ForLoc, diag::err_selector_element_const_type)
1930 return StmtError(
Diag(ForLoc, diag::err_selector_element_type)
1937 CollectionExprResult =
1938 ActOnFinishFullExpr(CollectionExprResult.
get(),
false);
1943 nullptr, ForLoc, RParenLoc);
1997 void NoteForRangeBeginEndFunction(
Sema &SemaRef,
Expr *E,
2007 std::string Description;
2008 bool IsTemplate =
false;
2015 SemaRef.
Diag(Loc, diag::note_for_range_begin_end)
2016 << BEF << IsTemplate << Description << E->
getType();
2067 return Diag(InitStmt->
getBeginLoc(), diag::err_objc_for_range_init_stmt)
2069 return ActOnObjCForCollectionStmt(ForLoc, First, Range, RParenLoc);
2073 assert(DS &&
"first part of for range not a decl stmt");
2082 DiagnoseUnexpandedParameterPack(Range, UPPC_Expression)) {
2090 if (!ActOnCoroutineBodyStart(S, CoawaitLoc,
"co_await"))
2096 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2098 VarDecl *RangeVar = BuildForRangeVarDecl(*
this, RangeLoc,
2100 std::string(
"__range") + DepthStr);
2102 diag::err_for_range_deduction_failure)) {
2110 StmtResult RangeDecl = ActOnDeclStmt(RangeGroup, RangeLoc, RangeLoc);
2116 return BuildCXXForRangeStmt(
2117 ForLoc, CoawaitLoc, InitStmt, ColonLoc, RangeDecl.
get(),
2119 nullptr,
nullptr, DS, RParenLoc,
Kind);
2146 auto BuildBegin = [&] {
2150 BeginMemberLookup, CandidateSet,
2151 BeginRange, BeginExpr);
2156 << ColonLoc << BEF_begin << BeginRange->
getType();
2169 diag::err_for_range_iter_deduction_failure)) {
2170 NoteForRangeBeginEndFunction(SemaRef, BeginExpr->
get(), *BEF);
2176 auto BuildEnd = [&] {
2180 EndMemberLookup, CandidateSet,
2185 << ColonLoc << BEF_end << EndRange->
getType();
2189 diag::err_for_range_iter_deduction_failure)) {
2190 NoteForRangeBeginEndFunction(SemaRef, EndExpr->
get(), *BEF);
2203 if (BeginMemberLookup.isAmbiguous())
2210 if (BeginMemberLookup.empty() != EndMemberLookup.
empty()) {
2215 auto BuildNonmember = [&](
2217 llvm::function_ref<Sema::ForRangeStatus()> BuildFound,
2218 llvm::function_ref<Sema::ForRangeStatus()> BuildNotFound) {
2225 switch (BuildFound()) {
2232 SemaRef.
PDiag(diag::err_for_range_invalid)
2233 << BeginRange->
getType() << BEFFound),
2239 SemaRef.
Diag(D->getLocation(),
2240 diag::note_for_range_member_begin_end_ignored)
2241 << BeginRange->
getType() << BEFFound;
2245 llvm_unreachable(
"unexpected ForRangeStatus");
2247 if (BeginMemberLookup.empty())
2248 return BuildNonmember(BEF_end, EndMemberLookup, BuildEnd, BuildBegin);
2249 return BuildNonmember(BEF_begin, BeginMemberLookup, BuildBegin, BuildEnd);
2281 AdjustedRange = SemaRef.
BuildUnaryOp(S, RangeLoc, UO_Deref, Range);
2286 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2295 SemaRef.
Diag(RangeLoc, diag::err_for_range_dereference)
2298 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2304 struct InvalidateOnErrorScope {
2305 InvalidateOnErrorScope(
Sema &SemaRef,
Decl *D,
bool Enabled)
2306 : Trap(SemaRef.
Diags), D(D), Enabled(Enabled) {}
2307 ~InvalidateOnErrorScope() {
2308 if (Enabled && Trap.hasErrorOccurred())
2335 Scope *S = getCurScope();
2337 DeclStmt *RangeDS = cast<DeclStmt>(RangeDecl);
2339 QualType RangeVarType = RangeVar->getType();
2341 DeclStmt *LoopVarDS = cast<DeclStmt>(LoopVarDecl);
2346 InvalidateOnErrorScope Invalidate(*
this, LoopVar,
2347 LoopVar->getType()->isUndeducedType());
2353 if (RangeVarType->isDependentType()) {
2355 RangeVar->markUsed(Context);
2359 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2360 if (
auto *DD = dyn_cast<DecompositionDecl>(LoopVar))
2361 for (
auto *Binding : DD->bindings())
2363 LoopVar->setType(SubstAutoType(LoopVar->getType(), Context.
DependentTy));
2365 }
else if (!BeginDeclStmt.get()) {
2370 ExprResult BeginRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2375 ExprResult EndRangeRef = BuildDeclRefExpr(RangeVar, RangeVarNonRefType,
2381 Expr *Range = RangeVar->getInit();
2386 if (RequireCompleteType(RangeLoc, RangeType,
2387 diag::err_for_range_incomplete_type))
2392 const auto DepthStr = std::to_string(S->
getDepth() / 2);
2393 VarDecl *BeginVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2394 std::string(
"__begin") + DepthStr);
2395 VarDecl *EndVar = BuildForRangeVarDecl(*
this, ColonLoc, AutoType,
2396 std::string(
"__end") + DepthStr);
2407 BeginExpr = BeginRangeRef;
2409 BeginExpr = ActOnCoawaitExpr(S, ColonLoc, BeginExpr.
get());
2414 diag::err_for_range_iter_deduction_failure)) {
2415 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2425 dyn_cast<VariableArrayType>(UnqAT)) {
2448 ExprResult SizeOfVLAExprR = ActOnUnaryExprOrTypeTraitExpr(
2452 VAT->desugar(), RangeLoc))
2458 ExprResult SizeOfEachElementExprR = ActOnUnaryExprOrTypeTraitExpr(
2461 CreateParsedType(VAT->desugar(),
2463 VAT->getElementType(), RangeLoc))
2471 SizeOfVLAExprR.
get(), SizeOfEachElementExprR.
get());
2478 llvm_unreachable(
"Unexpected array type in for-range");
2482 EndExpr = ActOnBinOp(S, ColonLoc, tok::plus, EndRangeRef.
get(),
2487 diag::err_for_range_iter_deduction_failure)) {
2488 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2496 *
this, BeginRangeRef.
get(), EndRangeRef.
get(), RangeType, BeginVar,
2497 EndVar,
ColonLoc, CoawaitLoc, &CandidateSet, &BeginExpr, &EndExpr,
2500 if (Kind == BFRK_Build && RangeStatus == FRS_NoViableFunction &&
2501 BEFFailure == BEF_begin) {
2504 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Range)) {
2505 if (
ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
2506 QualType ArrayTy = PVD->getOriginalType();
2507 QualType PointerTy = PVD->getType();
2510 << RangeLoc << PVD << ArrayTy << PointerTy;
2511 Diag(PVD->getLocation(), diag::note_declared_at);
2520 CoawaitLoc, InitStmt,
2521 LoopVarDecl, ColonLoc,
2529 if (RangeStatus == FRS_NoViableFunction) {
2530 Expr *Range = BEFFailure ? EndRangeRef.
get() : BeginRangeRef.
get();
2531 CandidateSet.NoteCandidates(
2533 PDiag(diag::err_for_range_invalid)
2534 << RangeLoc << Range->
getType()
2539 if (RangeStatus != FRS_Success)
2544 "invalid range expression in for loop");
2548 QualType BeginType = BeginVar->getType(), EndType = EndVar->
getType();
2551 ? diag::warn_for_range_begin_end_types_differ
2552 : diag::ext_for_range_begin_end_types_differ)
2553 << BeginType << EndType;
2554 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2555 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2559 ActOnDeclStmt(ConvertDeclToDeclGroup(BeginVar), ColonLoc, ColonLoc);
2561 ActOnDeclStmt(ConvertDeclToDeclGroup(EndVar), ColonLoc, ColonLoc);
2564 ExprResult BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2569 ExprResult EndRef = BuildDeclRefExpr(EndVar, EndType.getNonReferenceType(),
2575 NotEqExpr = ActOnBinOp(S, ColonLoc, tok::exclaimequal,
2576 BeginRef.
get(), EndRef.
get());
2578 NotEqExpr = CheckBooleanCondition(ColonLoc, NotEqExpr.
get());
2581 ActOnFinishFullExpr(NotEqExpr.
get(),
false);
2583 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2584 << RangeLoc << 0 << BeginRangeRef.
get()->getType();
2585 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2587 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2592 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2597 IncrExpr = ActOnUnaryOp(S, ColonLoc, tok::plusplus, BeginRef.
get());
2598 if (!IncrExpr.isInvalid() && CoawaitLoc.
isValid())
2602 IncrExpr = ActOnCoawaitExpr(S, CoawaitLoc, IncrExpr.get());
2603 if (!IncrExpr.isInvalid())
2604 IncrExpr = ActOnFinishFullExpr(IncrExpr.get(),
false);
2605 if (IncrExpr.isInvalid()) {
2606 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2607 << RangeLoc << 2 << BeginRangeRef.
get()->getType() ;
2608 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2613 BeginRef = BuildDeclRefExpr(BeginVar, BeginRefNonRefType,
2618 ExprResult DerefExpr = ActOnUnaryOp(S, ColonLoc, tok::star, BeginRef.
get());
2620 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
2621 << RangeLoc << 1 << BeginRangeRef.
get()->getType();
2622 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2628 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) {
2629 AddInitializerToDecl(LoopVar, DerefExpr.
get(),
false);
2630 if (LoopVar->isInvalidDecl())
2631 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2637 if (Kind == BFRK_Check)
2641 InitStmt, RangeDS, cast_or_null<DeclStmt>(BeginDeclStmt.get()),
2642 cast_or_null<DeclStmt>(EndDeclStmt.
get()), NotEqExpr.
get(),
2643 IncrExpr.get(), LoopVarDS,
nullptr, ForLoc, CoawaitLoc,
2674 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(InitExpr))
2675 if (!Cleanups->cleanupsHaveSideEffects())
2676 InitExpr = Cleanups->getSubExpr();
2689 while (!isa<CXXOperatorCallExpr>(E) && !isa<UnaryOperator>(E)) {
2693 const MemberExpr *ME = cast<MemberExpr>(Call->getCallee());
2702 bool ReturnsReference =
false;
2703 if (isa<UnaryOperator>(E)) {
2704 ReturnsReference =
true;
2708 QualType ReturnType = FD->getReturnType();
2712 if (ReturnsReference) {
2716 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_const_reference_copy)
2717 << VD << VariableType << E->
getType();
2727 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_variable_always_copy)
2728 << VD << RangeInitType;
2748 if (!CE->getConstructor()->isCopyConstructor())
2750 }
else if (
const CastExpr *CE = dyn_cast<CastExpr>(InitExpr)) {
2751 if (CE->getCastKind() != CK_LValueToRValue)
2766 << VD << VariableType << InitExpr->
getType();
2782 if (SemaRef.
Diags.
isIgnored(diag::warn_for_range_const_reference_copy,
2784 SemaRef.
Diags.
isIgnored(diag::warn_for_range_variable_always_copy,
2820 if (isa<ObjCForCollectionStmt>(S))
2821 return FinishObjCForCollectionStmt(S, B);
2827 diag::warn_empty_range_based_for_body);
2837 setFunctionHasBranchIntoScope();
2839 return new (Context)
GotoStmt(TheDecl, GotoLoc, LabelLoc);
2851 CheckSingleAssignmentConstraints(DestTy, ExprRes);
2855 if (DiagnoseAssignmentResult(ConvTy, StarLoc, DestTy, ETy, E, AA_Passing))
2859 ExprResult ExprRes = ActOnFinishFullExpr(E,
false);
2864 setFunctionHasIndirectGoto();
2870 const Scope &DestScope) {
2873 S.
Diag(Loc, diag::warn_jump_out_of_seh_finally);
2882 return StmtError(
Diag(ContinueLoc, diag::err_continue_not_in_loop));
2894 return StmtError(
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
2897 return StmtError(
Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt)
2901 return new (Context)
BreakStmt(BreakLoc);
2934 if (isCopyElisionCandidate(ReturnType, VD, CESK))
2949 if (!(CESK & CES_AllowDifferentTypes) && !VDType->
isDependentType() &&
2955 if (VD->
getKind() != Decl::Var &&
2956 !((CESK & CES_AllowParameters) && VD->
getKind() == Decl::ParmVar))
2967 if (VD->
hasAttr<BlocksAttr>())
return false;
2969 if (CESK & CES_AllowDifferentTypes)
3005 bool ConvertingConstructorsOnly,
3010 Expr *InitExpr = &AsRvalue;
3013 Value->getBeginLoc(), Value->getBeginLoc());
3026 if (ConvertingConstructorsOnly) {
3027 if (isa<CXXConstructorDecl>(FD)) {
3045 if (isa<CXXConstructorDecl>(FD)) {
3051 }
else if (isa<CXXMethodDecl>(FD)) {
3054 if (cast<CXXMethodDecl>(FD)->getRefQualifier() !=
RQ_RValue)
3068 Res = Seq.Perform(S, Entity, Kind, Value);
3096 bool AffectedByCWG1579 =
false;
3098 if (!NRVOCandidate) {
3099 NRVOCandidate = getCopyElisionCandidate(ResultType, Value, CES_Default);
3100 if (NRVOCandidate &&
3101 !getDiagnostics().isIgnored(diag::warn_return_std_move_in_cxx11,
3103 const VarDecl *NRVOCandidateInCXX11 =
3104 getCopyElisionCandidate(ResultType, Value, CES_FormerDefault);
3105 AffectedByCWG1579 = (!NRVOCandidateInCXX11);
3109 if (NRVOCandidate) {
3114 if (!Res.
isInvalid() && AffectedByCWG1579) {
3126 assert(!ResultType.
isNull());
3128 Str +=
"std::move(";
3133 << NRVOCandidate->
getDeclName() << ResultType << QT;
3138 !getDiagnostics().isIgnored(diag::warn_return_std_move,
3140 const VarDecl *FakeNRVOCandidate =
3141 getCopyElisionCandidate(
QualType(), Value, CES_AsIfByStdMove);
3142 if (FakeNRVOCandidate) {
3156 FakeValue,
false, FakeRes);
3161 Str +=
"std::move(";
3202 bool HasDeducedReturnType =
3205 if (ExprEvalContexts.back().Context ==
3206 ExpressionEvaluationContext::DiscardedStatement &&
3210 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3213 RetValExp = ER.
get();
3219 if (HasDeducedReturnType) {
3227 assert(AT &&
"lost auto type from lambda return type");
3228 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3238 if (RetValExp && !isa<InitListExpr>(RetValExp)) {
3239 ExprResult Result = DefaultFunctionArrayLvalueConversion(RetValExp);
3242 RetValExp = Result.
get();
3248 if (!CurContext->isDependentContext())
3257 Diag(ReturnLoc, diag::err_lambda_return_init_list)
3261 FnRetType = Context.
VoidTy;
3269 assert(!FnRetType.isNull());
3271 if (
BlockScopeInfo *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
3273 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr);
3277 dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
3278 Diag(ReturnLoc, diag::err_return_in_captured_stmt) << CurRegion->getRegionName();
3281 assert(CurLambda &&
"unknown kind of captured scope");
3283 ->getNoReturnAttr()) {
3284 Diag(ReturnLoc, diag::err_noreturn_lambda_has_return_expr);
3292 const VarDecl *NRVOCandidate =
nullptr;
3293 if (FnRetType->isDependentType()) {
3296 }
else if (FnRetType->isVoidType()) {
3297 if (RetValExp && !isa<InitListExpr>(RetValExp) &&
3298 !(getLangOpts().CPlusPlus &&
3301 if (!getLangOpts().CPlusPlus &&
3303 Diag(ReturnLoc, diag::ext_return_has_void_expr) <<
"literal" << 2;
3305 Diag(ReturnLoc, diag::err_return_block_has_expr);
3306 RetValExp =
nullptr;
3309 }
else if (!RetValExp) {
3310 return StmtError(
Diag(ReturnLoc, diag::err_block_return_missing_expr));
3320 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3323 NRVOCandidate !=
nullptr);
3324 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3325 FnRetType, RetValExp);
3330 RetValExp = Res.
get();
3331 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc);
3333 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3338 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3341 RetValExp = ER.
get();
3350 FunctionScopes.back()->Returns.push_back(Result);
3352 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3353 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3371 class LocalTypedefNameReferencer
3374 LocalTypedefNameReferencer(
Sema &S) : S(S) {}
3379 bool LocalTypedefNameReferencer::VisitRecordType(
const RecordType *RT) {
3381 if (!R || !R->isLocalClass() || !R->isLocalClass()->isExternallyVisible() ||
3382 R->isDependentType())
3384 for (
auto *TmpD : R->decls())
3385 if (
auto *T = dyn_cast<TypedefNameDecl>(TmpD))
3386 if (T->getAccess() !=
AS_private || R->hasFriends())
3411 TypeLoc OrigResultType = getReturnTypeLoc(FD);
3414 if (RetExpr && isa<InitListExpr>(RetExpr)) {
3418 getCurLambda() ? diag::err_lambda_return_init_list
3419 : diag::err_auto_fn_return_init_list)
3429 assert(AT->
isDeduced() &&
"should have deduced to dependent type");
3442 if (DAR != DAR_Succeeded)
3447 LocalTypedefNameReferencer Referencer(*
this);
3448 Referencer.TraverseType(RetExpr->
getType());
3456 Diag(ReturnLoc, diag::err_auto_fn_return_void_but_not_auto)
3461 Deduced = SubstAutoType(OrigResultType.
getType(), Context.
VoidTy);
3485 Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible)
3489 Diag(ReturnLoc, diag::err_auto_fn_different_deductions)
3508 ExprResult RetVal = CorrectDelayedTyposInExpr(RetValExp);
3512 if (R.
isInvalid() || ExprEvalContexts.back().Context ==
3513 ExpressionEvaluationContext::DiscardedStatement)
3517 const_cast<VarDecl*>(cast<ReturnStmt>(R.
get())->getNRVOCandidate())) {
3530 if (RetValExp && DiagnoseUnexpandedParameterPack(RetValExp))
3533 if (isa<CapturingScopeInfo>(getCurFunction()))
3534 return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp);
3538 const AttrVec *Attrs =
nullptr;
3539 bool isObjCMethod =
false;
3542 FnRetType = FD->getReturnType();
3544 Attrs = &FD->getAttrs();
3545 if (FD->isNoReturn())
3546 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr)
3547 << FD->getDeclName();
3548 if (FD->isMain() && RetValExp)
3549 if (isa<CXXBoolLiteralExpr>(RetValExp))
3550 Diag(ReturnLoc, diag::warn_main_returns_bool_literal)
3553 FnRetType = MD->getReturnType();
3554 isObjCMethod =
true;
3556 Attrs = &MD->getAttrs();
3557 if (MD->hasRelatedResultType() && MD->getClassInterface()) {
3569 if (ExprEvalContexts.back().Context ==
3570 ExpressionEvaluationContext::DiscardedStatement &&
3574 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3577 RetValExp = ER.
get();
3588 if (DeduceFunctionTypeFromReturnExpr(FD, ReturnLoc, RetValExp, AT)) {
3602 if (isa<InitListExpr>(RetValExp)) {
3606 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3607 int FunctionKind = 0;
3608 if (isa<ObjCMethodDecl>(CurDecl))
3610 else if (isa<CXXConstructorDecl>(CurDecl))
3612 else if (isa<CXXDestructorDecl>(CurDecl))
3615 Diag(ReturnLoc, diag::err_return_init_list)
3620 RetValExp =
nullptr;
3623 unsigned D = diag::ext_return_has_expr;
3625 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3626 if (isa<CXXConstructorDecl>(CurDecl) ||
3627 isa<CXXDestructorDecl>(CurDecl))
3628 D = diag::err_ctor_dtor_returns_void;
3630 D = diag::ext_return_has_void_expr;
3634 Result = IgnoredValueConversions(Result.
get());
3637 RetValExp = Result.
get();
3638 RetValExp = ImpCastExprToType(RetValExp,
3639 Context.
VoidTy, CK_ToVoid).get();
3642 if (D == diag::err_ctor_dtor_returns_void) {
3643 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3645 << CurDecl->
getDeclName() << isa<CXXDestructorDecl>(CurDecl)
3649 else if (D != diag::ext_return_has_void_expr ||
3651 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
3653 int FunctionKind = 0;
3654 if (isa<ObjCMethodDecl>(CurDecl))
3656 else if (isa<CXXConstructorDecl>(CurDecl))
3658 else if (isa<CXXDestructorDecl>(CurDecl))
3669 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3672 RetValExp = ER.
get();
3678 }
else if (!RetValExp && !HasDependentReturnType) {
3684 DiagID = diag::err_constexpr_return_missing_expr;
3686 }
else if (getLangOpts().
C99) {
3688 DiagID = diag::ext_return_missing_expr;
3691 DiagID = diag::warn_return_missing_expr;
3695 Diag(ReturnLoc, DiagID)
3698 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1;
3703 assert(RetValExp || HasDependentReturnType);
3704 const VarDecl *NRVOCandidate =
nullptr;
3706 QualType RetType = RelatedRetType.
isNull() ? FnRetType : RelatedRetType;
3715 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, CES_Strict);
3720 NRVOCandidate !=
nullptr);
3721 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate,
3722 RetType, RetValExp);
3733 if (!RelatedRetType.
isNull()) {
3736 Res = PerformCopyInitialization(Entity, ReturnLoc, RetValExp);
3744 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc, isObjCMethod, Attrs,
3745 getCurFunctionDecl());
3750 ActOnFinishFullExpr(RetValExp, ReturnLoc,
false);
3753 RetValExp = ER.
get();
3761 FunctionScopes.back()->Returns.push_back(Result);
3763 if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
3764 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
3773 VarDecl *Var = cast_or_null<VarDecl>(Parm);
3788 if (!getLangOpts().ObjCExceptions)
3789 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@try";
3791 setFunctionHasBranchProtectedScope();
3792 unsigned NumCatchStmts = CatchStmts.size();
3794 NumCatchStmts, Finally);
3799 ExprResult Result = DefaultLvalueConversion(Throw);
3803 Result = ActOnFinishFullExpr(Result.
get(),
false);
3806 Throw = Result.
get();
3814 return StmtError(
Diag(AtLoc, diag::err_objc_throw_expects_object)
3825 if (!getLangOpts().ObjCExceptions)
3826 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@throw";
3831 Scope *AtCatchParent = CurScope;
3833 AtCatchParent = AtCatchParent->
getParent();
3835 return StmtError(
Diag(AtLoc, diag::err_rethrow_used_outside_catch));
3837 return BuildObjCAtThrowStmt(AtLoc, Throw);
3845 operand = result.
get();
3853 if (getLangOpts().CPlusPlus) {
3854 if (RequireCompleteType(atLoc, type,
3855 diag::err_incomplete_receiver_type))
3856 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3859 ExprResult result = PerformContextuallyConvertToObjCPointer(operand);
3863 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3866 operand = result.
get();
3868 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
3875 return ActOnFinishFullExpr(operand,
false);
3882 setFunctionHasBranchProtectedScope();
3890 Stmt *HandlerBlock) {
3892 return new (Context)
3893 CXXCatchStmt(CatchLoc, cast_or_null<VarDecl>(ExDecl), HandlerBlock);
3898 setFunctionHasBranchProtectedScope();
3903 class CatchHandlerType {
3905 unsigned IsPointer : 1;
3910 enum Unique { ForDenseMap };
3911 CatchHandlerType(
QualType QT, Unique) : QT(QT), IsPointer(
false) {}
3917 CatchHandlerType(
QualType Q) : QT(Q), IsPointer(
false) {
3929 CatchHandlerType(
QualType QT,
bool IsPointer)
3930 : QT(QT), IsPointer(IsPointer) {}
3932 QualType underlying()
const {
return QT; }
3933 bool isPointer()
const {
return IsPointer; }
3935 friend bool operator==(
const CatchHandlerType &LHS,
3936 const CatchHandlerType &RHS) {
3938 if (LHS.IsPointer != RHS.IsPointer)
3941 return LHS.QT == RHS.QT;
3950 CatchHandlerType::ForDenseMap);
3955 CatchHandlerType::ForDenseMap);
3963 const CatchHandlerType &RHS) {
3970 class CatchTypePublicBases {
3972 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &TypesToCheck;
3973 const bool CheckAgainstPointer;
3979 CatchTypePublicBases(
3981 const llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> &T,
bool C)
3982 : Ctx(Ctx), TypesToCheck(T), CheckAgainstPointer(C),
3983 FoundHandler(
nullptr) {}
3985 CXXCatchStmt *getFoundHandler()
const {
return FoundHandler; }
3986 CanQualType getFoundHandlerType()
const {
return FoundHandlerType; }
3990 CatchHandlerType Check(S->
getType(), CheckAgainstPointer);
3991 const auto &M = TypesToCheck;
3992 auto I = M.find(Check);
3994 FoundHandler = I->second;
4009 if (!getLangOpts().CXXExceptions &&
4010 !getSourceManager().isInSystemHeader(TryLoc) && !getLangOpts().CUDA) {
4012 targetDiag(TryLoc, diag::err_exceptions_disabled) <<
"try";
4016 if (getLangOpts().CUDA)
4017 CUDADiagIfDeviceCode(TryLoc, diag::err_cuda_device_exceptions)
4018 <<
"try" << CurrentCUDATarget();
4020 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope())
4021 Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) <<
"try";
4027 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4031 const unsigned NumHandlers = Handlers.size();
4032 assert(!Handlers.empty() &&
4033 "The parser shouldn't call this if there are no handlers.");
4035 llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> HandledTypes;
4036 for (
unsigned i = 0;
i < NumHandlers; ++
i) {
4043 if (
i < NumHandlers - 1)
4052 CatchHandlerType HandlerCHT =
4058 QualType Underlying = HandlerCHT.underlying();
4060 if (!RD->hasDefinition())
4069 CatchTypePublicBases CTPB(Context, HandledTypes, HandlerCHT.isPointer());
4070 if (RD->lookupInBases(CTPB, Paths)) {
4072 if (!Paths.
isAmbiguous(CTPB.getFoundHandlerType())) {
4074 diag::warn_exception_caught_by_earlier_handler)
4077 diag::note_previous_exception_handler)
4085 auto R = HandledTypes.insert(std::make_pair(H->
getCaughtType(), H));
4089 diag::warn_exception_caught_by_earlier_handler)
4092 diag::note_previous_exception_handler)
4104 assert(TryBlock && Handler);
4110 if (!getLangOpts().Borland) {
4112 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try);
4128 Diag(TryLoc, diag::err_seh_try_outside_functions);
4132 Diag(TryLoc, diag::err_seh_try_unsupported);
4141 assert(FilterExpr && Block);
4145 diag::err_filter_expression_integral)
4153 CurrentSEHFinally.push_back(CurScope);
4157 CurrentSEHFinally.pop_back();
4162 CurrentSEHFinally.pop_back();
4168 Scope *SEHTryParent = CurScope;
4170 SEHTryParent = SEHTryParent->
getParent();
4172 return StmtError(
Diag(Loc, diag::err_ms___leave_not_in___try));
4185 QualifierLoc, NameInfo,
4186 cast<CompoundStmt>(Nested));
4195 return BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
4197 GetNameFromUnqualifiedId(Name),
4203 unsigned NumParams) {
4220 assert(NumParams > 0 &&
"CapturedStmt requires context parameter");
4263 CaptureInits.push_back(Init.
get());
4270 unsigned NumParams) {
4272 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, NumParams);
4286 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4289 PushDeclContext(CurScope, CD);
4293 PushExpressionEvaluationContext(
4294 ExpressionEvaluationContext::PotentiallyEvaluated);
4301 RecordDecl *RD = CreateCapturedStmtRecordDecl(CD, Loc, Params.size());
4305 bool ContextIsFound =
false;
4306 unsigned ParamNum = 0;
4309 I != E; ++I, ++ParamNum) {
4310 if (I->second.isNull()) {
4311 assert(!ContextIsFound &&
4312 "null type has been found already for '__context' parameter");
4322 ContextIsFound =
true;
4332 assert(ContextIsFound &&
"no null type for '__context' parameter");
4333 if (!ContextIsFound) {
4344 PushCapturedRegionScope(CurScope, CD, RD, Kind);
4347 PushDeclContext(CurScope, CD);
4351 PushExpressionEvaluationContext(
4352 ExpressionEvaluationContext::PotentiallyEvaluated);
4356 DiscardCleanupsInEvaluationContext();
4357 PopExpressionEvaluationContext();
4366 ActOnFields(
nullptr, Record->getLocation(), Record, Fields,
4373 DiscardCleanupsInEvaluationContext();
4374 PopExpressionEvaluationContext();
4388 getASTContext(), S, static_cast<CapturedRegionKind>(RSI->
CapRegionKind),
4389 Captures, CaptureInits, CD, RD);
A call to an overloaded operator written using operator syntax.
Defines the clang::ASTContext interface.
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it's either not been deduced or was deduce...
QualType withConst() const
Retrieves a version of this type with const applied.
void setImplicit(bool I=true)
Represents a function declaration or definition.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
void setOrigin(CXXRecordDecl *Rec)
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
Smart pointer class that efficiently represents Objective-C method names.
QualType getObjCIdType() const
Represents the Objective-CC id type.
PointerType - C99 6.7.5.1 - Pointer Declarators.
EvaluatedExprVisitor - This class visits 'Expr *'s.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isBlockPointerType() const
static void TryMoveInitialization(Sema &S, const InitializedEntity &Entity, const VarDecl *NRVOCandidate, QualType ResultType, Expr *&Value, bool ConvertingConstructorsOnly, ExprResult &Res)
Try to perform the initialization of a potentially-movable value, which is the operand to a return or...
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
bool isLambdaConversionOperator(CXXConversionDecl *C)
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
Instantiation or recovery rebuild of a for-range statement.
SourceLocation getExprLoc() const
static void AdjustAPSInt(llvm::APSInt &Val, unsigned BitWidth, bool IsSigned)
void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, CapturedRegionKind Kind, unsigned NumParams)
StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, Stmt *HandlerBlock)
ActOnCXXCatchBlock - Takes an exception declaration and a handler block and creates a proper catch ha...
bool operator==(CanQual< T > x, CanQual< U > y)
static unsigned getHashValue(const CatchHandlerType &Base)
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
Stmt - This represents one statement.
static StmtResult RebuildForRangeWithDereference(Sema &SemaRef, Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, Stmt *LoopVarDecl, SourceLocation ColonLoc, Expr *Range, SourceLocation RangeLoc, SourceLocation RParenLoc)
Speculatively attempt to dereference an invalid range expression.
VarDecl * getCopyElisionCandidate(QualType ReturnType, Expr *E, CopyElisionSemanticsKind CESK)
Determine whether the given expression is a candidate for copy elision in either a return statement o...
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt *> Elts, bool isStmtExpr)
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
void setParam(unsigned i, ImplicitParamDecl *P)
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isRecordType() const
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, Stmt *InitStmt, ConditionResult Cond)
SmallVector< Scope *, 2 > CurrentSEHFinally
Stack of active SEH __finally scopes. Can be empty.
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments...
bool isDecltypeAuto() const
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
AssignConvertType
AssignConvertType - All of the 'assignment' semantic checks return this enum to indicate whether the ...
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
Represents a C++11 auto or C++14 decltype(auto) type.
Represents an attribute applied to a statement.
ParenExpr - This represents a parethesized expression, e.g.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
The base class of the type hierarchy.
Represents Objective-C's @throw statement.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a call to a C++ constructor.
SourceLocation getBeginLoc() const LLVM_READONLY
StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, Stmt *Body)
virtual void completeDefinition()
Note that the definition of this type is now complete.
QualType withConst() const
const TargetInfo & getTargetInfo() const
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
A container of type source information.
Wrapper for void* pointer.
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr *> Attrs, Stmt *SubStmt)
StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope)
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by...
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Determining whether a for-range statement could be built.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
Retains information about a function, method, or block that is currently being parsed.
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
This file provides some common utility functions for processing Lambda related AST Constructs...
enumerator_range enumerators() const
Represents a variable declaration or definition.
ActionResult< Stmt * > StmtResult
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
const VarDecl * getNRVOCandidate() const
Retrieve the variable that might be used for the named return value optimization. ...
StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, MultiStmtArg Catch, Stmt *Finally)
QualType getReturnType() const
DiagnosticsEngine & Diags
bool isEnumeralType() const
const AstTypeMatcher< PointerType > pointerType
Matches pointer types, but does not match Objective-C object pointer types.
const T * getAs() const
Member-template getAs<specific type>'.
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl)
static bool ObjCEnumerationCollection(Expr *Collection)
SourceLocation getStarLoc() const
RAII class that determines when any errors have occurred between the time the instance was created an...
ObjCMethodDecl - Represents an instance or class method declaration.
bool isInvalidDecl() const
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
Defines the Objective-C statement AST node classes.
EntityKind getKind() const
Determine the kind of initialization.
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement. ...
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input)
llvm::PointerIntPair< SwitchStmt *, 1, bool > SwitchInfo
A SwitchStmt, along with a flag indicating if its list of case statements is incomplete (because we d...
Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
static void checkCaseValue(Sema &S, SourceLocation Loc, const llvm::APSInt &Val, unsigned UnpromotedWidth, bool UnpromotedSign)
Check the specified case value is in range for the given unpromoted switch type.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Base wrapper for a particular "section" of type source info.
LabelStmt - Represents a label, which has a substatement.
Represents a struct/union/class.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
One of these records is kept for each identifier that is lexed.
bool isAtCatchScope() const
isAtCatchScope - Return true if this scope is @catch.
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Expr * getFalseExpr() const
void DiagnoseUnusedExprResult(const Stmt *S)
DiagnoseUnusedExprResult - If the statement passed in is an expression whose result is unused...
StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue=true)
Represents a class type in Objective C.
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A C++ nested-name-specifier augmented with source location information.
QualType getCaughtType() const
FullExpr - Represents a "full-expression" node.
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a member of a struct/union/class.
StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, SourceLocation RParenLoc, BuildForRangeKind Kind)
ActOnCXXForRangeStmt - Check and build a C++11 for-range statement.
void setLocStart(SourceLocation L)
ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, Expr *collection)
void startDefinition()
Starts the definition of this tag declaration.
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
bool isReferenceType() const
StmtResult BuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt, ConditionResult Cond, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
std::pair< VarDecl *, Expr * > get() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by...
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
void ActOnAbortSEHFinallyBlock()
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
void setARCPseudoStrong(bool PS)
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr *> Attrs, Stmt *SubStmt)
static bool buildCapturedStmtCaptureList(Sema &S, CapturedRegionScopeInfo *RSI, SmallVectorImpl< CapturedStmt::Capture > &Captures, SmallVectorImpl< Expr *> &CaptureInits)
Represents Objective-C's @catch statement.
StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
IndirectGotoStmt - This represents an indirect goto.
static Sema::ForRangeStatus BuildNonArrayForRange(Sema &SemaRef, Expr *BeginRange, Expr *EndRange, QualType RangeType, VarDecl *BeginVar, VarDecl *EndVar, SourceLocation ColonLoc, SourceLocation CoawaitLoc, OverloadCandidateSet *CandidateSet, ExprResult *BeginExpr, ExprResult *EndExpr, BeginEndFunction *BEF)
Create the initialization, compare, and increment steps for the range-based for loop expression...
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD)
bool isThisCapture() const
Represents a C++ unqualified-id that has been parsed.
An rvalue reference type, per C++11 [dcl.ref].
static ExprResult CheckConvertedConstantExpression(Sema &S, Expr *From, QualType T, APValue &Value, Sema::CCEKind CCE, bool RequireInt)
CheckConvertedConstantExpression - Check that the expression From is a converted constant expression ...
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Represents the results of name lookup.
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
This is a scope that corresponds to a switch statement.
APValue Val
Val - This is the value the expression can be folded to.
void ActOnStartSEHFinallyBlock()
AccessSpecifier getAccessSpecifier() const
Returns the access specifier for this base specifier.
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
Parameter for captured context.
SourceLocation getRParenLoc() const
An x-value expression is a reference to an object with independent storage but which can be "moved"...
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
RecordDecl * CreateCapturedStmtRecordDecl(CapturedDecl *&CD, SourceLocation Loc, unsigned NumParams)
A builtin binary operation expression such as "x + y" or "x <= y".
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt *> Stmts, SourceLocation LB, SourceLocation RB)
StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope)
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
SmallVector< std::pair< llvm::APSInt, EnumConstantDecl * >, 64 > EnumValsTy
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Scope - A scope is a transient data structure that is used while parsing the program.
static void checkEnumTypesInSwitchStmt(Sema &S, const Expr *Cond, const Expr *Case)
CaseStmt - Represent a case statement.
SourceLocation getContinueLoc() const
bool isMacroBodyExpansion(SourceLocation Loc) const
Tests whether the given source location represents the expansion of a macro body. ...
Represents a C++ nested-name-specifier or a global scope specifier.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, bool AllowMask) const
IsValueInFlagEnum - Determine if a value is allowed as part of a flag enum.
ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond)
Represents binding an expression to a temporary.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
const LangOptions & getLangOpts() const
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
static CatchHandlerType getTombstoneKey()
StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block)
StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope)
Perform initialization via a constructor.
Perform a user-defined conversion, either via a conversion function or via a constructor.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, SourceLocation RangeLoc, const DeclarationNameInfo &NameInfo, LookupResult &MemberLookup, OverloadCandidateSet *CandidateSet, Expr *Range, ExprResult *CallExpr)
Build a call to 'begin' or 'end' for a C++11 for-range statement.
Represents the body of a CapturedStmt, and serves as its DeclContext.
Represents an ObjC class declaration.
ExprResult BuildCaptureInit(const sema::Capture &Capture, SourceLocation ImplicitCaptureLoc, bool IsOpenMPMapping=false)
Initialize the given capture with a suitable expression.
Member name lookup, which finds the names of class/struct/union members.
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
SourceLocation getTypeSpecStartLoc() const
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, Scope *CurScope)
void setStmt(LabelStmt *T)
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point...
bool isSEHTrySupported() const
Whether the target supports SEH __try.
Contains information about the compound statement currently being parsed.
SourceLocation FirstCXXTryLoc
First C++ 'try' statement in the current function.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
unsigned getFlags() const
getFlags - Return the flags for this scope.
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
ConditionalOperator - The ?: ternary operator.
Sema - This implements semantic analysis and AST building for C.
A little helper class used to produce diagnostics.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
CompoundStmt - This represents a group of statements like { stmt stmt }.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represents a prototype with parameter type info, e.g.
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
Describes the capture of either a variable, or 'this', or variable-length array type.
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
Retains information about a captured region.
bool inferObjCARCLifetime(ValueDecl *decl)
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp)
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getLocation() const
void ActOnFinishOfCompoundStmt()
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
QualType getAutoRRefDeductType() const
C++11 deduction pattern for 'auto &&' type.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Scope * getCurScope() const
Retrieve the parser's current scope.
bool isVariableCapture() const
SourceLocation getBeginLoc() const
Get the begin source location.
Allows QualTypes to be sorted and hence used in maps and sets.
Retains information about a block that is currently being parsed.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
This represents one expression.
QualType getPointeeType() const
Allow any unmodeled side effect.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
SourceLocation getDefaultLoc() const
TypeLoc getReturnTypeLoc(FunctionDecl *FD) const
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
const T * castAs() const
Member-template castAs<specific type>.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
VarDecl * getExceptionDecl() const
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
std::string getAsString() const
Retrieve the human-readable string for this name.
static void DiagnoseForRangeConstVariableCopies(Sema &SemaRef, const VarDecl *VD)
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
void setContextParam(unsigned i, ImplicitParamDecl *P)
bool isSEHTryScope() const
Determine whether this scope is a SEH '__try' block.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
Defines the clang::Preprocessor interface.
ObjCLifetime getObjCLifetime() const
bool isFileContext() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
The entity being initialized is an exception object that is being thrown.
Represents Objective-C's @synchronized statement.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
Defines the clang::TypeLoc interface and its subclasses.
static DeclContext * castToDeclContext(const CapturedDecl *D)
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type...
bool isFunctionOrMethod() const
static CapturedDecl * Create(ASTContext &C, DeclContext *DC, unsigned NumParams)
static bool isEqual(const CatchHandlerType &LHS, const CatchHandlerType &RHS)
DeclContext * getParent()
getParent - Returns the containing DeclContext.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
An expression that sends a message to the given Objective-C object or class.
SwitchCase * getSwitchCaseList()
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
void setLocation(SourceLocation L)
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL)
Create a while statement.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
void setHasCXXTry(SourceLocation TryLoc)
Represents a C++ conversion function within a class.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
const Expr * getSubExpr() const
unsigned short CapRegionKind
The kind of captured region.
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr.cast]), which uses the syntax (Type)expr.
llvm::iterator_range< semantics_iterator > semantics()
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level)
Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.) for FD based on DSA for the...
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1...
SourceLocation getEndLoc() const LLVM_READONLY
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr, bool DelayTypeCreation=false)
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
DoStmt - This represents a 'do/while' stmt.
bool isConstQualified() const
Determine whether this type is const-qualified.
RecordDecl * getDecl() const
static CatchHandlerType getEmptyKey()
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond)
Create a switch statement.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
SelectorTable & Selectors
Assigning into this object requires the old value to be released and the new value to be retained...
This captures a statement into a function.
static bool EqEnumVals(const std::pair< llvm::APSInt, EnumConstantDecl *> &lhs, const std::pair< llvm::APSInt, EnumConstantDecl *> &rhs)
EqEnumVals - Comparison preficate for uniqing enumeration values.
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
SourceLocation getBeginLoc() const LLVM_READONLY
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
VarDecl * getVariable() const
void setHasSEHTry(SourceLocation TryLoc)
bool isOpenMPLoopScope() const
Determine whether this scope is a loop having OpenMP loop directive attached.
DeduceAutoResult
Result type of DeduceAutoType.
Encodes a location in the source.
QualType getReturnType() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Expr * getSubExpr() const
void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, Expr *SrcExpr)
DiagnoseAssignmentEnum - Warn if assignment to enum is a constant integer not in the range of enum va...
CastKind getCastKind() const
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Scope *CurScope)
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
StmtResult ActOnForEachLValueExpr(Expr *E)
In an Objective C collection iteration statement: for (x in y) x can be an arbitrary l-value expressi...
Represents a call to a member function that may be written either with member call syntax (e...
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
IdentifierTable & getIdentifierTable()
Represents the declaration of a label.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
StmtResult ActOnCapturedRegionEnd(Stmt *S)
void setAllEnumCasesCovered()
Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a switch over an enum value then ...
bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, SourceLocation ReturnLoc, Expr *&RetExpr, AutoType *AT)
Deduce the return type for a function from a returned expression, per C++1y [dcl.spec.auto]p6.
static QualType GetTypeBeforeIntegralPromotion(const Expr *&E)
GetTypeBeforeIntegralPromotion - Returns the pre-promotion type of potentially integral-promoted expr...
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt *> Handlers)
ActOnCXXTryBlock - Takes a try compound-statement and a number of handlers and creates a try statemen...
const ParmVarDecl * getParamDecl(unsigned i) const
bool isVLATypeCapture() const
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
Describes the kind of initialization being performed, along with location information for tokens rela...
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
bool isKnownToHaveBooleanValue() const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
bool isObjCObjectPointerType() const
SmallVector< Capture, 4 > Captures
Captures - The captures.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
bool isMSAsmLabel() const
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Stmt * getCapturedStmt()
Retrieve the statement being captured.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language...
sema::CompoundScopeInfo & getCurCompoundScope() const
Requests that all candidates be shown.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ConditionResult Cond, Stmt *Body)
EnumDecl * getDecl() const
An rvalue ref-qualifier was provided (&&).
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
static void DiagnoseForRangeReferenceVariableCopies(Sema &SemaRef, const VarDecl *VD, QualType RangeInitType)
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
LabelStmt * getStmt() const
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
QualType withRestrict() const
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
NullStmt - This is the null statement ";": C99 6.8.3p3.
Dataflow Directional Tag Classes.
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
bool isValid() const
Return true if this is a valid SourceLocation object.
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
A single step in the initialization sequence.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
EvalResult is a struct with detailed info about an evaluated expression.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
QualType getType() const
Get the type for which this source info wrapper provides information.
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
void ActOnCapturedRegionError()
void addNRVOCandidate(VarDecl *VD)
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
StmtResult ActOnExprStmtError()
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
const Expr * getInit() const
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
bool isSingleDecl() const
static void DiagnoseForRangeVariableCopies(Sema &SemaRef, const CXXForRangeStmt *ForStmt)
DiagnoseForRangeVariableCopies - Diagnose three cases and fixes for them.
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
const Decl * getSingleDecl() const
bool isAmbiguous(CanQualType BaseType)
Determine whether the path from the most-derived type to the given base type is ambiguous (i...
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
ConstEvaluatedExprVisitor - This class visits 'const Expr *'s.
unsigned short OpenMPLevel
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl. ...
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Represents a __leave statement.
Represents a pointer to an Objective C object.
SwitchStmt - This represents a 'switch' stmt.
StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, CXXScopeSpec &SS, UnqualifiedId &Name, Stmt *Nested)
unsigned getIntWidth(QualType T) const
RecordDecl * TheRecordDecl
The captured record type.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, BuildForRangeKind Kind)
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
Represents Objective-C's collection statement.
ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E)
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
bool isReferenceCapture() const
static bool ShouldDiagnoseSwitchCaseNotInEnum(const Sema &S, const EnumDecl *ED, const Expr *CaseExpr, EnumValsTy::iterator &EI, EnumValsTy::iterator &EIEnd, const llvm::APSInt &Val)
Returns true if we should emit a diagnostic about this case expression not being a part of the enum u...
TypeSourceInfo * getTypeSourceInfo() const
void setUsesSEHTry(bool UST)
static bool CmpEnumVals(const std::pair< llvm::APSInt, EnumConstantDecl *> &lhs, const std::pair< llvm::APSInt, EnumConstantDecl *> &rhs)
CmpEnumVals - Comparison predicate for sorting enumeration values.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
DeduceAutoResult DeduceAutoType(TypeSourceInfo *AutoType, Expr *&Initializer, QualType &Result, Optional< unsigned > DependentDeductionDepth=None)
Represents Objective-C's @finally statement.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
void addDecl(Decl *D)
Add the declaration D into this context.
Represents a base class of a C++ class.
static bool DiagnoseUnusedComparison(Sema &S, const Expr *E)
Diagnose unused comparisons, both builtin and overloaded operators.
void ActOnStartOfCompoundStmt(bool IsStmtExpr)
void NoteCandidates(PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr *> Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
When overload resolution fails, prints diagnostic messages containing the candidates in the candidate...
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
DeclStmt * getRangeStmt()
FieldDecl * BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture)
Build a FieldDecl suitable to hold the given capture.
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
GotoStmt - This represents a direct goto.
bool isLValueReferenceType() const
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
static bool CmpCaseVals(const std::pair< llvm::APSInt, CaseStmt *> &lhs, const std::pair< llvm::APSInt, CaseStmt *> &rhs)
CmpCaseVals - Comparison predicate for sorting case values.
const SwitchCase * getNextSwitchCase() const
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, const VarDecl *NRVOCandidate, QualType ResultType, Expr *Value, bool AllowNRVO=true)
Perform the initialization of a potentially-movable value, which is the result of return value...
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD, QualType Type)
Create the initialization entity for a related result.
Describes the sequence of initializations required to initialize a given object or reference with a s...
ActionResult< Expr * > ExprResult
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
TypedefNameDecl * getTypedefNameForAnonDecl() const
StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp)
ActOnCapScopeReturnStmt - Utility routine to type-check return statements for capturing scopes...
Represents a C++ struct/union/class.
ContinueStmt - This represents a continue.
Expr * getTrueExpr() const
static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init, SourceLocation Loc, int DiagID)
Finish building a variable declaration for a for-range statement.
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, ArrayRef< Stmt *> handlers)
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
CXXCatchStmt - This represents a C++ catch block.
VarDecl * getLoopVariable()
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr.type.conv]).
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
WhileStmt - This represents a 'while' stmt.
std::unique_ptr< sema::FunctionScopeInfo, PoppedFunctionScopeDeleter > PoppedFunctionScopePtr
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
SourceLocation getBreakLoc() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
__DEVICE__ int min(int __a, int __b)
void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc)
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
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.
SourceManager & SourceMgr
CapturedRegionKind
The different kinds of captured statement.
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD, CopyElisionSemanticsKind CESK)
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
An l-value expression is a reference to an object with independent storage.
bool empty() const
Return true if no decls were found.
static bool hasDeducedReturnType(FunctionDecl *FD)
Determine whether the declared return type of the specified function contains 'auto'.
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
A boolean literal, per ([C++ lex.bool] Boolean literals).
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type...
Represents a C array with a specified size that is not an integer-constant-expression.
DeclStmt * getBeginStmt()
Describes an entity that is being initialized.
void setType(QualType newType)
Wrapper for source info for pointers.
StmtResult ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt, ConditionResult Cond, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
SourceLocation ColonLoc
Location of ':'.
Represents Objective-C's @autoreleasepool Statement.
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
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
Skip past any parentheses which might surround this expression until reaching a fixed point...
QualType getType() const
Retrieves the type of the base class.