Deleted Added
sdiff udiff text old ( 223017 ) new ( 224145 )
full compact
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 // suppress any potential 'unused variable' warning.
70 DG.getSingleDecl()->setUsed();
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)) {
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
954 Decl *D = DS->getSingleDecl();
955 FirstType = cast<ValueDecl>(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'.
959 VarDecl *VD = cast<VarDecl>(D);
960 if (VD->isLocalVarDecl() && !VD->hasLocalStorage())
961 return StmtError(Diag(VD->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
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 }
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,
1511 Expr *Value) {
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();
1519 if (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();
1729 Diag(ReturnLoc, D)
1730 << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
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
1759 // 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);
1800
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
1958 if (!Context.Target.isValidGCCRegisterName(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
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}
2312