blob: 7697dbda00c78cec33bf55b79859f922fa3504ed [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for statements.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Sema.h"
Anders Carlssone8bd9f22008-11-22 21:04:56 +000015#include "clang/AST/APValue.h"
Chris Lattner3429a812007-08-23 05:46:52 +000016#include "clang/AST/ASTContext.h"
Daniel Dunbar64789f82008-08-11 05:35:13 +000017#include "clang/AST/DeclObjC.h"
Chris Lattner4b009652007-07-25 00:24:17 +000018#include "clang/AST/Expr.h"
Anders Carlsson49dadd62007-11-25 00:25:21 +000019#include "clang/Basic/TargetInfo.h"
Chris Lattner4b009652007-07-25 00:24:17 +000020using namespace clang;
21
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000022Sema::OwningStmtResult Sema::ActOnExprStmt(ExprArg expr) {
23 Expr *E = static_cast<Expr*>(expr.release());
Steve Naroff5cbb02f2007-09-16 14:56:35 +000024 assert(E && "ActOnExprStmt(): missing expression");
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000025
Chris Lattnere02e4402008-07-25 23:18:17 +000026 // C99 6.8.3p2: The expression in an expression statement is evaluated as a
27 // void expression for its side effects. Conversion to void allows any
28 // operand, even incomplete types.
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000029
Chris Lattnere02e4402008-07-25 23:18:17 +000030 // Same thing in for stmt first clause (when expr) and third clause.
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000031 return Owned(static_cast<Stmt*>(E));
Chris Lattner4b009652007-07-25 00:24:17 +000032}
33
34
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000035Sema::OwningStmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) {
36 return Owned(new NullStmt(SemiLoc));
Chris Lattner4b009652007-07-25 00:24:17 +000037}
38
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000039Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclTy *decl,
40 SourceLocation StartLoc,
41 SourceLocation EndLoc) {
Chris Lattnera4ff4272008-03-13 06:29:04 +000042 if (decl == 0)
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000043 return StmtError();
44
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +000045 Decl *D = static_cast<Decl *>(decl);
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000046
Ted Kremenek1bc18e62008-10-07 23:09:49 +000047 // This is a temporary hack until we are always passing around
48 // DeclGroupRefs.
49 llvm::SmallVector<Decl*, 10> decls;
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +000050 while (D) {
51 Decl* d = D;
52 D = D->getNextDeclarator();
Ted Kremenek1bc18e62008-10-07 23:09:49 +000053 d->setNextDeclarator(0);
54 decls.push_back(d);
55 }
56
57 assert (!decls.empty());
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000058
Ted Kremenek1bc18e62008-10-07 23:09:49 +000059 if (decls.size() == 1) {
60 DeclGroupOwningRef DG(*decls.begin());
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000061 return Owned(new DeclStmt(DG, StartLoc, EndLoc));
Ted Kremenek1bc18e62008-10-07 23:09:49 +000062 }
63 else {
Chris Lattnerb1753422008-11-23 21:45:46 +000064 DeclGroupOwningRef DG(DeclGroup::Create(Context, decls.size(), &decls[0]));
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000065 return Owned(new DeclStmt(DG, StartLoc, EndLoc));
Ted Kremenek1bc18e62008-10-07 23:09:49 +000066 }
Chris Lattner4b009652007-07-25 00:24:17 +000067}
68
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000069Action::OwningStmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +000070Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R,
Sebastian Redl76b9ddb2008-12-21 12:04:03 +000071 MultiStmtArg elts, bool isStmtExpr) {
72 unsigned NumElts = elts.size();
73 Stmt **Elts = reinterpret_cast<Stmt**>(elts.release());
Chris Lattner3ea3b662007-08-27 04:29:41 +000074 // If we're in C89 mode, check that we don't have any decls after stmts. If
75 // so, emit an extension diagnostic.
76 if (!getLangOptions().C99 && !getLangOptions().CPlusPlus) {
77 // Note that __extension__ can be around a decl.
78 unsigned i = 0;
79 // Skip over all declarations.
80 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
81 /*empty*/;
82
83 // We found the end of the list or a statement. Scan for another declstmt.
84 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
85 /*empty*/;
86
87 if (i != NumElts) {
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +000088 Decl *D = *cast<DeclStmt>(Elts[i])->decl_begin();
Chris Lattner3ea3b662007-08-27 04:29:41 +000089 Diag(D->getLocation(), diag::ext_mixed_decls_code);
90 }
91 }
Chris Lattnerf2b07572007-08-31 21:49:55 +000092 // Warn about unused expressions in statements.
93 for (unsigned i = 0; i != NumElts; ++i) {
94 Expr *E = dyn_cast<Expr>(Elts[i]);
95 if (!E) continue;
96
97 // Warn about expressions with unused results.
98 if (E->hasLocalSideEffect() || E->getType()->isVoidType())
99 continue;
100
101 // The last expr in a stmt expr really is used.
102 if (isStmtExpr && i == NumElts-1)
103 continue;
104
105 /// DiagnoseDeadExpr - This expression is side-effect free and evaluated in
106 /// a context where the result is unused. Emit a diagnostic to warn about
107 /// this.
108 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E))
Chris Lattner8ba580c2008-11-19 05:08:23 +0000109 Diag(BO->getOperatorLoc(), diag::warn_unused_expr)
110 << BO->getLHS()->getSourceRange() << BO->getRHS()->getSourceRange();
Chris Lattnerf2b07572007-08-31 21:49:55 +0000111 else if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E))
Chris Lattner8ba580c2008-11-19 05:08:23 +0000112 Diag(UO->getOperatorLoc(), diag::warn_unused_expr)
113 << UO->getSubExpr()->getSourceRange();
Sebastian Redl76b9ddb2008-12-21 12:04:03 +0000114 else
Chris Lattner8ba580c2008-11-19 05:08:23 +0000115 Diag(E->getExprLoc(), diag::warn_unused_expr) << E->getSourceRange();
Chris Lattnerf2b07572007-08-31 21:49:55 +0000116 }
Sebastian Redl76b9ddb2008-12-21 12:04:03 +0000117
118 return Owned(new CompoundStmt(Elts, NumElts, L, R));
Chris Lattner4b009652007-07-25 00:24:17 +0000119}
120
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000121Action::OwningStmtResult
122Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprArg lhsval,
123 SourceLocation DotDotDotLoc, ExprArg rhsval,
124 SourceLocation ColonLoc, StmtArg subStmt) {
125 Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
126 assert((lhsval.get() != 0) && "missing expression in case statement");
127
Chris Lattner4b009652007-07-25 00:24:17 +0000128 // C99 6.8.4.2p3: The expression shall be an integer constant.
Anders Carlssone8bd9f22008-11-22 21:04:56 +0000129 // However, GCC allows any evaluatable integer expression.
Anders Carlsson613314d2008-12-01 02:13:02 +0000130
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000131 Expr *LHSVal = static_cast<Expr*>(lhsval.get());
Anders Carlsson613314d2008-12-01 02:13:02 +0000132 if (VerifyIntegerConstantExpression(LHSVal))
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000133 return Owned(SubStmt);
Chris Lattner4b009652007-07-25 00:24:17 +0000134
135 // GCC extension: The expression shall be an integer constant.
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000136
137 Expr *RHSVal = static_cast<Expr*>(rhsval.get());
138 if (RHSVal && VerifyIntegerConstantExpression(RHSVal)) {
Chris Lattner3429a812007-08-23 05:46:52 +0000139 RHSVal = 0; // Recover by just forgetting about it.
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000140 rhsval = 0;
141 }
142
Chris Lattner4b009652007-07-25 00:24:17 +0000143 if (SwitchStack.empty()) {
144 Diag(CaseLoc, diag::err_case_not_in_switch);
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000145 return Owned(SubStmt);
Chris Lattner4b009652007-07-25 00:24:17 +0000146 }
147
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000148 // Only now release the smart pointers.
149 lhsval.release();
150 rhsval.release();
Steve Naroff5d2fff82007-08-31 23:28:33 +0000151 CaseStmt *CS = new CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000152 SwitchStack.back()->addSwitchCase(CS);
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000153 return Owned(CS);
Chris Lattner4b009652007-07-25 00:24:17 +0000154}
155
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000156Action::OwningStmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000157Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc,
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000158 StmtArg subStmt, Scope *CurScope) {
159 Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
160
Chris Lattner4b009652007-07-25 00:24:17 +0000161 if (SwitchStack.empty()) {
162 Diag(DefaultLoc, diag::err_default_not_in_switch);
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000163 return Owned(SubStmt);
Chris Lattner4b009652007-07-25 00:24:17 +0000164 }
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000165
Chris Lattner4b009652007-07-25 00:24:17 +0000166 DefaultStmt *DS = new DefaultStmt(DefaultLoc, SubStmt);
167 SwitchStack.back()->addSwitchCase(DS);
Sebastian Redl0a23e8f2008-12-28 16:13:43 +0000168 return Owned(DS);
Chris Lattner4b009652007-07-25 00:24:17 +0000169}
170
Sebastian Redl2437ec62009-01-11 00:38:46 +0000171Action::OwningStmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000172Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
Sebastian Redl2437ec62009-01-11 00:38:46 +0000173 SourceLocation ColonLoc, StmtArg subStmt) {
174 Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
Chris Lattner4b009652007-07-25 00:24:17 +0000175 // Look up the record for this label identifier.
176 LabelStmt *&LabelDecl = LabelMap[II];
Sebastian Redl2437ec62009-01-11 00:38:46 +0000177
Chris Lattner4b009652007-07-25 00:24:17 +0000178 // If not forward referenced or defined already, just create a new LabelStmt.
179 if (LabelDecl == 0)
Sebastian Redl2437ec62009-01-11 00:38:46 +0000180 return Owned(LabelDecl = new LabelStmt(IdentLoc, II, SubStmt));
181
Chris Lattner4b009652007-07-25 00:24:17 +0000182 assert(LabelDecl->getID() == II && "Label mismatch!");
Sebastian Redl2437ec62009-01-11 00:38:46 +0000183
Chris Lattner4b009652007-07-25 00:24:17 +0000184 // Otherwise, this label was either forward reference or multiply defined. If
185 // multiply defined, reject it now.
186 if (LabelDecl->getSubStmt()) {
Chris Lattnerb1753422008-11-23 21:45:46 +0000187 Diag(IdentLoc, diag::err_redefinition_of_label) << LabelDecl->getID();
Chris Lattner1336cab2008-11-23 23:12:31 +0000188 Diag(LabelDecl->getIdentLoc(), diag::note_previous_definition);
Sebastian Redl2437ec62009-01-11 00:38:46 +0000189 return Owned(SubStmt);
Chris Lattner4b009652007-07-25 00:24:17 +0000190 }
Sebastian Redl2437ec62009-01-11 00:38:46 +0000191
Chris Lattner4b009652007-07-25 00:24:17 +0000192 // Otherwise, this label was forward declared, and we just found its real
193 // definition. Fill in the forward definition and return it.
194 LabelDecl->setIdentLoc(IdentLoc);
195 LabelDecl->setSubStmt(SubStmt);
Sebastian Redl2437ec62009-01-11 00:38:46 +0000196 return Owned(LabelDecl);
Chris Lattner4b009652007-07-25 00:24:17 +0000197}
198
Sebastian Redl2437ec62009-01-11 00:38:46 +0000199Action::OwningStmtResult
200Sema::ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
201 StmtArg ThenVal, SourceLocation ElseLoc,
202 StmtArg ElseVal) {
203 Expr *condExpr = (Expr *)CondVal.release();
204
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000205 assert(condExpr && "ActOnIfStmt(): missing expression");
Sebastian Redl2437ec62009-01-11 00:38:46 +0000206
Chris Lattner4b009652007-07-25 00:24:17 +0000207 DefaultFunctionArrayConversion(condExpr);
Sebastian Redl2437ec62009-01-11 00:38:46 +0000208 // Take ownership again until we're past the error checking.
209 CondVal = condExpr;
Chris Lattner4b009652007-07-25 00:24:17 +0000210 QualType condType = condExpr->getType();
Sebastian Redl2437ec62009-01-11 00:38:46 +0000211
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000212 if (getLangOptions().CPlusPlus) {
213 if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4
Sebastian Redl2437ec62009-01-11 00:38:46 +0000214 return StmtError();
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000215 } else if (!condType->isScalarType()) // C99 6.8.4.1p1
Sebastian Redl2437ec62009-01-11 00:38:46 +0000216 return StmtError(Diag(IfLoc, diag::err_typecheck_statement_requires_scalar)
217 << condType << condExpr->getSourceRange());
218
219 Stmt *thenStmt = (Stmt *)ThenVal.release();
Chris Lattner4b009652007-07-25 00:24:17 +0000220
Anders Carlsson663733e2007-10-10 20:50:11 +0000221 // Warn if the if block has a null body without an else value.
222 // this helps prevent bugs due to typos, such as
223 // if (condition);
224 // do_stuff();
Sebastian Redl2437ec62009-01-11 00:38:46 +0000225 if (!ElseVal.get()) {
Anders Carlsson663733e2007-10-10 20:50:11 +0000226 if (NullStmt* stmt = dyn_cast<NullStmt>(thenStmt))
227 Diag(stmt->getSemiLoc(), diag::warn_empty_if_body);
228 }
229
Sebastian Redl2437ec62009-01-11 00:38:46 +0000230 CondVal.release();
231 return Owned(new IfStmt(IfLoc, condExpr, thenStmt, (Stmt*)ElseVal.release()));
Chris Lattner4b009652007-07-25 00:24:17 +0000232}
233
Sebastian Redl2437ec62009-01-11 00:38:46 +0000234Action::OwningStmtResult
235Sema::ActOnStartOfSwitchStmt(ExprArg cond) {
236 Expr *Cond = static_cast<Expr*>(cond.release());
237
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000238 if (getLangOptions().CPlusPlus) {
239 // C++ 6.4.2.p2:
240 // The condition shall be of integral type, enumeration type, or of a class
241 // type for which a single conversion function to integral or enumeration
242 // type exists (12.3). If the condition is of class type, the condition is
243 // converted by calling that conversion function, and the result of the
244 // conversion is used in place of the original condition for the remainder
245 // of this section. Integral promotions are performed.
246
247 QualType Ty = Cond->getType();
248
249 // FIXME: Handle class types.
250
251 // If the type is wrong a diagnostic will be emitted later at
252 // ActOnFinishSwitchStmt.
253 if (Ty->isIntegralType() || Ty->isEnumeralType()) {
254 // Integral promotions are performed.
255 // FIXME: Integral promotions for C++ are not complete.
256 UsualUnaryConversions(Cond);
257 }
258 } else {
259 // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr.
260 UsualUnaryConversions(Cond);
261 }
Sebastian Redl2437ec62009-01-11 00:38:46 +0000262
Chris Lattner3429a812007-08-23 05:46:52 +0000263 SwitchStmt *SS = new SwitchStmt(Cond);
Chris Lattner4b009652007-07-25 00:24:17 +0000264 SwitchStack.push_back(SS);
Sebastian Redl2437ec62009-01-11 00:38:46 +0000265 return Owned(SS);
Chris Lattner4b009652007-07-25 00:24:17 +0000266}
267
Chris Lattner3429a812007-08-23 05:46:52 +0000268/// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
269/// the specified width and sign. If an overflow occurs, detect it and emit
270/// the specified diagnostic.
271void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
272 unsigned NewWidth, bool NewSign,
273 SourceLocation Loc,
274 unsigned DiagID) {
275 // Perform a conversion to the promoted condition type if needed.
276 if (NewWidth > Val.getBitWidth()) {
277 // If this is an extension, just do it.
278 llvm::APSInt OldVal(Val);
279 Val.extend(NewWidth);
280
281 // If the input was signed and negative and the output is unsigned,
282 // warn.
283 if (!NewSign && OldVal.isSigned() && OldVal.isNegative())
Chris Lattner77d52da2008-11-20 06:06:08 +0000284 Diag(Loc, DiagID) << OldVal.toString(10) << Val.toString(10);
Chris Lattner3429a812007-08-23 05:46:52 +0000285
286 Val.setIsSigned(NewSign);
287 } else if (NewWidth < Val.getBitWidth()) {
288 // If this is a truncation, check for overflow.
289 llvm::APSInt ConvVal(Val);
290 ConvVal.trunc(NewWidth);
Chris Lattner5c039602007-08-23 22:08:35 +0000291 ConvVal.setIsSigned(NewSign);
Chris Lattner3429a812007-08-23 05:46:52 +0000292 ConvVal.extend(Val.getBitWidth());
Chris Lattner5c039602007-08-23 22:08:35 +0000293 ConvVal.setIsSigned(Val.isSigned());
Chris Lattner3429a812007-08-23 05:46:52 +0000294 if (ConvVal != Val)
Chris Lattner77d52da2008-11-20 06:06:08 +0000295 Diag(Loc, DiagID) << Val.toString(10) << ConvVal.toString(10);
Chris Lattner3429a812007-08-23 05:46:52 +0000296
297 // Regardless of whether a diagnostic was emitted, really do the
298 // truncation.
299 Val.trunc(NewWidth);
Chris Lattner5c039602007-08-23 22:08:35 +0000300 Val.setIsSigned(NewSign);
Chris Lattner3429a812007-08-23 05:46:52 +0000301 } else if (NewSign != Val.isSigned()) {
302 // Convert the sign to match the sign of the condition. This can cause
303 // overflow as well: unsigned(INTMIN)
304 llvm::APSInt OldVal(Val);
305 Val.setIsSigned(NewSign);
306
307 if (Val.isNegative()) // Sign bit changes meaning.
Chris Lattner77d52da2008-11-20 06:06:08 +0000308 Diag(Loc, DiagID) << OldVal.toString(10) << Val.toString(10);
Chris Lattner3429a812007-08-23 05:46:52 +0000309 }
310}
311
Chris Lattner0ab833c2007-08-23 18:29:20 +0000312namespace {
313 struct CaseCompareFunctor {
314 bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS,
315 const llvm::APSInt &RHS) {
316 return LHS.first < RHS;
317 }
Chris Lattner2157f272007-09-03 18:31:57 +0000318 bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS,
319 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
320 return LHS.first < RHS.first;
321 }
Chris Lattner0ab833c2007-08-23 18:29:20 +0000322 bool operator()(const llvm::APSInt &LHS,
323 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
324 return LHS < RHS.first;
325 }
326 };
327}
328
Chris Lattner766afb82007-09-21 18:15:22 +0000329/// CmpCaseVals - Comparison predicate for sorting case values.
330///
331static bool CmpCaseVals(const std::pair<llvm::APSInt, CaseStmt*>& lhs,
332 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
333 if (lhs.first < rhs.first)
334 return true;
335
336 if (lhs.first == rhs.first &&
337 lhs.second->getCaseLoc().getRawEncoding()
338 < rhs.second->getCaseLoc().getRawEncoding())
339 return true;
340 return false;
341}
342
Sebastian Redl2437ec62009-01-11 00:38:46 +0000343Action::OwningStmtResult
344Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch,
345 StmtArg Body) {
346 Stmt *BodyStmt = (Stmt*)Body.release();
347
Chris Lattner4b009652007-07-25 00:24:17 +0000348 SwitchStmt *SS = SwitchStack.back();
Sebastian Redl2437ec62009-01-11 00:38:46 +0000349 assert(SS == (SwitchStmt*)Switch.get() && "switch stack missing push/pop!");
350
Steve Naroffa610eab2007-09-01 21:08:38 +0000351 SS->setBody(BodyStmt, SwitchLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000352 SwitchStack.pop_back();
353
Chris Lattner3429a812007-08-23 05:46:52 +0000354 Expr *CondExpr = SS->getCond();
355 QualType CondType = CondExpr->getType();
Sebastian Redl2437ec62009-01-11 00:38:46 +0000356
Chris Lattner3429a812007-08-23 05:46:52 +0000357 if (!CondType->isIntegerType()) { // C99 6.8.4.2p1
Chris Lattner77d52da2008-11-20 06:06:08 +0000358 Diag(SwitchLoc, diag::err_typecheck_statement_requires_integer)
Chris Lattner4bfd2232008-11-24 06:25:27 +0000359 << CondType << CondExpr->getSourceRange();
Sebastian Redl2437ec62009-01-11 00:38:46 +0000360 return StmtError();
Chris Lattner4b009652007-07-25 00:24:17 +0000361 }
Sebastian Redl2437ec62009-01-11 00:38:46 +0000362
Chris Lattner3429a812007-08-23 05:46:52 +0000363 // Get the bitwidth of the switched-on value before promotions. We must
364 // convert the integer case values to this width before comparison.
Chris Lattner8cd0e932008-03-05 18:54:05 +0000365 unsigned CondWidth = static_cast<unsigned>(Context.getTypeSize(CondType));
Chris Lattner3429a812007-08-23 05:46:52 +0000366 bool CondIsSigned = CondType->isSignedIntegerType();
367
368 // Accumulate all of the case values in a vector so that we can sort them
369 // and detect duplicates. This vector contains the APInt for the case after
370 // it has been converted to the condition type.
Chris Lattner0ab833c2007-08-23 18:29:20 +0000371 typedef llvm::SmallVector<std::pair<llvm::APSInt, CaseStmt*>, 64> CaseValsTy;
372 CaseValsTy CaseVals;
Chris Lattner3429a812007-08-23 05:46:52 +0000373
374 // Keep track of any GNU case ranges we see. The APSInt is the low value.
375 std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRanges;
376
377 DefaultStmt *TheDefaultStmt = 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000378
Chris Lattner1a4066d2007-08-23 06:23:56 +0000379 bool CaseListIsErroneous = false;
380
381 for (SwitchCase *SC = SS->getSwitchCaseList(); SC;
Chris Lattner4b009652007-07-25 00:24:17 +0000382 SC = SC->getNextSwitchCase()) {
Chris Lattner1a4066d2007-08-23 06:23:56 +0000383
Chris Lattner4b009652007-07-25 00:24:17 +0000384 if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC)) {
Chris Lattner3429a812007-08-23 05:46:52 +0000385 if (TheDefaultStmt) {
386 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
Chris Lattner1336cab2008-11-23 23:12:31 +0000387 Diag(TheDefaultStmt->getDefaultLoc(), diag::note_duplicate_case_prev);
Sebastian Redl2437ec62009-01-11 00:38:46 +0000388
Chris Lattner3429a812007-08-23 05:46:52 +0000389 // FIXME: Remove the default statement from the switch block so that
390 // we'll return a valid AST. This requires recursing down the
391 // AST and finding it, not something we are set up to do right now. For
392 // now, just lop the entire switch stmt out of the AST.
Chris Lattner1a4066d2007-08-23 06:23:56 +0000393 CaseListIsErroneous = true;
Chris Lattner4b009652007-07-25 00:24:17 +0000394 }
Chris Lattner3429a812007-08-23 05:46:52 +0000395 TheDefaultStmt = DS;
Chris Lattner4b009652007-07-25 00:24:17 +0000396
Chris Lattner3429a812007-08-23 05:46:52 +0000397 } else {
398 CaseStmt *CS = cast<CaseStmt>(SC);
399
400 // We already verified that the expression has a i-c-e value (C99
401 // 6.8.4.2p3) - get that value now.
Chris Lattnere992d6c2008-01-16 19:17:22 +0000402 Expr *Lo = CS->getLHS();
Anders Carlssone8bd9f22008-11-22 21:04:56 +0000403 llvm::APSInt LoVal = Lo->EvaluateAsInt(Context);
Chris Lattner3429a812007-08-23 05:46:52 +0000404
405 // Convert the value to the same width/sign as the condition.
406 ConvertIntegerToTypeWarnOnOverflow(LoVal, CondWidth, CondIsSigned,
407 CS->getLHS()->getLocStart(),
408 diag::warn_case_value_overflow);
Chris Lattner4b009652007-07-25 00:24:17 +0000409
Chris Lattnere992d6c2008-01-16 19:17:22 +0000410 // If the LHS is not the same type as the condition, insert an implicit
411 // cast.
412 ImpCastExprToType(Lo, CondType);
413 CS->setLHS(Lo);
414
Chris Lattner1a4066d2007-08-23 06:23:56 +0000415 // If this is a case range, remember it in CaseRanges, otherwise CaseVals.
Chris Lattner3429a812007-08-23 05:46:52 +0000416 if (CS->getRHS())
417 CaseRanges.push_back(std::make_pair(LoVal, CS));
Chris Lattner1a4066d2007-08-23 06:23:56 +0000418 else
419 CaseVals.push_back(std::make_pair(LoVal, CS));
Chris Lattner3429a812007-08-23 05:46:52 +0000420 }
421 }
422
Chris Lattner1a4066d2007-08-23 06:23:56 +0000423 // Sort all the scalar case values so we can easily detect duplicates.
Chris Lattner766afb82007-09-21 18:15:22 +0000424 std::stable_sort(CaseVals.begin(), CaseVals.end(), CmpCaseVals);
Chris Lattner3429a812007-08-23 05:46:52 +0000425
Chris Lattner2b1b9a82007-08-23 14:29:07 +0000426 if (!CaseVals.empty()) {
427 for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) {
428 if (CaseVals[i].first == CaseVals[i+1].first) {
429 // If we have a duplicate, report it.
430 Diag(CaseVals[i+1].second->getLHS()->getLocStart(),
Chris Lattner77d52da2008-11-20 06:06:08 +0000431 diag::err_duplicate_case) << CaseVals[i].first.toString(10);
Chris Lattner2b1b9a82007-08-23 14:29:07 +0000432 Diag(CaseVals[i].second->getLHS()->getLocStart(),
Chris Lattner1336cab2008-11-23 23:12:31 +0000433 diag::note_duplicate_case_prev);
Chris Lattner2b1b9a82007-08-23 14:29:07 +0000434 // FIXME: We really want to remove the bogus case stmt from the substmt,
435 // but we have no way to do this right now.
436 CaseListIsErroneous = true;
437 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000438 }
439 }
Chris Lattner3429a812007-08-23 05:46:52 +0000440
Chris Lattner1a4066d2007-08-23 06:23:56 +0000441 // Detect duplicate case ranges, which usually don't exist at all in the first
442 // place.
443 if (!CaseRanges.empty()) {
444 // Sort all the case ranges by their low value so we can easily detect
445 // overlaps between ranges.
Chris Lattner0ab833c2007-08-23 18:29:20 +0000446 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
Chris Lattner1a4066d2007-08-23 06:23:56 +0000447
448 // Scan the ranges, computing the high values and removing empty ranges.
449 std::vector<llvm::APSInt> HiVals;
Chris Lattner7443e0f2007-08-23 17:48:14 +0000450 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
Chris Lattner1a4066d2007-08-23 06:23:56 +0000451 CaseStmt *CR = CaseRanges[i].second;
Chris Lattnere992d6c2008-01-16 19:17:22 +0000452 Expr *Hi = CR->getRHS();
Anders Carlssone8bd9f22008-11-22 21:04:56 +0000453 llvm::APSInt HiVal = Hi->EvaluateAsInt(Context);
Chris Lattner1a4066d2007-08-23 06:23:56 +0000454
455 // Convert the value to the same width/sign as the condition.
456 ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned,
457 CR->getRHS()->getLocStart(),
458 diag::warn_case_value_overflow);
459
Chris Lattnere992d6c2008-01-16 19:17:22 +0000460 // If the LHS is not the same type as the condition, insert an implicit
461 // cast.
462 ImpCastExprToType(Hi, CondType);
463 CR->setRHS(Hi);
464
Chris Lattner7443e0f2007-08-23 17:48:14 +0000465 // If the low value is bigger than the high value, the case is empty.
466 if (CaseRanges[i].first > HiVal) {
Chris Lattner9d2cf082008-11-19 05:27:50 +0000467 Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range)
468 << SourceRange(CR->getLHS()->getLocStart(),
469 CR->getRHS()->getLocEnd());
Chris Lattner7443e0f2007-08-23 17:48:14 +0000470 CaseRanges.erase(CaseRanges.begin()+i);
471 --i, --e;
472 continue;
473 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000474 HiVals.push_back(HiVal);
475 }
476
477 // Rescan the ranges, looking for overlap with singleton values and other
Chris Lattner0ab833c2007-08-23 18:29:20 +0000478 // ranges. Since the range list is sorted, we only need to compare case
479 // ranges with their neighbors.
Chris Lattner1a4066d2007-08-23 06:23:56 +0000480 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
Chris Lattner0ab833c2007-08-23 18:29:20 +0000481 llvm::APSInt &CRLo = CaseRanges[i].first;
482 llvm::APSInt &CRHi = HiVals[i];
483 CaseStmt *CR = CaseRanges[i].second;
Chris Lattner1a4066d2007-08-23 06:23:56 +0000484
Chris Lattner0ab833c2007-08-23 18:29:20 +0000485 // Check to see whether the case range overlaps with any singleton cases.
486 CaseStmt *OverlapStmt = 0;
487 llvm::APSInt OverlapVal(32);
488
489 // Find the smallest value >= the lower bound. If I is in the case range,
490 // then we have overlap.
491 CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(),
492 CaseVals.end(), CRLo,
493 CaseCompareFunctor());
494 if (I != CaseVals.end() && I->first < CRHi) {
495 OverlapVal = I->first; // Found overlap with scalar.
496 OverlapStmt = I->second;
497 }
498
499 // Find the smallest value bigger than the upper bound.
500 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
501 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
502 OverlapVal = (I-1)->first; // Found overlap with scalar.
503 OverlapStmt = (I-1)->second;
504 }
505
506 // Check to see if this case stmt overlaps with the subsequent case range.
507 if (i && CRLo <= HiVals[i-1]) {
508 OverlapVal = HiVals[i-1]; // Found overlap with range.
509 OverlapStmt = CaseRanges[i-1].second;
510 }
511
512 if (OverlapStmt) {
513 // If we have a duplicate, report it.
Chris Lattner77d52da2008-11-20 06:06:08 +0000514 Diag(CR->getLHS()->getLocStart(), diag::err_duplicate_case)
515 << OverlapVal.toString(10);
Chris Lattner0ab833c2007-08-23 18:29:20 +0000516 Diag(OverlapStmt->getLHS()->getLocStart(),
Chris Lattner1336cab2008-11-23 23:12:31 +0000517 diag::note_duplicate_case_prev);
Chris Lattner0ab833c2007-08-23 18:29:20 +0000518 // FIXME: We really want to remove the bogus case stmt from the substmt,
519 // but we have no way to do this right now.
520 CaseListIsErroneous = true;
521 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000522 }
523 }
Chris Lattner3429a812007-08-23 05:46:52 +0000524
Chris Lattner1a4066d2007-08-23 06:23:56 +0000525 // FIXME: If the case list was broken is some way, we don't have a good system
526 // to patch it up. Instead, just return the whole substmt as broken.
527 if (CaseListIsErroneous)
Sebastian Redl2437ec62009-01-11 00:38:46 +0000528 return StmtError();
529
530 Switch.release();
531 return Owned(SS);
Chris Lattner4b009652007-07-25 00:24:17 +0000532}
533
Sebastian Redl19c74d32009-01-16 23:28:06 +0000534Action::OwningStmtResult
535Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond, StmtArg Body) {
536 Expr *condExpr = (Expr *)Cond.release();
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000537 assert(condExpr && "ActOnWhileStmt(): missing expression");
Sebastian Redl19c74d32009-01-16 23:28:06 +0000538
Chris Lattner4b009652007-07-25 00:24:17 +0000539 DefaultFunctionArrayConversion(condExpr);
Sebastian Redl19c74d32009-01-16 23:28:06 +0000540 Cond = condExpr;
Chris Lattner4b009652007-07-25 00:24:17 +0000541 QualType condType = condExpr->getType();
Sebastian Redl19c74d32009-01-16 23:28:06 +0000542
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000543 if (getLangOptions().CPlusPlus) {
544 if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4
Sebastian Redl19c74d32009-01-16 23:28:06 +0000545 return StmtError();
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000546 } else if (!condType->isScalarType()) // C99 6.8.5p2
Sebastian Redl19c74d32009-01-16 23:28:06 +0000547 return StmtError(Diag(WhileLoc,
548 diag::err_typecheck_statement_requires_scalar)
549 << condType << condExpr->getSourceRange());
Chris Lattner4b009652007-07-25 00:24:17 +0000550
Sebastian Redl19c74d32009-01-16 23:28:06 +0000551 Cond.release();
552 return Owned(new WhileStmt(condExpr, (Stmt*)Body.release(), WhileLoc));
Chris Lattner4b009652007-07-25 00:24:17 +0000553}
554
Sebastian Redl19c74d32009-01-16 23:28:06 +0000555Action::OwningStmtResult
556Sema::ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
557 SourceLocation WhileLoc, ExprArg Cond) {
558 Expr *condExpr = (Expr *)Cond.release();
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000559 assert(condExpr && "ActOnDoStmt(): missing expression");
Sebastian Redl19c74d32009-01-16 23:28:06 +0000560
Chris Lattner4b009652007-07-25 00:24:17 +0000561 DefaultFunctionArrayConversion(condExpr);
Sebastian Redl19c74d32009-01-16 23:28:06 +0000562 Cond = condExpr;
Chris Lattner4b009652007-07-25 00:24:17 +0000563 QualType condType = condExpr->getType();
Sebastian Redl19c74d32009-01-16 23:28:06 +0000564
Argiris Kirtzidisc362d382008-09-11 05:16:22 +0000565 if (getLangOptions().CPlusPlus) {
566 if (CheckCXXBooleanCondition(condExpr)) // C++ 6.4p4
Sebastian Redl19c74d32009-01-16 23:28:06 +0000567 return StmtError();
Argiris Kirtzidisc362d382008-09-11 05:16:22 +0000568 } else if (!condType->isScalarType()) // C99 6.8.5p2
Sebastian Redl19c74d32009-01-16 23:28:06 +0000569 return StmtError(Diag(DoLoc, diag::err_typecheck_statement_requires_scalar)
570 << condType << condExpr->getSourceRange());
Chris Lattner4b009652007-07-25 00:24:17 +0000571
Sebastian Redl19c74d32009-01-16 23:28:06 +0000572 Cond.release();
573 return Owned(new DoStmt((Stmt*)Body.release(), condExpr, DoLoc));
Chris Lattner4b009652007-07-25 00:24:17 +0000574}
575
Sebastian Redl19c74d32009-01-16 23:28:06 +0000576Action::OwningStmtResult
577Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
578 StmtArg first, ExprArg second, ExprArg third,
579 SourceLocation RParenLoc, StmtArg body) {
580 Stmt *First = static_cast<Stmt*>(first.get());
581 Expr *Second = static_cast<Expr*>(second.get());
582 Expr *Third = static_cast<Expr*>(third.get());
583 Stmt *Body = static_cast<Stmt*>(body.get());
584
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000585 if (!getLangOptions().CPlusPlus) {
586 if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
Chris Lattner10f2c2e2008-11-20 06:38:18 +0000587 // C99 6.8.5p3: The declaration part of a 'for' statement shall only
588 // declare identifiers for objects having storage class 'auto' or
589 // 'register'.
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000590 for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE=DS->decl_end();
591 DI!=DE; ++DI) {
592 VarDecl *VD = dyn_cast<VarDecl>(*DI);
593 if (VD && VD->isBlockVarDecl() && !VD->hasLocalStorage())
594 VD = 0;
595 if (VD == 0)
596 Diag((*DI)->getLocation(), diag::err_non_variable_decl_in_for);
597 // FIXME: mark decl erroneous!
598 }
Chris Lattner06611052007-08-28 05:03:08 +0000599 }
Chris Lattner4b009652007-07-25 00:24:17 +0000600 }
601 if (Second) {
Chris Lattner3332fbd2007-08-28 04:55:47 +0000602 DefaultFunctionArrayConversion(Second);
603 QualType SecondType = Second->getType();
Sebastian Redl19c74d32009-01-16 23:28:06 +0000604
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000605 if (getLangOptions().CPlusPlus) {
606 if (CheckCXXBooleanCondition(Second)) // C++ 6.4p4
Sebastian Redl19c74d32009-01-16 23:28:06 +0000607 return StmtError();
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +0000608 } else if (!SecondType->isScalarType()) // C99 6.8.5p2
Sebastian Redl19c74d32009-01-16 23:28:06 +0000609 return StmtError(Diag(ForLoc,
610 diag::err_typecheck_statement_requires_scalar)
611 << SecondType << Second->getSourceRange());
Chris Lattner4b009652007-07-25 00:24:17 +0000612 }
Sebastian Redl19c74d32009-01-16 23:28:06 +0000613 first.release();
614 second.release();
615 third.release();
616 body.release();
617 return Owned(new ForStmt(First, Second, Third, Body, ForLoc));
Chris Lattner4b009652007-07-25 00:24:17 +0000618}
619
Sebastian Redl19c74d32009-01-16 23:28:06 +0000620Action::OwningStmtResult
621Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
622 SourceLocation LParenLoc,
623 StmtArg first, ExprArg second,
624 SourceLocation RParenLoc, StmtArg body) {
625 Stmt *First = static_cast<Stmt*>(first.get());
626 Expr *Second = static_cast<Expr*>(second.get());
627 Stmt *Body = static_cast<Stmt*>(body.get());
Fariborz Jahanian6833b3b2008-01-10 20:33:58 +0000628 if (First) {
629 QualType FirstType;
630 if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
Ted Kremenek779e1c22008-10-06 20:58:11 +0000631 if (!DS->hasSolitaryDecl())
Sebastian Redl19c74d32009-01-16 23:28:06 +0000632 return StmtError(Diag((*DS->decl_begin())->getLocation(),
633 diag::err_toomany_element_decls));
634
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000635 Decl *D = DS->getSolitaryDecl();
Ted Kremenek779e1c22008-10-06 20:58:11 +0000636 FirstType = cast<ValueDecl>(D)->getType();
Chris Lattner10f2c2e2008-11-20 06:38:18 +0000637 // C99 6.8.5p3: The declaration part of a 'for' statement shall only
638 // declare identifiers for objects having storage class 'auto' or
639 // 'register'.
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000640 VarDecl *VD = cast<VarDecl>(D);
641 if (VD->isBlockVarDecl() && !VD->hasLocalStorage())
Sebastian Redl19c74d32009-01-16 23:28:06 +0000642 return StmtError(Diag(VD->getLocation(),
643 diag::err_non_variable_decl_in_for));
Anders Carlsson8d0bcb02008-08-25 18:16:36 +0000644 } else {
645 Expr::isLvalueResult lval = cast<Expr>(First)->isLvalue(Context);
Anders Carlsson8d0bcb02008-08-25 18:16:36 +0000646
Sebastian Redl19c74d32009-01-16 23:28:06 +0000647 if (lval != Expr::LV_Valid)
648 return StmtError(Diag(First->getLocStart(),
649 diag::err_selector_element_not_lvalue)
650 << First->getSourceRange());
651
652 FirstType = static_cast<Expr*>(First)->getType();
Anders Carlsson8d0bcb02008-08-25 18:16:36 +0000653 }
Ted Kremenek118930e2008-07-24 23:58:27 +0000654 if (!Context.isObjCObjectPointerType(FirstType))
Chris Lattner9d2cf082008-11-19 05:27:50 +0000655 Diag(ForLoc, diag::err_selector_element_type)
Chris Lattner4bfd2232008-11-24 06:25:27 +0000656 << FirstType << First->getSourceRange();
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000657 }
658 if (Second) {
659 DefaultFunctionArrayConversion(Second);
660 QualType SecondType = Second->getType();
Ted Kremenek118930e2008-07-24 23:58:27 +0000661 if (!Context.isObjCObjectPointerType(SecondType))
Chris Lattner9d2cf082008-11-19 05:27:50 +0000662 Diag(ForLoc, diag::err_collection_expr_type)
Chris Lattner4bfd2232008-11-24 06:25:27 +0000663 << SecondType << Second->getSourceRange();
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000664 }
Sebastian Redl19c74d32009-01-16 23:28:06 +0000665 first.release();
666 second.release();
667 body.release();
668 return Owned(new ObjCForCollectionStmt(First, Second, Body,
669 ForLoc, RParenLoc));
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000670}
Chris Lattner4b009652007-07-25 00:24:17 +0000671
Sebastian Redl539eb572009-01-18 13:19:59 +0000672Action::OwningStmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000673Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000674 IdentifierInfo *LabelII) {
Steve Naroff52a81c02008-09-03 18:15:37 +0000675 // If we are in a block, reject all gotos for now.
676 if (CurBlock)
Sebastian Redl539eb572009-01-18 13:19:59 +0000677 return StmtError(Diag(GotoLoc, diag::err_goto_in_block));
Steve Naroff52a81c02008-09-03 18:15:37 +0000678
Chris Lattner4b009652007-07-25 00:24:17 +0000679 // Look up the record for this label identifier.
680 LabelStmt *&LabelDecl = LabelMap[LabelII];
681
682 // If we haven't seen this label yet, create a forward reference.
683 if (LabelDecl == 0)
684 LabelDecl = new LabelStmt(LabelLoc, LabelII, 0);
Sebastian Redl539eb572009-01-18 13:19:59 +0000685
686 return Owned(new GotoStmt(LabelDecl, GotoLoc, LabelLoc));
Chris Lattner4b009652007-07-25 00:24:17 +0000687}
688
Sebastian Redl539eb572009-01-18 13:19:59 +0000689Action::OwningStmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000690Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
Sebastian Redl539eb572009-01-18 13:19:59 +0000691 ExprArg DestExp) {
Chris Lattner4b009652007-07-25 00:24:17 +0000692 // FIXME: Verify that the operand is convertible to void*.
Sebastian Redl539eb572009-01-18 13:19:59 +0000693
694 return Owned(new IndirectGotoStmt((Expr*)DestExp.release()));
Chris Lattner4b009652007-07-25 00:24:17 +0000695}
696
Sebastian Redl539eb572009-01-18 13:19:59 +0000697Action::OwningStmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000698Sema::ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) {
Chris Lattner4b009652007-07-25 00:24:17 +0000699 Scope *S = CurScope->getContinueParent();
700 if (!S) {
701 // C99 6.8.6.2p1: A break shall appear only in or as a loop body.
Sebastian Redl539eb572009-01-18 13:19:59 +0000702 return StmtError(Diag(ContinueLoc, diag::err_continue_not_in_loop));
Chris Lattner4b009652007-07-25 00:24:17 +0000703 }
Sebastian Redl539eb572009-01-18 13:19:59 +0000704
705 return Owned(new ContinueStmt(ContinueLoc));
Chris Lattner4b009652007-07-25 00:24:17 +0000706}
707
Sebastian Redl539eb572009-01-18 13:19:59 +0000708Action::OwningStmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000709Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
Chris Lattner4b009652007-07-25 00:24:17 +0000710 Scope *S = CurScope->getBreakParent();
711 if (!S) {
712 // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
Sebastian Redl539eb572009-01-18 13:19:59 +0000713 return StmtError(Diag(BreakLoc, diag::err_break_not_in_loop_or_switch));
Chris Lattner4b009652007-07-25 00:24:17 +0000714 }
Sebastian Redl539eb572009-01-18 13:19:59 +0000715
716 return Owned(new BreakStmt(BreakLoc));
Chris Lattner4b009652007-07-25 00:24:17 +0000717}
718
Douglas Gregor81c29152008-10-29 00:13:59 +0000719/// ActOnBlockReturnStmt - Utility routine to figure out block's return type.
Steve Naroff52a81c02008-09-03 18:15:37 +0000720///
Sebastian Redl539eb572009-01-18 13:19:59 +0000721Action::OwningStmtResult
Steve Naroff52a81c02008-09-03 18:15:37 +0000722Sema::ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp) {
Sebastian Redl539eb572009-01-18 13:19:59 +0000723
Steve Naroff52a81c02008-09-03 18:15:37 +0000724 // If this is the first return we've seen in the block, infer the type of
725 // the block from it.
726 if (CurBlock->ReturnType == 0) {
Steve Naroff503996b2008-09-16 22:25:10 +0000727 if (RetValExp) {
Steve Naroffe2b66a82008-09-24 22:26:48 +0000728 // Don't call UsualUnaryConversions(), since we don't want to do
729 // integer promotions here.
730 DefaultFunctionArrayConversion(RetValExp);
Steve Naroff52a81c02008-09-03 18:15:37 +0000731 CurBlock->ReturnType = RetValExp->getType().getTypePtr();
Steve Naroff503996b2008-09-16 22:25:10 +0000732 } else
Steve Naroff52a81c02008-09-03 18:15:37 +0000733 CurBlock->ReturnType = Context.VoidTy.getTypePtr();
Steve Naroff52a81c02008-09-03 18:15:37 +0000734 }
Mike Stumpc1fddff2009-02-04 22:31:32 +0000735 QualType FnRetType = QualType(CurBlock->ReturnType, 0);
Sebastian Redl539eb572009-01-18 13:19:59 +0000736
Steve Naroff52a81c02008-09-03 18:15:37 +0000737 // Otherwise, verify that this result type matches the previous one. We are
738 // pickier with blocks than for normal functions because we don't have GCC
739 // compatibility to worry about here.
740 if (CurBlock->ReturnType->isVoidType()) {
741 if (RetValExp) {
742 Diag(ReturnLoc, diag::err_return_block_has_expr);
743 delete RetValExp;
744 RetValExp = 0;
745 }
Sebastian Redl539eb572009-01-18 13:19:59 +0000746 return Owned(new ReturnStmt(ReturnLoc, RetValExp));
Steve Naroff52a81c02008-09-03 18:15:37 +0000747 }
Sebastian Redl539eb572009-01-18 13:19:59 +0000748
749 if (!RetValExp)
750 return StmtError(Diag(ReturnLoc, diag::err_block_return_missing_expr));
751
Mike Stumpc1fddff2009-02-04 22:31:32 +0000752 if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
753 // we have a non-void block with an expression, continue checking
754 QualType RetValType = RetValExp->getType();
Sebastian Redl539eb572009-01-18 13:19:59 +0000755
Mike Stumpc1fddff2009-02-04 22:31:32 +0000756 // C99 6.8.6.4p3(136): The return statement is not an assignment. The
757 // overlap restriction of subclause 6.5.16.1 does not apply to the case of
758 // function return.
759
760 // In C++ the return statement is handled via a copy initialization.
761 // the C version of which boils down to CheckSingleAssignmentConstraints.
762 // FIXME: Leaks RetValExp.
763 if (PerformCopyInitialization(RetValExp, FnRetType, "returning"))
764 return StmtError();
765
766 if (RetValExp) CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
Steve Naroff52a81c02008-09-03 18:15:37 +0000767 }
Sebastian Redl539eb572009-01-18 13:19:59 +0000768
Sebastian Redl539eb572009-01-18 13:19:59 +0000769 return Owned(new ReturnStmt(ReturnLoc, RetValExp));
Steve Naroff52a81c02008-09-03 18:15:37 +0000770}
Chris Lattner4b009652007-07-25 00:24:17 +0000771
Sebastian Redl539eb572009-01-18 13:19:59 +0000772Action::OwningStmtResult
773Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) {
774 Expr *RetValExp = static_cast<Expr *>(rex.release());
Steve Naroff52a81c02008-09-03 18:15:37 +0000775 if (CurBlock)
776 return ActOnBlockReturnStmt(ReturnLoc, RetValExp);
Sebastian Redl539eb572009-01-18 13:19:59 +0000777
Chris Lattnere5cb5862008-12-04 23:50:19 +0000778 QualType FnRetType;
779 if (FunctionDecl *FD = getCurFunctionDecl())
780 FnRetType = FD->getResultType();
781 else
782 FnRetType = getCurMethodDecl()->getResultType();
Chris Lattner4b009652007-07-25 00:24:17 +0000783
Chris Lattner005ed752008-01-04 18:04:52 +0000784 if (FnRetType->isVoidType()) {
Chris Lattner65cae292008-11-19 08:23:25 +0000785 if (RetValExp) {// C99 6.8.6.4p1 (ext_ since GCC warns)
Chris Lattner6ed167c2008-12-18 02:01:17 +0000786 unsigned D = diag::ext_return_has_expr;
787 if (RetValExp->getType()->isVoidType())
788 D = diag::ext_return_has_void_expr;
Sebastian Redl539eb572009-01-18 13:19:59 +0000789
Chris Lattnerd1a05392008-12-18 02:03:48 +0000790 // return (some void expression); is legal in C++.
791 if (D != diag::ext_return_has_void_expr ||
792 !getLangOptions().CPlusPlus) {
793 NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
794 Diag(ReturnLoc, D)
795 << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
796 << RetValExp->getSourceRange();
797 }
Chris Lattner4b009652007-07-25 00:24:17 +0000798 }
Sebastian Redl539eb572009-01-18 13:19:59 +0000799 return Owned(new ReturnStmt(ReturnLoc, RetValExp));
Chris Lattner4b009652007-07-25 00:24:17 +0000800 }
Sebastian Redl539eb572009-01-18 13:19:59 +0000801
Chris Lattner65cae292008-11-19 08:23:25 +0000802 if (!RetValExp) {
803 unsigned DiagID = diag::warn_return_missing_expr; // C90 6.6.6.4p4
804 // C99 6.8.6.4p1 (ext_ since GCC warns)
805 if (getLangOptions().C99) DiagID = diag::ext_return_missing_expr;
806
807 if (FunctionDecl *FD = getCurFunctionDecl())
Chris Lattnerb1753422008-11-23 21:45:46 +0000808 Diag(ReturnLoc, DiagID) << FD->getIdentifier() << 0/*fn*/;
Chris Lattner65cae292008-11-19 08:23:25 +0000809 else
Chris Lattnerb1753422008-11-23 21:45:46 +0000810 Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 1/*meth*/;
Sebastian Redl539eb572009-01-18 13:19:59 +0000811 return Owned(new ReturnStmt(ReturnLoc, (Expr*)0));
Chris Lattner65cae292008-11-19 08:23:25 +0000812 }
Sebastian Redl539eb572009-01-18 13:19:59 +0000813
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000814 if (!FnRetType->isDependentType() && !RetValExp->isTypeDependent()) {
815 // we have a non-void function with an expression, continue checking
816 QualType RetValType = RetValExp->getType();
Sebastian Redl539eb572009-01-18 13:19:59 +0000817
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000818 // C99 6.8.6.4p3(136): The return statement is not an assignment. The
819 // overlap restriction of subclause 6.5.16.1 does not apply to the case of
Sebastian Redl539eb572009-01-18 13:19:59 +0000820 // function return.
821
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000822 // In C++ the return statement is handled via a copy initialization.
Sebastian Redl539eb572009-01-18 13:19:59 +0000823 // the C version of which boils down to CheckSingleAssignmentConstraints.
824 // FIXME: Leaks RetValExp.
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000825 if (PerformCopyInitialization(RetValExp, FnRetType, "returning"))
Sebastian Redl539eb572009-01-18 13:19:59 +0000826 return StmtError();
827
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000828 if (RetValExp) CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
829 }
830
Sebastian Redl539eb572009-01-18 13:19:59 +0000831 return Owned(new ReturnStmt(ReturnLoc, RetValExp));
Chris Lattner4b009652007-07-25 00:24:17 +0000832}
833
Sebastian Redlc6b86332009-01-18 16:53:17 +0000834Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
835 bool IsSimple,
836 bool IsVolatile,
837 unsigned NumOutputs,
838 unsigned NumInputs,
839 std::string *Names,
840 MultiExprArg constraints,
841 MultiExprArg exprs,
842 ExprArg asmString,
843 MultiExprArg clobbers,
844 SourceLocation RParenLoc) {
845 unsigned NumClobbers = clobbers.size();
846 StringLiteral **Constraints =
847 reinterpret_cast<StringLiteral**>(constraints.get());
848 Expr **Exprs = reinterpret_cast<Expr **>(exprs.get());
849 StringLiteral *AsmString = cast<StringLiteral>((Expr *)asmString.get());
850 StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.get());
851
Anders Carlssondd3a4fe2009-01-27 20:38:24 +0000852 llvm::SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
853
Chris Lattnerb052a832008-08-18 19:55:17 +0000854 // The parser verifies that there is a string literal here.
Chris Lattner84418022008-07-23 06:46:56 +0000855 if (AsmString->isWide())
Sebastian Redlc6b86332009-01-18 16:53:17 +0000856 return StmtError(Diag(AsmString->getLocStart(),diag::err_asm_wide_character)
857 << AsmString->getSourceRange());
858
859
Chris Lattnerb052a832008-08-18 19:55:17 +0000860 for (unsigned i = 0; i != NumOutputs; i++) {
861 StringLiteral *Literal = Constraints[i];
Chris Lattner84418022008-07-23 06:46:56 +0000862 if (Literal->isWide())
Sebastian Redlc6b86332009-01-18 16:53:17 +0000863 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
864 << Literal->getSourceRange());
865
Anders Carlsson4ce42302007-11-27 04:11:28 +0000866 std::string OutputConstraint(Literal->getStrData(),
867 Literal->getByteLength());
Sebastian Redlc6b86332009-01-18 16:53:17 +0000868
Anders Carlsson4ce42302007-11-27 04:11:28 +0000869 TargetInfo::ConstraintInfo info;
Chris Lattner84418022008-07-23 06:46:56 +0000870 if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info))
Sebastian Redlc6b86332009-01-18 16:53:17 +0000871 return StmtError(Diag(Literal->getLocStart(),
872 diag::err_asm_invalid_output_constraint) << OutputConstraint);
873
Anders Carlsson4ce42302007-11-27 04:11:28 +0000874 // Check that the output exprs are valid lvalues.
Chris Lattnerb052a832008-08-18 19:55:17 +0000875 ParenExpr *OutputExpr = cast<ParenExpr>(Exprs[i]);
Chris Lattner25168a52008-07-26 21:30:36 +0000876 Expr::isLvalueResult Result = OutputExpr->isLvalue(Context);
Anders Carlssonb4487a82007-11-23 19:43:50 +0000877 if (Result != Expr::LV_Valid) {
Sebastian Redlc6b86332009-01-18 16:53:17 +0000878 return StmtError(Diag(OutputExpr->getSubExpr()->getLocStart(),
Chris Lattner9d2cf082008-11-19 05:27:50 +0000879 diag::err_asm_invalid_lvalue_in_output)
Sebastian Redlc6b86332009-01-18 16:53:17 +0000880 << OutputExpr->getSubExpr()->getSourceRange());
Anders Carlssonb4487a82007-11-23 19:43:50 +0000881 }
Anders Carlssondd3a4fe2009-01-27 20:38:24 +0000882
883 OutputConstraintInfos.push_back(info);
Anders Carlssonb4487a82007-11-23 19:43:50 +0000884 }
Sebastian Redlc6b86332009-01-18 16:53:17 +0000885
Anders Carlssonb4487a82007-11-23 19:43:50 +0000886 for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
Chris Lattnerb052a832008-08-18 19:55:17 +0000887 StringLiteral *Literal = Constraints[i];
Chris Lattner84418022008-07-23 06:46:56 +0000888 if (Literal->isWide())
Sebastian Redlc6b86332009-01-18 16:53:17 +0000889 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
890 << Literal->getSourceRange());
891
892 std::string InputConstraint(Literal->getStrData(),
Anders Carlsson4ce42302007-11-27 04:11:28 +0000893 Literal->getByteLength());
Sebastian Redlc6b86332009-01-18 16:53:17 +0000894
Anders Carlsson4ce42302007-11-27 04:11:28 +0000895 TargetInfo::ConstraintInfo info;
896 if (!Context.Target.validateInputConstraint(InputConstraint.c_str(),
Anders Carlsson7b49cec2009-01-17 23:36:15 +0000897 &Names[0],
Anders Carlssondd3a4fe2009-01-27 20:38:24 +0000898 &Names[0] + NumOutputs,
899 &OutputConstraintInfos[0],
900 info)) {
Sebastian Redlc6b86332009-01-18 16:53:17 +0000901 return StmtError(Diag(Literal->getLocStart(),
902 diag::err_asm_invalid_input_constraint) << InputConstraint);
Anders Carlsson4ce42302007-11-27 04:11:28 +0000903 }
Sebastian Redlc6b86332009-01-18 16:53:17 +0000904
Chris Lattnerb052a832008-08-18 19:55:17 +0000905 ParenExpr *InputExpr = cast<ParenExpr>(Exprs[i]);
Sebastian Redlc6b86332009-01-18 16:53:17 +0000906
Anders Carlssone7d92702009-01-20 20:49:22 +0000907 // Only allow void types for memory constraints.
Anders Carlssonde93d332009-01-21 06:27:20 +0000908 if ((info & TargetInfo::CI_AllowsMemory)
909 && !(info & TargetInfo::CI_AllowsRegister)) {
Anders Carlssone7d92702009-01-20 20:49:22 +0000910 if (InputExpr->isLvalue(Context) != Expr::LV_Valid)
911 return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(),
912 diag::err_asm_invalid_lvalue_in_input)
913 << InputConstraint << InputExpr->getSubExpr()->getSourceRange());
Anders Carlssonb4487a82007-11-23 19:43:50 +0000914 }
Sebastian Redlc6b86332009-01-18 16:53:17 +0000915
Anders Carlssone7d92702009-01-20 20:49:22 +0000916 if (info & TargetInfo::CI_AllowsRegister) {
917 if (InputExpr->getType()->isVoidType()) {
918 return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(),
919 diag::err_asm_invalid_type_in_input)
920 << InputExpr->getType() << InputConstraint
921 << InputExpr->getSubExpr()->getSourceRange());
922 }
923
Anders Carlssonc06c2792008-12-31 07:27:38 +0000924 DefaultFunctionArrayConversion(Exprs[i]);
Anders Carlssone7d92702009-01-20 20:49:22 +0000925 }
Anders Carlssonb4487a82007-11-23 19:43:50 +0000926 }
Sebastian Redlc6b86332009-01-18 16:53:17 +0000927
Anders Carlsson49dadd62007-11-25 00:25:21 +0000928 // Check that the clobbers are valid.
Chris Lattnerb052a832008-08-18 19:55:17 +0000929 for (unsigned i = 0; i != NumClobbers; i++) {
930 StringLiteral *Literal = Clobbers[i];
Chris Lattner84418022008-07-23 06:46:56 +0000931 if (Literal->isWide())
Sebastian Redlc6b86332009-01-18 16:53:17 +0000932 return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
933 << Literal->getSourceRange());
934
935 llvm::SmallString<16> Clobber(Literal->getStrData(),
936 Literal->getStrData() +
Anders Carlsson49dadd62007-11-25 00:25:21 +0000937 Literal->getByteLength());
Sebastian Redlc6b86332009-01-18 16:53:17 +0000938
Chris Lattner84418022008-07-23 06:46:56 +0000939 if (!Context.Target.isValidGCCRegisterName(Clobber.c_str()))
Sebastian Redlc6b86332009-01-18 16:53:17 +0000940 return StmtError(Diag(Literal->getLocStart(),
941 diag::err_asm_unknown_register_name) << Clobber.c_str());
Anders Carlsson49dadd62007-11-25 00:25:21 +0000942 }
Sebastian Redlc6b86332009-01-18 16:53:17 +0000943
944 constraints.release();
945 exprs.release();
946 asmString.release();
947 clobbers.release();
948 return Owned(new AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs,
949 Names, Constraints, Exprs, AsmString, NumClobbers,
950 Clobbers, RParenLoc));
Chris Lattner8a40a832007-10-29 04:04:16 +0000951}
Fariborz Jahanian06798362007-11-01 23:59:59 +0000952
Sebastian Redlb3860a72009-01-18 17:43:11 +0000953Action::OwningStmtResult
954Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc,
955 SourceLocation RParen, StmtArg Parm,
956 StmtArg Body, StmtArg catchList) {
957 Stmt *CatchList = static_cast<Stmt*>(catchList.release());
958 ObjCAtCatchStmt *CS = new ObjCAtCatchStmt(AtLoc, RParen,
959 static_cast<Stmt*>(Parm.release()), static_cast<Stmt*>(Body.release()),
960 CatchList);
961 return Owned(CatchList ? CatchList : CS);
Fariborz Jahanian06798362007-11-01 23:59:59 +0000962}
963
Sebastian Redlb3860a72009-01-18 17:43:11 +0000964Action::OwningStmtResult
965Sema::ActOnObjCAtFinallyStmt(SourceLocation AtLoc, StmtArg Body) {
966 return Owned(new ObjCAtFinallyStmt(AtLoc,
967 static_cast<Stmt*>(Body.release())));
Fariborz Jahaniande3abf82007-11-02 00:18:53 +0000968}
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000969
Sebastian Redlb3860a72009-01-18 17:43:11 +0000970Action::OwningStmtResult
971Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc,
972 StmtArg Try, StmtArg Catch, StmtArg Finally) {
973 return Owned(new ObjCAtTryStmt(AtLoc, static_cast<Stmt*>(Try.release()),
974 static_cast<Stmt*>(Catch.release()),
975 static_cast<Stmt*>(Finally.release())));
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000976}
977
Sebastian Redlb3860a72009-01-18 17:43:11 +0000978Action::OwningStmtResult
979Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg Throw) {
980 return Owned(new ObjCAtThrowStmt(AtLoc, static_cast<Expr*>(Throw.release())));
Fariborz Jahanian08df2c62007-11-07 02:00:49 +0000981}
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000982
Sebastian Redlb3860a72009-01-18 17:43:11 +0000983Action::OwningStmtResult
984Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprArg SynchExpr,
985 StmtArg SynchBody) {
986 return Owned(new ObjCAtSynchronizedStmt(AtLoc,
987 static_cast<Stmt*>(SynchExpr.release()),
988 static_cast<Stmt*>(SynchBody.release())));
Fariborz Jahanianc9fd4d12008-01-29 19:14:59 +0000989}
Sebastian Redl743c8162008-12-22 19:15:10 +0000990
991/// ActOnCXXCatchBlock - Takes an exception declaration and a handler block
992/// and creates a proper catch handler from them.
993Action::OwningStmtResult
994Sema::ActOnCXXCatchBlock(SourceLocation CatchLoc, DeclTy *ExDecl,
995 StmtArg HandlerBlock) {
996 // There's nothing to test that ActOnExceptionDecl didn't already test.
997 return Owned(new CXXCatchStmt(CatchLoc, static_cast<VarDecl*>(ExDecl),
998 static_cast<Stmt*>(HandlerBlock.release())));
999}
Sebastian Redl237116b2008-12-22 21:35:02 +00001000
1001/// ActOnCXXTryBlock - Takes a try compound-statement and a number of
1002/// handlers and creates a try statement from them.
1003Action::OwningStmtResult
1004Sema::ActOnCXXTryBlock(SourceLocation TryLoc, StmtArg TryBlock,
1005 MultiStmtArg RawHandlers) {
1006 unsigned NumHandlers = RawHandlers.size();
1007 assert(NumHandlers > 0 &&
1008 "The parser shouldn't call this if there are no handlers.");
1009 Stmt **Handlers = reinterpret_cast<Stmt**>(RawHandlers.get());
1010
1011 for(unsigned i = 0; i < NumHandlers - 1; ++i) {
1012 CXXCatchStmt *Handler = llvm::cast<CXXCatchStmt>(Handlers[i]);
1013 if (!Handler->getExceptionDecl())
1014 return StmtError(Diag(Handler->getLocStart(), diag::err_early_catch_all));
1015 }
1016 // FIXME: We should detect handlers for the same type as an earlier one.
1017 // This one is rather easy.
1018 // FIXME: We should detect handlers that cannot catch anything because an
1019 // earlier handler catches a superclass. Need to find a method that is not
1020 // quadratic for this.
1021 // Neither of these are explicitly forbidden, but every compiler detects them
1022 // and warns.
1023
1024 RawHandlers.release();
1025 return Owned(new CXXTryStmt(TryLoc, static_cast<Stmt*>(TryBlock.release()),
1026 Handlers, NumHandlers));
1027}