Lines Matching +full:class +full:- +full:dg

1 //===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
56 FE = ActOnFinishFullExpr(FE.get(), FE.get()->getExprLoc(), DiscardedValue); in ActOnExprStmt()
79 StmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg, SourceLocation StartLoc, in ActOnDeclStmt() argument
81 DeclGroupRef DG = dg.get(); in ActOnDeclStmt() local
84 if (DG.isNull()) return StmtError(); in ActOnDeclStmt()
86 return new (Context) DeclStmt(DG, StartLoc, EndLoc); in ActOnDeclStmt()
89 void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) { in ActOnForEachDeclStmt() argument
90 DeclGroupRef DG = dg.get(); in ActOnForEachDeclStmt() local
94 if (DG.isNull() || !DG.isSingleDecl()) in ActOnForEachDeclStmt()
97 Decl *decl = DG.getSingleDecl(); in ActOnForEachDeclStmt()
98 if (!decl || decl->isInvalidDecl()) in ActOnForEachDeclStmt()
104 Diag(decl->getLocation(), diag::err_non_variable_decl_in_for); in ActOnForEachDeclStmt()
105 decl->setInvalidDecl(); in ActOnForEachDeclStmt()
111 var->setInit(nullptr); in ActOnForEachDeclStmt()
117 QualType type = var->getType(); in ActOnForEachDeclStmt()
123 // Add 'const' and mark the variable as pseudo-strong. in ActOnForEachDeclStmt()
124 var->setType(type.withConst()); in ActOnForEachDeclStmt()
125 var->setARCPseudoStrong(true); in ActOnForEachDeclStmt()
141 if (!Op->isComparisonOp()) in DiagnoseUnusedComparison()
144 if (Op->getOpcode() == BO_EQ) in DiagnoseUnusedComparison()
146 else if (Op->getOpcode() == BO_NE) in DiagnoseUnusedComparison()
148 else if (Op->getOpcode() == BO_Cmp) in DiagnoseUnusedComparison()
151 assert(Op->isRelationalOp()); in DiagnoseUnusedComparison()
154 Loc = Op->getOperatorLoc(); in DiagnoseUnusedComparison()
155 CanAssign = Op->getLHS()->IgnoreParenImpCasts()->isLValue(); in DiagnoseUnusedComparison()
157 switch (Op->getOperator()) { in DiagnoseUnusedComparison()
177 Loc = Op->getOperatorLoc(); in DiagnoseUnusedComparison()
178 CanAssign = Op->getArg(0)->IgnoreParenImpCasts()->isLValue(); in DiagnoseUnusedComparison()
180 // Not a typo-prone comparison. in DiagnoseUnusedComparison()
190 << (unsigned)Kind << E->getSourceRange(); in DiagnoseUnusedComparison()
211 StringRef Msg = A->getMessage(); in DiagnoseNoDiscard()
227 return DiagnoseUnusedExprResult(Label->getSubStmt(), DiagID); in DiagnoseUnusedExprResult()
238 SourceLocation ExprLoc = E->IgnoreParenImpCasts()->getExprLoc(); in DiagnoseUnusedExprResult()
243 // checks need to happen, we factor out the macro-related test here. in DiagnoseUnusedExprResult()
251 if (!E->isUnusedResultAWarning(WarnExpr, Loc, R1, R2, Context)) in DiagnoseUnusedExprResult()
255 // unused because it is a function-like macro that can be used as either an in DiagnoseUnusedExprResult()
263 // but its implementation makes clang's -Wunused-value fire. Prevent this. in DiagnoseUnusedExprResult()
264 if (isa<ParenExpr>(E->IgnoreImpCasts()) && Loc.isMacroID()) { in DiagnoseUnusedExprResult()
274 E = Temps->getSubExpr(); in DiagnoseUnusedExprResult()
276 E = TempExpr->getSubExpr(); in DiagnoseUnusedExprResult()
283 if (Cast->getCastKind() == CK_NoOp || in DiagnoseUnusedExprResult()
284 Cast->getCastKind() == CK_ConstructorConversion) in DiagnoseUnusedExprResult()
285 E = Cast->getSubExpr()->IgnoreImpCasts(); in DiagnoseUnusedExprResult()
288 if (E->getType()->isVoidType()) in DiagnoseUnusedExprResult()
292 CE->getUnusedResultAttr(Context)), in DiagnoseUnusedExprResult()
300 if (const Decl *FD = CE->getCalleeDecl()) { in DiagnoseUnusedExprResult()
303 if (FD->hasAttr<PureAttr>()) { in DiagnoseUnusedExprResult()
307 if (FD->hasAttr<ConstAttr>()) { in DiagnoseUnusedExprResult()
313 if (const CXXConstructorDecl *Ctor = CE->getConstructor()) { in DiagnoseUnusedExprResult()
314 const auto *A = Ctor->getAttr<WarnUnusedResultAttr>(); in DiagnoseUnusedExprResult()
315 A = A ? A : Ctor->getParent()->getAttr<WarnUnusedResultAttr>(); in DiagnoseUnusedExprResult()
320 if (const TagDecl *TD = ILE->getType()->getAsTagDecl()) { in DiagnoseUnusedExprResult()
322 if (DiagnoseNoDiscard(*this, TD->getAttr<WarnUnusedResultAttr>(), Loc, R1, in DiagnoseUnusedExprResult()
331 if (getLangOpts().ObjCAutoRefCount && ME->isDelegateInitCall()) { in DiagnoseUnusedExprResult()
335 const ObjCMethodDecl *MD = ME->getMethodDecl(); in DiagnoseUnusedExprResult()
337 if (DiagnoseNoDiscard(*this, MD->getAttr<WarnUnusedResultAttr>(), Loc, R1, in DiagnoseUnusedExprResult()
342 const Expr *Source = POE->getSyntacticForm(); in DiagnoseUnusedExprResult()
345 POE->getNumSemanticExprs() == 1 && in DiagnoseUnusedExprResult()
346 isa<CallExpr>(POE->getSemanticExpr(0))) in DiagnoseUnusedExprResult()
347 return DiagnoseUnusedExprResult(POE->getSemanticExpr(0), DiagID); in DiagnoseUnusedExprResult()
354 const Expr *E = FC->getSubExpr(); in DiagnoseUnusedExprResult()
356 E = TE->getSubExpr(); in DiagnoseUnusedExprResult()
360 if (const CXXRecordDecl *RD = CE->getType()->getAsCXXRecordDecl()) in DiagnoseUnusedExprResult()
361 if (!RD->getAttr<WarnUnusedAttr>()) in DiagnoseUnusedExprResult()
366 TypeSourceInfo *TI = CE->getTypeInfoAsWritten(); in DiagnoseUnusedExprResult()
367 QualType T = TI->getType(); in DiagnoseUnusedExprResult()
369 // We really do want to use the non-canonical type here. in DiagnoseUnusedExprResult()
371 PointerTypeLoc TL = TI->getTypeLoc().castAs<PointerTypeLoc>(); in DiagnoseUnusedExprResult()
381 if (E->isGLValue() && E->getType().isVolatileQualified() && in DiagnoseUnusedExprResult()
382 !E->getType()->isArrayType()) { in DiagnoseUnusedExprResult()
403 FSI->setUsesFPIntrin(); in ActOnAfterCompoundStatementLeadingPragmas()
412 return getCurFunction()->CompoundScopes.back(); in getCurCompoundScope()
437 Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin(); in ActOnCompoundStmt()
438 Diag(D->getLocation(), MixedDeclsCodeID); in ActOnCompoundStmt()
447 for (unsigned i = 0; i != NumElts - 1; ++i) in ActOnCompoundStmt()
455 FPOptions FPO = (getCurFunction()->CompoundScopes.size() == 1) in ActOnCompoundStmt()
473 if (getCurFunction()->SwitchStack.empty()) in ActOnCaseExpr()
474 return ActOnFinishFullExpr(Val.get(), Val.get()->getExprLoc(), false, in ActOnCaseExpr()
478 getCurFunction()->SwitchStack.back().getPointer()->getCond(); in ActOnCaseExpr()
481 QualType CondType = CondExpr->getType(); in ActOnCaseExpr()
484 if (CondType->isDependentType() || E->isTypeDependent()) in ActOnCaseExpr()
488 // C++11 [stmt.switch]p2: the constant-expression shall be a converted in ActOnCaseExpr()
496 if (!E->isValueDependent()) in ActOnCaseExpr()
503 ER = ActOnFinishFullExpr(ER.get(), ER.get()->getExprLoc(), false); in ActOnCaseExpr()
524 if (getCurFunction()->SwitchStack.empty()) { in ActOnCaseStmt()
530 getCurFunction()->SwitchStack.back().setInt(true); in ActOnCaseStmt()
535 getCurScope()->isInOpenACCComputeConstructScope(Scope::SwitchScope)) { in ActOnCaseStmt()
543 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(CS); in ActOnCaseStmt()
548 cast<CaseStmt>(S)->setSubStmt(SubStmt); in ActOnCaseStmtBody()
554 if (getCurFunction()->SwitchStack.empty()) { in ActOnDefaultStmt()
560 getCurScope()->isInOpenACCComputeConstructScope(Scope::SwitchScope)) { in ActOnDefaultStmt()
567 getCurFunction()->SwitchStack.back().getPointer()->addSwitchCase(DS); in ActOnDefaultStmt()
575 if (TheDecl->getStmt()) { in ActOnLabelStmt()
576 Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->getDeclName(); in ActOnLabelStmt()
577 Diag(TheDecl->getLocation(), diag::note_previous_definition); in ActOnLabelStmt()
581 ReservedIdentifierStatus Status = TheDecl->isReserved(getLangOpts()); in ActOnLabelStmt()
589 if (getCurScope()->isInOpenACCComputeConstructScope()) in ActOnLabelStmt()
594 TheDecl->setStmt(LS); in ActOnLabelStmt()
595 if (!TheDecl->isGnuLocal()) { in ActOnLabelStmt()
596 TheDecl->setLocStart(IdentLoc); in ActOnLabelStmt()
597 if (!TheDecl->isMSAsmLabel()) { in ActOnLabelStmt()
600 TheDecl->setLocation(IdentLoc); in ActOnLabelStmt()
612 if (A->getKind() == attr::MustTail) { in BuildAttributedStmt()
637 Expr *E = R->getRetValue(); in checkAndRewriteMustTailAttr()
639 if (CurContext->isDependentContext() || (E && E->isInstantiationDependent())) in checkAndRewriteMustTailAttr()
649 auto IgnoreImplicitAsWritten = [](Expr *E) -> Expr * { in checkAndRewriteMustTailAttr()
656 R->setRetValue(IgnoreImplicitAsWritten(E)); in checkAndRewriteMustTailAttr()
661 assert(!CurContext->isDependentContext() && in checkMustTailAttr()
665 auto IgnoreParenImplicitAsWritten = [](const Expr *E) -> const Expr * { in checkMustTailAttr()
671 const Expr *E = cast<ReturnStmt>(St)->getRetValue(); in checkMustTailAttr()
675 Diag(St->getBeginLoc(), diag::err_musttail_needs_call) << &MTA; in checkMustTailAttr()
680 if (EWC->cleanupsHaveSideEffects()) { in checkMustTailAttr()
681 Diag(St->getBeginLoc(), diag::err_musttail_needs_trivial_args) << &MTA; in checkMustTailAttr()
702 bool IsCallee) -> bool { in checkMustTailAttr()
704 Diag(St->getBeginLoc(), diag::err_musttail_structors_forbidden) in checkMustTailAttr()
707 Diag(CMD->getBeginLoc(), diag::note_musttail_structors_forbidden) in checkMustTailAttr()
712 if (CMD->isStatic()) in checkMustTailAttr()
715 Type.This = CMD->getFunctionObjectParameterType(); in checkMustTailAttr()
718 Type.Func = CMD->getType()->castAs<FunctionProtoType>(); in checkMustTailAttr()
733 Diag(St->getBeginLoc(), diag::err_musttail_forbidden_from_this_context) in checkMustTailAttr()
737 // Caller is a class/struct method. in checkMustTailAttr()
741 // Caller is a non-method function. in checkMustTailAttr()
742 CallerType.Func = CallerDecl->getType()->getAs<FunctionProtoType>(); in checkMustTailAttr()
745 const Expr *CalleeExpr = CE->getCallee()->IgnoreParens(); in checkMustTailAttr()
747 SourceLocation CalleeLoc = CE->getCalleeDecl() in checkMustTailAttr()
748 ? CE->getCalleeDecl()->getBeginLoc() in checkMustTailAttr()
749 : St->getBeginLoc(); in checkMustTailAttr()
753 dyn_cast_or_null<CXXMethodDecl>(CE->getCalleeDecl())) { in checkMustTailAttr()
754 // Call is: obj.method(), obj->method(), functor(), etc. in checkMustTailAttr()
757 } else if (CalleeBinOp && CalleeBinOp->isPtrMemOp()) { in checkMustTailAttr()
758 // Call is: obj->*method_ptr or obj.*method_ptr in checkMustTailAttr()
760 CalleeBinOp->getRHS()->getType()->castAs<MemberPointerType>(); in checkMustTailAttr()
761 CalleeType.This = QualType(MPT->getClass(), 0); in checkMustTailAttr()
762 CalleeType.Func = MPT->getPointeeType()->castAs<FunctionProtoType>(); in checkMustTailAttr()
765 Diag(St->getBeginLoc(), diag::err_musttail_structors_forbidden) in checkMustTailAttr()
770 // Non-method function. in checkMustTailAttr()
772 CalleeExpr->getType()->getPointeeType()->getAs<FunctionProtoType>(); in checkMustTailAttr()
777 Diag(St->getBeginLoc(), diag::err_musttail_needs_prototype) << &MTA; in checkMustTailAttr()
778 if (!CalleeType.Func && CE->getDirectCallee()) { in checkMustTailAttr()
779 Diag(CE->getDirectCallee()->getBeginLoc(), in checkMustTailAttr()
783 Diag(CallerDecl->getBeginLoc(), diag::note_musttail_fix_non_prototype); in checkMustTailAttr()
794 if (CallerType.Func->getCallConv() != CalleeType.Func->getCallConv()) { in checkMustTailAttr()
795 if (const auto *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) in checkMustTailAttr()
796 Diag(St->getBeginLoc(), diag::err_musttail_callconv_mismatch) in checkMustTailAttr()
797 << true << ND->getDeclName(); in checkMustTailAttr()
799 Diag(St->getBeginLoc(), diag::err_musttail_callconv_mismatch) << false; in checkMustTailAttr()
801 << FunctionType::getNameForCallConv(CallerType.Func->getCallConv()) in checkMustTailAttr()
802 << FunctionType::getNameForCallConv(CalleeType.Func->getCallConv()); in checkMustTailAttr()
807 if (CalleeType.Func->isVariadic() || CallerType.Func->isVariadic()) { in checkMustTailAttr()
808 Diag(St->getBeginLoc(), diag::err_musttail_no_variadic) << &MTA; in checkMustTailAttr()
812 const auto *CalleeDecl = CE->getCalleeDecl(); in checkMustTailAttr()
813 if (CalleeDecl && CalleeDecl->hasAttr<CXX11NoReturnAttr>()) { in checkMustTailAttr()
814 Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA; in checkMustTailAttr()
820 if (const auto *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) { in checkMustTailAttr()
821 Diag(St->getBeginLoc(), diag::err_musttail_member_mismatch) in checkMustTailAttr()
823 << ND->getDeclName(); in checkMustTailAttr()
825 << ND->getDeclName(); in checkMustTailAttr()
827 Diag(St->getBeginLoc(), diag::err_musttail_member_mismatch) in checkMustTailAttr()
834 PartialDiagnostic &PD) -> bool { in checkMustTailAttr()
843 unsigned Select) -> bool { in checkMustTailAttr()
855 if (!DoTypesMatch(CallerType.Func->getReturnType(), in checkMustTailAttr()
856 CalleeType.Func->getReturnType(), ft_return_type)) in checkMustTailAttr()
859 if (CallerType.Func->getNumParams() != CalleeType.Func->getNumParams()) { in checkMustTailAttr()
860 PD << ft_parameter_arity << CallerType.Func->getNumParams() in checkMustTailAttr()
861 << CalleeType.Func->getNumParams(); in checkMustTailAttr()
865 ArrayRef<QualType> CalleeParams = CalleeType.Func->getParamTypes(); in checkMustTailAttr()
866 ArrayRef<QualType> CallerParams = CallerType.Func->getParamTypes(); in checkMustTailAttr()
867 size_t N = CallerType.Func->getNumParams(); in checkMustTailAttr()
881 if (const auto *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) in checkMustTailAttr()
882 Diag(St->getBeginLoc(), diag::err_musttail_mismatch) in checkMustTailAttr()
883 << true << ND->getDeclName(); in checkMustTailAttr()
885 Diag(St->getBeginLoc(), diag::err_musttail_mismatch) << false; in checkMustTailAttr()
895 class CommaVisitor : public EvaluatedExprVisitor<CommaVisitor> {
901 if (E->getOpcode() == BO_Comma) in VisitBinaryOperator()
902 SemaRef.DiagnoseCommaOperator(E->getLHS(), E->getExprLoc()); in VisitBinaryOperator()
926 !Diags.isIgnored(diag::warn_comma_operator, CondExpr->getExprLoc())) in ActOnIfStmt()
936 Diags.Report(A->getLocation(), in ActOnIfStmt()
938 << A << ConstevalOrNegatedConsteval << A->getRange(); in ActOnIfStmt()
943 ? thenStmt->getBeginLoc() in ActOnIfStmt()
945 .getLocWithOffset(-1)); in ActOnIfStmt()
956 Diags.Report(ThenAttr->getLocation(), in ActOnIfStmt()
958 << ThenAttr << ThenAttr->getRange(); in ActOnIfStmt()
959 Diags.Report(ElseAttr->getLocation(), diag::note_conflicting_attribute) in ActOnIfStmt()
960 << ElseAttr << ElseAttr->getRange(); in ActOnIfStmt()
967 if (CurContext->isFunctionOrMethod()) { in ActOnIfStmt()
970 if (FD && FD->isImmediateFunction()) in ActOnIfStmt()
1016 /// CmpCaseVals - Comparison predicate for sorting case values.
1024 lhs.second->getCaseLoc() < rhs.second->getCaseLoc()) in CmpCaseVals()
1029 /// CmpEnumVals - Comparison predicate for sorting enumeration values.
1037 /// EqEnumVals - Comparison preficate for uniqing enumeration values.
1045 /// GetTypeBeforeIntegralPromotion - Returns the pre-promotion type of
1046 /// potentially integral-promoted expression @p expr.
1049 E = FE->getSubExpr(); in GetTypeBeforeIntegralPromotion()
1051 if (ImpCast->getCastKind() != CK_IntegralCast) break; in GetTypeBeforeIntegralPromotion()
1052 E = ImpCast->getSubExpr(); in GetTypeBeforeIntegralPromotion()
1054 return E->getType(); in GetTypeBeforeIntegralPromotion()
1058 class SwitchConvertDiagnoser : public ICEConvertDiagnoser { in CheckSwitchCondition()
1074 << T << Cond->getSourceRange(); in CheckSwitchCondition()
1084 return S.Diag(Conv->getLocation(), diag::note_switch_conversion) in CheckSwitchCondition()
1085 << ConvTy->isEnumeralType() << ConvTy; in CheckSwitchCondition()
1095 return S.Diag(Conv->getLocation(), diag::note_switch_conversion) in CheckSwitchCondition()
1096 << ConvTy->isEnumeralType() << ConvTy; in CheckSwitchCondition()
1113 if (!Cond->isTypeDependent() && in CheckSwitchCondition()
1114 !Cond->getType()->isIntegralOrEnumerationType()) in CheckSwitchCondition()
1117 // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr. in CheckSwitchCondition()
1128 if (CondExpr && !CondExpr->isTypeDependent()) { in ActOnStartOfSwitchStmt()
1131 // have an appropriate type, e.g. a typo-expr Cond was corrected to an in ActOnStartOfSwitchStmt()
1132 // inappropriate-type expr, we just return an error. in ActOnStartOfSwitchStmt()
1133 if (!CondExpr->getType()->isIntegralOrEnumerationType()) in ActOnStartOfSwitchStmt()
1135 if (CondExpr->isKnownToHaveBooleanValue()) { in ActOnStartOfSwitchStmt()
1137 // switch(n && mask) { ... } // Doh - should be "n & mask". in ActOnStartOfSwitchStmt()
1140 << CondExpr->getSourceRange(); in ActOnStartOfSwitchStmt()
1148 getCurFunction()->SwitchStack.push_back( in ActOnStartOfSwitchStmt()
1167 // unsigned, don't bother to warn: this is implementation-defined behavior. in checkCaseValue()
1168 // FIXME: Introduce a second, default-ignored warning for this case? in checkCaseValue()
1192 if (!ED->isClosed()) in ShouldDiagnoseSwitchCaseNotInEnum()
1196 dyn_cast<DeclRefExpr>(CaseExpr->IgnoreParenImpCasts())) { in ShouldDiagnoseSwitchCaseNotInEnum()
1197 if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) { in ShouldDiagnoseSwitchCaseNotInEnum()
1198 QualType VarType = VD->getType(); in ShouldDiagnoseSwitchCaseNotInEnum()
1200 if (VD->hasGlobalStorage() && VarType.isConstQualified() && in ShouldDiagnoseSwitchCaseNotInEnum()
1206 if (ED->hasAttr<FlagEnumAttr>()) in ShouldDiagnoseSwitchCaseNotInEnum()
1209 while (EI != EIEnd && EI->first < Val) in ShouldDiagnoseSwitchCaseNotInEnum()
1212 if (EI != EIEnd && EI->first == Val) in ShouldDiagnoseSwitchCaseNotInEnum()
1220 QualType CondType = Cond->getType(); in checkEnumTypesInSwitchStmt()
1221 QualType CaseType = Case->getType(); in checkEnumTypesInSwitchStmt()
1223 const EnumType *CondEnumType = CondType->getAs<EnumType>(); in checkEnumTypesInSwitchStmt()
1224 const EnumType *CaseEnumType = CaseType->getAs<EnumType>(); in checkEnumTypesInSwitchStmt()
1229 if (!CondEnumType->getDecl()->getIdentifier() && in checkEnumTypesInSwitchStmt()
1230 !CondEnumType->getDecl()->getTypedefNameForAnonDecl()) in checkEnumTypesInSwitchStmt()
1232 if (!CaseEnumType->getDecl()->getIdentifier() && in checkEnumTypesInSwitchStmt()
1233 !CaseEnumType->getDecl()->getTypedefNameForAnonDecl()) in checkEnumTypesInSwitchStmt()
1239 S.Diag(Case->getExprLoc(), diag::warn_comparison_of_mixed_enum_types_switch) in checkEnumTypesInSwitchStmt()
1240 << CondType << CaseType << Cond->getSourceRange() in checkEnumTypesInSwitchStmt()
1241 << Case->getSourceRange(); in checkEnumTypesInSwitchStmt()
1248 bool CaseListIsIncomplete = getCurFunction()->SwitchStack.back().getInt(); in ActOnFinishSwitchStmt()
1249 assert(SS == getCurFunction()->SwitchStack.back().getPointer() && in ActOnFinishSwitchStmt()
1252 getCurFunction()->SwitchStack.pop_back(); in ActOnFinishSwitchStmt()
1255 SS->setBody(BodyStmt, SwitchLoc); in ActOnFinishSwitchStmt()
1257 Expr *CondExpr = SS->getCond(); in ActOnFinishSwitchStmt()
1260 QualType CondType = CondExpr->getType(); in ActOnFinishSwitchStmt()
1268 // the pre-promotion type of the switch condition. in ActOnFinishSwitchStmt()
1273 // Get the bitwidth of the switched-on value after promotions. We must in ActOnFinishSwitchStmt()
1276 = CondExpr->isTypeDependent() || CondExpr->isValueDependent(); in ActOnFinishSwitchStmt()
1278 bool CondIsSigned = CondType->isSignedIntegerOrEnumerationType(); in ActOnFinishSwitchStmt()
1287 = CondTypeBeforePromotion->isSignedIntegerOrEnumerationType(); in ActOnFinishSwitchStmt()
1306 for (SwitchCase *SC = SS->getSwitchCaseList(); SC && !HasDependentValue; in ActOnFinishSwitchStmt()
1307 SC = SC->getNextSwitchCase()) { in ActOnFinishSwitchStmt()
1311 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined); in ActOnFinishSwitchStmt()
1312 Diag(TheDefaultStmt->getDefaultLoc(), diag::note_duplicate_case_prev); in ActOnFinishSwitchStmt()
1325 Expr *Lo = CS->getLHS(); in ActOnFinishSwitchStmt()
1327 if (Lo->isValueDependent()) { in ActOnFinishSwitchStmt()
1336 llvm::APSInt LoVal = LoBeforePromotion->EvaluateKnownConstInt(Context); in ActOnFinishSwitchStmt()
1340 checkCaseValue(*this, Lo->getBeginLoc(), LoVal, CondWidthBeforePromotion, in ActOnFinishSwitchStmt()
1351 if (CS->getRHS()) { in ActOnFinishSwitchStmt()
1352 if (CS->getRHS()->isValueDependent()) { in ActOnFinishSwitchStmt()
1369 HasConstantCond = CondExpr->EvaluateAsInt(Result, Context, in ActOnFinishSwitchStmt()
1389 if (i != 0 && CaseVals[i].first == CaseVals[i-1].first) { in ActOnFinishSwitchStmt()
1393 Expr *PrevCase = CaseVals[i-1].second->getLHS()->IgnoreParenCasts(); in ActOnFinishSwitchStmt()
1394 Expr *CurrCase = CaseVals[i].second->getLHS()->IgnoreParenCasts(); in ActOnFinishSwitchStmt()
1396 PrevString = DeclRef->getDecl()->getName(); in ActOnFinishSwitchStmt()
1399 CurrString = DeclRef->getDecl()->getName(); in ActOnFinishSwitchStmt()
1402 CaseVals[i-1].first.toString(CaseValStr); in ActOnFinishSwitchStmt()
1405 Diag(CaseVals[i].second->getLHS()->getBeginLoc(), in ActOnFinishSwitchStmt()
1409 Diag(CaseVals[i].second->getLHS()->getBeginLoc(), in ActOnFinishSwitchStmt()
1415 Diag(CaseVals[i - 1].second->getLHS()->getBeginLoc(), in ActOnFinishSwitchStmt()
1436 Expr *Hi = CR->getRHS(); in ActOnFinishSwitchStmt()
1440 llvm::APSInt HiVal = HiBeforePromotion->EvaluateKnownConstInt(Context); in ActOnFinishSwitchStmt()
1444 checkCaseValue(*this, Hi->getBeginLoc(), HiVal, in ActOnFinishSwitchStmt()
1452 Diag(CR->getLHS()->getBeginLoc(), diag::warn_case_empty_range) in ActOnFinishSwitchStmt()
1453 << SourceRange(CR->getLHS()->getBeginLoc(), Hi->getEndLoc()); in ActOnFinishSwitchStmt()
1455 --i; in ActOnFinishSwitchStmt()
1456 --e; in ActOnFinishSwitchStmt()
1485 if (I != CaseVals.end() && I->first < CRHi) { in ActOnFinishSwitchStmt()
1486 OverlapVal = I->first; // Found overlap with scalar. in ActOnFinishSwitchStmt()
1487 OverlapStmt = I->second; in ActOnFinishSwitchStmt()
1492 if (I != CaseVals.begin() && (I-1)->first >= CRLo) { in ActOnFinishSwitchStmt()
1493 OverlapVal = (I-1)->first; // Found overlap with scalar. in ActOnFinishSwitchStmt()
1494 OverlapStmt = (I-1)->second; in ActOnFinishSwitchStmt()
1499 if (i && CRLo <= HiVals[i-1]) { in ActOnFinishSwitchStmt()
1500 OverlapVal = HiVals[i-1]; // Found overlap with range. in ActOnFinishSwitchStmt()
1501 OverlapStmt = CaseRanges[i-1].second; in ActOnFinishSwitchStmt()
1506 Diag(CR->getLHS()->getBeginLoc(), diag::err_duplicate_case) in ActOnFinishSwitchStmt()
1508 Diag(OverlapStmt->getLHS()->getBeginLoc(), in ActOnFinishSwitchStmt()
1522 Diag(CondExpr->getExprLoc(), diag::warn_missing_case_for_condition) in ActOnFinishSwitchStmt()
1524 << CondExpr->getSourceRange(); in ActOnFinishSwitchStmt()
1530 // (which can be used by flow-based analyes). in ActOnFinishSwitchStmt()
1532 const EnumType *ET = CondTypeBeforePromotion->getAs<EnumType>(); in ActOnFinishSwitchStmt()
1536 ET && ET->getDecl()->isCompleteDefinition() && in ActOnFinishSwitchStmt()
1537 !ET->getDecl()->enumerators().empty()) { in ActOnFinishSwitchStmt()
1538 const EnumDecl *ED = ET->getDecl(); in ActOnFinishSwitchStmt()
1543 for (auto *EDI : ED->enumerators()) { in ActOnFinishSwitchStmt()
1544 llvm::APSInt Val = EDI->getInitVal(); in ActOnFinishSwitchStmt()
1555 Expr *CaseExpr = CI->second->getLHS(); in ActOnFinishSwitchStmt()
1557 CI->first)) in ActOnFinishSwitchStmt()
1558 Diag(CaseExpr->getExprLoc(), diag::warn_not_in_enum) in ActOnFinishSwitchStmt()
1566 Expr *CaseExpr = RI->second->getLHS(); in ActOnFinishSwitchStmt()
1568 RI->first)) in ActOnFinishSwitchStmt()
1569 Diag(CaseExpr->getExprLoc(), diag::warn_not_in_enum) in ActOnFinishSwitchStmt()
1573 RI->second->getRHS()->EvaluateKnownConstInt(Context); in ActOnFinishSwitchStmt()
1576 CaseExpr = RI->second->getRHS(); in ActOnFinishSwitchStmt()
1579 Diag(CaseExpr->getExprLoc(), diag::warn_not_in_enum) in ActOnFinishSwitchStmt()
1592 switch (EI->second->getAvailability()) { in ActOnFinishSwitchStmt()
1600 // suppress -Wunguarded-availability diagnostics for such uses. in ActOnFinishSwitchStmt()
1605 if (EI->second->hasAttr<UnusedAttr>()) in ActOnFinishSwitchStmt()
1609 while (CI != CaseVals.end() && CI->first < EI->first) in ActOnFinishSwitchStmt()
1612 if (CI != CaseVals.end() && CI->first == EI->first) in ActOnFinishSwitchStmt()
1618 RI->second->getRHS()->EvaluateKnownConstInt(Context); in ActOnFinishSwitchStmt()
1620 if (EI->first <= Hi) in ActOnFinishSwitchStmt()
1624 if (RI == CaseRanges.end() || EI->first < RI->first) { in ActOnFinishSwitchStmt()
1626 UnhandledNames.push_back(EI->second->getDeclName()); in ActOnFinishSwitchStmt()
1630 if (TheDefaultStmt && UnhandledNames.empty() && ED->isClosedNonFlag()) in ActOnFinishSwitchStmt()
1631 Diag(TheDefaultStmt->getDefaultLoc(), diag::warn_unreachable_default); in ActOnFinishSwitchStmt()
1635 auto DB = Diag(CondExpr->getExprLoc(), TheDefaultStmt in ActOnFinishSwitchStmt()
1638 << CondExpr->getSourceRange() << (int)UnhandledNames.size(); in ActOnFinishSwitchStmt()
1646 SS->setAllEnumCasesCovered(); in ActOnFinishSwitchStmt()
1651 DiagnoseEmptyStmtBody(CondExpr->getEndLoc(), BodyStmt, in ActOnFinishSwitchStmt()
1665 if (Diags.isIgnored(diag::warn_not_in_enum_assignment, SrcExpr->getExprLoc())) in DiagnoseAssignmentEnum()
1668 if (const EnumType *ET = DstType->getAs<EnumType>()) in DiagnoseAssignmentEnum()
1670 SrcType->isIntegerType()) { in DiagnoseAssignmentEnum()
1671 if (!SrcExpr->isTypeDependent() && !SrcExpr->isValueDependent() && in DiagnoseAssignmentEnum()
1672 SrcExpr->isIntegerConstantExpr(Context)) { in DiagnoseAssignmentEnum()
1675 bool DstIsSigned = DstType->isSignedIntegerOrEnumerationType(); in DiagnoseAssignmentEnum()
1677 llvm::APSInt RhsVal = SrcExpr->EvaluateKnownConstInt(Context); in DiagnoseAssignmentEnum()
1679 const EnumDecl *ED = ET->getDecl(); in DiagnoseAssignmentEnum()
1681 if (!ED->isClosed()) in DiagnoseAssignmentEnum()
1684 if (ED->hasAttr<FlagEnumAttr>()) { in DiagnoseAssignmentEnum()
1686 Diag(SrcExpr->getExprLoc(), diag::warn_not_in_enum_assignment) in DiagnoseAssignmentEnum()
1695 for (auto *EDI : ED->enumerators()) { in DiagnoseAssignmentEnum()
1696 llvm::APSInt Val = EDI->getInitVal(); in DiagnoseAssignmentEnum()
1708 while (EI != EIend && EI->first < RhsVal) in DiagnoseAssignmentEnum()
1710 if (EI == EIend || EI->first != RhsVal) { in DiagnoseAssignmentEnum()
1711 Diag(SrcExpr->getExprLoc(), diag::warn_not_in_enum_assignment) in DiagnoseAssignmentEnum()
1729 !Diags.isIgnored(diag::warn_comma_operator, CondVal.second->getExprLoc())) in ActOnWhileStmt()
1758 !Diags.isIgnored(diag::warn_comma_operator, Cond->getExprLoc())) in ActOnDoStmt()
1771 class DeclExtractor : public EvaluatedExprVisitor<DeclExtractor> {
1797 Visit(E->getLHS()); in VisitBinaryOperator()
1798 Visit(E->getRHS()); in VisitBinaryOperator()
1802 Visit(E->getSubExpr()); in VisitCastExpr()
1807 if (E->getOpcode() == UO_Deref) in VisitUnaryOperator()
1810 Visit(E->getSubExpr()); in VisitUnaryOperator()
1814 Visit(E->getCond()); in VisitConditionalOperator()
1815 Visit(E->getTrueExpr()); in VisitConditionalOperator()
1816 Visit(E->getFalseExpr()); in VisitConditionalOperator()
1820 Visit(E->getSubExpr()); in VisitParenExpr()
1824 Visit(E->getOpaqueValue()->getSourceExpr()); in VisitBinaryConditionalOperator()
1825 Visit(E->getFalseExpr()); in VisitBinaryConditionalOperator()
1836 VarDecl *VD = dyn_cast<VarDecl>(E->getDecl()); in VisitDeclRefExpr()
1843 Ranges.push_back(E->getSourceRange()); in VisitDeclRefExpr()
1848 }; // end class DeclExtractor
1850 // DeclMatcher checks to see if the decls are used in a non-evaluated
1852 class DeclMatcher : public EvaluatedExprVisitor<DeclMatcher> {
1879 if (E->getCastKind() == CK_LValueToRValue) in VisitCastExpr()
1880 CheckLValueToRValueCast(E->getSubExpr()); in VisitCastExpr()
1882 Visit(E->getSubExpr()); in VisitCastExpr()
1886 E = E->IgnoreParenImpCasts(); in CheckLValueToRValueCast()
1893 Visit(CO->getCond()); in CheckLValueToRValueCast()
1894 CheckLValueToRValueCast(CO->getTrueExpr()); in CheckLValueToRValueCast()
1895 CheckLValueToRValueCast(CO->getFalseExpr()); in CheckLValueToRValueCast()
1901 CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr()); in CheckLValueToRValueCast()
1902 CheckLValueToRValueCast(BCO->getFalseExpr()); in CheckLValueToRValueCast()
1910 if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) in VisitDeclRefExpr()
1918 for (auto *S : POE->semantics()) { in VisitPseudoObjectExpr()
1921 Visit(OVE->getSourceExpr()); in VisitPseudoObjectExpr()
1929 }; // end class DeclMatcher
1937 Second->getBeginLoc())) in CheckForLoopConditionalStatement()
1954 if (VD->getType().isVolatileQualified() || VD->hasGlobalStorage()) in CheckForLoopConditionalStatement()
1968 PDiag << VD->getDeclName(); in CheckForLoopConditionalStatement()
1974 S.Diag(Ranges.begin()->getBegin(), PDiag); in CheckForLoopConditionalStatement()
1982 if (!Cleanups->cleanupsHaveSideEffects()) in ProcessIterationStmt()
1983 Statement = Cleanups->getSubExpr(); in ProcessIterationStmt()
1986 switch (UO->getOpcode()) { in ProcessIterationStmt()
1997 DRE = dyn_cast<DeclRefExpr>(UO->getSubExpr()); in ProcessIterationStmt()
2002 FunctionDecl *FD = Call->getDirectCallee(); in ProcessIterationStmt()
2003 if (!FD || !FD->isOverloadedOperator()) return false; in ProcessIterationStmt()
2004 switch (FD->getOverloadedOperator()) { in ProcessIterationStmt()
2013 DRE = dyn_cast<DeclRefExpr>(Call->getArg(0)); in ProcessIterationStmt()
2022 class BreakContinueFinder : public ConstEvaluatedExprVisitor<BreakContinueFinder> {
2036 ContinueLoc = E->getContinueLoc(); in VisitContinueStmt()
2041 BreakLoc = E->getBreakLoc(); in VisitBreakStmt()
2045 if (const Stmt *Init = S->getInit()) in VisitSwitchStmt()
2047 if (const Stmt *CondVar = S->getConditionVariableDeclStmt()) in VisitSwitchStmt()
2049 if (const Stmt *Cond = S->getCond()) in VisitSwitchStmt()
2054 if (const Stmt *Body = S->getBody()) in VisitSwitchStmt()
2062 if (const Stmt *Init = S->getInit()) in VisitForStmt()
2079 if (const Stmt *Init = S->getInit()) in VisitCXXForRangeStmt()
2081 if (const Stmt *Range = S->getRangeStmt()) in VisitCXXForRangeStmt()
2083 if (const Stmt *Begin = S->getBeginStmt()) in VisitCXXForRangeStmt()
2085 if (const Stmt *End = S->getEndStmt()) in VisitCXXForRangeStmt()
2092 if (const Stmt *Element = S->getElement()) in VisitObjCForCollectionStmt()
2094 if (const Stmt *Collection = S->getCollection()) in VisitObjCForCollectionStmt()
2103 }; // end class BreakContinueFinder
2115 Third->getBeginLoc())) in CheckForRedundantIteration()
2120 if (!CS || CS->body_empty()) return; in CheckForRedundantIteration()
2121 Stmt *LastStmt = CS->body_back(); in CheckForRedundantIteration()
2133 LoopDRE->getDecl() != LastDRE->getDecl()) return; in CheckForRedundantIteration()
2137 S.Diag(LastDRE->getLocation(), diag::warn_redundant_loop_iteration) in CheckForRedundantIteration()
2138 << LastDRE->getDecl() << LastIncrement; in CheckForRedundantIteration()
2139 S.Diag(LoopDRE->getLocation(), diag::note_loop_iteration_here) in CheckForRedundantIteration()
2150 Scope *BreakParent = CurScope->getBreakParent(); in CheckBreakContinueBinding()
2152 if (BreakParent->getFlags() & Scope::SwitchScope) { in CheckBreakContinueBinding()
2158 } else if (BCFinder.ContinueFound() && CurScope->getContinueParent()) { in CheckBreakContinueBinding()
2174 // declare identifiers for objects having storage class 'auto' or in ActOnForStmt()
2178 for (auto *DI : DS->decls()) { in ActOnForStmt()
2181 if (VD->isLocalVarDecl() && !VD->hasLocalStorage()) { in ActOnForStmt()
2182 Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for); in ActOnForStmt()
2183 DI->setInvalidDecl(); in ActOnForStmt()
2186 // Keep track of the first non-variable declaration we saw so that in ActOnForStmt()
2193 // Diagnose if we saw a non-variable declaration but no variable in ActOnForStmt()
2196 Diag(NonVarSeen->getLocation(), diag::err_non_variable_decl_in_for); in ActOnForStmt()
2210 Second.get().second->getExprLoc())) in ActOnForStmt()
2224 // use of pseudo-object l-values in this position. in ActOnForEachLValueExpr()
2235 /// Finish building a variable declaration for a for-range statement.
2239 if (Decl->getType()->isUndeducedType()) { in FinishForRangeVarDecl()
2242 Decl->setInvalidDecl(); in FinishForRangeVarDecl()
2251 if (!isa<InitListExpr>(Init) && Init->getType()->isVoidType()) { in FinishForRangeVarDecl()
2252 SemaRef.Diag(Loc, DiagID) << Init->getType(); in FinishForRangeVarDecl()
2254 TemplateDeductionInfo Info(Init->getExprLoc()); in FinishForRangeVarDecl()
2256 Decl->getTypeSourceInfo()->getTypeLoc(), Init, InitType, Info); in FinishForRangeVarDecl()
2259 SemaRef.Diag(Loc, DiagID) << Init->getType(); in FinishForRangeVarDecl()
2263 Decl->setInvalidDecl(); in FinishForRangeVarDecl()
2266 Decl->setType(InitType); in FinishForRangeVarDecl()
2273 Decl->setInvalidDecl(); in FinishForRangeVarDecl()
2277 SemaRef.CurContext->addHiddenDecl(Decl); in FinishForRangeVarDecl()
2283 // or a call to end() in a range-based for loop.
2290 /// by a C++11 for-range statement. This is often not obvious from the code,
2292 /// required in a for-range statement.
2298 FunctionDecl *D = dyn_cast<FunctionDecl>(CE->getCalleeDecl()); in NoteForRangeBeginEndFunction()
2301 SourceLocation Loc = D->getLocation(); in NoteForRangeBeginEndFunction()
2305 if (FunctionTemplateDecl *FunTmpl = D->getPrimaryTemplate()) { in NoteForRangeBeginEndFunction()
2307 FunTmpl->getTemplateParameters(), *D->getTemplateSpecializationArgs()); in NoteForRangeBeginEndFunction()
2312 << BEF << IsTemplate << Description << E->getType(); in NoteForRangeBeginEndFunction()
2315 /// Build a variable declaration for a for-range statement.
2323 Decl->setImplicit(); in BuildForRangeVarDecl()
2330 return !Collection->isTypeDependent() in ObjCEnumerationCollection()
2331 && Collection->getType()->getAs<ObjCObjectPointerType>() != nullptr; in ObjCEnumerationCollection()
2344 // FIXME: Support init-statements in Objective-C++20 ranged for statement. in ActOnCXXForRangeStmt()
2346 return Diag(InitStmt->getBeginLoc(), diag::err_objc_for_range_init_stmt) in ActOnCXXForRangeStmt()
2347 << InitStmt->getSourceRange(); in ActOnCXXForRangeStmt()
2354 if (!DS->isSingleDecl()) { in ActOnCXXForRangeStmt()
2355 Diag(DS->getBeginLoc(), diag::err_type_defined_in_for_range); in ActOnCXXForRangeStmt()
2361 Decl *LoopVar = DS->getSingleDecl(); in ActOnCXXForRangeStmt()
2362 if (LoopVar->isInvalidDecl() || !Range || in ActOnCXXForRangeStmt()
2377 // Build auto && __range = range-init in ActOnCXXForRangeStmt()
2379 const auto DepthStr = std::to_string(S->getDepth() / 2); in ActOnCXXForRangeStmt()
2380 SourceLocation RangeLoc = Range->getBeginLoc(); in ActOnCXXForRangeStmt()
2413 /// the range-based for loop expression.
2414 /// This function does not handle array-based for loops,
2419 /// CandidateSet and BEF are set and some non-success value is returned on
2445 SemaRef.Diag(BeginRange->getBeginLoc(), diag::note_in_for_range) in BuildNonArrayForRange()
2446 << ColonLoc << BEF_begin << BeginRange->getType(); in BuildNonArrayForRange()
2454 BeginExpr->get()); in BuildNonArrayForRange()
2455 if (BeginExpr->isInvalid()) in BuildNonArrayForRange()
2458 if (FinishForRangeVarDecl(SemaRef, BeginVar, BeginExpr->get(), ColonLoc, in BuildNonArrayForRange()
2460 NoteForRangeBeginEndFunction(SemaRef, BeginExpr->get(), *BEF); in BuildNonArrayForRange()
2474 SemaRef.Diag(EndRange->getBeginLoc(), diag::note_in_for_range) in BuildNonArrayForRange()
2475 << ColonLoc << BEF_end << EndRange->getType(); in BuildNonArrayForRange()
2478 if (FinishForRangeVarDecl(SemaRef, EndVar, EndExpr->get(), ColonLoc, in BuildNonArrayForRange()
2480 NoteForRangeBeginEndFunction(SemaRef, EndExpr->get(), *BEF); in BuildNonArrayForRange()
2486 if (CXXRecordDecl *D = RangeType->getAsCXXRecordDecl()) { in BuildNonArrayForRange()
2487 // - if _RangeT is a class type, the unqualified-ids begin and end are in BuildNonArrayForRange()
2488 // looked up in the scope of class _RangeT as if by class member access in BuildNonArrayForRange()
2490 // declaration, begin-expr and end-expr are __range.begin() and in BuildNonArrayForRange()
2501 // Look up the non-member form of the member we didn't find, first. in BuildNonArrayForRange()
2520 CandidateSet->NoteCandidates( in BuildNonArrayForRange()
2521 PartialDiagnosticAt(BeginRange->getBeginLoc(), in BuildNonArrayForRange()
2523 << BeginRange->getType() << BEFFound), in BuildNonArrayForRange()
2529 SemaRef.Diag(D->getLocation(), in BuildNonArrayForRange()
2531 << BeginRange->getType() << BEFFound; in BuildNonArrayForRange()
2542 // - otherwise, begin-expr and end-expr are begin(__range) and in BuildNonArrayForRange()
2544 // argument-dependent lookup (3.4.2). For the purposes of this name in BuildNonArrayForRange()
2565 // Determine whether we can rebuild the for-range statement with a in RebuildForRangeWithDereference()
2584 // case there are any other (non-fatal) problems with it. in RebuildForRangeWithDereference()
2586 << Range->getType() << FixItHint::CreateInsertion(RangeLoc, "*"); in RebuildForRangeWithDereference()
2602 // Testcase (accepts-invalid): in BuildCXXForRangeStmt()
2610 VarDecl *RangeVar = cast<VarDecl>(RangeDS->getSingleDecl()); in BuildCXXForRangeStmt()
2611 QualType RangeVarType = RangeVar->getType(); in BuildCXXForRangeStmt()
2614 VarDecl *LoopVar = cast<VarDecl>(LoopVarDS->getSingleDecl()); in BuildCXXForRangeStmt()
2620 if (RangeVarType->isDependentType()) { in BuildCXXForRangeStmt()
2622 RangeVar->markUsed(Context); in BuildCXXForRangeStmt()
2626 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) { in BuildCXXForRangeStmt()
2628 for (auto *Binding : DD->bindings()) in BuildCXXForRangeStmt()
2629 Binding->setType(Context.DependentTy); in BuildCXXForRangeStmt()
2630 LoopVar->setType(SubstAutoTypeDependent(LoopVar->getType())); in BuildCXXForRangeStmt()
2633 SourceLocation RangeLoc = RangeVar->getLocation(); in BuildCXXForRangeStmt()
2648 Expr *Range = RangeVar->getInit(); in BuildCXXForRangeStmt()
2651 QualType RangeType = Range->getType(); in BuildCXXForRangeStmt()
2657 // P2718R0 - Lifetime extension in range-based for loops. in BuildCXXForRangeStmt()
2662 MTE->setExtendingDecl(RangeVar, Entity.allocateManglingNumber()); in BuildCXXForRangeStmt()
2665 // Build auto __begin = begin-expr, __end = end-expr. in BuildCXXForRangeStmt()
2667 const auto DepthStr = std::to_string(S->getDepth() / 2); in BuildCXXForRangeStmt()
2673 // Build begin-expr and end-expr and attach to __begin and __end variables. in BuildCXXForRangeStmt()
2675 if (const ArrayType *UnqAT = RangeType->getAsArrayTypeUnsafe()) { in BuildCXXForRangeStmt()
2676 // - if _RangeT is an array type, begin-expr and end-expr are __range and in BuildCXXForRangeStmt()
2679 // the program is ill-formed; in BuildCXXForRangeStmt()
2681 // begin-expr is __range. in BuildCXXForRangeStmt()
2698 Context, CAT->getSize(), Context.getPointerDiffType(), RangeLoc); in BuildCXXForRangeStmt()
2702 // the array bounds, since we don't want that to be re-evaluated here. in BuildCXXForRangeStmt()
2704 // created - so we resort to using sizeof(vla)/sizeof(element). in BuildCXXForRangeStmt()
2708 // b = -1; <-- This should not affect the num of iterations below in BuildCXXForRangeStmt()
2713 // run-time number of elements (as opposed to just using the IR Value in BuildCXXForRangeStmt()
2714 // that corresponds to the run-time value of each bound that was in BuildCXXForRangeStmt()
2716 // even for unoptimized IR, consider passing a magic-value/cookie to in BuildCXXForRangeStmt()
2720 // customized form of coupling between the two components - which could in BuildCXXForRangeStmt()
2724 EndVar->getLocation(), UETT_SizeOf, in BuildCXXForRangeStmt()
2726 CreateParsedType(VAT->desugar(), Context.getTrivialTypeSourceInfo( in BuildCXXForRangeStmt()
2727 VAT->desugar(), RangeLoc)) in BuildCXXForRangeStmt()
2729 EndVar->getSourceRange()); in BuildCXXForRangeStmt()
2734 EndVar->getLocation(), UETT_SizeOf, in BuildCXXForRangeStmt()
2736 CreateParsedType(VAT->desugar(), in BuildCXXForRangeStmt()
2738 VAT->getElementType(), RangeLoc)) in BuildCXXForRangeStmt()
2740 EndVar->getSourceRange()); in BuildCXXForRangeStmt()
2745 ActOnBinOp(S, EndVar->getLocation(), tok::slash, in BuildCXXForRangeStmt()
2752 // UnqAT is not incomplete and Range is not type-dependent. in BuildCXXForRangeStmt()
2753 llvm_unreachable("Unexpected array type in for-range"); in BuildCXXForRangeStmt()
2756 // end-expr is __range + __bound. in BuildCXXForRangeStmt()
2780 if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { in BuildCXXForRangeStmt()
2781 QualType ArrayTy = PVD->getOriginalType(); in BuildCXXForRangeStmt()
2782 QualType PointerTy = PVD->getType(); in BuildCXXForRangeStmt()
2783 if (PointerTy->isPointerType() && ArrayTy->isArrayType()) { in BuildCXXForRangeStmt()
2784 Diag(Range->getBeginLoc(), diag::err_range_on_array_parameter) in BuildCXXForRangeStmt()
2786 Diag(PVD->getLocation(), diag::note_declared_at); in BuildCXXForRangeStmt()
2807 PartialDiagnosticAt(Range->getBeginLoc(), in BuildCXXForRangeStmt()
2809 << RangeLoc << Range->getType() in BuildCXXForRangeStmt()
2823 QualType BeginType = BeginVar->getType(), EndType = EndVar->getType(); in BuildCXXForRangeStmt()
2859 << RangeLoc << 0 << BeginRangeRef.get()->getType(); in BuildCXXForRangeStmt()
2882 << RangeLoc << 2 << BeginRangeRef.get()->getType() ; in BuildCXXForRangeStmt()
2896 << RangeLoc << 1 << BeginRangeRef.get()->getType(); in BuildCXXForRangeStmt()
2903 if (!LoopVar->isInvalidDecl() && Kind != BFRK_Check) { in BuildCXXForRangeStmt()
2905 if (LoopVar->isInvalidDecl() || in BuildCXXForRangeStmt()
2906 (LoopVar->getInit() && LoopVar->getInit()->containsErrors())) in BuildCXXForRangeStmt()
2929 // Suggest using the non-reference type for copies. If a copy can be prevented
2938 const Expr *InitExpr = VD->getInit(); in DiagnoseForRangeReferenceVariableCopies()
2942 QualType VariableType = VD->getType(); in DiagnoseForRangeReferenceVariableCopies()
2945 if (!Cleanups->cleanupsHaveSideEffects()) in DiagnoseForRangeReferenceVariableCopies()
2946 InitExpr = Cleanups->getSubExpr(); in DiagnoseForRangeReferenceVariableCopies()
2955 const Expr *E = MTE->getSubExpr()->IgnoreImpCasts(); in DiagnoseForRangeReferenceVariableCopies()
2961 E = CCE->getArg(0); in DiagnoseForRangeReferenceVariableCopies()
2963 const MemberExpr *ME = cast<MemberExpr>(Call->getCallee()); in DiagnoseForRangeReferenceVariableCopies()
2964 E = ME->getBase(); in DiagnoseForRangeReferenceVariableCopies()
2967 E = MTE->getSubExpr(); in DiagnoseForRangeReferenceVariableCopies()
2969 E = E->IgnoreImpCasts(); in DiagnoseForRangeReferenceVariableCopies()
2974 ReferenceReturnType = SemaRef.Context.getLValueReferenceType(E->getType()); in DiagnoseForRangeReferenceVariableCopies()
2977 const FunctionDecl *FD = Call->getDirectCallee(); in DiagnoseForRangeReferenceVariableCopies()
2978 QualType ReturnType = FD->getReturnType(); in DiagnoseForRangeReferenceVariableCopies()
2979 if (ReturnType->isReferenceType()) in DiagnoseForRangeReferenceVariableCopies()
2985 // non-reference loop variable to indicate a copy is made, or in DiagnoseForRangeReferenceVariableCopies()
2987 SemaRef.Diag(VD->getLocation(), in DiagnoseForRangeReferenceVariableCopies()
2993 SemaRef.Context.getLValueReferenceType(E->getType().withConst()); in DiagnoseForRangeReferenceVariableCopies()
2994 SemaRef.Diag(VD->getBeginLoc(), diag::note_use_type_or_non_reference) in DiagnoseForRangeReferenceVariableCopies()
2995 << NonReferenceType << NewReferenceType << VD->getSourceRange() in DiagnoseForRangeReferenceVariableCopies()
2996 << FixItHint::CreateRemoval(VD->getTypeSpecEndLoc()); in DiagnoseForRangeReferenceVariableCopies()
2997 } else if (!VariableType->isRValueReferenceType()) { in DiagnoseForRangeReferenceVariableCopies()
3002 SemaRef.Diag(VD->getLocation(), diag::warn_for_range_ref_binds_ret_temp) in DiagnoseForRangeReferenceVariableCopies()
3006 SemaRef.Diag(VD->getBeginLoc(), diag::note_use_non_reference_type) in DiagnoseForRangeReferenceVariableCopies()
3007 << NonReferenceType << VD->getSourceRange() in DiagnoseForRangeReferenceVariableCopies()
3008 << FixItHint::CreateRemoval(VD->getTypeSpecEndLoc()); in DiagnoseForRangeReferenceVariableCopies()
3015 if (CXXRecordDecl *RD = VariableType->getAsCXXRecordDecl()) in hasTrivialABIAttr()
3016 return RD->hasAttr<TrivialABIAttr>(); in hasTrivialABIAttr()
3026 const Expr *InitExpr = VD->getInit(); in DiagnoseForRangeConstVariableCopies()
3030 QualType VariableType = VD->getType(); in DiagnoseForRangeConstVariableCopies()
3033 if (!CE->getConstructor()->isCopyConstructor()) in DiagnoseForRangeConstVariableCopies()
3036 if (CE->getCastKind() != CK_LValueToRValue) in DiagnoseForRangeConstVariableCopies()
3053 SemaRef.Diag(VD->getLocation(), diag::warn_for_range_copy) in DiagnoseForRangeConstVariableCopies()
3055 SemaRef.Diag(VD->getBeginLoc(), diag::note_use_reference_type) in DiagnoseForRangeConstVariableCopies()
3057 << VD->getSourceRange() in DiagnoseForRangeConstVariableCopies()
3058 << FixItHint::CreateInsertion(VD->getLocation(), "&"); in DiagnoseForRangeConstVariableCopies()
3061 /// DiagnoseForRangeVariableCopies - Diagnose three cases and fixes for them.
3076 ForStmt->getBeginLoc()) && in DiagnoseForRangeVariableCopies()
3078 ForStmt->getBeginLoc()) && in DiagnoseForRangeVariableCopies()
3080 ForStmt->getBeginLoc())) { in DiagnoseForRangeVariableCopies()
3084 const VarDecl *VD = ForStmt->getLoopVariable(); in DiagnoseForRangeVariableCopies()
3088 QualType VariableType = VD->getType(); in DiagnoseForRangeVariableCopies()
3090 if (VariableType->isIncompleteType()) in DiagnoseForRangeVariableCopies()
3093 const Expr *InitExpr = VD->getInit(); in DiagnoseForRangeVariableCopies()
3097 if (InitExpr->getExprLoc().isMacroID()) in DiagnoseForRangeVariableCopies()
3100 if (VariableType->isReferenceType()) { in DiagnoseForRangeVariableCopies()
3102 ForStmt->getRangeInit()->getType()); in DiagnoseForRangeVariableCopies()
3116 ForStmt->setBody(B); in FinishCXXForRangeStmt()
3118 DiagnoseEmptyStmtBody(ForStmt->getRParenLoc(), B, in FinishCXXForRangeStmt()
3133 if (getCurScope()->isInOpenACCComputeConstructScope()) in ActOnGotoStmt()
3136 TheDecl->markUsed(Context); in ActOnGotoStmt()
3144 if (!E->isTypeDependent()) { in ActOnIndirectGotoStmt()
3145 QualType ETy = E->getType(); in ActOnIndirectGotoStmt()
3166 if (getCurScope()->isInOpenACCComputeConstructScope()) in ActOnIndirectGotoStmt()
3182 Scope *S = CurScope->getContinueParent(); in ActOnContinueStmt()
3187 if (S->isConditionVarScope()) { in ActOnContinueStmt()
3197 if (S->isOpenACCComputeConstructScope()) in ActOnContinueStmt()
3209 Scope *S = CurScope->getBreakParent(); in ActOnBreakStmt()
3214 if (S->isOpenMPLoopScope()) in ActOnBreakStmt()
3219 // we are trying to do so. This can come in 2 flavors: 1-the break'able thing in ActOnBreakStmt()
3225 if (S->isOpenACCComputeConstructScope() || in ActOnBreakStmt()
3226 (S->isLoopScope() && S->getParent() && in ActOnBreakStmt()
3227 S->getParent()->isOpenACCComputeConstructScope())) in ActOnBreakStmt()
3241 // - in a return statement in a function [where] ... in getNamedReturnInfo()
3242 // ... the expression is the name of a non-volatile automatic object ... in getNamedReturnInfo()
3243 const auto *DR = dyn_cast<DeclRefExpr>(E->IgnoreParens()); in getNamedReturnInfo()
3244 if (!DR || DR->refersToEnclosingVariableOrCapture()) in getNamedReturnInfo()
3246 const auto *VD = dyn_cast<VarDecl>(DR->getDecl()); in getNamedReturnInfo()
3249 if (VD->getInit() && VD->getInit()->containsErrors()) in getNamedReturnInfo()
3252 if (Res.Candidate && !E->isXValue() && in getNamedReturnInfo()
3256 E = ImplicitCastExpr::Create(Context, VD->getType().getNonReferenceType(), in getNamedReturnInfo()
3266 // C++20 [class.copy.elision]p3: in getNamedReturnInfo()
3267 // - in a return statement in a function with ... in getNamedReturnInfo()
3269 if (VD->getKind() == Decl::ParmVar) in getNamedReturnInfo()
3271 else if (VD->getKind() != Decl::Var) in getNamedReturnInfo()
3274 // (other than ... a catch-clause parameter) in getNamedReturnInfo()
3275 if (VD->isExceptionVariable()) in getNamedReturnInfo()
3279 if (!VD->hasLocalStorage()) in getNamedReturnInfo()
3284 if (VD->hasAttr<BlocksAttr>()) in getNamedReturnInfo()
3287 QualType VDType = VD->getType(); in getNamedReturnInfo()
3288 if (VDType->isObjectType()) { in getNamedReturnInfo()
3289 // C++17 [class.copy.elision]p3: in getNamedReturnInfo()
3290 // ...non-volatile automatic object... in getNamedReturnInfo()
3293 } else if (VDType->isRValueReferenceType()) { in getNamedReturnInfo()
3294 // C++20 [class.copy.elision]p3: in getNamedReturnInfo()
3295 // ...either a non-volatile object or an rvalue reference to a non-volatile in getNamedReturnInfo()
3299 !VDReferencedType->isObjectType()) in getNamedReturnInfo()
3308 if (!VD->hasDependentAlignment() && !VDType->isIncompleteType() && in getNamedReturnInfo()
3325 // If we got a non-deduced auto ReturnType, we are in a dependent context and in getCopyElisionCandidate()
3329 if ((ReturnType->getTypeClass() == Type::TypeClass::Auto && in getCopyElisionCandidate()
3330 ReturnType->isCanonicalUnqualified()) || in getCopyElisionCandidate()
3331 ReturnType->isSpecificBuiltinType(BuiltinType::Dependent)) in getCopyElisionCandidate()
3334 if (!ReturnType->isDependentType()) { in getCopyElisionCandidate()
3335 // - in a return statement in a function with ... in getCopyElisionCandidate()
3336 // ... a class return type ... in getCopyElisionCandidate()
3337 if (!ReturnType->isRecordType()) in getCopyElisionCandidate()
3340 QualType VDType = Info.Candidate->getType(); in getCopyElisionCandidate()
3341 // ... the same cv-unqualified type as the function return type ... in getCopyElisionCandidate()
3343 if (!VDType->isDependentType() && in getCopyElisionCandidate()
3354 /// or user conversion operators which are not ref-qualified.
3363 const auto *FD = Step->Function.Function; in VerifyInitializationSequenceCXX98()
3365 ? !FD->getParamDecl(0)->getType()->isRValueReferenceType() in VerifyInitializationSequenceCXX98()
3366 : cast<CXXMethodDecl>(FD)->getRefQualifier() == RQ_None) in VerifyInitializationSequenceCXX98()
3378 ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(), in PerformMoveOrCopyInitialization()
3381 auto Kind = InitializationKind::CreateCopy(Value->getBeginLoc(), in PerformMoveOrCopyInitialization()
3382 Value->getBeginLoc()); in PerformMoveOrCopyInitialization()
3391 ImplicitCastExpr::Create(Context, Value->getType(), CK_NoOp, Value, in PerformMoveOrCopyInitialization()
3393 // Complete type-checking the initialization of the return type in PerformMoveOrCopyInitialization()
3408 FD->getTypeSourceInfo()->getType()->castAs<FunctionProtoType>(); in hasDeducedReturnType()
3409 return FPT->getReturnType()->isUndeducedType(); in hasDeducedReturnType()
3419 QualType FnRetType = CurCap->ReturnType; in ActOnCapScopeReturnStmt()
3421 if (CurLambda && CurLambda->CallOperator->getType().isNull()) in ActOnCapScopeReturnStmt()
3424 CurLambda && hasDeducedReturnType(CurLambda->CallOperator); in ActOnCapScopeReturnStmt()
3427 (HasDeducedReturnType || CurCap->HasImplicitReturnType)) { in ActOnCapScopeReturnStmt()
3440 FunctionDecl *FD = CurLambda->CallOperator; in ActOnCapScopeReturnStmt()
3444 if (FD->isInvalidDecl()) in ActOnCapScopeReturnStmt()
3448 if (CurCap->ReturnType.isNull()) in ActOnCapScopeReturnStmt()
3449 CurCap->ReturnType = FD->getReturnType(); in ActOnCapScopeReturnStmt()
3451 AutoType *AT = CurCap->ReturnType->getContainedAutoType(); in ActOnCapScopeReturnStmt()
3454 FD->setInvalidDecl(); in ActOnCapScopeReturnStmt()
3455 // FIXME: preserve the ill-formed return expression. in ActOnCapScopeReturnStmt()
3458 CurCap->ReturnType = FnRetType = FD->getReturnType(); in ActOnCapScopeReturnStmt()
3459 } else if (CurCap->HasImplicitReturnType) { in ActOnCapScopeReturnStmt()
3471 // when deducing a return type for a lambda-expression (or by extension in ActOnCapScopeReturnStmt()
3473 // that they remove top-level cv-qualifiers. in ActOnCapScopeReturnStmt()
3474 if (!CurContext->isDependentContext()) in ActOnCapScopeReturnStmt()
3475 FnRetType = RetValExp->getType().getUnqualifiedType(); in ActOnCapScopeReturnStmt()
3477 FnRetType = CurCap->ReturnType = Context.DependentTy; in ActOnCapScopeReturnStmt()
3484 << RetValExp->getSourceRange(); in ActOnCapScopeReturnStmt()
3492 if (CurCap->ReturnType.isNull()) in ActOnCapScopeReturnStmt()
3493 CurCap->ReturnType = FnRetType; in ActOnCapScopeReturnStmt()
3498 if (CurBlock->FunctionType->castAs<FunctionType>()->getNoReturnAttr()) { in ActOnCapScopeReturnStmt()
3503 Diag(ReturnLoc, diag::err_return_in_captured_stmt) << CurRegion->getRegionName(); in ActOnCapScopeReturnStmt()
3507 if (CurLambda->CallOperator->getType() in ActOnCapScopeReturnStmt()
3508 ->castAs<FunctionType>() in ActOnCapScopeReturnStmt()
3509 ->getNoReturnAttr()) { in ActOnCapScopeReturnStmt()
3518 if (FnRetType->isDependentType()) { in ActOnCapScopeReturnStmt()
3521 } else if (FnRetType->isVoidType()) { in ActOnCapScopeReturnStmt()
3524 (RetValExp->isTypeDependent() || in ActOnCapScopeReturnStmt()
3525 RetValExp->getType()->isVoidType()))) { in ActOnCapScopeReturnStmt()
3527 RetValExp->getType()->isVoidType()) in ActOnCapScopeReturnStmt()
3536 } else if (!RetValExp->isTypeDependent()) { in ActOnCapScopeReturnStmt()
3537 // we have a non-void block with an expression, continue checking in ActOnCapScopeReturnStmt()
3570 if (CurCap->HasImplicitReturnType || NRVOCandidate) in ActOnCapScopeReturnStmt()
3571 FunctionScopes.back()->Returns.push_back(Result); in ActOnCapScopeReturnStmt()
3573 if (FunctionScopes.back()->FirstReturnLoc.isInvalid()) in ActOnCapScopeReturnStmt()
3574 FunctionScopes.back()->FirstReturnLoc = ReturnLoc; in ActOnCapScopeReturnStmt()
3577 CurBlock && CurCap->HasImplicitReturnType && RetValExp && in ActOnCapScopeReturnStmt()
3578 RetValExp->containsErrors()) in ActOnCapScopeReturnStmt()
3579 CurBlock->TheDecl->setInvalidDecl(); in ActOnCapScopeReturnStmt()
3597 class LocalTypedefNameReferencer
3606 auto *R = dyn_cast<CXXRecordDecl>(RT->getDecl()); in VisitRecordType()
3607 if (!R || !R->isLocalClass() || !R->isLocalClass()->isExternallyVisible() || in VisitRecordType()
3608 R->isDependentType()) in VisitRecordType()
3610 for (auto *TmpD : R->decls()) in VisitRecordType()
3612 if (T->getAccess() != AS_private || R->hasFriends()) in VisitRecordType()
3613 S.MarkAnyDeclReferenced(T->getLocation(), T, /*OdrUse=*/false); in VisitRecordType()
3619 return FD->getTypeSourceInfo() in getReturnTypeLoc()
3620 ->getTypeLoc() in getReturnTypeLoc()
3636 // a braced-init-list, the program is ill-formed. in DeduceFunctionTypeFromReturnExpr()
3637 Diag(RetExpr->getExprLoc(), in DeduceFunctionTypeFromReturnExpr()
3640 << RetExpr->getSourceRange(); in DeduceFunctionTypeFromReturnExpr()
3644 if (FD->isDependentContext()) { in DeduceFunctionTypeFromReturnExpr()
3648 // statement with a non-type-dependent operand. in DeduceFunctionTypeFromReturnExpr()
3649 assert(AT->isDeduced() && "should have deduced to dependent type"); in DeduceFunctionTypeFromReturnExpr()
3660 // 'decltype(auto)', possibly cv-qualified or constrained, but not in DeduceFunctionTypeFromReturnExpr()
3661 // ref-qualified. in DeduceFunctionTypeFromReturnExpr()
3662 if (!OrigResultType.getType()->getAs<AutoType>()) { in DeduceFunctionTypeFromReturnExpr()
3670 QualType Deduced = AT->getDeducedType(); in DeduceFunctionTypeFromReturnExpr()
3674 auto RetExprLoc = RetExpr->getExprLoc(); in DeduceFunctionTypeFromReturnExpr()
3677 if (RetExpr->getType() == Context.OverloadTy) { in DeduceFunctionTypeFromReturnExpr()
3680 TemplateSpecLoc = FindResult.Expression->getNameLoc(); in DeduceFunctionTypeFromReturnExpr()
3686 if (Res != TemplateDeductionResult::Success && FD->isInvalidDecl()) in DeduceFunctionTypeFromReturnExpr()
3697 // each deduction, the program is ill-formed. in DeduceFunctionTypeFromReturnExpr()
3699 if (LambdaSI && LambdaSI->HasImplicitReturnType) in DeduceFunctionTypeFromReturnExpr()
3704 << (AT->isDecltypeAuto() ? 1 : 0) << Info.SecondArg in DeduceFunctionTypeFromReturnExpr()
3709 Diag(RetExpr->getExprLoc(), diag::err_auto_fn_deduction_failure) in DeduceFunctionTypeFromReturnExpr()
3710 << OrigResultType.getType() << RetExpr->getType(); in DeduceFunctionTypeFromReturnExpr()
3718 LocalTypedefNameReferencer(*this).TraverseType(RetExpr->getType()); in DeduceFunctionTypeFromReturnExpr()
3721 if (getLangOpts().CUDA && FD->hasAttr<CUDAGlobalAttr>() && in DeduceFunctionTypeFromReturnExpr()
3722 !Deduced->isVoidType()) { in DeduceFunctionTypeFromReturnExpr()
3723 Diag(FD->getLocation(), diag::err_kern_type_not_void_return) in DeduceFunctionTypeFromReturnExpr()
3724 << FD->getType() << FD->getSourceRange(); in DeduceFunctionTypeFromReturnExpr()
3728 if (!FD->isInvalidDecl() && AT->getDeducedType() != Deduced) in DeduceFunctionTypeFromReturnExpr()
3745 if (getCurScope()->isInOpenACCComputeConstructScope()) in ActOnReturnStmt()
3756 const_cast<VarDecl *>(cast<ReturnStmt>(R.get())->getNRVOCandidate()); in ActOnReturnStmt()
3758 CurScope->updateNRVOCandidate(VD); in ActOnReturnStmt()
3760 CheckJumpOutOfSEHFinally(*this, ReturnLoc, *CurScope->getFnParent()); in ActOnReturnStmt()
3769 const Decl *D = E->getReferencedDeclOfCallee(); in CheckSimplerImplicitMovesMSVCWorkaround()
3770 if (!D || !S.SourceMgr.isInSystemHeader(D->getLocation())) in CheckSimplerImplicitMovesMSVCWorkaround()
3772 for (const DeclContext *DC = D->getDeclContext(); DC; DC = DC->getParent()) { in CheckSimplerImplicitMovesMSVCWorkaround()
3773 if (DC->isStdNamespace()) in CheckSimplerImplicitMovesMSVCWorkaround()
3804 FnRetType = FD->getReturnType(); in BuildReturnStmt()
3805 if (FD->hasAttrs()) in BuildReturnStmt()
3806 Attrs = &FD->getAttrs(); in BuildReturnStmt()
3807 if (FD->isNoReturn()) in BuildReturnStmt()
3809 if (FD->isMain() && RetValExp) in BuildReturnStmt()
3812 << RetValExp->getSourceRange(); in BuildReturnStmt()
3813 if (FD->hasAttr<CmseNSEntryAttr>() && RetValExp) { in BuildReturnStmt()
3815 if (RT->getDecl()->isOrContainsUnion()) in BuildReturnStmt()
3816 Diag(RetValExp->getBeginLoc(), diag::warn_cmse_nonsecure_union) << 1; in BuildReturnStmt()
3820 FnRetType = MD->getReturnType(); in BuildReturnStmt()
3822 if (MD->hasAttrs()) in BuildReturnStmt()
3823 Attrs = &MD->getAttrs(); in BuildReturnStmt()
3824 if (MD->hasRelatedResultType() && MD->getClassInterface()) { in BuildReturnStmt()
3826 // type used to type-check the validity of return statements within the in BuildReturnStmt()
3827 // method body is a pointer to the type of the class being implemented. in BuildReturnStmt()
3828 RelatedRetType = Context.getObjCInterfaceType(MD->getClassInterface()); in BuildReturnStmt()
3835 const auto *ATy = dyn_cast<ArrayType>(RetValExp->getType()); in BuildReturnStmt()
3836 if (ATy && ATy->getElementType().isWebAssemblyReferenceType()) { in BuildReturnStmt()
3845 FnRetType->getContainedAutoType()) { in BuildReturnStmt()
3860 if (AutoType *AT = FnRetType->getContainedAutoType()) { in BuildReturnStmt()
3866 if (FD->isInvalidDecl() || in BuildReturnStmt()
3868 FD->setInvalidDecl(); in BuildReturnStmt()
3876 RetValExp->getBeginLoc(), RetValExp->getEndLoc(), RetValExp, in BuildReturnStmt()
3877 AT->isDeduced() ? FnRetType : QualType()); in BuildReturnStmt()
3885 FnRetType = FD->getReturnType(); in BuildReturnStmt()
3891 bool HasDependentReturnType = FnRetType->isDependentType(); in BuildReturnStmt()
3894 if (FnRetType->isVoidType()) { in BuildReturnStmt()
3910 << CurDecl << FunctionKind << RetValExp->getSourceRange(); in BuildReturnStmt()
3914 ? CreateRecoveryExpr(ILE->getLBraceLoc(), in BuildReturnStmt()
3915 ILE->getRBraceLoc(), ILE->inits()) in BuildReturnStmt()
3918 } else if (!RetValExp->isTypeDependent()) { in BuildReturnStmt()
3921 if (RetValExp->getType()->isVoidType()) { in BuildReturnStmt()
3942 << RetValExp->getSourceRange(); in BuildReturnStmt()
3958 << CurDecl << FunctionKind << RetValExp->getSourceRange(); in BuildReturnStmt()
3976 if ((FD && FD->isInvalidDecl()) || FnRetType->containsErrors()) { in BuildReturnStmt()
3978 } else if (getLangOpts().CPlusPlus11 && FD && FD->isConstexpr()) { in BuildReturnStmt()
3981 << FD << FD->isConsteval(); in BuildReturnStmt()
3982 FD->setInvalidDecl(); in BuildReturnStmt()
3989 // getCurMethodDecl() must be non-null (see above). in BuildReturnStmt()
4010 if (!HasDependentReturnType && !RetValExp->isTypeDependent()) { in BuildReturnStmt()
4011 // we have a non-void function with an expression, continue checking in BuildReturnStmt()
4017 Res = CreateRecoveryExpr(RetValExp->getBeginLoc(), in BuildReturnStmt()
4018 RetValExp->getEndLoc(), RetValExp, RetType); in BuildReturnStmt()
4027 // initialize the result again --- we might end double-retaining in BuildReturnStmt()
4028 // --- so instead we initialize a notional temporary. in BuildReturnStmt()
4056 if (Result->getNRVOCandidate()) in BuildReturnStmt()
4057 FunctionScopes.back()->Returns.push_back(Result); in BuildReturnStmt()
4059 if (FunctionScopes.back()->FirstReturnLoc.isInvalid()) in BuildReturnStmt()
4060 FunctionScopes.back()->FirstReturnLoc = ReturnLoc; in BuildReturnStmt()
4074 class CatchHandlerType {
4088 /// level pointer and cv-qualifiers.
4090 if (QT->isPointerType()) in CatchHandlerType()
4094 if (IsPointer || QT->isReferenceType()) in CatchHandlerType()
4095 QT = QT->getPointeeType(); in CatchHandlerType()
4098 /// Used when creating a CatchHandlerType from a base class type; pretends the
4112 // Otherwise, check the underlying type without cv-qualifiers. in operator ==()
4142 class CatchTypePublicBases {
4158 if (S->getAccessSpecifier() == AccessSpecifier::AS_public) { in operator ()()
4159 QualType Check = S->getType().getCanonicalType(); in operator ()()
4173 if (I->second->getCaughtType()->isPointerType() == in operator ()()
4174 TestAgainstType->isPointerType()) { in operator ()()
4175 FoundHandler = I->second; in operator ()()
4209 if (getCurScope() && getCurScope()->isOpenMPSimdDirectiveScope()) in ActOnCXXTryBlock()
4215 if (!getLangOpts().Borland && FSI->FirstSEHTryLoc.isValid()) { in ActOnCXXTryBlock()
4217 Diag(FSI->FirstSEHTryLoc, diag::note_conflicting_try_here) << "'__try'"; in ActOnCXXTryBlock()
4229 // Diagnose when the handler is a catch-all handler, but it isn't the last in ActOnCXXTryBlock()
4232 if (!H->getExceptionDecl()) { in ActOnCXXTryBlock()
4233 if (i < NumHandlers - 1) in ActOnCXXTryBlock()
4234 return StmtError(Diag(H->getBeginLoc(), diag::err_early_catch_all)); in ActOnCXXTryBlock()
4236 } else if (H->getExceptionDecl()->isInvalidDecl()) in ActOnCXXTryBlock()
4241 // ignore top-level cv-qualifiers, per [except.handle]p3 in ActOnCXXTryBlock()
4242 CatchHandlerType HandlerCHT = H->getCaughtType().getCanonicalType(); in ActOnCXXTryBlock()
4248 if (auto *RD = Underlying->getAsCXXRecordDecl()) { in ActOnCXXTryBlock()
4249 if (!RD->hasDefinition()) in ActOnCXXTryBlock()
4254 // comparison against the handler type using the same top-level pointer in ActOnCXXTryBlock()
4259 H->getCaughtType().getCanonicalType()); in ActOnCXXTryBlock()
4260 if (RD->lookupInBases(CTPB, Paths)) { in ActOnCXXTryBlock()
4264 Diag(H->getExceptionDecl()->getTypeSpecStartLoc(), in ActOnCXXTryBlock()
4266 << H->getCaughtType(); in ActOnCXXTryBlock()
4267 Diag(Problem->getExceptionDecl()->getTypeSpecStartLoc(), in ActOnCXXTryBlock()
4269 << Problem->getCaughtType(); in ActOnCXXTryBlock()
4273 // type to the base type specifiers of a class, which are ignored in a in ActOnCXXTryBlock()
4274 // base specifier per [class.derived.general]p2. in ActOnCXXTryBlock()
4281 std::make_pair(H->getCaughtType().getCanonicalType(), H)); in ActOnCXXTryBlock()
4283 const CXXCatchStmt *Problem = R.first->second; in ActOnCXXTryBlock()
4284 Diag(H->getExceptionDecl()->getTypeSpecStartLoc(), in ActOnCXXTryBlock()
4286 << H->getCaughtType(); in ActOnCXXTryBlock()
4287 Diag(Problem->getExceptionDecl()->getTypeSpecStartLoc(), in ActOnCXXTryBlock()
4289 << Problem->getCaughtType(); in ActOnCXXTryBlock()
4293 FSI->setHasCXXTry(TryLoc); in ActOnCXXTryBlock()
4308 if (FSI->FirstCXXOrObjCTryLoc.isValid()) { in ActOnSEHTryBlock()
4309 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try) << FSI->FirstTryType; in ActOnSEHTryBlock()
4310 Diag(FSI->FirstCXXOrObjCTryLoc, diag::note_conflicting_try_here) in ActOnSEHTryBlock()
4311 << (FSI->FirstTryType == sema::FunctionScopeInfo::TryLocIsCXX in ActOnSEHTryBlock()
4317 FSI->setHasSEHTry(TryLoc); in ActOnSEHTryBlock()
4319 // Reject __try in Obj-C methods, blocks, and captured decls, since we don't in ActOnSEHTryBlock()
4322 while (DC && !DC->isFunctionOrMethod()) in ActOnSEHTryBlock()
4323 DC = DC->getParent(); in ActOnSEHTryBlock()
4326 FD->setUsesSEHTry(true); in ActOnSEHTryBlock()
4340 QualType FTy = FilterExpr->getType(); in ActOnSEHExceptBlock()
4341 if (!FTy->isIntegerType() && !FTy->isDependentType()) { in ActOnSEHExceptBlock()
4343 Diag(FilterExpr->getExprLoc(), diag::err_filter_expression_integral) in ActOnSEHExceptBlock()
4366 while (SEHTryParent && !SEHTryParent->isSEHTryScope()) in ActOnSEHLeaveStmt()
4367 SEHTryParent = SEHTryParent->getParent(); in ActOnSEHLeaveStmt()
4402 while (!(DC->isFunctionOrMethod() || DC->isRecord() || DC->isFileContext())) in CreateCapturedStmtRecordDecl()
4403 DC = DC->getParent(); in CreateCapturedStmtRecordDecl()
4413 RD->setCapturedRecord(); in CreateCapturedStmtRecordDecl()
4414 DC->addDecl(RD); in CreateCapturedStmtRecordDecl()
4415 RD->setImplicit(); in CreateCapturedStmtRecordDecl()
4416 RD->startDefinition(); in CreateCapturedStmtRecordDecl()
4420 DC->addDecl(CD); in CreateCapturedStmtRecordDecl()
4428 for (const sema::Capture &Cap : RSI->Captures) { in buildCapturedStmtCaptureList()
4434 RSI->CapRegionKind == CR_OpenMP); in buildCapturedStmtCaptureList()
4437 // no side-effects. in buildCapturedStmtCaptureList()
4440 FieldDecl *Field = S.BuildCaptureField(RSI->TheRecordDecl, Cap); in buildCapturedStmtCaptureList()
4452 if (S.getLangOpts().OpenMP && RSI->CapRegionKind == CR_OpenMP) in buildCapturedStmtCaptureList()
4454 RSI->OpenMPLevel); in buildCapturedStmtCaptureList()
4480 DC->addDecl(Param); in ActOnCapturedRegionStart()
4482 CD->setContextParam(0, Param); in ActOnCapturedRegionStart()
4511 if (I->second.isNull()) { in ActOnCapturedRegionStart()
4521 DC->addDecl(Param); in ActOnCapturedRegionStart()
4522 CD->setContextParam(ParamNum, Param); in ActOnCapturedRegionStart()
4525 IdentifierInfo *ParamName = &Context.Idents.get(I->first); in ActOnCapturedRegionStart()
4527 ImplicitParamDecl::Create(Context, DC, Loc, ParamName, I->second, in ActOnCapturedRegionStart()
4529 DC->addDecl(Param); in ActOnCapturedRegionStart()
4530 CD->setParam(ParamNum, Param); in ActOnCapturedRegionStart()
4541 DC->addDecl(Param); in ActOnCapturedRegionStart()
4542 CD->setContextParam(ParamNum, Param); in ActOnCapturedRegionStart()
4563 RecordDecl *Record = RSI->TheRecordDecl; in ActOnCapturedRegionError()
4564 Record->setInvalidDecl(); in ActOnCapturedRegionError()
4566 SmallVector<Decl*, 4> Fields(Record->fields()); in ActOnCapturedRegionError()
4567 ActOnFields(/*Scope=*/nullptr, Record->getLocation(), Record, Fields, in ActOnCapturedRegionError()
4585 CapturedDecl *CD = RSI->TheCapturedDecl; in ActOnCapturedRegionEnd()
4586 RecordDecl *RD = RSI->TheRecordDecl; in ActOnCapturedRegionEnd()
4589 getASTContext(), S, static_cast<CapturedRegionKind>(RSI->CapRegionKind), in ActOnCapturedRegionEnd()
4592 CD->setBody(Res->getCapturedStmt()); in ActOnCapturedRegionEnd()
4593 RD->completeDefinition(); in ActOnCapturedRegionEnd()