SemaStmt.cpp (223017) | SemaStmt.cpp (224145) |
---|---|
1//===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 52 unchanged lines hidden (view full) --- 61 return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc)); 62} 63 64void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) { 65 DeclGroupRef DG = dg.getAsVal<DeclGroupRef>(); 66 67 // If we have an invalid decl, just return. 68 if (DG.isNull() || !DG.isSingleDecl()) return; | 1//===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 52 unchanged lines hidden (view full) --- 61 return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc)); 62} 63 64void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) { 65 DeclGroupRef DG = dg.getAsVal<DeclGroupRef>(); 66 67 // If we have an invalid decl, just return. 68 if (DG.isNull() || !DG.isSingleDecl()) return; |
69 VarDecl *var = cast<VarDecl>(DG.getSingleDecl()); 70 |
|
69 // suppress any potential 'unused variable' warning. | 71 // suppress any potential 'unused variable' warning. |
70 DG.getSingleDecl()->setUsed(); | 72 var->setUsed(); 73 74 // foreach variables are never actually initialized in the way that 75 // the parser came up with. 76 var->setInit(0); 77 78 // In ARC, we don't need to retain the iteration variable of a fast 79 // enumeration loop. Rather than actually trying to catch that 80 // during declaration processing, we remove the consequences here. 81 if (getLangOptions().ObjCAutoRefCount) { 82 QualType type = var->getType(); 83 84 // Only do this if we inferred the lifetime. Inferred lifetime 85 // will show up as a local qualifier because explicit lifetime 86 // should have shown up as an AttributedType instead. 87 if (type.getLocalQualifiers().getObjCLifetime() == Qualifiers::OCL_Strong) { 88 // Add 'const' and mark the variable as pseudo-strong. 89 var->setType(type.withConst()); 90 var->setARCPseudoStrong(true); 91 } 92 } |
71} 72 73void Sema::DiagnoseUnusedExprResult(const Stmt *S) { 74 if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) 75 return DiagnoseUnusedExprResult(Label->getSubStmt()); 76 77 const Expr *E = dyn_cast_or_null<Expr>(S); 78 if (!E) --- 30 unchanged lines hidden (view full) --- 109 return; 110 } 111 if (FD->getAttr<ConstAttr>()) { 112 Diag(Loc, diag::warn_unused_call) << R1 << R2 << "const"; 113 return; 114 } 115 } 116 } else if (const ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) { | 93} 94 95void Sema::DiagnoseUnusedExprResult(const Stmt *S) { 96 if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) 97 return DiagnoseUnusedExprResult(Label->getSubStmt()); 98 99 const Expr *E = dyn_cast_or_null<Expr>(S); 100 if (!E) --- 30 unchanged lines hidden (view full) --- 131 return; 132 } 133 if (FD->getAttr<ConstAttr>()) { 134 Diag(Loc, diag::warn_unused_call) << R1 << R2 << "const"; 135 return; 136 } 137 } 138 } else if (const ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) { |
139 if (getLangOptions().ObjCAutoRefCount && ME->isDelegateInitCall()) { 140 Diag(Loc, diag::err_arc_unused_init_message) << R1; 141 return; 142 } |
|
117 const ObjCMethodDecl *MD = ME->getMethodDecl(); 118 if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 119 Diag(Loc, diag::warn_unused_call) << R1 << R2 << "warn_unused_result"; 120 return; 121 } 122 } else if (isa<ObjCPropertyRefExpr>(E)) { 123 DiagID = diag::warn_unused_property_expr; 124 } else if (const CXXFunctionalCastExpr *FC --- 821 unchanged lines hidden (view full) --- 946 SourceLocation RParenLoc, Stmt *Body) { 947 if (First) { 948 QualType FirstType; 949 if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) { 950 if (!DS->isSingleDecl()) 951 return StmtError(Diag((*DS->decl_begin())->getLocation(), 952 diag::err_toomany_element_decls)); 953 | 143 const ObjCMethodDecl *MD = ME->getMethodDecl(); 144 if (MD && MD->getAttr<WarnUnusedResultAttr>()) { 145 Diag(Loc, diag::warn_unused_call) << R1 << R2 << "warn_unused_result"; 146 return; 147 } 148 } else if (isa<ObjCPropertyRefExpr>(E)) { 149 DiagID = diag::warn_unused_property_expr; 150 } else if (const CXXFunctionalCastExpr *FC --- 821 unchanged lines hidden (view full) --- 972 SourceLocation RParenLoc, Stmt *Body) { 973 if (First) { 974 QualType FirstType; 975 if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) { 976 if (!DS->isSingleDecl()) 977 return StmtError(Diag((*DS->decl_begin())->getLocation(), 978 diag::err_toomany_element_decls)); 979 |
954 Decl *D = DS->getSingleDecl(); 955 FirstType = cast<ValueDecl>(D)->getType(); | 980 VarDecl *D = cast<VarDecl>(DS->getSingleDecl()); 981 FirstType = D->getType(); |
956 // C99 6.8.5p3: The declaration part of a 'for' statement shall only 957 // declare identifiers for objects having storage class 'auto' or 958 // 'register'. | 982 // C99 6.8.5p3: The declaration part of a 'for' statement shall only 983 // declare identifiers for objects having storage class 'auto' or 984 // 'register'. |
959 VarDecl *VD = cast<VarDecl>(D); 960 if (VD->isLocalVarDecl() && !VD->hasLocalStorage()) 961 return StmtError(Diag(VD->getLocation(), | 985 if (!D->hasLocalStorage()) 986 return StmtError(Diag(D->getLocation(), |
962 diag::err_non_variable_decl_in_for)); 963 } else { 964 Expr *FirstE = cast<Expr>(First); 965 if (!FirstE->isTypeDependent() && !FirstE->isLValue()) 966 return StmtError(Diag(First->getLocStart(), 967 diag::err_selector_element_not_lvalue) 968 << First->getSourceRange()); 969 --- 72 unchanged lines hidden (view full) --- 1042 SemaRef.Diag(Loc, diag) << Init->getType(); 1043 if (!InitTSI) { 1044 Decl->setInvalidDecl(); 1045 return true; 1046 } 1047 Decl->setTypeSourceInfo(InitTSI); 1048 Decl->setType(InitTSI->getType()); 1049 | 987 diag::err_non_variable_decl_in_for)); 988 } else { 989 Expr *FirstE = cast<Expr>(First); 990 if (!FirstE->isTypeDependent() && !FirstE->isLValue()) 991 return StmtError(Diag(First->getLocStart(), 992 diag::err_selector_element_not_lvalue) 993 << First->getSourceRange()); 994 --- 72 unchanged lines hidden (view full) --- 1067 SemaRef.Diag(Loc, diag) << Init->getType(); 1068 if (!InitTSI) { 1069 Decl->setInvalidDecl(); 1070 return true; 1071 } 1072 Decl->setTypeSourceInfo(InitTSI); 1073 Decl->setType(InitTSI->getType()); 1074 |
1075 // In ARC, infer lifetime. 1076 // FIXME: ARC may want to turn this into 'const __unsafe_unretained' if 1077 // we're doing the equivalent of fast iteration. 1078 if (SemaRef.getLangOptions().ObjCAutoRefCount && 1079 SemaRef.inferObjCARCLifetime(Decl)) 1080 Decl->setInvalidDecl(); 1081 |
|
1050 SemaRef.AddInitializerToDecl(Decl, Init, /*DirectInit=*/false, 1051 /*TypeMayContainAuto=*/false); 1052 SemaRef.FinalizeDeclaration(Decl); 1053 SemaRef.CurContext->addHiddenDecl(Decl); 1054 return false; 1055} 1056 1057/// Produce a note indicating which begin/end function was implicitly called --- 311 unchanged lines hidden (view full) --- 1369 1370 // Attach *__begin as initializer for VD. 1371 if (!LoopVar->isInvalidDecl()) { 1372 AddInitializerToDecl(LoopVar, DerefExpr.get(), /*DirectInit=*/false, 1373 /*TypeMayContainAuto=*/true); 1374 if (LoopVar->isInvalidDecl()) 1375 NoteForRangeBeginEndFunction(*this, BeginExpr.get(), BEF_begin); 1376 } | 1082 SemaRef.AddInitializerToDecl(Decl, Init, /*DirectInit=*/false, 1083 /*TypeMayContainAuto=*/false); 1084 SemaRef.FinalizeDeclaration(Decl); 1085 SemaRef.CurContext->addHiddenDecl(Decl); 1086 return false; 1087} 1088 1089/// Produce a note indicating which begin/end function was implicitly called --- 311 unchanged lines hidden (view full) --- 1401 1402 // Attach *__begin as initializer for VD. 1403 if (!LoopVar->isInvalidDecl()) { 1404 AddInitializerToDecl(LoopVar, DerefExpr.get(), /*DirectInit=*/false, 1405 /*TypeMayContainAuto=*/true); 1406 if (LoopVar->isInvalidDecl()) 1407 NoteForRangeBeginEndFunction(*this, BeginExpr.get(), BEF_begin); 1408 } |
1409 } else { 1410 // The range is implicitly used as a placeholder when it is dependent. 1411 RangeVar->setUsed(); |
|
1377 } 1378 1379 return Owned(new (Context) CXXForRangeStmt(RangeDS, 1380 cast_or_null<DeclStmt>(BeginEndDecl.get()), 1381 NotEqExpr.take(), IncrExpr.take(), 1382 LoopVarDS, /*Body=*/0, ForLoc, 1383 ColonLoc, RParenLoc)); 1384} --- 118 unchanged lines hidden (view full) --- 1503/// 1504/// This routine implements C++0x [class.copy]p33, which attempts to treat 1505/// returned lvalues as rvalues in certain cases (to prefer move construction), 1506/// then falls back to treating them as lvalues if that failed. 1507ExprResult 1508Sema::PerformMoveOrCopyInitialization(const InitializedEntity &Entity, 1509 const VarDecl *NRVOCandidate, 1510 QualType ResultType, | 1412 } 1413 1414 return Owned(new (Context) CXXForRangeStmt(RangeDS, 1415 cast_or_null<DeclStmt>(BeginEndDecl.get()), 1416 NotEqExpr.take(), IncrExpr.take(), 1417 LoopVarDS, /*Body=*/0, ForLoc, 1418 ColonLoc, RParenLoc)); 1419} --- 118 unchanged lines hidden (view full) --- 1538/// 1539/// This routine implements C++0x [class.copy]p33, which attempts to treat 1540/// returned lvalues as rvalues in certain cases (to prefer move construction), 1541/// then falls back to treating them as lvalues if that failed. 1542ExprResult 1543Sema::PerformMoveOrCopyInitialization(const InitializedEntity &Entity, 1544 const VarDecl *NRVOCandidate, 1545 QualType ResultType, |
1511 Expr *Value) { | 1546 Expr *Value, 1547 bool AllowNRVO) { |
1512 // C++0x [class.copy]p33: 1513 // When the criteria for elision of a copy operation are met or would 1514 // be met save for the fact that the source object is a function 1515 // parameter, and the object to be copied is designated by an lvalue, 1516 // overload resolution to select the constructor for the copy is first 1517 // performed as if the object were designated by an rvalue. 1518 ExprResult Res = ExprError(); | 1548 // C++0x [class.copy]p33: 1549 // When the criteria for elision of a copy operation are met or would 1550 // be met save for the fact that the source object is a function 1551 // parameter, and the object to be copied is designated by an lvalue, 1552 // overload resolution to select the constructor for the copy is first 1553 // performed as if the object were designated by an rvalue. 1554 ExprResult Res = ExprError(); |
1519 if (NRVOCandidate || getCopyElisionCandidate(ResultType, Value, true)) { | 1555 if (AllowNRVO && 1556 (NRVOCandidate || getCopyElisionCandidate(ResultType, Value, true))) { |
1520 ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, 1521 Value->getType(), CK_LValueToRValue, 1522 Value, VK_XValue); 1523 1524 Expr *InitExpr = &AsRvalue; 1525 InitializationKind Kind 1526 = InitializationKind::CreateCopy(Value->getLocStart(), 1527 Value->getLocStart()); --- 193 unchanged lines hidden (view full) --- 1721 RetValExp = ImpCastExprToType(RetValExp, 1722 Context.VoidTy, CK_ToVoid).take(); 1723 } 1724 1725 // return (some void expression); is legal in C++. 1726 if (D != diag::ext_return_has_void_expr || 1727 !getLangOptions().CPlusPlus) { 1728 NamedDecl *CurDecl = getCurFunctionOrMethodDecl(); | 1557 ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, 1558 Value->getType(), CK_LValueToRValue, 1559 Value, VK_XValue); 1560 1561 Expr *InitExpr = &AsRvalue; 1562 InitializationKind Kind 1563 = InitializationKind::CreateCopy(Value->getLocStart(), 1564 Value->getLocStart()); --- 193 unchanged lines hidden (view full) --- 1758 RetValExp = ImpCastExprToType(RetValExp, 1759 Context.VoidTy, CK_ToVoid).take(); 1760 } 1761 1762 // return (some void expression); is legal in C++. 1763 if (D != diag::ext_return_has_void_expr || 1764 !getLangOptions().CPlusPlus) { 1765 NamedDecl *CurDecl = getCurFunctionOrMethodDecl(); |
1766 1767 int FunctionKind = 0; 1768 if (isa<ObjCMethodDecl>(CurDecl)) 1769 FunctionKind = 1; 1770 else if (isa<CXXConstructorDecl>(CurDecl)) 1771 FunctionKind = 2; 1772 else if (isa<CXXDestructorDecl>(CurDecl)) 1773 FunctionKind = 3; 1774 |
|
1729 Diag(ReturnLoc, D) | 1775 Diag(ReturnLoc, D) |
1730 << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl) | 1776 << CurDecl->getDeclName() << FunctionKind |
1731 << RetValExp->getSourceRange(); 1732 } 1733 } 1734 1735 CheckImplicitConversions(RetValExp, ReturnLoc); 1736 RetValExp = MaybeCreateExprWithCleanups(RetValExp); 1737 } 1738 --- 12 unchanged lines hidden (view full) --- 1751 const VarDecl *NRVOCandidate = 0; 1752 if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) { 1753 // we have a non-void function with an expression, continue checking 1754 1755 // C99 6.8.6.4p3(136): The return statement is not an assignment. The 1756 // overlap restriction of subclause 6.5.16.1 does not apply to the case of 1757 // function return. 1758 | 1777 << RetValExp->getSourceRange(); 1778 } 1779 } 1780 1781 CheckImplicitConversions(RetValExp, ReturnLoc); 1782 RetValExp = MaybeCreateExprWithCleanups(RetValExp); 1783 } 1784 --- 12 unchanged lines hidden (view full) --- 1797 const VarDecl *NRVOCandidate = 0; 1798 if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) { 1799 // we have a non-void function with an expression, continue checking 1800 1801 // C99 6.8.6.4p3(136): The return statement is not an assignment. The 1802 // overlap restriction of subclause 6.5.16.1 does not apply to the case of 1803 // function return. 1804 |
1759 // In C++ the return statement is handled via a copy initialization. | 1805 // In C++ the return statement is handled via a copy initialization, |
1760 // the C version of which boils down to CheckSingleAssignmentConstraints. 1761 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, false); 1762 InitializedEntity Entity = InitializedEntity::InitializeResult(ReturnLoc, 1763 FnRetType, 1764 NRVOCandidate != 0); 1765 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate, 1766 FnRetType, RetValExp); 1767 if (Res.isInvalid()) { --- 24 unchanged lines hidden (view full) --- 1792 Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate); 1793 } 1794 1795 // If we need to check for the named return value optimization, save the 1796 // return statement in our scope for later processing. 1797 if (getLangOptions().CPlusPlus && FnRetType->isRecordType() && 1798 !CurContext->isDependentContext()) 1799 FunctionScopes.back()->Returns.push_back(Result); | 1806 // the C version of which boils down to CheckSingleAssignmentConstraints. 1807 NRVOCandidate = getCopyElisionCandidate(FnRetType, RetValExp, false); 1808 InitializedEntity Entity = InitializedEntity::InitializeResult(ReturnLoc, 1809 FnRetType, 1810 NRVOCandidate != 0); 1811 ExprResult Res = PerformMoveOrCopyInitialization(Entity, NRVOCandidate, 1812 FnRetType, RetValExp); 1813 if (Res.isInvalid()) { --- 24 unchanged lines hidden (view full) --- 1838 Result = new (Context) ReturnStmt(ReturnLoc, RetValExp, NRVOCandidate); 1839 } 1840 1841 // If we need to check for the named return value optimization, save the 1842 // return statement in our scope for later processing. 1843 if (getLangOptions().CPlusPlus && FnRetType->isRecordType() && 1844 !CurContext->isDependentContext()) 1845 FunctionScopes.back()->Returns.push_back(Result); |
1800 | 1846 |
1801 return Owned(Result); 1802} 1803 1804/// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently 1805/// ignore "noop" casts in places where an lvalue is required by an inline asm. 1806/// We emulate this behavior when -fheinous-gnu-extensions is specified, but 1807/// provide a strong guidance to not use it. 1808/// --- 141 unchanged lines hidden (view full) --- 1950 for (unsigned i = 0; i != NumClobbers; i++) { 1951 StringLiteral *Literal = Clobbers[i]; 1952 if (Literal->isWide()) 1953 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) 1954 << Literal->getSourceRange()); 1955 1956 llvm::StringRef Clobber = Literal->getString(); 1957 | 1847 return Owned(Result); 1848} 1849 1850/// CheckAsmLValue - GNU C has an extremely ugly extension whereby they silently 1851/// ignore "noop" casts in places where an lvalue is required by an inline asm. 1852/// We emulate this behavior when -fheinous-gnu-extensions is specified, but 1853/// provide a strong guidance to not use it. 1854/// --- 141 unchanged lines hidden (view full) --- 1996 for (unsigned i = 0; i != NumClobbers; i++) { 1997 StringLiteral *Literal = Clobbers[i]; 1998 if (Literal->isWide()) 1999 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) 2000 << Literal->getSourceRange()); 2001 2002 llvm::StringRef Clobber = Literal->getString(); 2003 |
1958 if (!Context.Target.isValidGCCRegisterName(Clobber)) | 2004 if (!Context.Target.isValidClobber(Clobber)) |
1959 return StmtError(Diag(Literal->getLocStart(), 1960 diag::err_asm_unknown_register_name) << Clobber); 1961 } 1962 1963 AsmStmt *NS = 1964 new (Context) AsmStmt(Context, AsmLoc, IsSimple, IsVolatile, MSAsm, 1965 NumOutputs, NumInputs, Names, Constraints, Exprs, 1966 AsmString, NumClobbers, Clobbers, RParenLoc); --- 207 unchanged lines hidden (view full) --- 2174Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, 2175 Stmt *HandlerBlock) { 2176 // There's nothing to test that ActOnExceptionDecl didn't already test. 2177 return Owned(new (Context) CXXCatchStmt(CatchLoc, 2178 cast_or_null<VarDecl>(ExDecl), 2179 HandlerBlock)); 2180} 2181 | 2005 return StmtError(Diag(Literal->getLocStart(), 2006 diag::err_asm_unknown_register_name) << Clobber); 2007 } 2008 2009 AsmStmt *NS = 2010 new (Context) AsmStmt(Context, AsmLoc, IsSimple, IsVolatile, MSAsm, 2011 NumOutputs, NumInputs, Names, Constraints, Exprs, 2012 AsmString, NumClobbers, Clobbers, RParenLoc); --- 207 unchanged lines hidden (view full) --- 2220Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, Decl *ExDecl, 2221 Stmt *HandlerBlock) { 2222 // There's nothing to test that ActOnExceptionDecl didn't already test. 2223 return Owned(new (Context) CXXCatchStmt(CatchLoc, 2224 cast_or_null<VarDecl>(ExDecl), 2225 HandlerBlock)); 2226} 2227 |
2228StmtResult 2229Sema::ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body) { 2230 getCurFunction()->setHasBranchProtectedScope(); 2231 return Owned(new (Context) ObjCAutoreleasePoolStmt(AtLoc, Body)); 2232} 2233 |
|
2182namespace { 2183 2184class TypeWithHandler { 2185 QualType t; 2186 CXXCatchStmt *stmt; 2187public: 2188 TypeWithHandler(const QualType &type, CXXCatchStmt *statement) 2189 : t(type), stmt(statement) {} --- 114 unchanged lines hidden (view full) --- 2304} 2305 2306StmtResult 2307Sema::ActOnSEHFinallyBlock(SourceLocation Loc, 2308 Stmt *Block) { 2309 assert(Block); 2310 return Owned(SEHFinallyStmt::Create(Context,Loc,Block)); 2311} | 2234namespace { 2235 2236class TypeWithHandler { 2237 QualType t; 2238 CXXCatchStmt *stmt; 2239public: 2240 TypeWithHandler(const QualType &type, CXXCatchStmt *statement) 2241 : t(type), stmt(statement) {} --- 114 unchanged lines hidden (view full) --- 2356} 2357 2358StmtResult 2359Sema::ActOnSEHFinallyBlock(SourceLocation Loc, 2360 Stmt *Block) { 2361 assert(Block); 2362 return Owned(SEHFinallyStmt::Create(Context,Loc,Block)); 2363} |
2312 | |