blob: 5ed77f4c6df5ad858953b3fcc24aaf3710c95529 [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"
Chris Lattner3429a812007-08-23 05:46:52 +000015#include "clang/AST/ASTContext.h"
Daniel Dunbar64789f82008-08-11 05:35:13 +000016#include "clang/AST/DeclObjC.h"
Chris Lattner4b009652007-07-25 00:24:17 +000017#include "clang/AST/Expr.h"
Chris Lattner3429a812007-08-23 05:46:52 +000018#include "clang/AST/Stmt.h"
Chris Lattner4b009652007-07-25 00:24:17 +000019#include "clang/Parse/Scope.h"
Anders Carlsson49dadd62007-11-25 00:25:21 +000020#include "clang/Basic/TargetInfo.h"
Chris Lattner4b009652007-07-25 00:24:17 +000021#include "clang/Basic/Diagnostic.h"
22#include "clang/Basic/LangOptions.h"
Anders Carlsson49dadd62007-11-25 00:25:21 +000023#include "llvm/ADT/SmallString.h"
Chris Lattner4b009652007-07-25 00:24:17 +000024using namespace clang;
25
Steve Naroff5cbb02f2007-09-16 14:56:35 +000026Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) {
Chris Lattner4b009652007-07-25 00:24:17 +000027 Expr *E = static_cast<Expr*>(expr);
Steve Naroff5cbb02f2007-09-16 14:56:35 +000028 assert(E && "ActOnExprStmt(): missing expression");
Chris Lattnere02e4402008-07-25 23:18:17 +000029
30 // C99 6.8.3p2: The expression in an expression statement is evaluated as a
31 // void expression for its side effects. Conversion to void allows any
32 // operand, even incomplete types.
33
34 // Same thing in for stmt first clause (when expr) and third clause.
Chris Lattner4b009652007-07-25 00:24:17 +000035 return E;
36}
37
38
Steve Naroff5cbb02f2007-09-16 14:56:35 +000039Sema::StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) {
Chris Lattner4b009652007-07-25 00:24:17 +000040 return new NullStmt(SemiLoc);
41}
42
Chris Lattnera4ff4272008-03-13 06:29:04 +000043Sema::StmtResult Sema::ActOnDeclStmt(DeclTy *decl, SourceLocation StartLoc,
44 SourceLocation EndLoc) {
45 if (decl == 0)
46 return true;
47
48 ScopedDecl *SD = cast<ScopedDecl>(static_cast<Decl *>(decl));
49 return new DeclStmt(SD, StartLoc, EndLoc);
Chris Lattner4b009652007-07-25 00:24:17 +000050}
51
52Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +000053Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattnerf2b07572007-08-31 21:49:55 +000054 StmtTy **elts, unsigned NumElts, bool isStmtExpr) {
Chris Lattner3ea3b662007-08-27 04:29:41 +000055 Stmt **Elts = reinterpret_cast<Stmt**>(elts);
56 // If we're in C89 mode, check that we don't have any decls after stmts. If
57 // so, emit an extension diagnostic.
58 if (!getLangOptions().C99 && !getLangOptions().CPlusPlus) {
59 // Note that __extension__ can be around a decl.
60 unsigned i = 0;
61 // Skip over all declarations.
62 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
63 /*empty*/;
64
65 // We found the end of the list or a statement. Scan for another declstmt.
66 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
67 /*empty*/;
68
69 if (i != NumElts) {
Steve Naroffcb597472007-09-13 21:41:19 +000070 ScopedDecl *D = cast<DeclStmt>(Elts[i])->getDecl();
Chris Lattner3ea3b662007-08-27 04:29:41 +000071 Diag(D->getLocation(), diag::ext_mixed_decls_code);
72 }
73 }
Chris Lattnerf2b07572007-08-31 21:49:55 +000074 // Warn about unused expressions in statements.
75 for (unsigned i = 0; i != NumElts; ++i) {
76 Expr *E = dyn_cast<Expr>(Elts[i]);
77 if (!E) continue;
78
79 // Warn about expressions with unused results.
80 if (E->hasLocalSideEffect() || E->getType()->isVoidType())
81 continue;
82
83 // The last expr in a stmt expr really is used.
84 if (isStmtExpr && i == NumElts-1)
85 continue;
86
87 /// DiagnoseDeadExpr - This expression is side-effect free and evaluated in
88 /// a context where the result is unused. Emit a diagnostic to warn about
89 /// this.
90 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E))
91 Diag(BO->getOperatorLoc(), diag::warn_unused_expr,
92 BO->getLHS()->getSourceRange(), BO->getRHS()->getSourceRange());
93 else if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E))
94 Diag(UO->getOperatorLoc(), diag::warn_unused_expr,
95 UO->getSubExpr()->getSourceRange());
96 else
97 Diag(E->getExprLoc(), diag::warn_unused_expr, E->getSourceRange());
98 }
99
Steve Naroff5d2fff82007-08-31 23:28:33 +0000100 return new CompoundStmt(Elts, NumElts, L, R);
Chris Lattner4b009652007-07-25 00:24:17 +0000101}
102
103Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000104Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval,
Chris Lattner4b009652007-07-25 00:24:17 +0000105 SourceLocation DotDotDotLoc, ExprTy *rhsval,
106 SourceLocation ColonLoc, StmtTy *subStmt) {
107 Stmt *SubStmt = static_cast<Stmt*>(subStmt);
108 Expr *LHSVal = ((Expr *)lhsval), *RHSVal = ((Expr *)rhsval);
109 assert((LHSVal != 0) && "missing expression in case statement");
110
111 SourceLocation ExpLoc;
112 // C99 6.8.4.2p3: The expression shall be an integer constant.
113 if (!LHSVal->isIntegerConstantExpr(Context, &ExpLoc)) {
114 Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr,
115 LHSVal->getSourceRange());
116 return SubStmt;
117 }
118
119 // GCC extension: The expression shall be an integer constant.
120 if (RHSVal && !RHSVal->isIntegerConstantExpr(Context, &ExpLoc)) {
121 Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr,
122 RHSVal->getSourceRange());
Chris Lattner3429a812007-08-23 05:46:52 +0000123 RHSVal = 0; // Recover by just forgetting about it.
Chris Lattner4b009652007-07-25 00:24:17 +0000124 }
125
126 if (SwitchStack.empty()) {
127 Diag(CaseLoc, diag::err_case_not_in_switch);
128 return SubStmt;
129 }
130
Steve Naroff5d2fff82007-08-31 23:28:33 +0000131 CaseStmt *CS = new CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000132 SwitchStack.back()->addSwitchCase(CS);
133 return CS;
134}
135
136Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000137Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000138 StmtTy *subStmt, Scope *CurScope) {
139 Stmt *SubStmt = static_cast<Stmt*>(subStmt);
140
141 if (SwitchStack.empty()) {
142 Diag(DefaultLoc, diag::err_default_not_in_switch);
143 return SubStmt;
144 }
145
146 DefaultStmt *DS = new DefaultStmt(DefaultLoc, SubStmt);
147 SwitchStack.back()->addSwitchCase(DS);
148
149 return DS;
150}
151
152Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000153Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
Chris Lattner4b009652007-07-25 00:24:17 +0000154 SourceLocation ColonLoc, StmtTy *subStmt) {
155 Stmt *SubStmt = static_cast<Stmt*>(subStmt);
156 // Look up the record for this label identifier.
157 LabelStmt *&LabelDecl = LabelMap[II];
158
159 // If not forward referenced or defined already, just create a new LabelStmt.
160 if (LabelDecl == 0)
161 return LabelDecl = new LabelStmt(IdentLoc, II, SubStmt);
162
163 assert(LabelDecl->getID() == II && "Label mismatch!");
164
165 // Otherwise, this label was either forward reference or multiply defined. If
166 // multiply defined, reject it now.
167 if (LabelDecl->getSubStmt()) {
168 Diag(IdentLoc, diag::err_redefinition_of_label, LabelDecl->getName());
169 Diag(LabelDecl->getIdentLoc(), diag::err_previous_definition);
170 return SubStmt;
171 }
172
173 // Otherwise, this label was forward declared, and we just found its real
174 // definition. Fill in the forward definition and return it.
175 LabelDecl->setIdentLoc(IdentLoc);
176 LabelDecl->setSubStmt(SubStmt);
177 return LabelDecl;
178}
179
180Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000181Sema::ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
Chris Lattner4b009652007-07-25 00:24:17 +0000182 StmtTy *ThenVal, SourceLocation ElseLoc,
183 StmtTy *ElseVal) {
184 Expr *condExpr = (Expr *)CondVal;
Anders Carlsson663733e2007-10-10 20:50:11 +0000185 Stmt *thenStmt = (Stmt *)ThenVal;
186
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000187 assert(condExpr && "ActOnIfStmt(): missing expression");
Chris Lattner4b009652007-07-25 00:24:17 +0000188
189 DefaultFunctionArrayConversion(condExpr);
190 QualType condType = condExpr->getType();
191
192 if (!condType->isScalarType()) // C99 6.8.4.1p1
193 return Diag(IfLoc, diag::err_typecheck_statement_requires_scalar,
194 condType.getAsString(), condExpr->getSourceRange());
195
Anders Carlsson663733e2007-10-10 20:50:11 +0000196 // Warn if the if block has a null body without an else value.
197 // this helps prevent bugs due to typos, such as
198 // if (condition);
199 // do_stuff();
200 if (!ElseVal) {
201 if (NullStmt* stmt = dyn_cast<NullStmt>(thenStmt))
202 Diag(stmt->getSemiLoc(), diag::warn_empty_if_body);
203 }
204
205 return new IfStmt(IfLoc, condExpr, thenStmt, (Stmt*)ElseVal);
Chris Lattner4b009652007-07-25 00:24:17 +0000206}
207
208Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000209Sema::ActOnStartOfSwitchStmt(ExprTy *cond) {
Chris Lattner3429a812007-08-23 05:46:52 +0000210 Expr *Cond = static_cast<Expr*>(cond);
211
212 // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr.
213 UsualUnaryConversions(Cond);
214
215 SwitchStmt *SS = new SwitchStmt(Cond);
Chris Lattner4b009652007-07-25 00:24:17 +0000216 SwitchStack.push_back(SS);
217 return SS;
218}
219
Chris Lattner3429a812007-08-23 05:46:52 +0000220/// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
221/// the specified width and sign. If an overflow occurs, detect it and emit
222/// the specified diagnostic.
223void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
224 unsigned NewWidth, bool NewSign,
225 SourceLocation Loc,
226 unsigned DiagID) {
227 // Perform a conversion to the promoted condition type if needed.
228 if (NewWidth > Val.getBitWidth()) {
229 // If this is an extension, just do it.
230 llvm::APSInt OldVal(Val);
231 Val.extend(NewWidth);
232
233 // If the input was signed and negative and the output is unsigned,
234 // warn.
235 if (!NewSign && OldVal.isSigned() && OldVal.isNegative())
236 Diag(Loc, DiagID, OldVal.toString(), Val.toString());
237
238 Val.setIsSigned(NewSign);
239 } else if (NewWidth < Val.getBitWidth()) {
240 // If this is a truncation, check for overflow.
241 llvm::APSInt ConvVal(Val);
242 ConvVal.trunc(NewWidth);
Chris Lattner5c039602007-08-23 22:08:35 +0000243 ConvVal.setIsSigned(NewSign);
Chris Lattner3429a812007-08-23 05:46:52 +0000244 ConvVal.extend(Val.getBitWidth());
Chris Lattner5c039602007-08-23 22:08:35 +0000245 ConvVal.setIsSigned(Val.isSigned());
Chris Lattner3429a812007-08-23 05:46:52 +0000246 if (ConvVal != Val)
247 Diag(Loc, DiagID, Val.toString(), ConvVal.toString());
248
249 // Regardless of whether a diagnostic was emitted, really do the
250 // truncation.
251 Val.trunc(NewWidth);
Chris Lattner5c039602007-08-23 22:08:35 +0000252 Val.setIsSigned(NewSign);
Chris Lattner3429a812007-08-23 05:46:52 +0000253 } else if (NewSign != Val.isSigned()) {
254 // Convert the sign to match the sign of the condition. This can cause
255 // overflow as well: unsigned(INTMIN)
256 llvm::APSInt OldVal(Val);
257 Val.setIsSigned(NewSign);
258
259 if (Val.isNegative()) // Sign bit changes meaning.
260 Diag(Loc, DiagID, OldVal.toString(), Val.toString());
261 }
262}
263
Chris Lattner0ab833c2007-08-23 18:29:20 +0000264namespace {
265 struct CaseCompareFunctor {
266 bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS,
267 const llvm::APSInt &RHS) {
268 return LHS.first < RHS;
269 }
Chris Lattner2157f272007-09-03 18:31:57 +0000270 bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS,
271 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
272 return LHS.first < RHS.first;
273 }
Chris Lattner0ab833c2007-08-23 18:29:20 +0000274 bool operator()(const llvm::APSInt &LHS,
275 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
276 return LHS < RHS.first;
277 }
278 };
279}
280
Chris Lattner766afb82007-09-21 18:15:22 +0000281/// CmpCaseVals - Comparison predicate for sorting case values.
282///
283static bool CmpCaseVals(const std::pair<llvm::APSInt, CaseStmt*>& lhs,
284 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
285 if (lhs.first < rhs.first)
286 return true;
287
288 if (lhs.first == rhs.first &&
289 lhs.second->getCaseLoc().getRawEncoding()
290 < rhs.second->getCaseLoc().getRawEncoding())
291 return true;
292 return false;
293}
294
Chris Lattner4b009652007-07-25 00:24:17 +0000295Action::StmtResult
Chris Lattner766afb82007-09-21 18:15:22 +0000296Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
297 ExprTy *Body) {
Chris Lattner4b009652007-07-25 00:24:17 +0000298 Stmt *BodyStmt = (Stmt*)Body;
299
300 SwitchStmt *SS = SwitchStack.back();
301 assert(SS == (SwitchStmt*)Switch && "switch stack missing push/pop!");
302
Steve Naroffa610eab2007-09-01 21:08:38 +0000303 SS->setBody(BodyStmt, SwitchLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000304 SwitchStack.pop_back();
305
Chris Lattner3429a812007-08-23 05:46:52 +0000306 Expr *CondExpr = SS->getCond();
307 QualType CondType = CondExpr->getType();
Chris Lattner4b009652007-07-25 00:24:17 +0000308
Chris Lattner3429a812007-08-23 05:46:52 +0000309 if (!CondType->isIntegerType()) { // C99 6.8.4.2p1
Chris Lattner4b009652007-07-25 00:24:17 +0000310 Diag(SwitchLoc, diag::err_typecheck_statement_requires_integer,
Chris Lattner3429a812007-08-23 05:46:52 +0000311 CondType.getAsString(), CondExpr->getSourceRange());
312 return true;
Chris Lattner4b009652007-07-25 00:24:17 +0000313 }
Chris Lattner3429a812007-08-23 05:46:52 +0000314
315 // Get the bitwidth of the switched-on value before promotions. We must
316 // convert the integer case values to this width before comparison.
Chris Lattner8cd0e932008-03-05 18:54:05 +0000317 unsigned CondWidth = static_cast<unsigned>(Context.getTypeSize(CondType));
Chris Lattner3429a812007-08-23 05:46:52 +0000318 bool CondIsSigned = CondType->isSignedIntegerType();
319
320 // Accumulate all of the case values in a vector so that we can sort them
321 // and detect duplicates. This vector contains the APInt for the case after
322 // it has been converted to the condition type.
Chris Lattner0ab833c2007-08-23 18:29:20 +0000323 typedef llvm::SmallVector<std::pair<llvm::APSInt, CaseStmt*>, 64> CaseValsTy;
324 CaseValsTy CaseVals;
Chris Lattner3429a812007-08-23 05:46:52 +0000325
326 // Keep track of any GNU case ranges we see. The APSInt is the low value.
327 std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRanges;
328
329 DefaultStmt *TheDefaultStmt = 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000330
Chris Lattner1a4066d2007-08-23 06:23:56 +0000331 bool CaseListIsErroneous = false;
332
333 for (SwitchCase *SC = SS->getSwitchCaseList(); SC;
Chris Lattner4b009652007-07-25 00:24:17 +0000334 SC = SC->getNextSwitchCase()) {
Chris Lattner1a4066d2007-08-23 06:23:56 +0000335
Chris Lattner4b009652007-07-25 00:24:17 +0000336 if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC)) {
Chris Lattner3429a812007-08-23 05:46:52 +0000337 if (TheDefaultStmt) {
338 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
339 Diag(TheDefaultStmt->getDefaultLoc(), diag::err_first_label);
Chris Lattner4b009652007-07-25 00:24:17 +0000340
Chris Lattner3429a812007-08-23 05:46:52 +0000341 // FIXME: Remove the default statement from the switch block so that
342 // we'll return a valid AST. This requires recursing down the
343 // AST and finding it, not something we are set up to do right now. For
344 // now, just lop the entire switch stmt out of the AST.
Chris Lattner1a4066d2007-08-23 06:23:56 +0000345 CaseListIsErroneous = true;
Chris Lattner4b009652007-07-25 00:24:17 +0000346 }
Chris Lattner3429a812007-08-23 05:46:52 +0000347 TheDefaultStmt = DS;
Chris Lattner4b009652007-07-25 00:24:17 +0000348
Chris Lattner3429a812007-08-23 05:46:52 +0000349 } else {
350 CaseStmt *CS = cast<CaseStmt>(SC);
351
352 // We already verified that the expression has a i-c-e value (C99
353 // 6.8.4.2p3) - get that value now.
354 llvm::APSInt LoVal(32);
Chris Lattnere992d6c2008-01-16 19:17:22 +0000355 Expr *Lo = CS->getLHS();
356 Lo->isIntegerConstantExpr(LoVal, Context);
Chris Lattner3429a812007-08-23 05:46:52 +0000357
358 // Convert the value to the same width/sign as the condition.
359 ConvertIntegerToTypeWarnOnOverflow(LoVal, CondWidth, CondIsSigned,
360 CS->getLHS()->getLocStart(),
361 diag::warn_case_value_overflow);
Chris Lattner4b009652007-07-25 00:24:17 +0000362
Chris Lattnere992d6c2008-01-16 19:17:22 +0000363 // If the LHS is not the same type as the condition, insert an implicit
364 // cast.
365 ImpCastExprToType(Lo, CondType);
366 CS->setLHS(Lo);
367
Chris Lattner1a4066d2007-08-23 06:23:56 +0000368 // If this is a case range, remember it in CaseRanges, otherwise CaseVals.
Chris Lattner3429a812007-08-23 05:46:52 +0000369 if (CS->getRHS())
370 CaseRanges.push_back(std::make_pair(LoVal, CS));
Chris Lattner1a4066d2007-08-23 06:23:56 +0000371 else
372 CaseVals.push_back(std::make_pair(LoVal, CS));
Chris Lattner3429a812007-08-23 05:46:52 +0000373 }
374 }
375
Chris Lattner1a4066d2007-08-23 06:23:56 +0000376 // Sort all the scalar case values so we can easily detect duplicates.
Chris Lattner766afb82007-09-21 18:15:22 +0000377 std::stable_sort(CaseVals.begin(), CaseVals.end(), CmpCaseVals);
Chris Lattner3429a812007-08-23 05:46:52 +0000378
Chris Lattner2b1b9a82007-08-23 14:29:07 +0000379 if (!CaseVals.empty()) {
380 for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) {
381 if (CaseVals[i].first == CaseVals[i+1].first) {
382 // If we have a duplicate, report it.
383 Diag(CaseVals[i+1].second->getLHS()->getLocStart(),
384 diag::err_duplicate_case, CaseVals[i].first.toString());
385 Diag(CaseVals[i].second->getLHS()->getLocStart(),
386 diag::err_duplicate_case_prev);
387 // FIXME: We really want to remove the bogus case stmt from the substmt,
388 // but we have no way to do this right now.
389 CaseListIsErroneous = true;
390 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000391 }
392 }
Chris Lattner3429a812007-08-23 05:46:52 +0000393
Chris Lattner1a4066d2007-08-23 06:23:56 +0000394 // Detect duplicate case ranges, which usually don't exist at all in the first
395 // place.
396 if (!CaseRanges.empty()) {
397 // Sort all the case ranges by their low value so we can easily detect
398 // overlaps between ranges.
Chris Lattner0ab833c2007-08-23 18:29:20 +0000399 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
Chris Lattner1a4066d2007-08-23 06:23:56 +0000400
401 // Scan the ranges, computing the high values and removing empty ranges.
402 std::vector<llvm::APSInt> HiVals;
Chris Lattner7443e0f2007-08-23 17:48:14 +0000403 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
Chris Lattner1a4066d2007-08-23 06:23:56 +0000404 CaseStmt *CR = CaseRanges[i].second;
405 llvm::APSInt HiVal(32);
Chris Lattnere992d6c2008-01-16 19:17:22 +0000406 Expr *Hi = CR->getRHS();
407 Hi->isIntegerConstantExpr(HiVal, Context);
Chris Lattner1a4066d2007-08-23 06:23:56 +0000408
409 // Convert the value to the same width/sign as the condition.
410 ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned,
411 CR->getRHS()->getLocStart(),
412 diag::warn_case_value_overflow);
413
Chris Lattnere992d6c2008-01-16 19:17:22 +0000414 // If the LHS is not the same type as the condition, insert an implicit
415 // cast.
416 ImpCastExprToType(Hi, CondType);
417 CR->setRHS(Hi);
418
Chris Lattner7443e0f2007-08-23 17:48:14 +0000419 // If the low value is bigger than the high value, the case is empty.
420 if (CaseRanges[i].first > HiVal) {
421 Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range,
422 SourceRange(CR->getLHS()->getLocStart(),
423 CR->getRHS()->getLocEnd()));
424 CaseRanges.erase(CaseRanges.begin()+i);
425 --i, --e;
426 continue;
427 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000428 HiVals.push_back(HiVal);
429 }
430
431 // Rescan the ranges, looking for overlap with singleton values and other
Chris Lattner0ab833c2007-08-23 18:29:20 +0000432 // ranges. Since the range list is sorted, we only need to compare case
433 // ranges with their neighbors.
Chris Lattner1a4066d2007-08-23 06:23:56 +0000434 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
Chris Lattner0ab833c2007-08-23 18:29:20 +0000435 llvm::APSInt &CRLo = CaseRanges[i].first;
436 llvm::APSInt &CRHi = HiVals[i];
437 CaseStmt *CR = CaseRanges[i].second;
Chris Lattner1a4066d2007-08-23 06:23:56 +0000438
Chris Lattner0ab833c2007-08-23 18:29:20 +0000439 // Check to see whether the case range overlaps with any singleton cases.
440 CaseStmt *OverlapStmt = 0;
441 llvm::APSInt OverlapVal(32);
442
443 // Find the smallest value >= the lower bound. If I is in the case range,
444 // then we have overlap.
445 CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(),
446 CaseVals.end(), CRLo,
447 CaseCompareFunctor());
448 if (I != CaseVals.end() && I->first < CRHi) {
449 OverlapVal = I->first; // Found overlap with scalar.
450 OverlapStmt = I->second;
451 }
452
453 // Find the smallest value bigger than the upper bound.
454 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
455 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
456 OverlapVal = (I-1)->first; // Found overlap with scalar.
457 OverlapStmt = (I-1)->second;
458 }
459
460 // Check to see if this case stmt overlaps with the subsequent case range.
461 if (i && CRLo <= HiVals[i-1]) {
462 OverlapVal = HiVals[i-1]; // Found overlap with range.
463 OverlapStmt = CaseRanges[i-1].second;
464 }
465
466 if (OverlapStmt) {
467 // If we have a duplicate, report it.
468 Diag(CR->getLHS()->getLocStart(),
469 diag::err_duplicate_case, OverlapVal.toString());
470 Diag(OverlapStmt->getLHS()->getLocStart(),
471 diag::err_duplicate_case_prev);
472 // FIXME: We really want to remove the bogus case stmt from the substmt,
473 // but we have no way to do this right now.
474 CaseListIsErroneous = true;
475 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000476 }
477 }
Chris Lattner3429a812007-08-23 05:46:52 +0000478
Chris Lattner1a4066d2007-08-23 06:23:56 +0000479 // FIXME: If the case list was broken is some way, we don't have a good system
480 // to patch it up. Instead, just return the whole substmt as broken.
481 if (CaseListIsErroneous)
482 return true;
Chris Lattner3429a812007-08-23 05:46:52 +0000483
Chris Lattner4b009652007-07-25 00:24:17 +0000484 return SS;
485}
486
487Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000488Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, StmtTy *Body) {
Chris Lattner4b009652007-07-25 00:24:17 +0000489 Expr *condExpr = (Expr *)Cond;
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000490 assert(condExpr && "ActOnWhileStmt(): missing expression");
Chris Lattner4b009652007-07-25 00:24:17 +0000491
492 DefaultFunctionArrayConversion(condExpr);
493 QualType condType = condExpr->getType();
494
495 if (!condType->isScalarType()) // C99 6.8.5p2
496 return Diag(WhileLoc, diag::err_typecheck_statement_requires_scalar,
497 condType.getAsString(), condExpr->getSourceRange());
498
Steve Naroff5d2fff82007-08-31 23:28:33 +0000499 return new WhileStmt(condExpr, (Stmt*)Body, WhileLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000500}
501
502Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000503Sema::ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
Chris Lattner4b009652007-07-25 00:24:17 +0000504 SourceLocation WhileLoc, ExprTy *Cond) {
505 Expr *condExpr = (Expr *)Cond;
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000506 assert(condExpr && "ActOnDoStmt(): missing expression");
Chris Lattner4b009652007-07-25 00:24:17 +0000507
508 DefaultFunctionArrayConversion(condExpr);
509 QualType condType = condExpr->getType();
510
511 if (!condType->isScalarType()) // C99 6.8.5p2
512 return Diag(DoLoc, diag::err_typecheck_statement_requires_scalar,
513 condType.getAsString(), condExpr->getSourceRange());
514
Steve Naroff5d2fff82007-08-31 23:28:33 +0000515 return new DoStmt((Stmt*)Body, condExpr, DoLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000516}
517
518Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000519Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chris Lattner3332fbd2007-08-28 04:55:47 +0000520 StmtTy *first, ExprTy *second, ExprTy *third,
521 SourceLocation RParenLoc, StmtTy *body) {
522 Stmt *First = static_cast<Stmt*>(first);
523 Expr *Second = static_cast<Expr*>(second);
524 Expr *Third = static_cast<Expr*>(third);
525 Stmt *Body = static_cast<Stmt*>(body);
526
Chris Lattner06611052007-08-28 05:03:08 +0000527 if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
528 // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
529 // identifiers for objects having storage class 'auto' or 'register'.
Ted Kremenekac7c4572008-08-08 02:45:18 +0000530 for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE=DS->decl_end();
531 DI!=DE; ++DI) {
532 VarDecl *VD = dyn_cast<VarDecl>(*DI);
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000533 if (VD && VD->isBlockVarDecl() && !VD->hasLocalStorage())
534 VD = 0;
535 if (VD == 0)
Ted Kremenekac7c4572008-08-08 02:45:18 +0000536 Diag((*DI)->getLocation(), diag::err_non_variable_decl_in_for);
Chris Lattner06611052007-08-28 05:03:08 +0000537 // FIXME: mark decl erroneous!
538 }
Chris Lattner4b009652007-07-25 00:24:17 +0000539 }
540 if (Second) {
Chris Lattner3332fbd2007-08-28 04:55:47 +0000541 DefaultFunctionArrayConversion(Second);
542 QualType SecondType = Second->getType();
Chris Lattner4b009652007-07-25 00:24:17 +0000543
Chris Lattner3332fbd2007-08-28 04:55:47 +0000544 if (!SecondType->isScalarType()) // C99 6.8.5p2
Chris Lattner4b009652007-07-25 00:24:17 +0000545 return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar,
Chris Lattnere02e4402008-07-25 23:18:17 +0000546 SecondType.getAsString(), Second->getSourceRange());
Chris Lattner4b009652007-07-25 00:24:17 +0000547 }
Steve Naroff5d2fff82007-08-31 23:28:33 +0000548 return new ForStmt(First, Second, Third, Body, ForLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000549}
550
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000551Action::StmtResult
Fariborz Jahaniandf2b0952008-01-10 00:24:29 +0000552Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000553 SourceLocation LParenLoc,
554 StmtTy *first, ExprTy *second,
555 SourceLocation RParenLoc, StmtTy *body) {
556 Stmt *First = static_cast<Stmt*>(first);
557 Expr *Second = static_cast<Expr*>(second);
558 Stmt *Body = static_cast<Stmt*>(body);
Fariborz Jahanian6833b3b2008-01-10 20:33:58 +0000559 if (First) {
560 QualType FirstType;
561 if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
562 FirstType = cast<ValueDecl>(DS->getDecl())->getType();
563 // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
564 // identifiers for objects having storage class 'auto' or 'register'.
565 ScopedDecl *D = DS->getDecl();
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000566 VarDecl *VD = cast<VarDecl>(D);
567 if (VD->isBlockVarDecl() && !VD->hasLocalStorage())
568 return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for);
Fariborz Jahanian6833b3b2008-01-10 20:33:58 +0000569 if (D->getNextDeclarator())
570 return Diag(D->getLocation(), diag::err_toomany_element_decls);
Steve Naroff72a6ebc2008-04-15 22:42:06 +0000571 } else
Fariborz Jahanian6833b3b2008-01-10 20:33:58 +0000572 FirstType = static_cast<Expr*>(first)->getType();
Ted Kremenek118930e2008-07-24 23:58:27 +0000573 if (!Context.isObjCObjectPointerType(FirstType))
Fariborz Jahanian6833b3b2008-01-10 20:33:58 +0000574 Diag(ForLoc, diag::err_selector_element_type,
575 FirstType.getAsString(), First->getSourceRange());
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000576 }
577 if (Second) {
578 DefaultFunctionArrayConversion(Second);
579 QualType SecondType = Second->getType();
Ted Kremenek118930e2008-07-24 23:58:27 +0000580 if (!Context.isObjCObjectPointerType(SecondType))
Fariborz Jahaniandf2b0952008-01-10 00:24:29 +0000581 Diag(ForLoc, diag::err_collection_expr_type,
Fariborz Jahanianfe0982d2008-01-04 00:27:46 +0000582 SecondType.getAsString(), Second->getSourceRange());
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000583 }
Fariborz Jahaniandf2b0952008-01-10 00:24:29 +0000584 return new ObjCForCollectionStmt(First, Second, Body, ForLoc, RParenLoc);
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000585}
Chris Lattner4b009652007-07-25 00:24:17 +0000586
587Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000588Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000589 IdentifierInfo *LabelII) {
590 // Look up the record for this label identifier.
591 LabelStmt *&LabelDecl = LabelMap[LabelII];
592
593 // If we haven't seen this label yet, create a forward reference.
594 if (LabelDecl == 0)
595 LabelDecl = new LabelStmt(LabelLoc, LabelII, 0);
596
Ted Kremeneka65ad462007-09-06 17:11:52 +0000597 return new GotoStmt(LabelDecl, GotoLoc, LabelLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000598}
599
600Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000601Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000602 ExprTy *DestExp) {
603 // FIXME: Verify that the operand is convertible to void*.
604
605 return new IndirectGotoStmt((Expr*)DestExp);
606}
607
608Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000609Sema::ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) {
Chris Lattner4b009652007-07-25 00:24:17 +0000610 Scope *S = CurScope->getContinueParent();
611 if (!S) {
612 // C99 6.8.6.2p1: A break shall appear only in or as a loop body.
613 Diag(ContinueLoc, diag::err_continue_not_in_loop);
614 return true;
615 }
616
Steve Naroffc32a20d2007-08-31 23:49:30 +0000617 return new ContinueStmt(ContinueLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000618}
619
620Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000621Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
Chris Lattner4b009652007-07-25 00:24:17 +0000622 Scope *S = CurScope->getBreakParent();
623 if (!S) {
624 // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
625 Diag(BreakLoc, diag::err_break_not_in_loop_or_switch);
626 return true;
627 }
628
Steve Naroffc32a20d2007-08-31 23:49:30 +0000629 return new BreakStmt(BreakLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000630}
631
632
633Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000634Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
Chris Lattner4b009652007-07-25 00:24:17 +0000635 Expr *RetValExp = static_cast<Expr *>(rex);
Argiris Kirtzidis95256e62008-06-28 06:07:14 +0000636 QualType FnRetType =
637 getCurFunctionDecl() ? getCurFunctionDecl()->getResultType() :
638 getCurMethodDecl()->getResultType();
Chris Lattner4b009652007-07-25 00:24:17 +0000639
Chris Lattner005ed752008-01-04 18:04:52 +0000640 if (FnRetType->isVoidType()) {
Chris Lattner4b009652007-07-25 00:24:17 +0000641 if (RetValExp) // C99 6.8.6.4p1 (ext_ since GCC warns)
Fariborz Jahanian336b2e82007-12-04 19:20:11 +0000642 Diag(ReturnLoc, diag::ext_return_has_expr,
Argiris Kirtzidis95256e62008-06-28 06:07:14 +0000643 ( getCurFunctionDecl() ?
644 getCurFunctionDecl()->getIdentifier()->getName() :
645 getCurMethodDecl()->getSelector().getName() ),
Chris Lattner4b009652007-07-25 00:24:17 +0000646 RetValExp->getSourceRange());
Steve Naroffc32a20d2007-08-31 23:49:30 +0000647 return new ReturnStmt(ReturnLoc, RetValExp);
Chris Lattner4b009652007-07-25 00:24:17 +0000648 } else {
649 if (!RetValExp) {
Argiris Kirtzidis95256e62008-06-28 06:07:14 +0000650 const char *funcName =
651 getCurFunctionDecl() ?
652 getCurFunctionDecl()->getIdentifier()->getName() :
653 getCurMethodDecl()->getSelector().getName().c_str();
Chris Lattner4b009652007-07-25 00:24:17 +0000654 if (getLangOptions().C99) // C99 6.8.6.4p1 (ext_ since GCC warns)
655 Diag(ReturnLoc, diag::ext_return_missing_expr, funcName);
656 else // C90 6.6.6.4p4
657 Diag(ReturnLoc, diag::warn_return_missing_expr, funcName);
Steve Naroffc32a20d2007-08-31 23:49:30 +0000658 return new ReturnStmt(ReturnLoc, (Expr*)0);
Chris Lattner4b009652007-07-25 00:24:17 +0000659 }
660 }
661 // we have a non-void function with an expression, continue checking
Chris Lattner005ed752008-01-04 18:04:52 +0000662 QualType RetValType = RetValExp->getType();
Chris Lattner4b009652007-07-25 00:24:17 +0000663
664 // C99 6.8.6.4p3(136): The return statement is not an assignment. The
665 // overlap restriction of subclause 6.5.16.1 does not apply to the case of
666 // function return.
Chris Lattner005ed752008-01-04 18:04:52 +0000667 AssignConvertType ConvTy = CheckSingleAssignmentConstraints(FnRetType,
668 RetValExp);
669 if (DiagnoseAssignmentResult(ConvTy, ReturnLoc, FnRetType,
670 RetValType, RetValExp, "returning"))
671 return true;
Ted Kremenek45925ab2007-08-17 16:46:58 +0000672
Chris Lattner005ed752008-01-04 18:04:52 +0000673 if (RetValExp) CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
Ted Kremenek45925ab2007-08-17 16:46:58 +0000674
Steve Naroffc32a20d2007-08-31 23:49:30 +0000675 return new ReturnStmt(ReturnLoc, (Expr*)RetValExp);
Chris Lattner4b009652007-07-25 00:24:17 +0000676}
677
Anders Carlsson076c1112007-11-20 19:21:03 +0000678Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
Anders Carlssonde6a9c42008-02-05 23:03:50 +0000679 bool IsSimple,
Anders Carlsson759f45d2007-11-23 23:12:25 +0000680 bool IsVolatile,
Anders Carlsson965d5202007-11-22 01:36:19 +0000681 unsigned NumOutputs,
682 unsigned NumInputs,
683 std::string *Names,
684 ExprTy **Constraints,
685 ExprTy **Exprs,
Chris Lattner84418022008-07-23 06:46:56 +0000686 ExprTy *asmString,
Anders Carlsson965d5202007-11-22 01:36:19 +0000687 unsigned NumClobbers,
688 ExprTy **Clobbers,
Chris Lattner8a40a832007-10-29 04:04:16 +0000689 SourceLocation RParenLoc) {
Chris Lattner84418022008-07-23 06:46:56 +0000690 // The parser verifies that there is a string literal here.
691 StringLiteral *AsmString = cast<StringLiteral>((Expr *)asmString);
692 if (AsmString->isWide())
693 // FIXME: We currently leak memory here.
694 return Diag(AsmString->getLocStart(), diag::err_asm_wide_character,
695 AsmString->getSourceRange());
696
697
Anders Carlssonb4487a82007-11-23 19:43:50 +0000698 for (unsigned i = 0; i < NumOutputs; i++) {
Anders Carlsson4ce42302007-11-27 04:11:28 +0000699 StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]);
Chris Lattner84418022008-07-23 06:46:56 +0000700 if (Literal->isWide())
701 // FIXME: We currently leak memory here.
702 return Diag(Literal->getLocStart(), diag::err_asm_wide_character,
703 Literal->getSourceRange());
704
Anders Carlsson4ce42302007-11-27 04:11:28 +0000705 std::string OutputConstraint(Literal->getStrData(),
706 Literal->getByteLength());
707
708 TargetInfo::ConstraintInfo info;
Chris Lattner84418022008-07-23 06:46:56 +0000709 if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info))
Anders Carlsson4ce42302007-11-27 04:11:28 +0000710 // FIXME: We currently leak memory here.
Chris Lattner84418022008-07-23 06:46:56 +0000711 return Diag(Literal->getLocStart(),
712 diag::err_invalid_output_constraint_in_asm);
Anders Carlsson4ce42302007-11-27 04:11:28 +0000713
714 // Check that the output exprs are valid lvalues.
Anders Carlssonb4487a82007-11-23 19:43:50 +0000715 Expr *OutputExpr = (Expr *)Exprs[i];
Chris Lattner25168a52008-07-26 21:30:36 +0000716 Expr::isLvalueResult Result = OutputExpr->isLvalue(Context);
Anders Carlssonb4487a82007-11-23 19:43:50 +0000717 if (Result != Expr::LV_Valid) {
718 ParenExpr *PE = cast<ParenExpr>(OutputExpr);
719
Anders Carlssonb4487a82007-11-23 19:43:50 +0000720 // FIXME: We currently leak memory here.
Chris Lattner84418022008-07-23 06:46:56 +0000721 return Diag(PE->getSubExpr()->getLocStart(),
722 diag::err_invalid_lvalue_in_asm_output,
723 PE->getSubExpr()->getSourceRange());
Anders Carlssonb4487a82007-11-23 19:43:50 +0000724 }
725 }
726
Anders Carlssonb4487a82007-11-23 19:43:50 +0000727 for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
Anders Carlsson4ce42302007-11-27 04:11:28 +0000728 StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]);
Chris Lattner84418022008-07-23 06:46:56 +0000729 if (Literal->isWide())
730 // FIXME: We currently leak memory here.
731 return Diag(Literal->getLocStart(), diag::err_asm_wide_character,
732 Literal->getSourceRange());
Anders Carlssonb4487a82007-11-23 19:43:50 +0000733
Anders Carlsson4ce42302007-11-27 04:11:28 +0000734 std::string InputConstraint(Literal->getStrData(),
735 Literal->getByteLength());
736
737 TargetInfo::ConstraintInfo info;
738 if (!Context.Target.validateInputConstraint(InputConstraint.c_str(),
739 NumOutputs,
740 info)) {
741 // FIXME: We currently leak memory here.
Chris Lattner84418022008-07-23 06:46:56 +0000742 return Diag(Literal->getLocStart(),
743 diag::err_invalid_input_constraint_in_asm);
Anders Carlsson4ce42302007-11-27 04:11:28 +0000744 }
745
746 // Check that the input exprs aren't of type void.
747 Expr *InputExpr = (Expr *)Exprs[i];
Anders Carlssonb4487a82007-11-23 19:43:50 +0000748 if (InputExpr->getType()->isVoidType()) {
749 ParenExpr *PE = cast<ParenExpr>(InputExpr);
750
Anders Carlssonb4487a82007-11-23 19:43:50 +0000751 // FIXME: We currently leak memory here.
Chris Lattner84418022008-07-23 06:46:56 +0000752 return Diag(PE->getSubExpr()->getLocStart(),
753 diag::err_invalid_type_in_asm_input,
754 PE->getType().getAsString(),
755 PE->getSubExpr()->getSourceRange());
Anders Carlssonb4487a82007-11-23 19:43:50 +0000756 }
757 }
Anders Carlsson965d5202007-11-22 01:36:19 +0000758
Anders Carlsson49dadd62007-11-25 00:25:21 +0000759 // Check that the clobbers are valid.
760 for (unsigned i = 0; i < NumClobbers; i++) {
761 StringLiteral *Literal = cast<StringLiteral>((Expr *)Clobbers[i]);
Chris Lattner84418022008-07-23 06:46:56 +0000762 if (Literal->isWide())
763 // FIXME: We currently leak memory here.
764 return Diag(Literal->getLocStart(), diag::err_asm_wide_character,
765 Literal->getSourceRange());
Anders Carlsson49dadd62007-11-25 00:25:21 +0000766
767 llvm::SmallString<16> Clobber(Literal->getStrData(),
768 Literal->getStrData() +
769 Literal->getByteLength());
770
Chris Lattner84418022008-07-23 06:46:56 +0000771 if (!Context.Target.isValidGCCRegisterName(Clobber.c_str()))
Anders Carlsson49dadd62007-11-25 00:25:21 +0000772 // FIXME: We currently leak memory here.
Chris Lattner84418022008-07-23 06:46:56 +0000773 return Diag(Literal->getLocStart(),
774 diag::err_unknown_register_name_in_asm, Clobber.c_str());
Anders Carlsson49dadd62007-11-25 00:25:21 +0000775 }
776
Anders Carlsson965d5202007-11-22 01:36:19 +0000777 return new AsmStmt(AsmLoc,
Anders Carlssonde6a9c42008-02-05 23:03:50 +0000778 IsSimple,
Anders Carlsson759f45d2007-11-23 23:12:25 +0000779 IsVolatile,
Anders Carlsson965d5202007-11-22 01:36:19 +0000780 NumOutputs,
781 NumInputs,
782 Names,
783 reinterpret_cast<StringLiteral**>(Constraints),
784 reinterpret_cast<Expr**>(Exprs),
Chris Lattner84418022008-07-23 06:46:56 +0000785 AsmString, NumClobbers,
Anders Carlsson965d5202007-11-22 01:36:19 +0000786 reinterpret_cast<StringLiteral**>(Clobbers),
787 RParenLoc);
Chris Lattner8a40a832007-10-29 04:04:16 +0000788}
Fariborz Jahanian06798362007-11-01 23:59:59 +0000789
790Action::StmtResult
Ted Kremenek42730c52008-01-07 19:49:32 +0000791Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc,
Fariborz Jahanian06798362007-11-01 23:59:59 +0000792 SourceLocation RParen, StmtTy *Parm,
793 StmtTy *Body, StmtTy *CatchList) {
Ted Kremenek42730c52008-01-07 19:49:32 +0000794 ObjCAtCatchStmt *CS = new ObjCAtCatchStmt(AtLoc, RParen,
Fariborz Jahanian06798362007-11-01 23:59:59 +0000795 static_cast<Stmt*>(Parm), static_cast<Stmt*>(Body),
796 static_cast<Stmt*>(CatchList));
797 return CatchList ? CatchList : CS;
798}
799
Fariborz Jahaniande3abf82007-11-02 00:18:53 +0000800Action::StmtResult
Ted Kremenek42730c52008-01-07 19:49:32 +0000801Sema::ActOnObjCAtFinallyStmt(SourceLocation AtLoc, StmtTy *Body) {
802 ObjCAtFinallyStmt *FS = new ObjCAtFinallyStmt(AtLoc,
Fariborz Jahaniande3abf82007-11-02 00:18:53 +0000803 static_cast<Stmt*>(Body));
804 return FS;
805}
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000806
807Action::StmtResult
Ted Kremenek42730c52008-01-07 19:49:32 +0000808Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc,
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000809 StmtTy *Try, StmtTy *Catch, StmtTy *Finally) {
Ted Kremenek42730c52008-01-07 19:49:32 +0000810 ObjCAtTryStmt *TS = new ObjCAtTryStmt(AtLoc, static_cast<Stmt*>(Try),
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000811 static_cast<Stmt*>(Catch),
812 static_cast<Stmt*>(Finally));
813 return TS;
814}
815
Fariborz Jahanian08df2c62007-11-07 02:00:49 +0000816Action::StmtResult
Ted Kremenek42730c52008-01-07 19:49:32 +0000817Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, StmtTy *Throw) {
818 ObjCAtThrowStmt *TS = new ObjCAtThrowStmt(AtLoc, static_cast<Stmt*>(Throw));
Fariborz Jahanian08df2c62007-11-07 02:00:49 +0000819 return TS;
820}
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000821
Fariborz Jahanianc9fd4d12008-01-29 19:14:59 +0000822Action::StmtResult
823Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprTy *SynchExpr,
824 StmtTy *SynchBody) {
825 ObjCAtSynchronizedStmt *SS = new ObjCAtSynchronizedStmt(AtLoc,
Fariborz Jahanian499bf412008-01-29 22:59:37 +0000826 static_cast<Stmt*>(SynchExpr), static_cast<Stmt*>(SynchBody));
Fariborz Jahanianc9fd4d12008-01-29 19:14:59 +0000827 return SS;
828}