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 |
71 // suppress any potential 'unused variable' warning. |
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 } |
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 } |
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 |
980 VarDecl *D = cast<VarDecl>(DS->getSingleDecl()); 981 FirstType = D->getType(); |
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'. |
985 if (!D->hasLocalStorage()) 986 return StmtError(Diag(D->getLocation(), |
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 |
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(); |
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, |
1546 Expr *Value, 1547 bool AllowNRVO) { |
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(); |
1555 if (AllowNRVO && 1556 (NRVOCandidate || getCopyElisionCandidate(ResultType, Value, true))) { |
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 |
1775 Diag(ReturnLoc, D) |
1776 << CurDecl->getDeclName() << FunctionKind |
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 |
1805 // In C++ the return statement is handled via a copy initialization, |
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); |
1846 |
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 |
2004 if (!Context.Target.isValidClobber(Clobber)) |
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 |
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} |