39#include "llvm/ADT/ArrayRef.h"
40#include "llvm/ADT/DenseMap.h"
41#include "llvm/ADT/STLExtras.h"
42#include "llvm/ADT/STLForwardCompat.h"
43#include "llvm/ADT/SmallPtrSet.h"
44#include "llvm/ADT/SmallString.h"
45#include "llvm/ADT/SmallVector.h"
46#include "llvm/ADT/StringExtras.h"
74 bool HasLeadingEmptyMacro) {
103 Diag(
decl->getLocation(), diag::err_non_variable_decl_in_for);
104 decl->setInvalidDecl();
137 enum { Equality, Inequality, Relational, ThreeWay } Kind;
140 if (!Op->isComparisonOp())
143 if (Op->getOpcode() == BO_EQ)
145 else if (Op->getOpcode() == BO_NE)
147 else if (Op->getOpcode() == BO_Cmp)
150 assert(Op->isRelationalOp());
153 Loc = Op->getOperatorLoc();
154 CanAssign = Op->getLHS()->IgnoreParenImpCasts()->isLValue();
156 switch (Op->getOperator()) {
160 case OO_ExclaimEqual:
165 case OO_GreaterEqual:
176 Loc = Op->getOperatorLoc();
177 CanAssign = Op->getArg(0)->IgnoreParenImpCasts()->isLValue();
188 S.
Diag(Loc, diag::warn_unused_comparison)
194 if (Kind == Inequality)
195 S.
Diag(Loc, diag::note_inequality_comparison_to_or_assign)
197 else if (Kind == Equality)
198 S.
Diag(Loc, diag::note_equality_comparison_to_assign)
210 StringRef Msg = A->getMessage();
214 return S.
Diag(Loc, diag::warn_unused_constructor) << A << R1 << R2;
215 return S.
Diag(Loc, diag::warn_unused_result) << A << R1 << R2;
219 return S.
Diag(Loc, diag::warn_unused_constructor_msg) << A << Msg << R1
221 return S.
Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
228 const Expr *E = dyn_cast_or_null<Expr>(S);
243 bool ShouldSuppress =
247 const Expr *WarnExpr;
272 if (
const FullExpr *Temps = dyn_cast<FullExpr>(E))
273 E = Temps->getSubExpr();
275 E = TempExpr->getSubExpr();
281 if (
const auto *Cast = dyn_cast<CastExpr>(E))
282 if (Cast->getCastKind() == CK_NoOp ||
283 Cast->getCastKind() == CK_ConstructorConversion)
284 E = Cast->getSubExpr()->IgnoreImpCasts();
286 if (
const CallExpr *CE = dyn_cast<CallExpr>(E)) {
291 CE->getUnusedResultAttr(
Context)),
299 if (
const Decl *FD = CE->getCalleeDecl()) {
302 if (FD->hasAttr<PureAttr>()) {
303 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"pure";
306 if (FD->hasAttr<ConstAttr>()) {
307 Diag(Loc, diag::warn_unused_call) << R1 << R2 <<
"const";
311 }
else if (
const auto *CE = dyn_cast<CXXConstructExpr>(E)) {
313 const auto *A = Ctor->getAttr<WarnUnusedResultAttr>();
314 A = A ? A : Ctor->getParent()->getAttr<WarnUnusedResultAttr>();
318 }
else if (
const auto *ILE = dyn_cast<InitListExpr>(E)) {
319 if (
const TagDecl *TD = ILE->getType()->getAsTagDecl()) {
325 }
else if (ShouldSuppress)
330 if (
getLangOpts().ObjCAutoRefCount && ME->isDelegateInitCall()) {
331 Diag(Loc, diag::err_arc_unused_init_message) << R1;
341 const Expr *Source = POE->getSyntacticForm();
343 if (
LangOpts.OpenMP && isa<CallExpr>(Source) &&
344 POE->getNumSemanticExprs() == 1 &&
345 isa<CallExpr>(POE->getSemanticExpr(0)))
347 if (isa<ObjCSubscriptRefExpr>(Source))
348 DiagID = diag::warn_unused_container_subscript_expr;
349 else if (isa<ObjCPropertyRefExpr>(Source))
350 DiagID = diag::warn_unused_property_expr;
352 = dyn_cast<CXXFunctionalCastExpr>(E)) {
353 const Expr *E = FC->getSubExpr();
355 E = TE->getSubExpr();
356 if (isa<CXXTemporaryObjectExpr>(E))
359 if (
const CXXRecordDecl *RD = CE->getType()->getAsCXXRecordDecl())
360 if (!RD->getAttr<WarnUnusedAttr>())
364 else if (
const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(E)) {
372 Diag(Loc, diag::warn_unused_voidptr)
382 Diag(Loc, diag::warn_unused_volatile) << R1 << R2;
389 if (DiagID != diag::warn_unused_comma_left_operand || !
isSFINAEContext())
391 PDiag(DiagID) << R1 << R2);
416 const unsigned NumElts = Elts.size();
421 const unsigned MixedDeclsCodeID =
getLangOpts().C99
422 ? diag::warn_mixed_decls_code
423 : diag::ext_mixed_decls_code;
428 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
432 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
436 Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
446 for (
unsigned i = 0; i != NumElts - 1; ++i)
482 auto CheckAndFinish = [&](
Expr *E) {
489 llvm::APSInt TempVal;
495 if (!E->isValueDependent())
509 if (Converted.
get() == Val.
get())
510 Converted = CheckAndFinish(Val.
get());
518 assert((LHSVal.
isInvalid() || LHSVal.
get()) &&
"missing LHS value");
521 "missing RHS value");
524 Diag(CaseLoc, diag::err_case_not_in_switch);
535 Diag(CaseLoc, diag::err_acc_branch_in_out_compute_construct)
541 CaseLoc, DotDotDotLoc, ColonLoc);
548 cast<CaseStmt>(S)->setSubStmt(SubStmt);
555 Diag(DefaultLoc, diag::err_default_not_in_switch);
561 Diag(DefaultLoc, diag::err_acc_branch_in_out_compute_construct)
576 Diag(IdentLoc, diag::err_redefinition_of_label) << TheDecl->
getDeclName();
584 Diag(IdentLoc, diag::warn_reserved_extern_symbol)
585 << TheDecl << static_cast<int>(Status);
589 if (
getCurScope()->isInOpenACCComputeConstructScope())
611 for (
const auto *A : Attrs) {
612 if (A->getKind() == attr::MustTail) {
627 if (!SemanticAttrs.empty())
643 if (!checkMustTailAttr(St, MTA))
649 auto IgnoreImplicitAsWritten = [](
Expr *E) ->
Expr * {
660bool Sema::checkMustTailAttr(
const Stmt *St,
const Attr &MTA) {
662 "musttail cannot be checked from a dependent context");
665 auto IgnoreParenImplicitAsWritten = [](
const Expr *E) ->
const Expr * {
671 const Expr *E = cast<ReturnStmt>(St)->getRetValue();
672 const auto *CE = dyn_cast_or_null<CallExpr>(IgnoreParenImplicitAsWritten(E));
679 if (
const auto *EWC = dyn_cast<ExprWithCleanups>(E)) {
680 if (EWC->cleanupsHaveSideEffects()) {
681 Diag(St->
getBeginLoc(), diag::err_musttail_needs_trivial_args) << &MTA;
692 ft_non_static_member,
693 ft_pointer_to_member,
694 } MemberType = ft_non_member;
699 } CallerType, CalleeType;
702 bool IsCallee) ->
bool {
703 if (isa<CXXConstructorDecl, CXXDestructorDecl>(CMD)) {
705 << IsCallee << isa<CXXDestructorDecl>(CMD);
707 Diag(CMD->getBeginLoc(), diag::note_musttail_structors_forbidden)
708 << isa<CXXDestructorDecl>(CMD);
713 Type.MemberType = FuncType::ft_static_member;
715 Type.This = CMD->getFunctionObjectParameterType();
716 Type.MemberType = FuncType::ft_non_static_member;
722 const auto *CallerDecl = dyn_cast<FunctionDecl>(
CurContext);
733 Diag(St->
getBeginLoc(), diag::err_musttail_forbidden_from_this_context)
736 }
else if (
const auto *CMD = dyn_cast<CXXMethodDecl>(
CurContext)) {
738 if (!GetMethodType(CMD, CallerType,
false))
746 const auto *CalleeBinOp = dyn_cast<BinaryOperator>(CalleeExpr);
748 ? CE->getCalleeDecl()->getBeginLoc()
753 dyn_cast_or_null<CXXMethodDecl>(CE->getCalleeDecl())) {
755 if (!GetMethodType(CMD, CalleeType,
true))
757 }
else if (CalleeBinOp && CalleeBinOp->isPtrMemOp()) {
761 CalleeType.This =
QualType(MPT->getClass(), 0);
763 CalleeType.MemberType = FuncType::ft_pointer_to_member;
764 }
else if (isa<CXXPseudoDestructorExpr>(CalleeExpr)) {
776 if (!CalleeType.Func || !CallerType.Func) {
778 if (!CalleeType.Func && CE->getDirectCallee()) {
779 Diag(CE->getDirectCallee()->getBeginLoc(),
780 diag::note_musttail_fix_non_prototype);
782 if (!CallerType.Func)
783 Diag(CallerDecl->getBeginLoc(), diag::note_musttail_fix_non_prototype);
794 if (CallerType.Func->getCallConv() != CalleeType.Func->getCallConv()) {
795 if (
const auto *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl()))
797 <<
true << ND->getDeclName();
799 Diag(St->
getBeginLoc(), diag::err_musttail_callconv_mismatch) <<
false;
800 Diag(CalleeLoc, diag::note_musttail_callconv_mismatch)
807 if (CalleeType.Func->isVariadic() || CallerType.Func->isVariadic()) {
812 const auto *CalleeDecl = CE->getCalleeDecl();
813 if (CalleeDecl && CalleeDecl->hasAttr<CXX11NoReturnAttr>()) {
819 if (CallerType.This.isNull() != CalleeType.This.isNull()) {
820 if (
const auto *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl())) {
822 << CallerType.MemberType << CalleeType.MemberType <<
true
823 << ND->getDeclName();
824 Diag(CalleeLoc, diag::note_musttail_callee_defined_here)
825 << ND->getDeclName();
828 << CallerType.MemberType << CalleeType.MemberType <<
false;
833 auto CheckTypesMatch = [
this](FuncType CallerType, FuncType CalleeType,
843 unsigned Select) ->
bool {
851 if (!CallerType.This.isNull() &&
855 if (!DoTypesMatch(CallerType.Func->getReturnType(),
859 if (CallerType.Func->getNumParams() != CalleeType.Func->getNumParams()) {
861 << CalleeType.Func->getNumParams();
867 size_t N = CallerType.Func->getNumParams();
868 for (
size_t I = 0; I < N; I++) {
869 if (!DoTypesMatch(CalleeParams[I], CallerParams[I],
871 PD << static_cast<int>(I) + 1;
880 if (!CheckTypesMatch(CallerType, CalleeType, PD)) {
881 if (
const auto *ND = dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl()))
883 <<
true << ND->getDeclName();
899 CommaVisitor(
Sema &SemaRef) : Inherited(SemaRef.Context), SemaRef(SemaRef) {}
917 bool ConstevalOrNegatedConsteval =
921 Expr *CondExpr = Cond.
get().second;
922 assert((CondExpr || ConstevalOrNegatedConsteval) &&
923 "If statement: missing condition");
927 CommaVisitor(*this).Visit(CondExpr);
929 if (!ConstevalOrNegatedConsteval && !elseStmt)
932 if (ConstevalOrNegatedConsteval ||
934 auto DiagnoseLikelihood = [&](
const Stmt *S) {
937 diag::warn_attribute_has_no_effect_on_compile_time_if)
938 << A << ConstevalOrNegatedConsteval << A->getRange();
940 diag::note_attribute_has_no_effect_on_compile_time_if_here)
941 << ConstevalOrNegatedConsteval
948 DiagnoseLikelihood(thenStmt);
949 DiagnoseLikelihood(elseStmt);
951 std::tuple<bool, const Attr *, const Attr *> LHC =
953 if (std::get<0>(LHC)) {
954 const Attr *ThenAttr = std::get<1>(LHC);
955 const Attr *ElseAttr = std::get<2>(LHC);
957 diag::warn_attributes_likelihood_ifstmt_conflict)
958 << ThenAttr << ThenAttr->
getRange();
960 << ElseAttr << ElseAttr->
getRange();
964 if (ConstevalOrNegatedConsteval) {
970 if (FD && FD->isImmediateFunction())
974 Diags.
Report(IfLoc, diag::warn_consteval_if_always_true) << Immediate;
977 return BuildIfStmt(IfLoc, StatementKind, LParenLoc, InitStmt, Cond, RParenLoc,
978 thenStmt, ElseLoc, elseStmt);
991 isa<ObjCAvailabilityCheckExpr>(Cond.
get().second))
995 Cond.
get().first, Cond.
get().second, LParenLoc,
996 RParenLoc, thenStmt, ElseLoc, elseStmt);
1000 struct CaseCompareFunctor {
1001 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
1002 const llvm::APSInt &RHS) {
1003 return LHS.first < RHS;
1005 bool operator()(
const std::pair<llvm::APSInt, CaseStmt*> &LHS,
1006 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
1007 return LHS.first < RHS.first;
1009 bool operator()(
const llvm::APSInt &LHS,
1010 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
1011 return LHS < RHS.first;
1019 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
1020 if (lhs.first < rhs.first)
1023 if (lhs.first == rhs.first &&
1024 lhs.second->getCaseLoc() < rhs.second->getCaseLoc())
1031static bool CmpEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
1032 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
1034 return lhs.first < rhs.first;
1039static bool EqEnumVals(
const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
1040 const std::pair<llvm::APSInt, EnumConstantDecl*>& rhs)
1042 return lhs.first == rhs.first;
1048 if (
const auto *FE = dyn_cast<FullExpr>(E))
1049 E = FE->getSubExpr();
1050 while (
const auto *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
1051 if (ImpCast->getCastKind() != CK_IntegralCast)
break;
1052 E = ImpCast->getSubExpr();
1062 SwitchConvertDiagnoser(
Expr *Cond)
1068 return S.
Diag(Loc, diag::err_typecheck_statement_requires_integer) <<
T;
1073 return S.
Diag(Loc, diag::err_switch_incomplete_class_type)
1079 return S.
Diag(Loc, diag::err_switch_explicit_conversion) <<
T << ConvTy;
1090 return S.
Diag(Loc, diag::err_switch_multiple_conversions) <<
T;
1101 llvm_unreachable(
"conversion functions are permitted");
1103 } SwitchDiagnoser(Cond);
1112 Cond = CondResult.
get();
1125 Expr *CondExpr = Cond.
get().second;
1126 assert((Cond.
isInvalid() || CondExpr) &&
"switch with no condition");
1139 Diag(SwitchLoc, diag::warn_bool_switch_condition)
1147 LParenLoc, RParenLoc);
1153static void AdjustAPSInt(llvm::APSInt &Val,
unsigned BitWidth,
bool IsSigned) {
1154 Val = Val.extOrTrunc(BitWidth);
1155 Val.setIsSigned(IsSigned);
1161 unsigned UnpromotedWidth,
bool UnpromotedSign) {
1169 if (UnpromotedWidth < Val.getBitWidth()) {
1170 llvm::APSInt ConvVal(Val);
1171 AdjustAPSInt(ConvVal, UnpromotedWidth, UnpromotedSign);
1172 AdjustAPSInt(ConvVal, Val.getBitWidth(), Val.isSigned());
1177 S.
Diag(Loc, diag::warn_case_value_overflow) <<
toString(Val, 10)
1188 const Expr *CaseExpr,
1189 EnumValsTy::iterator &EI,
1190 EnumValsTy::iterator &EIEnd,
1191 const llvm::APSInt &Val) {
1197 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
1206 if (ED->
hasAttr<FlagEnumAttr>())
1209 while (EI != EIEnd && EI->first < Val)
1212 if (EI != EIEnd && EI->first == Val)
1225 if (!CondEnumType || !CaseEnumType)
1232 if (!CaseEnumType->getDecl()->getIdentifier() &&
1233 !CaseEnumType->getDecl()->getTypedefNameForAnonDecl())
1239 S.
Diag(Case->
getExprLoc(), diag::warn_comparison_of_mixed_enum_types_switch)
1249 assert(SS ==
getCurFunction()->SwitchStack.back().getPointer() &&
1250 "switch stack missing push/pop!");
1255 SS->
setBody(BodyStmt, SwitchLoc);
1269 const Expr *CondExprBeforePromotion = CondExpr;
1275 bool HasDependentValue
1284 unsigned CondWidthBeforePromotion
1286 bool CondIsSignedBeforePromotion
1293 CaseValsTy CaseVals;
1296 typedef std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRangesTy;
1297 CaseRangesTy CaseRanges;
1301 bool CaseListIsErroneous =
false;
1309 if (
DefaultStmt *DS = dyn_cast<DefaultStmt>(SC)) {
1310 if (TheDefaultStmt) {
1311 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
1318 CaseListIsErroneous =
true;
1320 TheDefaultStmt = DS;
1328 HasDependentValue =
true;
1334 const Expr *LoBeforePromotion = Lo;
1341 CondIsSignedBeforePromotion);
1353 HasDependentValue =
true;
1356 CaseRanges.push_back(std::make_pair(LoVal, CS));
1358 CaseVals.push_back(std::make_pair(LoVal, CS));
1362 if (!HasDependentValue) {
1365 llvm::APSInt ConstantCondValue;
1366 bool HasConstantCond =
false;
1367 if (!TheDefaultStmt) {
1372 ConstantCondValue =
Result.Val.getInt();
1373 assert(!HasConstantCond ||
1374 (ConstantCondValue.getBitWidth() == CondWidth &&
1375 ConstantCondValue.isSigned() == CondIsSigned));
1376 Diag(SwitchLoc, diag::warn_switch_default);
1378 bool ShouldCheckConstantCond = HasConstantCond;
1383 if (!CaseVals.empty()) {
1384 for (
unsigned i = 0, e = CaseVals.size(); i != e; ++i) {
1385 if (ShouldCheckConstantCond &&
1386 CaseVals[i].first == ConstantCondValue)
1387 ShouldCheckConstantCond =
false;
1389 if (i != 0 && CaseVals[i].first == CaseVals[i-1].first) {
1392 StringRef PrevString, CurrString;
1395 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(PrevCase)) {
1396 PrevString = DeclRef->getDecl()->getName();
1398 if (
DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(CurrCase)) {
1399 CurrString = DeclRef->getDecl()->getName();
1402 CaseVals[i-1].first.toString(CaseValStr);
1404 if (PrevString == CurrString)
1405 Diag(CaseVals[i].second->getLHS()->getBeginLoc(),
1406 diag::err_duplicate_case)
1407 << (PrevString.empty() ? CaseValStr.str() : PrevString);
1409 Diag(CaseVals[i].second->getLHS()->getBeginLoc(),
1410 diag::err_duplicate_case_differing_expr)
1411 << (PrevString.empty() ? CaseValStr.str() : PrevString)
1412 << (CurrString.empty() ? CaseValStr.str() : CurrString)
1415 Diag(CaseVals[i - 1].second->getLHS()->getBeginLoc(),
1416 diag::note_duplicate_case_prev);
1419 CaseListIsErroneous =
true;
1426 if (!CaseRanges.empty()) {
1429 llvm::stable_sort(CaseRanges);
1432 std::vector<llvm::APSInt> HiVals;
1433 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1434 llvm::APSInt &LoVal = CaseRanges[i].first;
1435 CaseStmt *CR = CaseRanges[i].second;
1438 const Expr *HiBeforePromotion = Hi;
1445 CondWidthBeforePromotion, CondIsSignedBeforePromotion);
1451 if (LoVal > HiVal) {
1454 CaseRanges.erase(CaseRanges.begin()+i);
1460 if (ShouldCheckConstantCond &&
1461 LoVal <= ConstantCondValue &&
1462 ConstantCondValue <= HiVal)
1463 ShouldCheckConstantCond =
false;
1465 HiVals.push_back(HiVal);
1471 for (
unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
1472 llvm::APSInt &CRLo = CaseRanges[i].first;
1473 llvm::APSInt &CRHi = HiVals[i];
1474 CaseStmt *CR = CaseRanges[i].second;
1479 llvm::APSInt OverlapVal(32);
1483 CaseValsTy::iterator I =
1484 llvm::lower_bound(CaseVals, CRLo, CaseCompareFunctor());
1485 if (I != CaseVals.end() && I->first < CRHi) {
1486 OverlapVal = I->first;
1487 OverlapStmt = I->second;
1491 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
1492 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
1493 OverlapVal = (I-1)->first;
1494 OverlapStmt = (I-1)->second;
1499 if (i && CRLo <= HiVals[i-1]) {
1500 OverlapVal = HiVals[i-1];
1501 OverlapStmt = CaseRanges[i-1].second;
1509 diag::note_duplicate_case_prev);
1512 CaseListIsErroneous =
true;
1518 if (!CaseListIsErroneous && !CaseListIsIncomplete &&
1519 ShouldCheckConstantCond) {
1522 Diag(CondExpr->
getExprLoc(), diag::warn_missing_case_for_condition)
1535 if (!CaseListIsErroneous && !CaseListIsIncomplete && !HasConstantCond &&
1544 llvm::APSInt Val = EDI->getInitVal();
1546 EnumVals.push_back(std::make_pair(Val, EDI));
1549 auto EI = EnumVals.begin(), EIEnd =
1550 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1553 for (CaseValsTy::const_iterator CI = CaseVals.begin();
1554 CI != CaseVals.end(); CI++) {
1555 Expr *CaseExpr = CI->second->getLHS();
1559 << CondTypeBeforePromotion;
1563 EI = EnumVals.begin();
1564 for (CaseRangesTy::const_iterator RI = CaseRanges.begin();
1565 RI != CaseRanges.end(); RI++) {
1566 Expr *CaseExpr = RI->second->getLHS();
1570 << CondTypeBeforePromotion;
1573 RI->second->getRHS()->EvaluateKnownConstInt(
Context);
1576 CaseExpr = RI->second->getRHS();
1580 << CondTypeBeforePromotion;
1584 auto CI = CaseVals.begin();
1585 auto RI = CaseRanges.begin();
1586 bool hasCasesNotInSwitch =
false;
1590 for (EI = EnumVals.begin(); EI != EIEnd; EI++) {
1592 switch (EI->second->getAvailability()) {
1605 if (EI->second->hasAttr<UnusedAttr>())
1609 while (CI != CaseVals.end() && CI->first < EI->first)
1612 if (CI != CaseVals.end() && CI->first == EI->first)
1616 for (; RI != CaseRanges.end(); RI++) {
1618 RI->second->getRHS()->EvaluateKnownConstInt(
Context);
1620 if (EI->first <= Hi)
1624 if (RI == CaseRanges.end() || EI->first < RI->first) {
1625 hasCasesNotInSwitch =
true;
1626 UnhandledNames.push_back(EI->second->getDeclName());
1630 if (TheDefaultStmt && UnhandledNames.empty() && ED->
isClosedNonFlag())
1634 if (!UnhandledNames.empty()) {
1636 ? diag::warn_def_missing_case
1637 : diag::warn_missing_case)
1640 for (
size_t I = 0, E = std::min(UnhandledNames.size(), (
size_t)3);
1642 DB << UnhandledNames[I];
1645 if (!hasCasesNotInSwitch)
1652 diag::warn_empty_switch_body);
1656 if (CaseListIsErroneous)
1679 const EnumDecl *ED = ET->getDecl();
1684 if (ED->
hasAttr<FlagEnumAttr>()) {
1696 llvm::APSInt Val = EDI->getInitVal();
1698 EnumVals.push_back(std::make_pair(Val, EDI));
1700 if (EnumVals.empty())
1703 EnumValsTy::iterator EIend =
1704 std::unique(EnumVals.begin(), EnumVals.end(),
EqEnumVals);
1707 EnumValsTy::const_iterator EI = EnumVals.begin();
1708 while (EI != EIend && EI->first < RhsVal)
1710 if (EI == EIend || EI->first != RhsVal) {
1725 auto CondVal = Cond.
get();
1726 CheckBreakContinueBinding(CondVal.second);
1728 if (CondVal.second &&
1729 !
Diags.
isIgnored(diag::warn_comma_operator, CondVal.second->getExprLoc()))
1730 CommaVisitor(*this).Visit(CondVal.second);
1732 if (isa<NullStmt>(Body))
1736 WhileLoc, LParenLoc, RParenLoc);
1743 assert(Cond &&
"ActOnDoStmt(): missing expression");
1745 CheckBreakContinueBinding(Cond);
1749 Cond = CondResult.
get();
1754 Cond = CondResult.
get();
1759 CommaVisitor(*this).Visit(Cond);
1761 return new (
Context)
DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen);
1772 DeclSetVector &Decls;
1778 DeclExtractor(
Sema &S, DeclSetVector &Decls,
1780 Inherited(S.Context),
1785 bool isSimple() {
return Simple; }
1794 void VisitStmt(
Stmt *S) { Simple =
false; }
1853 DeclSetVector &Decls;
1859 DeclMatcher(
Sema &S, DeclSetVector &Decls,
Stmt *Statement) :
1860 Inherited(S.Context), Decls(Decls), FoundDecl(
false) {
1861 if (!Statement)
return;
1885 void CheckLValueToRValueCast(
Expr *E) {
1888 if (isa<DeclRefExpr>(E)) {
1893 Visit(CO->getCond());
1894 CheckLValueToRValueCast(CO->getTrueExpr());
1895 CheckLValueToRValueCast(CO->getFalseExpr());
1900 dyn_cast<BinaryConditionalOperator>(E)) {
1901 CheckLValueToRValueCast(BCO->getOpaqueValue()->getSourceExpr());
1902 CheckLValueToRValueCast(BCO->getFalseExpr());
1911 if (Decls.count(VD))
1919 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(S))
1921 Visit(OVE->getSourceExpr());
1927 bool FoundDeclInUse() {
return FoundDecl; }
1931 void CheckForLoopConditionalStatement(
Sema &S,
Expr *Second,
1934 if (!Second)
return;
1941 DeclSetVector Decls;
1943 DeclExtractor DE(S, Decls, Ranges);
1947 if (!DE.isSimple())
return;
1950 if (Decls.size() == 0)
return;
1953 for (
auto *VD : Decls)
1957 if (DeclMatcher(S, Decls, Second).FoundDeclInUse() ||
1958 DeclMatcher(S, Decls, Third).FoundDeclInUse() ||
1959 DeclMatcher(S, Decls, Body).FoundDeclInUse())
1963 if (Decls.size() > 4) {
1967 for (
auto *VD : Decls)
1971 for (
auto Range : Ranges)
1974 S.
Diag(Ranges.begin()->getBegin(), PDiag);
1979 bool ProcessIterationStmt(
Sema &S,
Stmt* Statement,
bool &Increment,
1981 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(Statement))
1982 if (!Cleanups->cleanupsHaveSideEffects())
1985 if (
UnaryOperator *UO = dyn_cast<UnaryOperator>(Statement)) {
1986 switch (UO->getOpcode()) {
1987 default:
return false;
1997 DRE = dyn_cast<DeclRefExpr>(UO->getSubExpr());
2005 default:
return false;
2013 DRE = dyn_cast<DeclRefExpr>(
Call->getArg(0));
2025 bool InSwitch =
false;
2028 BreakContinueFinder(
Sema &S,
const Stmt* Body) :
2029 Inherited(S.Context) {
2039 void VisitBreakStmt(
const BreakStmt* E) {
2045 if (
const Stmt *
Init = S->getInit())
2047 if (
const Stmt *CondVar = S->getConditionVariableDeclStmt())
2049 if (
const Stmt *Cond = S->getCond())
2054 if (
const Stmt *Body = S->getBody())
2059 void VisitForStmt(
const ForStmt *S) {
2062 if (
const Stmt *
Init = S->getInit())
2066 void VisitWhileStmt(
const WhileStmt *) {
2071 void VisitDoStmt(
const DoStmt *) {
2079 if (
const Stmt *
Init = S->getInit())
2081 if (
const Stmt *Range = S->getRangeStmt())
2083 if (
const Stmt *
Begin = S->getBeginStmt())
2085 if (
const Stmt *End = S->getEndStmt())
2092 if (
const Stmt *Element = S->getElement())
2094 if (
const Stmt *Collection = S->getCollection())
2098 bool ContinueFound() {
return ContinueLoc.
isValid(); }
2099 bool BreakFound() {
return BreakLoc.
isValid(); }
2110 void CheckForRedundantIteration(
Sema &S,
Expr *Third,
Stmt *Body) {
2112 if (!Body || !Third)
return;
2122 if (!LastStmt)
return;
2124 bool LoopIncrement, LastIncrement;
2127 if (!ProcessIterationStmt(S, Third, LoopIncrement, LoopDRE))
return;
2128 if (!ProcessIterationStmt(S, LastStmt, LastIncrement, LastDRE))
return;
2132 if (LoopIncrement != LastIncrement ||
2135 if (BreakContinueFinder(S, Body).ContinueFound())
return;
2138 << LastDRE->
getDecl() << LastIncrement;
2146void Sema::CheckBreakContinueBinding(
Expr *E) {
2149 BreakContinueFinder BCFinder(*
this, E);
2151 if (BCFinder.BreakFound() && BreakParent) {
2153 Diag(BCFinder.GetBreakLoc(), diag::warn_break_binds_to_switch);
2155 Diag(BCFinder.GetBreakLoc(), diag::warn_loop_ctrl_binds_to_inner)
2159 Diag(BCFinder.GetContinueLoc(), diag::warn_loop_ctrl_binds_to_inner)
2176 const Decl *NonVarSeen =
nullptr;
2177 bool VarDeclSeen =
false;
2178 for (
auto *DI : DS->decls()) {
2179 if (
VarDecl *VD = dyn_cast<VarDecl>(DI)) {
2182 Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
2183 DI->setInvalidDecl();
2185 }
else if (!NonVarSeen) {
2195 if (NonVarSeen && !VarDeclSeen)
2200 CheckBreakContinueBinding(Second.
get().second);
2201 CheckBreakContinueBinding(third.
get());
2203 if (!Second.
get().first)
2204 CheckForLoopConditionalStatement(*
this, Second.
get().second, third.
get(),
2206 CheckForRedundantIteration(*
this, third.
get(), Body);
2208 if (Second.
get().second &&
2210 Second.
get().second->getExprLoc()))
2211 CommaVisitor(*this).Visit(Second.
get().second);
2214 if (isa<NullStmt>(Body))
2219 Body, ForLoc, LParenLoc, RParenLoc);
2247 collection = result.
get();
2256 collection = result.
get();
2263 return Diag(forLoc, diag::err_collection_expr_type)
2276 diag::err_arc_collection_forward, collection)
2280 }
else if (iface || !objectType->
qual_empty()) {
2301 Diag(forLoc, diag::warn_collection_expr_type)
2324 if (!DS->isSingleDecl())
2326 diag::err_toomany_element_decls));
2328 VarDecl *D = dyn_cast<VarDecl>(DS->getSingleDecl());
2338 diag::err_non_local_variable_decl_in_for));
2344 Expr *DeducedInit = &OpaqueId;
2352 if (FirstType.
isNull()) {
2362 Diag(Loc, diag::warn_auto_var_is_id)
2371 Diag(
First->getBeginLoc(), diag::err_selector_element_not_lvalue)
2372 <<
First->getSourceRange());
2374 FirstType =
static_cast<Expr*
>(
First)->getType();
2376 Diag(ForLoc, diag::err_selector_element_const_type)
2377 << FirstType <<
First->getSourceRange();
2382 return StmtError(
Diag(ForLoc, diag::err_selector_element_type)
2383 << FirstType <<
First->getSourceRange());
2389 CollectionExprResult =
2395 nullptr, ForLoc, RParenLoc);
2402 if (
Decl->getType()->isUndeducedType()) {
2414 if (!isa<InitListExpr>(
Init) &&
Init->getType()->isVoidType()) {
2415 SemaRef.
Diag(Loc, DiagID) <<
Init->getType();
2419 Decl->getTypeSourceInfo()->getTypeLoc(),
Init, InitType, Info);
2422 SemaRef.
Diag(Loc, DiagID) <<
Init->getType();
2429 Decl->setType(InitType);
2447enum BeginEndFunction {
2456void NoteForRangeBeginEndFunction(
Sema &SemaRef,
Expr *E,
2457 BeginEndFunction BEF) {
2458 CallExpr *CE = dyn_cast<CallExpr>(E);
2466 std::string Description;
2467 bool IsTemplate =
false;
2474 SemaRef.
Diag(Loc, diag::note_for_range_begin_end)
2475 << BEF << IsTemplate << Description << E->
getType();
2527 return Diag(InitStmt->
getBeginLoc(), diag::err_objc_for_range_init_stmt)
2533 assert(DS &&
"first part of for range not a decl stmt");
2560 const auto DepthStr = std::to_string(S->getDepth() / 2);
2562 VarDecl *RangeVar = BuildForRangeVarDecl(*
this, RangeLoc,
2564 std::string(
"__range") + DepthStr);
2566 diag::err_for_range_deduction_failure)) {
2581 ForLoc, CoawaitLoc, InitStmt, ColonLoc, RangeDecl.
get(),
2583 nullptr,
nullptr, DS, RParenLoc, Kind,
2584 LifetimeExtendTemps);
2607 ExprResult *EndExpr, BeginEndFunction *BEF) {
2617 auto BuildBegin = [&] {
2621 BeginMemberLookup, CandidateSet,
2622 BeginRange, BeginExpr);
2627 << ColonLoc << BEF_begin << BeginRange->
getType();
2640 diag::err_for_range_iter_deduction_failure)) {
2641 NoteForRangeBeginEndFunction(SemaRef, BeginExpr->
get(), *BEF);
2647 auto BuildEnd = [&] {
2651 EndMemberLookup, CandidateSet,
2656 << ColonLoc << BEF_end << EndRange->
getType();
2660 diag::err_for_range_iter_deduction_failure)) {
2661 NoteForRangeBeginEndFunction(SemaRef, EndExpr->
get(), *BEF);
2681 if (BeginMemberLookup.
empty() != EndMemberLookup.
empty()) {
2686 auto BuildNonmember = [&](
2696 switch (BuildFound()) {
2703 SemaRef.
PDiag(diag::err_for_range_invalid)
2704 << BeginRange->
getType() << BEFFound),
2711 diag::note_for_range_member_begin_end_ignored)
2712 << BeginRange->
getType() << BEFFound;
2716 llvm_unreachable(
"unexpected ForRangeStatus");
2718 if (BeginMemberLookup.
empty())
2719 return BuildNonmember(BEF_end, EndMemberLookup, BuildEnd, BuildBegin);
2720 return BuildNonmember(BEF_begin, BeginMemberLookup, BuildBegin, BuildEnd);
2752 AdjustedRange = SemaRef.
BuildUnaryOp(S, RangeLoc, UO_Deref, Range);
2757 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2766 SemaRef.
Diag(RangeLoc, diag::err_for_range_dereference)
2769 S, ForLoc, CoawaitLoc, InitStmt, LoopVarDecl, ColonLoc,
2791 DeclStmt *RangeDS = cast<DeclStmt>(RangeDecl);
2795 DeclStmt *LoopVarDS = cast<DeclStmt>(LoopVarDecl);
2809 if (
auto *DD = dyn_cast<DecompositionDecl>(LoopVar))
2810 for (
auto *Binding : DD->bindings())
2814 }
else if (!BeginDeclStmt.
get()) {
2833 QualType RangeType = Range->getType();
2836 diag::err_for_range_incomplete_type))
2843 for (
auto *MTE : LifetimeExtendTemps)
2849 const auto DepthStr = std::to_string(S->getDepth() / 2);
2851 std::string(
"__begin") + DepthStr);
2853 std::string(
"__end") + DepthStr);
2864 BeginExpr = BeginRangeRef;
2871 diag::err_for_range_iter_deduction_failure)) {
2872 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
2882 dyn_cast<VariableArrayType>(UnqAT)) {
2909 VAT->desugar(), RangeLoc))
2920 VAT->getElementType(), RangeLoc))
2928 SizeOfVLAExprR.
get(), SizeOfEachElementExprR.
get());
2935 llvm_unreachable(
"Unexpected array type in for-range");
2939 EndExpr =
ActOnBinOp(S, ColonLoc, tok::plus, EndRangeRef.
get(),
2944 diag::err_for_range_iter_deduction_failure)) {
2945 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
2951 BeginEndFunction BEFFailure;
2953 *
this, BeginRangeRef.
get(), EndRangeRef.
get(), RangeType, BeginVar,
2954 EndVar, ColonLoc, CoawaitLoc, &CandidateSet, &BeginExpr, &EndExpr,
2958 BEFFailure == BEF_begin) {
2961 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Range)) {
2963 QualType ArrayTy = PVD->getOriginalType();
2964 QualType PointerTy = PVD->getType();
2966 Diag(Range->getBeginLoc(), diag::err_range_on_array_parameter)
2967 << RangeLoc << PVD << ArrayTy << PointerTy;
2968 Diag(PVD->getLocation(), diag::note_declared_at);
2977 CoawaitLoc, InitStmt,
2978 LoopVarDecl, ColonLoc,
2987 Expr *Range = BEFFailure ? EndRangeRef.
get() : BeginRangeRef.
get();
2990 PDiag(diag::err_for_range_invalid)
2991 << RangeLoc << Range->getType()
3001 "invalid range expression in for loop");
3008 ? diag::warn_for_range_begin_end_types_differ
3009 : diag::ext_for_range_begin_end_types_differ)
3010 << BeginType << EndType;
3011 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
3012 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
3032 NotEqExpr =
ActOnBinOp(S, ColonLoc, tok::exclaimequal,
3033 BeginRef.
get(), EndRef.
get());
3040 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
3041 << RangeLoc << 0 << BeginRangeRef.
get()->
getType();
3042 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
3044 NoteForRangeBeginEndFunction(*
this, EndExpr.
get(), BEF_end);
3055 if (!IncrExpr.isInvalid() && CoawaitLoc.
isValid())
3060 if (!IncrExpr.isInvalid())
3062 if (IncrExpr.isInvalid()) {
3063 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
3064 << RangeLoc << 2 << BeginRangeRef.
get()->
getType() ;
3065 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
3077 Diag(RangeLoc, diag::note_for_range_invalid_iterator)
3078 << RangeLoc << 1 << BeginRangeRef.
get()->
getType();
3079 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
3089 NoteForRangeBeginEndFunction(*
this, BeginExpr.
get(), BEF_begin);
3104 InitStmt, RangeDS, cast_or_null<DeclStmt>(BeginDeclStmt.
get()),
3105 cast_or_null<DeclStmt>(EndDeclStmt.
get()), NotEqExpr.
get(),
3106 IncrExpr.get(), LoopVarDS,
nullptr, ForLoc, CoawaitLoc,
3107 ColonLoc, RParenLoc);
3137 if (
auto Cleanups = dyn_cast<ExprWithCleanups>(InitExpr))
3138 if (!Cleanups->cleanupsHaveSideEffects())
3139 InitExpr = Cleanups->getSubExpr();
3142 dyn_cast<MaterializeTemporaryExpr>(InitExpr);
3152 while (!isa<CXXOperatorCallExpr>(E) && !isa<UnaryOperator>(E)) {
3166 if (isa<UnaryOperator>(E)) {
3173 ReferenceReturnType = ReturnType;
3176 if (!ReferenceReturnType.
isNull()) {
3181 diag::warn_for_range_const_ref_binds_temp_built_from_ref)
3182 << VD << VariableType << ReferenceReturnType;
3195 SemaRef.
Diag(VD->
getLocation(), diag::warn_for_range_ref_binds_ret_temp)
3196 << VD << RangeInitType;
3209 return RD->hasAttr<TrivialABIAttr>();
3226 if (!CE->getConstructor()->isCopyConstructor())
3228 }
else if (
const CastExpr *CE = dyn_cast<CastExpr>(InitExpr)) {
3229 if (CE->getCastKind() != CK_LValueToRValue)
3247 << VD << VariableType;
3268 diag::warn_for_range_const_ref_binds_temp_built_from_ref,
3295 ForStmt->getRangeInit()->getType());
3309 if (isa<ObjCForCollectionStmt>(S))
3316 diag::warn_empty_range_based_for_body);
3330 if (
getCurScope()->isInOpenACCComputeConstructScope())
3363 if (
getCurScope()->isInOpenACCComputeConstructScope())
3370 const Scope &DestScope) {
3373 S.
Diag(Loc, diag::warn_jump_out_of_seh_finally);
3382 return StmtError(
Diag(ContinueLoc, diag::err_continue_not_in_loop));
3384 if (S->isConditionVarScope()) {
3388 return StmtError(
Diag(ContinueLoc, diag::err_continue_from_cond_var_init));
3394 if (S->isOpenACCComputeConstructScope())
3396 Diag(ContinueLoc, diag::err_acc_branch_in_out_compute_construct)
3409 return StmtError(
Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
3411 if (S->isOpenMPLoopScope())
3412 return StmtError(
Diag(BreakLoc, diag::err_omp_loop_cannot_use_stmt)
3422 if (S->isOpenACCComputeConstructScope() ||
3423 (S->isLoopScope() && S->getParent() &&
3424 S->getParent()->isOpenACCComputeConstructScope()))
3426 Diag(BreakLoc, diag::err_acc_branch_in_out_compute_construct)
3454 const auto *DR = dyn_cast<DeclRefExpr>(E->
IgnoreParens());
3455 if (!DR || DR->refersToEnclosingVariableOrCapture())
3457 const auto *VD = dyn_cast<VarDecl>(DR->getDecl());
3488 if (VD->
getKind() == Decl::ParmVar)
3490 else if (VD->
getKind() != Decl::Var)
3503 if (VD->
hasAttr<BlocksAttr>())
3548 auto invalidNRVO = [&] {
3557 if ((ReturnType->
getTypeClass() == Type::TypeClass::Auto &&
3560 return invalidNRVO();
3566 return invalidNRVO();
3586 const auto *Step = llvm::find_if(
Seq.steps(), [](
const auto &Step) {
3587 return Step.Kind == InitializationSequence::SK_ConstructorInitialization ||
3588 Step.Kind == InitializationSequence::SK_UserConversion;
3590 if (Step !=
Seq.step_end()) {
3591 const auto *FD = Step->Function.Function;
3592 if (isa<CXXConstructorDecl>(FD)
3594 : cast<CXXMethodDecl>(FD)->getRefQualifier() ==
RQ_None)
3608 bool SupressSimplerImplicitMoves) {
3614 Expr *InitExpr = &AsRvalue;
3616 Value->getBeginLoc());
3618 auto Res =
Seq.getFailedOverloadResult();
3629 return Seq.Perform(*
this, Entity, Kind,
Value);
3652 bool SupressSimplerImplicitMoves) {
3660 bool HasDeducedReturnType =
3670 RetValExp = ER.
get();
3676 if (HasDeducedReturnType) {
3689 assert(AT &&
"lost auto type from lambda return type");
3701 if (RetValExp && !isa<InitListExpr>(RetValExp)) {
3705 RetValExp =
Result.get();
3720 Diag(ReturnLoc, diag::err_lambda_return_init_list)
3734 if (
auto *CurBlock = dyn_cast<BlockScopeInfo>(CurCap)) {
3736 Diag(ReturnLoc, diag::err_noreturn_block_has_return_expr);
3739 }
else if (
auto *CurRegion = dyn_cast<CapturedRegionScopeInfo>(CurCap)) {
3740 Diag(ReturnLoc, diag::err_return_in_captured_stmt) << CurRegion->getRegionName();
3743 assert(CurLambda &&
"unknown kind of captured scope");
3747 Diag(ReturnLoc, diag::err_noreturn_lambda_has_return_expr);
3759 if (RetValExp && !isa<InitListExpr>(RetValExp) &&
3765 Diag(ReturnLoc, diag::ext_return_has_void_expr) <<
"literal" << 2;
3767 Diag(ReturnLoc, diag::err_return_block_has_expr);
3768 RetValExp =
nullptr;
3771 }
else if (!RetValExp) {
3772 return StmtError(
Diag(ReturnLoc, diag::err_block_return_missing_expr));
3785 Entity, NRInfo, RetValExp, SupressSimplerImplicitMoves);
3790 RetValExp = Res.
get();
3791 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc);
3799 RetValExp = ER.
get();
3813 if (
auto *CurBlock = dyn_cast<BlockScopeInfo>(CurCap);
3816 CurBlock->TheDecl->setInvalidDecl();
3834class LocalTypedefNameReferencer
3837 LocalTypedefNameReferencer(
Sema &S) : S(S) {}
3842bool LocalTypedefNameReferencer::VisitRecordType(
const RecordType *RT) {
3843 auto *R = dyn_cast<CXXRecordDecl>(RT->
getDecl());
3844 if (!R || !R->isLocalClass() || !R->isLocalClass()->isExternallyVisible() ||
3845 R->isDependentType())
3847 for (
auto *TmpD : R->decls())
3848 if (
auto *
T = dyn_cast<TypedefNameDecl>(TmpD))
3849 if (
T->getAccess() !=
AS_private || R->hasFriends())
3873 if (RetExpr && isa<InitListExpr>(RetExpr)) {
3878 : diag::err_auto_fn_return_init_list)
3888 assert(AT->
isDeduced() &&
"should have deduced to dependent type");
3902 Diag(ReturnLoc, diag::err_auto_fn_return_void_but_not_auto)
3918 if (FindResult.Expression)
3919 TemplateSpecLoc = FindResult.Expression->getNameLoc();
3923 OrigResultType, RetExpr, Deduced, Info,
false,
3939 Diag(ReturnLoc, diag::err_typecheck_missing_return_type_incompatible)
3942 Diag(ReturnLoc, diag::err_auto_fn_different_deductions)
3957 LocalTypedefNameReferencer(*this).TraverseType(RetExpr->
getType());
3980 RetValExp,
nullptr,
true);
3984 if (
getCurScope()->isInOpenACCComputeConstructScope())
3986 Diag(ReturnLoc, diag::err_acc_branch_in_out_compute_construct)
3995 const_cast<VarDecl *
>(cast<ReturnStmt>(R.
get())->getNRVOCandidate());
4019 bool AllowRecovery) {
4027 bool SupressSimplerImplicitMoves =
4035 SupressSimplerImplicitMoves);
4039 const AttrVec *Attrs =
nullptr;
4040 bool isObjCMethod =
false;
4047 Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) << FD;
4048 if (FD->
isMain() && RetValExp)
4049 if (isa<CXXBoolLiteralExpr>(RetValExp))
4050 Diag(ReturnLoc, diag::warn_main_returns_bool_literal)
4052 if (FD->
hasAttr<CmseNSEntryAttr>() && RetValExp) {
4059 FnRetType = MD->getReturnType();
4060 isObjCMethod =
true;
4062 Attrs = &MD->getAttrs();
4063 if (MD->hasRelatedResultType() && MD->getClassInterface()) {
4074 const auto *ATy = dyn_cast<ArrayType>(RetValExp->
getType());
4075 if (ATy && ATy->getElementType().isWebAssemblyReferenceType()) {
4076 Diag(ReturnLoc, diag::err_wasm_table_art) << 1;
4090 RetValExp = ER.
get();
4116 AT->isDeduced() ? FnRetType :
QualType());
4117 if (Recovery.isInvalid())
4119 RetValExp = Recovery.get();
4135 if (
auto *ILE = dyn_cast<InitListExpr>(RetValExp)) {
4140 int FunctionKind = 0;
4141 if (isa<ObjCMethodDecl>(CurDecl))
4143 else if (isa<CXXConstructorDecl>(CurDecl))
4145 else if (isa<CXXDestructorDecl>(CurDecl))
4148 Diag(ReturnLoc, diag::err_return_init_list)
4152 RetValExp = AllowRecovery
4154 ILE->getRBraceLoc(), ILE->inits())
4159 unsigned D = diag::ext_return_has_expr;
4162 if (isa<CXXConstructorDecl>(CurDecl) ||
4163 isa<CXXDestructorDecl>(CurDecl))
4164 D = diag::err_ctor_dtor_returns_void;
4166 D = diag::ext_return_has_void_expr;
4173 RetValExp =
Result.get();
4178 if (D == diag::err_ctor_dtor_returns_void) {
4180 Diag(ReturnLoc, D) << CurDecl << isa<CXXDestructorDecl>(CurDecl)
4184 else if (D != diag::ext_return_has_void_expr ||
4188 int FunctionKind = 0;
4189 if (isa<ObjCMethodDecl>(CurDecl))
4191 else if (isa<CXXConstructorDecl>(CurDecl))
4193 else if (isa<CXXDestructorDecl>(CurDecl))
4206 RetValExp = ER.
get();
4212 }
else if (!RetValExp && !HasDependentReturnType) {
4219 Diag(ReturnLoc, diag::err_constexpr_return_missing_expr)
4225 unsigned DiagID =
getLangOpts().C99 ? diag::ext_return_missing_expr
4226 : diag::warn_return_missing_expr;
4230 "Not in a FunctionDecl or ObjCMethodDecl?");
4231 bool IsMethod = FD ==
nullptr;
4234 Diag(ReturnLoc, DiagID) << ND << IsMethod;
4240 assert(RetValExp || HasDependentReturnType);
4241 QualType RetType = RelatedRetType.
isNull() ? FnRetType : RelatedRetType;
4254 Entity, NRInfo, RetValExp, SupressSimplerImplicitMoves);
4257 RetValExp->
getEndLoc(), RetValExp, RetType);
4268 if (!RelatedRetType.
isNull()) {
4279 CheckReturnValExpr(RetValExp, FnRetType, ReturnLoc, isObjCMethod, Attrs,
4288 RetValExp = ER.
get();
4295 if (
Result->getNRVOCandidate())
4308 VarDecl *Var = cast_or_null<VarDecl>(Parm);
4324 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@try";
4329 Diag(AtLoc, diag::err_mixing_cxx_try_seh_try) << 1;
4334 unsigned NumCatchStmts = CatchStmts.size();
4336 NumCatchStmts, Finally);
4356 return StmtError(
Diag(AtLoc, diag::err_objc_throw_expects_object)
4368 Diag(AtLoc, diag::err_objc_exceptions_disabled) <<
"@throw";
4373 Scope *AtCatchParent = CurScope;
4375 AtCatchParent = AtCatchParent->
getParent();
4377 return StmtError(
Diag(AtLoc, diag::err_rethrow_used_outside_catch));
4387 operand = result.
get();
4391 if (!
type->isDependentType() &&
4392 !
type->isObjCObjectPointerType()) {
4397 diag::err_incomplete_receiver_type))
4398 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
4405 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
4408 operand = result.
get();
4410 return Diag(atLoc, diag::err_objc_synchronized_expects_object)
4432 Stmt *HandlerBlock) {
4435 CXXCatchStmt(CatchLoc, cast_or_null<VarDecl>(ExDecl), HandlerBlock);
4445class CatchHandlerType {
4447 LLVM_PREFERRED_TYPE(
bool)
4448 unsigned IsPointer : 1;
4452 friend struct llvm::DenseMapInfo<CatchHandlerType>;
4453 enum Unique { ForDenseMap };
4454 CatchHandlerType(
QualType QT, Unique) : QT(QT), IsPointer(
false) {}
4472 CatchHandlerType(
QualType QT,
bool IsPointer)
4473 : QT(QT), IsPointer(IsPointer) {}
4475 QualType underlying()
const {
return QT; }
4476 bool isPointer()
const {
return IsPointer; }
4478 friend bool operator==(
const CatchHandlerType &LHS,
4479 const CatchHandlerType &RHS) {
4481 if (LHS.IsPointer != RHS.IsPointer)
4484 return LHS.QT == RHS.QT;
4490template <>
struct DenseMapInfo<CatchHandlerType> {
4492 return CatchHandlerType(DenseMapInfo<QualType>::getEmptyKey(),
4493 CatchHandlerType::ForDenseMap);
4497 return CatchHandlerType(DenseMapInfo<QualType>::getTombstoneKey(),
4498 CatchHandlerType::ForDenseMap);
4502 return DenseMapInfo<QualType>::getHashValue(
Base.underlying());
4506 const CatchHandlerType &RHS) {
4513class CatchTypePublicBases {
4514 const llvm::DenseMap<QualType, CXXCatchStmt *> &TypesToCheck;
4521 CatchTypePublicBases(
const llvm::DenseMap<QualType, CXXCatchStmt *> &
T,
4523 : TypesToCheck(
T), FoundHandler(nullptr), TestAgainstType(QT) {}
4525 CXXCatchStmt *getFoundHandler()
const {
return FoundHandler; }
4526 QualType getFoundHandlerType()
const {
return FoundHandlerType; }
4529 if (S->getAccessSpecifier() == AccessSpecifier::AS_public) {
4530 QualType Check = S->getType().getCanonicalType();
4531 const auto &M = TypesToCheck;
4532 auto I = M.find(Check);
4544 if (I->second->getCaughtType()->isPointerType() ==
4546 FoundHandler = I->second;
4547 FoundHandlerType = Check;
4562 const bool IsOpenMPGPUTarget =
4563 getLangOpts().OpenMPIsTargetDevice && (
T.isNVPTX() ||
T.isAMDGCN());
4566 if (!IsOpenMPGPUTarget && !
getLangOpts().CXXExceptions &&
4569 targetDiag(TryLoc, diag::err_exceptions_disabled) <<
"try";
4574 if (IsOpenMPGPUTarget)
4575 targetDiag(TryLoc, diag::warn_try_not_valid_on_target) <<
T.str();
4580 <<
"try" << llvm::to_underlying(
CUDA().CurrentTarget());
4583 Diag(TryLoc, diag::err_omp_simd_region_cannot_use_stmt) <<
"try";
4589 Diag(TryLoc, diag::err_mixing_cxx_try_seh_try) << 0;
4593 const unsigned NumHandlers = Handlers.size();
4594 assert(!Handlers.empty() &&
4595 "The parser shouldn't call this if there are no handlers.");
4597 llvm::DenseMap<QualType, CXXCatchStmt *> HandledBaseTypes;
4598 llvm::DenseMap<CatchHandlerType, CXXCatchStmt *> HandledTypes;
4599 for (
unsigned i = 0; i < NumHandlers; ++i) {
4606 if (i < NumHandlers - 1)
4620 QualType Underlying = HandlerCHT.underlying();
4622 if (!RD->hasDefinition())
4630 Paths.setOrigin(RD);
4631 CatchTypePublicBases CTPB(HandledBaseTypes,
4633 if (RD->lookupInBases(CTPB, Paths)) {
4635 if (!Paths.isAmbiguous(
4638 diag::warn_exception_caught_by_earlier_handler)
4641 diag::note_previous_exception_handler)
4653 auto R = HandledTypes.insert(
4658 diag::warn_exception_caught_by_earlier_handler)
4661 diag::note_previous_exception_handler)
4674 assert(TryBlock && Handler);
4701 Diag(TryLoc, diag::err_seh_try_outside_functions);
4705 Diag(TryLoc, diag::err_seh_try_unsupported);
4712 assert(FilterExpr &&
Block);
4716 Diag(FilterExpr->
getExprLoc(), diag::err_filter_expression_integral)
4738 Scope *SEHTryParent = CurScope;
4740 SEHTryParent = SEHTryParent->
getParent();
4742 return StmtError(
Diag(Loc, diag::err_ms___leave_not_in___try));
4755 QualifierLoc, NameInfo,
4756 cast<CompoundStmt>(Nested));
4773 unsigned NumParams) {
4791 assert(NumParams > 0 &&
"CapturedStmt requires context parameter");
4835 CaptureInits.push_back(
Init.get());
4842 unsigned NumParams) {
4873 unsigned OpenMPCaptureLevel) {
4879 bool ContextIsFound =
false;
4880 unsigned ParamNum = 0;
4883 I != E; ++I, ++ParamNum) {
4884 if (I->second.isNull()) {
4885 assert(!ContextIsFound &&
4886 "null type has been found already for '__context' parameter");
4896 ContextIsFound =
true;
4906 assert(ContextIsFound &&
"no null type for '__context' parameter");
4907 if (!ContextIsFound) {
4963 Captures, CaptureInits, CD, RD);
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines the clang::Expr interface and subclasses for C++ expressions.
llvm::MachO::Record Record
Defines the clang::Preprocessor interface.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
This file declares semantic analysis for CUDA constructs.
This file declares semantic analysis for OpenMP constructs and clauses.
static bool CmpEnumVals(const std::pair< llvm::APSInt, EnumConstantDecl * > &lhs, const std::pair< llvm::APSInt, EnumConstantDecl * > &rhs)
CmpEnumVals - Comparison predicate for sorting enumeration values.
static bool FinishForRangeVarDecl(Sema &SemaRef, VarDecl *Decl, Expr *Init, SourceLocation Loc, int DiagID)
Finish building a variable declaration for a for-range statement.
static bool CmpCaseVals(const std::pair< llvm::APSInt, CaseStmt * > &lhs, const std::pair< llvm::APSInt, CaseStmt * > &rhs)
CmpCaseVals - Comparison predicate for sorting case values.
SmallVector< std::pair< llvm::APSInt, EnumConstantDecl * >, 64 > EnumValsTy
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...
static bool DiagnoseUnusedComparison(Sema &S, const Expr *E)
Diagnose unused comparisons, both builtin and overloaded operators.
static bool EqEnumVals(const std::pair< llvm::APSInt, EnumConstantDecl * > &lhs, const std::pair< llvm::APSInt, EnumConstantDecl * > &rhs)
EqEnumVals - Comparison preficate for uniqing enumeration values.
static bool hasDeducedReturnType(FunctionDecl *FD)
Determine whether the declared return type of the specified function contains 'auto'.
static bool ObjCEnumerationCollection(Expr *Collection)
static void DiagnoseForRangeConstVariableCopies(Sema &SemaRef, const VarDecl *VD)
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.
static void checkEnumTypesInSwitchStmt(Sema &S, const Expr *Cond, const Expr *Case)
static void DiagnoseForRangeReferenceVariableCopies(Sema &SemaRef, const VarDecl *VD, QualType RangeInitType)
static void DiagnoseForRangeVariableCopies(Sema &SemaRef, const CXXForRangeStmt *ForStmt)
DiagnoseForRangeVariableCopies - Diagnose three cases and fixes for them.
static bool CheckSimplerImplicitMovesMSVCWorkaround(const Sema &S, const Expr *E)
static bool VerifyInitializationSequenceCXX98(const Sema &S, const InitializationSequence &Seq)
Verify that the initialization sequence that was picked for the first overload resolution is permissi...
static QualType GetTypeBeforeIntegralPromotion(const Expr *&E)
GetTypeBeforeIntegralPromotion - Returns the pre-promotion type of potentially integral-promoted expr...
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 bool DiagnoseNoDiscard(Sema &S, const WarnUnusedResultAttr *A, SourceLocation Loc, SourceRange R1, SourceRange R2, bool IsCtor)
static bool hasTrivialABIAttr(QualType VariableType)
Determines whether the VariableType's declaration is a record with the clang::trivial_abi attribute.
static void AdjustAPSInt(llvm::APSInt &Val, unsigned BitWidth, bool IsSigned)
static bool buildCapturedStmtCaptureList(Sema &S, CapturedRegionScopeInfo *RSI, SmallVectorImpl< CapturedStmt::Capture > &Captures, SmallVectorImpl< Expr * > &CaptureInits)
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.
static void CheckJumpOutOfSEHFinally(Sema &S, SourceLocation Loc, const Scope &DestScope)
Defines the Objective-C statement AST node classes.
enum clang::format::@1259::AnnotatingParser::Context::@341 ContextType
Defines the clang::TypeLoc interface and its subclasses.
Allows QualTypes to be sorted and hence used in maps and sets.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
unsigned getIntWidth(QualType T) const
bool hasSimilarType(QualType T1, QualType T2)
Determine if two types are similar, according to the C++ rules.
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getAutoRRefDeductType() const
C++11 deduction pattern for 'auto &&' type.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
SelectorTable & Selectors
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
QualType getObjCIdType() const
Represents the Objective-CC id type.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
const TargetInfo & getTargetInfo() const
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Attr - This represents one attribute.
SourceLocation getLocation() const
SourceRange getRange() const
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
bool isDecltypeAuto() const
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condnition evaluates to false;...
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
A builtin binary operation expression such as "x + y" or "x <= y".
SourceLocation getExprLoc() const
BreakStmt - This represents a break.
SourceLocation getBreakLoc() const
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
A boolean literal, per ([C++ lex.bool] Boolean literals).
CXXCatchStmt - This represents a C++ catch block.
SourceLocation getBeginLoc() const LLVM_READONLY
VarDecl * getExceptionDecl() const
QualType getCaughtType() const
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
Represents a C++ conversion function within a class.
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Represents a call to a member function that may be written either with member call syntax (e....
Represents a static or instance method of a struct/union/class.
A call to an overloaded operator written using operator syntax.
Represents a C++ struct/union/class.
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr, bool DelayTypeCreation=false)
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Represents a C++ nested-name-specifier or a global scope specifier.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
static CanQual< Type > CreateUnsafe(QualType Other)
Builds a canonical type from a QualType.
QualType withConst() const
Retrieves a version of this type with const applied.
Represents the body of a CapturedStmt, and serves as its DeclContext.
static DeclContext * castToDeclContext(const CapturedDecl *D)
void setContextParam(unsigned i, ImplicitParamDecl *P)
void setParam(unsigned i, ImplicitParamDecl *P)
static CapturedDecl * Create(ASTContext &C, DeclContext *DC, unsigned NumParams)
Describes the capture of either a variable, or 'this', or variable-length array type.
This captures a statement into a function.
Stmt * getCapturedStmt()
Retrieve the statement being captured.
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr * > CaptureInits, CapturedDecl *CD, RecordDecl *RD)
CaseStmt - Represent a case statement.
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
ConditionalOperator - The ?: ternary operator.
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?: operator.
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
ConstEvaluatedExprVisitor - This class visits 'const Expr *'s.
Represents the canonical version of C arrays with a specified constant size.
ContinueStmt - This represents a continue.
SourceLocation getContinueLoc() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isFileContext() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
void addDecl(Decl *D)
Add the declaration D into this context.
bool isStdNamespace() const
bool isFunctionOrMethod() const
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
bool isSingleDecl() const
A reference to a declared variable, function, enum, etc.
SourceLocation getLocation() const
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
const Decl * getSingleDecl() const
SourceLocation getBeginLoc() const LLVM_READONLY
Decl - This represents one declaration (or definition), e.g.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
static Decl * castFromDeclContext(const DeclContext *)
bool isInvalidDecl() const
SourceLocation getLocation() const
void setImplicit(bool I=true)
void setLocation(SourceLocation L)
DeclContext * getDeclContext()
SourceLocation getTypeSpecEndLoc() const
SourceLocation getTypeSpecStartLoc() const
SourceLocation getBeginLoc() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
SourceLocation getDefaultLoc() const
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
DoStmt - This represents a 'do/while' stmt.
enumerator_range enumerators() const
bool isClosed() const
Returns true if this enum is either annotated with enum_extensibility(closed) or isn't annotated with...
bool isClosedNonFlag() const
Returns true if this enum is annotated with neither flag_enum nor enum_extensibility(open).
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
EnumDecl * getDecl() const
EvaluatedExprVisitor - This class visits 'Expr *'s.
This represents one expression.
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,...
@ SE_AllowSideEffects
Allow any unmodeled side effect.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, SourceRange &R1, SourceRange &R2, ASTContext &Ctx) const
isUnusedResultAWarning - Return true if this immediate expression should be warned about if the resul...
bool isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Decl * getReferencedDeclOfCallee()
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
bool isIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool isKnownToHaveBooleanValue(bool Semantic=true) const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
Represents difference between two FPOptions values.
FPOptionsOverride getChangesFrom(const FPOptions &Base) const
Return difference with the given option set.
Represents a member of a struct/union/class.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
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.
ForStmt - This represents a 'for (init;cond;inc)' stmt.
SourceLocation getRParenLoc() const
SourceLocation getBeginLoc() const
FullExpr - Represents a "full-expression" node.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
void setUsesSEHTry(bool UST)
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
QualType getReturnType() const
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any.
Represents a prototype with parameter type info, e.g.
Declaration of a template function.
FunctionType - C99 6.7.5.3 - Function Declarators.
static StringRef getNameForCallConv(CallingConv CC)
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
QualType getReturnType() const
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
GotoStmt - This represents a direct goto.
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
IndirectGotoStmt - This represents an indirect goto.
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
Describes the sequence of initializations required to initialize a given object or reference with a s...
Describes an entity that is being initialized.
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type)
Create the initialization entity for the result of a function.
static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD, QualType Type)
Create the initialization entity for a related result.
unsigned allocateManglingNumber() const
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
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'.
Represents the declaration of a label.
void setLocStart(SourceLocation L)
LabelStmt * getStmt() const
void setStmt(LabelStmt *T)
bool isMSAsmLabel() const
LabelStmt - Represents a label, which has a substatement.
Represents the results of name lookup.
bool empty() const
Return true if no decls were found.
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name.
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine if the declaration obeys the reserved identifier rules of the given language.
A C++ nested-name-specifier augmented with source location information.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Represents Objective-C's @catch statement.
Represents Objective-C's @finally statement.
Represents Objective-C's @synchronized statement.
Represents Objective-C's @throw statement.
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Represents Objective-C's @autoreleasepool Statement.
Represents Objective-C's collection statement.
Represents an ObjC class declaration.
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
ObjCMethodDecl * lookupPrivateMethod(const Selector &Sel, bool Instance=true) const
Lookup a method in the classes implementation hierarchy.
An expression that sends a message to the given Objective-C object or class.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents a pointer to an Objective C object.
Represents a class type in Objective C.
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface.
Wrapper for void* pointer.
void * getAsOpaquePtr() const
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
@ CSK_Normal
Normal lookup.
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...
static FindResult find(Expr *E)
Finds the overloaded expression in the given expression E of OverloadTy.
ParenExpr - This represents a parethesized expression, e.g.
const Expr * getSubExpr() const
Represents a parameter to a function.
ParsedAttributes - A collection of parsed attributes.
Wrapper for source info for pointers.
SourceLocation getStarLoc() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
IdentifierTable & getIdentifierTable()
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
QualType withRestrict() const
QualType withConst() const
bool isTriviallyCopyConstructibleType(const ASTContext &Context) const
Return true if this is a trivially copyable type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
bool isConstQualified() const
Determine whether this type is const-qualified.
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Represents a struct/union/class.
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
bool isOrContainsUnion() const
Returns whether this record is a union, or contains (at any nesting level) a union member.
virtual void completeDefinition()
Note that the definition of this type is now complete.
void setCapturedRecord()
Mark the record as a record for captured variables in CapturedStmt construct.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
void setRetValue(Expr *E)
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Represents a __leave statement.
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
Scope - A scope is a transient data structure that is used while parsing the program.
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
bool isAtCatchScope() const
isAtCatchScope - Return true if this scope is @catch.
bool Contains(const Scope &rhs) const
Returns if rhs has a higher scope depth than this.
unsigned getFlags() const
getFlags - Return the flags for this scope.
Scope * getContinueParent()
getContinueParent - Return the closest scope that a continue statement would be affected by.
bool isSEHTryScope() const
Determine whether this scope is a SEH '__try' block.
Scope * getBreakParent()
getBreakParent - Return the closest scope that a break statement would be affected by.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
void updateNRVOCandidate(VarDecl *VD)
@ SwitchScope
This is a scope that corresponds to a switch statement.
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Smart pointer class that efficiently represents Objective-C method names.
A generic diagnostic builder for errors which may or may not be deferred.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
SemaDiagnosticBuilder DiagIfDeviceCode(SourceLocation Loc, unsigned DiagID)
Creates a SemaDiagnosticBuilder that emits the diagnostic if the current context is "used as device c...
void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init)
Check if the current region is an OpenMP loop region and if it is, mark loop control variable,...
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...
std::pair< VarDecl *, Expr * > get() const
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
Sema - This implements semantic analysis and AST building for C.
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
ExprResult PerformContextuallyConvertToObjCPointer(Expr *From)
PerformContextuallyConvertToObjCPointer - Perform a contextual conversion of the expression From to a...
SmallVector< Scope *, 2 > CurrentSEHFinally
Stack of active SEH __finally scopes. Can be empty.
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
Scope * getCurScope() const
Retrieve the parser's current scope.
void ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributes &InAttrs, SmallVectorImpl< const Attr * > &OutAttrs)
Process the attributes before creating an attributed statement.
ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, Expr *Input, bool IsAfterAmp=false)
StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
ExprResult IgnoredValueConversions(Expr *E)
IgnoredValueConversions - Given that an expression's result is syntactically ignored,...
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, StringRef Keyword)
StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope)
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
StmtResult ActOnForEachLValueExpr(Expr *E)
In an Objective C collection iteration statement: for (x in y) x can be an arbitrary l-value expressi...
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl)
void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl=nullptr, ExpressionEvaluationContextRecord::ExpressionKind Type=ExpressionEvaluationContextRecord::EK_Other)
ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr=false)
CheckBooleanCondition - Diagnose problems involving the use of the given expression as a boolean cond...
@ Switch
An integral condition for a 'switch' statement.
SmallVector< sema::FunctionScopeInfo *, 4 > FunctionScopes
Stack containing information about each of the nested function, block, and method scopes that are cur...
PoppedFunctionScopePtr PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP=nullptr, const Decl *D=nullptr, QualType BlockType=QualType())
Pop a function (or block or lambda or captured region) scope from the stack.
bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA)
Check whether the given statement can have musttail applied to it, issuing a diagnostic and returning...
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, Scope *CurScope)
void setFunctionHasBranchIntoScope()
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, AllowFoldKind CanFold=NoFold)
VerifyIntegerConstantExpression - Verifies that an expression is an ICE, and reports the appropriate ...
StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue=true)
FieldDecl * BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture)
Build a FieldDecl suitable to hold the given capture.
ObjCMethodDecl * LookupMethodInQualifiedType(Selector Sel, const ObjCObjectPointerType *OPT, bool IsInstance)
LookupMethodInQualifiedType - Lookups up a method in protocol qualifier list of a qualified objective...
StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
FunctionDecl * getCurFunctionDecl(bool AllowLambda=false) const
Returns a pointer to the innermost enclosing function, or nullptr if the current context is not insid...
ExprResult PerformContextualImplicitConversion(SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter)
Perform a contextual implicit conversion.
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
ExprResult UsualUnaryConversions(Expr *E)
UsualUnaryConversions - Performs various conversions that are common to most operators (C99 6....
void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc)
ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond)
bool DiagIfReachable(SourceLocation Loc, ArrayRef< const Stmt * > Stmts, const PartialDiagnostic &PD)
Conditionally issue a diagnostic based on the statements's reachability analysis.
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
void ActOnCapturedRegionError()
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, bool Diagnose=true)
ASTContext & getASTContext() const
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input, bool IsAfterAmp=false)
void PopExpressionEvaluationContext()
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
ObjCMethodDecl * getCurMethodDecl()
getCurMethodDecl - If inside of a method body, this returns a pointer to the method decl for the meth...
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, llvm::APSInt &Value, CCEKind CCE)
void setFunctionHasIndirectGoto()
ExprResult BuildCaptureInit(const sema::Capture &Capture, SourceLocation ImplicitCaptureLoc, bool IsOpenMPMapping=false)
Initialize the given capture with a suitable expression.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
NamedReturnInfo getNamedReturnInfo(Expr *&E, SimplerImplicitMoveMode Mode=SimplerImplicitMoveMode::Normal)
Determine whether the given expression might be move-eligible or copy-elidable in either a (co_)retur...
ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, Expr *collection)
std::unique_ptr< sema::FunctionScopeInfo, PoppedFunctionScopeDeleter > PoppedFunctionScopePtr
void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID)
DiagnoseUnusedExprResult - If the statement passed in is an expression whose result is unused,...
FPOptions & getCurFPFeatures()
@ UPPC_Expression
An arbitrary expression.
StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, MultiStmtArg Catch, Stmt *Finally)
const LangOptions & getLangOpts() const
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
const LangOptions & LangOpts
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement.
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
void ActOnStartOfCompoundStmt(bool IsStmtExpr)
bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, SourceLocation ReturnLoc, Expr *RetExpr, const AutoType *AT)
Deduce the return type for a function from a returned expression, per C++1y [dcl.spec....
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
TypeLoc getReturnTypeLoc(FunctionDecl *FD) const
StmtResult ActOnExprStmtError()
const VarDecl * getCopyElisionCandidate(NamedReturnInfo &Info, QualType ReturnType)
Updates given NamedReturnInfo's move-eligible and copy-elidable statuses, considering the function re...
NamedDecl * getCurFunctionOrMethodDecl() const
getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method or C function we're in,...
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
RecordDecl * CreateCapturedStmtRecordDecl(CapturedDecl *&CD, SourceLocation Loc, unsigned NumParams)
void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, CapturedRegionKind Kind, unsigned NumParams)
sema::FunctionScopeInfo * getCurFunction() const
void PushCompoundScope(bool IsStmtExpr)
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
AssignConvertType CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &RHS, bool Diagnose=true, bool DiagnoseCFAudited=false, bool ConvertRHS=true)
Check assignment constraints for an assignment of RHS to LHSType.
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...
ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E)
std::optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
bool findMacroSpelling(SourceLocation &loc, StringRef name)
Looks through the macro-expansion chain for the given location, looking for a macro expansion with th...
void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, const Stmt *Body, unsigned DiagID)
Emit DiagID if statement located on StmtLoc has a suspicious null statement as a Body,...
void DiagnoseEmptyLoopBody(const Stmt *S, const Stmt *PossibleBody)
Warn if a for/while loop statement S, which is followed by PossibleBody, has a suspicious null statem...
ExprResult DefaultLvalueConversion(Expr *E)
void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name)
Retrieves the declaration name from a parsed unqualified-id.
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5.
StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, NamedReturnInfo &NRInfo, bool SupressSimplerImplicitMoves)
ActOnCapScopeReturnStmt - Utility routine to type-check return statements for capturing scopes.
AssignConvertType
AssignConvertType - All of the 'assignment' semantic checks return this enum to indicate whether the ...
StmtResult ActOnCapturedRegionEnd(Stmt *S)
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
SourceManager & getSourceManager() const
StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, Scope *CurScope)
ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, const NamedReturnInfo &NRInfo, Expr *Value, bool SupressSimplerImplicitMoves=false)
Perform the initialization of a potentially-movable value, which is the result of return value.
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection, SourceLocation RParenLoc, BuildForRangeKind Kind, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
ActOnCXXForRangeStmt - Check and build a C++11 for-range statement.
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
bool isCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind=CompleteTypeKind::Default)
ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr)
void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, RecordDecl *RD, CapturedRegionKind K, unsigned OpenMPCaptureLevel=0)
void setFunctionHasMustTail()
void setFunctionHasBranchProtectedScope()
StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block)
StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope)
@ CCEK_CaseValue
Expression in a case label.
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, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, CXXScopeSpec &SS, UnqualifiedId &Name, Stmt *Nested)
bool inferObjCARCLifetime(ValueDecl *decl)
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
void ActOnAfterCompoundStatementLeadingPragmas()
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, ArrayRef< Decl * > Fields, SourceLocation LBrac, SourceLocation RBrac, const ParsedAttributesView &AttrList)
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
void DiscardCleanupsInEvaluationContext()
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
void PushDeclContext(Scope *S, DeclContext *DC)
Set the current declaration context until it gets popped.
StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList, Stmt *SubStmt)
SourceManager & SourceMgr
DiagnosticsEngine & Diags
StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope)
void ActOnStartSEHFinallyBlock()
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
void ActOnAbortSEHFinallyBlock()
QualType SubstAutoTypeDependent(QualType TypeWithAuto)
@ BFRK_Check
Determining whether a for-range statement could be built.
@ BFRK_Build
Initial building of a for-range statement.
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, Stmt *HandlerBlock)
ActOnCXXCatchBlock - Takes an exception declaration and a handler block and creates a proper catch ha...
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
bool DiagnoseAssignmentResult(AssignConvertType ConvTy, SourceLocation Loc, QualType DstType, QualType SrcType, Expr *SrcExpr, AssignmentAction Action, bool *Complained=nullptr)
DiagnoseAssignmentResult - Emit a diagnostic, if required, for the assignment conversion type specifi...
SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, const FunctionDecl *FD=nullptr)
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, Stmt *Body)
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
std::string getTemplateArgumentBindingsText(const TemplateParameterList *Params, const TemplateArgumentList &Args)
Produces a formatted string that describes the binding of template parameters to template arguments.
ExprResult ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, bool IsType, void *TyOrEx, SourceRange ArgRange)
ActOnUnaryExprOrTypeTraitExpr - Handle sizeof(type) and sizeof expr and the same for alignof and __al...
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.
sema::CompoundScopeInfo & getCurCompoundScope() const
TemplateDeductionResult DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, QualType &Result, sema::TemplateDeductionInfo &Info, bool DependentDeduction=false, bool IgnoreConstraints=false, TemplateSpecCandidateSet *FailedTSC=nullptr)
Deduce the type for an auto type-specifier (C++11 [dcl.spec.auto]p6)
void ActOnFinishOfCompoundStmt()
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
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.
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
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...
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, bool RecoverUncorrectedTypos=false, 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...
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
bool isMacroBodyExpansion(SourceLocation Loc) const
Tests whether the given source location represents the expansion of a macro body.
bool isInSystemMacro(SourceLocation loc) const
Returns whether Loc is expanded from a macro in a system header.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
static std::tuple< bool, const Attr *, const Attr * > determineLikelihoodConflict(const Stmt *Then, const Stmt *Else)
static const Attr * getLikelihoodAttr(const Stmt *S)
SourceLocation getBeginLoc() const LLVM_READONLY
const SwitchCase * getNextSwitchCase() const
SwitchStmt - This represents a 'switch' stmt.
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
SwitchCase * getSwitchCaseList()
void setAllEnumCasesCovered()
Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a switch over an enum value then ...
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
TypedefNameDecl * getTypedefNameForAnonDecl() const
void startDefinition()
Starts the definition of this tag declaration.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool isSEHTrySupported() const
Whether the target supports SEH __try.
TemplateSpecCandidateSet - A set of generalized overload candidates, used in template specializations...
void NoteCandidates(Sema &S, SourceLocation Loc)
NoteCandidates - When no template specialization match is found, prints diagnostic messages containin...
Base wrapper for a particular "section" of type source info.
QualType getType() const
Get the type for which this source info wrapper provides information.
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
SourceLocation getBeginLoc() const
Get the begin source location.
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
QualType getType() const
Return the type wrapped by this type source info.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBlockPointerType() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
bool isRValueReferenceType() const
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool containsErrors() const
Whether this type is an error type.
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
bool isObjectType() const
Determine whether this type is an object type.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isObjCObjectPointerType() const
TypeClass getTypeClass() const
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Expr * getSubExpr() const
Represents a C++ unqualified-id that has been parsed.
void setType(QualType newType)
Represents a variable declaration or definition.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
void setARCPseudoStrong(bool PS)
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool isExceptionVariable() const
Determine whether this variable is the exception variable in a C++ catch statememt or an Objective-C ...
const Expr * getInit() const
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
bool hasDependentAlignment() const
Determines if this variable's alignment is dependent.
Represents a C array with a specified size that is not an integer-constant-expression.
WhileStmt - This represents a 'while' stmt.
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
ValueDecl * getVariable() const
bool isVariableCapture() const
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
bool isVLATypeCapture() const
bool isThisCapture() const
bool isReferenceCapture() const
Retains information about a captured region.
unsigned short OpenMPLevel
unsigned short CapRegionKind
The kind of captured region.
RecordDecl * TheRecordDecl
The captured record type.
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
SmallVector< Capture, 4 > Captures
Captures - The captures.
bool HasImplicitReturnType
Contains information about the compound statement currently being parsed.
FPOptions InitialFPFeatures
FP options at the beginning of the compound statement, prior to any pragma.
void setHasEmptyLoopBodies()
Retains information about a function, method, or block that is currently being parsed.
llvm::PointerIntPair< SwitchStmt *, 1, bool > SwitchInfo
A SwitchStmt, along with a flag indicating if its list of case statements is incomplete (because we d...
void setHasObjCTry(SourceLocation TryLoc)
SourceLocation FirstCXXOrObjCTryLoc
First C++ 'try' or ObjC @try statement in the current function.
enum clang::sema::FunctionScopeInfo::@241 FirstTryType
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
void setHasCXXTry(SourceLocation TryLoc)
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound statement scopes in the function.
void setHasSEHTry(SourceLocation TryLoc)
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Provides information about an attempted template argument deduction, whose success or failure was des...
TemplateArgument SecondArg
The second template argument to which the template argument deduction failure refers.
TemplateArgument FirstArg
The first template argument to which the template argument deduction failure refers.
Defines the clang::TargetInfo interface.
const AstTypeMatcher< PointerType > pointerType
Matches pointer types, but does not match Objective-C object pointer types.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
bool This(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
@ Seq
'seq' clause, allowed on 'loop' and 'routine' directives.
Expr * IgnoreElidableImplicitConstructorSingleStep(Expr *E)
@ OR_Deleted
Succeeded, but refers to a deleted function.
@ OR_Success
Overload resolution succeeded.
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
Expr * IgnoreExprNodes(Expr *E, FnTys &&... Fns)
Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *, Recursively apply each of the f...
@ RQ_None
No ref-qualifier was provided.
@ OCD_AllCandidates
Requests that all candidates be shown.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
CapturedRegionKind
The different kinds of captured statement.
@ Result
The result type of a method or function.
ActionResult< Expr * > ExprResult
@ Struct
The "struct" keyword.
bool isLambdaConversionOperator(CXXConversionDecl *C)
ActionResult< Stmt * > StmtResult
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_XValue
An x-value expression is a reference to an object with independent storage but which can be "moved",...
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Expr * IgnoreParensSingleStep(Expr *E)
const FunctionProtoType * T
Expr * IgnoreImplicitAsWrittenSingleStep(Expr *E)
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs.
TemplateDeductionResult
Describes the result of template argument deduction.
@ Success
Template argument deduction was successful.
@ Inconsistent
Template argument deduction produced inconsistent deduced values for the given template parameter.
@ AlreadyDiagnosed
Some error which was already diagnosed.
@ CapturedContext
Parameter for captured context.
Diagnostic wrappers for TextAPI types for error reporting.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
EvalResult is a struct with detailed info about an evaluated expression.
@ MoveEligibleAndCopyElidable
bool isMoveEligible() const
bool isCopyElidable() const
const VarDecl * Candidate
static CatchHandlerType getEmptyKey()
static CatchHandlerType getTombstoneKey()
static unsigned getHashValue(const CatchHandlerType &Base)
static bool isEqual(const CatchHandlerType &LHS, const CatchHandlerType &RHS)