Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements semantic analysis for statements. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Sema.h" |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 16 | #include "clang/AST/Expr.h" |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 17 | #include "clang/AST/Stmt.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 18 | #include "clang/Parse/Scope.h" |
| 19 | #include "clang/Basic/Diagnostic.h" |
| 20 | #include "clang/Basic/LangOptions.h" |
| 21 | #include "clang/Lex/IdentifierTable.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 24 | Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 25 | Expr *E = static_cast<Expr*>(expr); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 26 | assert(E && "ActOnExprStmt(): missing expression"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 27 | return E; |
| 28 | } |
| 29 | |
| 30 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 31 | Sema::StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 32 | return new NullStmt(SemiLoc); |
| 33 | } |
| 34 | |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 35 | Sema::StmtResult Sema::ActOnDeclStmt(DeclTy *decl) { |
Steve Naroff | cb59747 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 36 | if (decl) { |
| 37 | ScopedDecl *SD = dyn_cast<ScopedDecl>(static_cast<Decl *>(decl)); |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 38 | assert(SD && "Sema::ActOnDeclStmt(): expected ScopedDecl"); |
Steve Naroff | cb59747 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 39 | return new DeclStmt(SD); |
| 40 | } else |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 41 | return true; // error |
| 42 | } |
| 43 | |
| 44 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 45 | Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
Chris Lattner | f2b0757 | 2007-08-31 21:49:55 +0000 | [diff] [blame] | 46 | StmtTy **elts, unsigned NumElts, bool isStmtExpr) { |
Chris Lattner | 3ea3b66 | 2007-08-27 04:29:41 +0000 | [diff] [blame] | 47 | Stmt **Elts = reinterpret_cast<Stmt**>(elts); |
| 48 | // If we're in C89 mode, check that we don't have any decls after stmts. If |
| 49 | // so, emit an extension diagnostic. |
| 50 | if (!getLangOptions().C99 && !getLangOptions().CPlusPlus) { |
| 51 | // Note that __extension__ can be around a decl. |
| 52 | unsigned i = 0; |
| 53 | // Skip over all declarations. |
| 54 | for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i) |
| 55 | /*empty*/; |
| 56 | |
| 57 | // We found the end of the list or a statement. Scan for another declstmt. |
| 58 | for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i) |
| 59 | /*empty*/; |
| 60 | |
| 61 | if (i != NumElts) { |
Steve Naroff | cb59747 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 62 | ScopedDecl *D = cast<DeclStmt>(Elts[i])->getDecl(); |
Chris Lattner | 3ea3b66 | 2007-08-27 04:29:41 +0000 | [diff] [blame] | 63 | Diag(D->getLocation(), diag::ext_mixed_decls_code); |
| 64 | } |
| 65 | } |
Chris Lattner | f2b0757 | 2007-08-31 21:49:55 +0000 | [diff] [blame] | 66 | // Warn about unused expressions in statements. |
| 67 | for (unsigned i = 0; i != NumElts; ++i) { |
| 68 | Expr *E = dyn_cast<Expr>(Elts[i]); |
| 69 | if (!E) continue; |
| 70 | |
| 71 | // Warn about expressions with unused results. |
| 72 | if (E->hasLocalSideEffect() || E->getType()->isVoidType()) |
| 73 | continue; |
| 74 | |
| 75 | // The last expr in a stmt expr really is used. |
| 76 | if (isStmtExpr && i == NumElts-1) |
| 77 | continue; |
| 78 | |
| 79 | /// DiagnoseDeadExpr - This expression is side-effect free and evaluated in |
| 80 | /// a context where the result is unused. Emit a diagnostic to warn about |
| 81 | /// this. |
| 82 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) |
| 83 | Diag(BO->getOperatorLoc(), diag::warn_unused_expr, |
| 84 | BO->getLHS()->getSourceRange(), BO->getRHS()->getSourceRange()); |
| 85 | else if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) |
| 86 | Diag(UO->getOperatorLoc(), diag::warn_unused_expr, |
| 87 | UO->getSubExpr()->getSourceRange()); |
| 88 | else |
| 89 | Diag(E->getExprLoc(), diag::warn_unused_expr, E->getSourceRange()); |
| 90 | } |
| 91 | |
Steve Naroff | 5d2fff8 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 92 | return new CompoundStmt(Elts, NumElts, L, R); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 96 | Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 97 | SourceLocation DotDotDotLoc, ExprTy *rhsval, |
| 98 | SourceLocation ColonLoc, StmtTy *subStmt) { |
| 99 | Stmt *SubStmt = static_cast<Stmt*>(subStmt); |
| 100 | Expr *LHSVal = ((Expr *)lhsval), *RHSVal = ((Expr *)rhsval); |
| 101 | assert((LHSVal != 0) && "missing expression in case statement"); |
| 102 | |
| 103 | SourceLocation ExpLoc; |
| 104 | // C99 6.8.4.2p3: The expression shall be an integer constant. |
| 105 | if (!LHSVal->isIntegerConstantExpr(Context, &ExpLoc)) { |
| 106 | Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr, |
| 107 | LHSVal->getSourceRange()); |
| 108 | return SubStmt; |
| 109 | } |
| 110 | |
| 111 | // GCC extension: The expression shall be an integer constant. |
| 112 | if (RHSVal && !RHSVal->isIntegerConstantExpr(Context, &ExpLoc)) { |
| 113 | Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr, |
| 114 | RHSVal->getSourceRange()); |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 115 | RHSVal = 0; // Recover by just forgetting about it. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (SwitchStack.empty()) { |
| 119 | Diag(CaseLoc, diag::err_case_not_in_switch); |
| 120 | return SubStmt; |
| 121 | } |
| 122 | |
Steve Naroff | 5d2fff8 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 123 | CaseStmt *CS = new CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 124 | SwitchStack.back()->addSwitchCase(CS); |
| 125 | return CS; |
| 126 | } |
| 127 | |
| 128 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 129 | Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 130 | StmtTy *subStmt, Scope *CurScope) { |
| 131 | Stmt *SubStmt = static_cast<Stmt*>(subStmt); |
| 132 | |
| 133 | if (SwitchStack.empty()) { |
| 134 | Diag(DefaultLoc, diag::err_default_not_in_switch); |
| 135 | return SubStmt; |
| 136 | } |
| 137 | |
| 138 | DefaultStmt *DS = new DefaultStmt(DefaultLoc, SubStmt); |
| 139 | SwitchStack.back()->addSwitchCase(DS); |
| 140 | |
| 141 | return DS; |
| 142 | } |
| 143 | |
| 144 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 145 | Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 146 | SourceLocation ColonLoc, StmtTy *subStmt) { |
| 147 | Stmt *SubStmt = static_cast<Stmt*>(subStmt); |
| 148 | // Look up the record for this label identifier. |
| 149 | LabelStmt *&LabelDecl = LabelMap[II]; |
| 150 | |
| 151 | // If not forward referenced or defined already, just create a new LabelStmt. |
| 152 | if (LabelDecl == 0) |
| 153 | return LabelDecl = new LabelStmt(IdentLoc, II, SubStmt); |
| 154 | |
| 155 | assert(LabelDecl->getID() == II && "Label mismatch!"); |
| 156 | |
| 157 | // Otherwise, this label was either forward reference or multiply defined. If |
| 158 | // multiply defined, reject it now. |
| 159 | if (LabelDecl->getSubStmt()) { |
| 160 | Diag(IdentLoc, diag::err_redefinition_of_label, LabelDecl->getName()); |
| 161 | Diag(LabelDecl->getIdentLoc(), diag::err_previous_definition); |
| 162 | return SubStmt; |
| 163 | } |
| 164 | |
| 165 | // Otherwise, this label was forward declared, and we just found its real |
| 166 | // definition. Fill in the forward definition and return it. |
| 167 | LabelDecl->setIdentLoc(IdentLoc); |
| 168 | LabelDecl->setSubStmt(SubStmt); |
| 169 | return LabelDecl; |
| 170 | } |
| 171 | |
| 172 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 173 | Sema::ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 174 | StmtTy *ThenVal, SourceLocation ElseLoc, |
| 175 | StmtTy *ElseVal) { |
| 176 | Expr *condExpr = (Expr *)CondVal; |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 177 | assert(condExpr && "ActOnIfStmt(): missing expression"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 178 | |
| 179 | DefaultFunctionArrayConversion(condExpr); |
| 180 | QualType condType = condExpr->getType(); |
| 181 | |
| 182 | if (!condType->isScalarType()) // C99 6.8.4.1p1 |
| 183 | return Diag(IfLoc, diag::err_typecheck_statement_requires_scalar, |
| 184 | condType.getAsString(), condExpr->getSourceRange()); |
| 185 | |
Steve Naroff | 5d2fff8 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 186 | return new IfStmt(IfLoc, condExpr, (Stmt*)ThenVal, (Stmt*)ElseVal); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 190 | Sema::ActOnStartOfSwitchStmt(ExprTy *cond) { |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 191 | Expr *Cond = static_cast<Expr*>(cond); |
| 192 | |
| 193 | // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr. |
| 194 | UsualUnaryConversions(Cond); |
| 195 | |
| 196 | SwitchStmt *SS = new SwitchStmt(Cond); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 197 | SwitchStack.push_back(SS); |
| 198 | return SS; |
| 199 | } |
| 200 | |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 201 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
| 202 | /// the specified width and sign. If an overflow occurs, detect it and emit |
| 203 | /// the specified diagnostic. |
| 204 | void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val, |
| 205 | unsigned NewWidth, bool NewSign, |
| 206 | SourceLocation Loc, |
| 207 | unsigned DiagID) { |
| 208 | // Perform a conversion to the promoted condition type if needed. |
| 209 | if (NewWidth > Val.getBitWidth()) { |
| 210 | // If this is an extension, just do it. |
| 211 | llvm::APSInt OldVal(Val); |
| 212 | Val.extend(NewWidth); |
| 213 | |
| 214 | // If the input was signed and negative and the output is unsigned, |
| 215 | // warn. |
| 216 | if (!NewSign && OldVal.isSigned() && OldVal.isNegative()) |
| 217 | Diag(Loc, DiagID, OldVal.toString(), Val.toString()); |
| 218 | |
| 219 | Val.setIsSigned(NewSign); |
| 220 | } else if (NewWidth < Val.getBitWidth()) { |
| 221 | // If this is a truncation, check for overflow. |
| 222 | llvm::APSInt ConvVal(Val); |
| 223 | ConvVal.trunc(NewWidth); |
Chris Lattner | 5c03960 | 2007-08-23 22:08:35 +0000 | [diff] [blame] | 224 | ConvVal.setIsSigned(NewSign); |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 225 | ConvVal.extend(Val.getBitWidth()); |
Chris Lattner | 5c03960 | 2007-08-23 22:08:35 +0000 | [diff] [blame] | 226 | ConvVal.setIsSigned(Val.isSigned()); |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 227 | if (ConvVal != Val) |
| 228 | Diag(Loc, DiagID, Val.toString(), ConvVal.toString()); |
| 229 | |
| 230 | // Regardless of whether a diagnostic was emitted, really do the |
| 231 | // truncation. |
| 232 | Val.trunc(NewWidth); |
Chris Lattner | 5c03960 | 2007-08-23 22:08:35 +0000 | [diff] [blame] | 233 | Val.setIsSigned(NewSign); |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 234 | } else if (NewSign != Val.isSigned()) { |
| 235 | // Convert the sign to match the sign of the condition. This can cause |
| 236 | // overflow as well: unsigned(INTMIN) |
| 237 | llvm::APSInt OldVal(Val); |
| 238 | Val.setIsSigned(NewSign); |
| 239 | |
| 240 | if (Val.isNegative()) // Sign bit changes meaning. |
| 241 | Diag(Loc, DiagID, OldVal.toString(), Val.toString()); |
| 242 | } |
| 243 | } |
| 244 | |
Chris Lattner | 0ab833c | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 245 | namespace { |
| 246 | struct CaseCompareFunctor { |
| 247 | bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS, |
| 248 | const llvm::APSInt &RHS) { |
| 249 | return LHS.first < RHS; |
| 250 | } |
Chris Lattner | 2157f27 | 2007-09-03 18:31:57 +0000 | [diff] [blame] | 251 | bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS, |
| 252 | const std::pair<llvm::APSInt, CaseStmt*> &RHS) { |
| 253 | return LHS.first < RHS.first; |
| 254 | } |
Chris Lattner | 0ab833c | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 255 | bool operator()(const llvm::APSInt &LHS, |
| 256 | const std::pair<llvm::APSInt, CaseStmt*> &RHS) { |
| 257 | return LHS < RHS.first; |
| 258 | } |
| 259 | }; |
| 260 | } |
| 261 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 262 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 263 | Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, ExprTy *Body) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 264 | Stmt *BodyStmt = (Stmt*)Body; |
| 265 | |
| 266 | SwitchStmt *SS = SwitchStack.back(); |
| 267 | assert(SS == (SwitchStmt*)Switch && "switch stack missing push/pop!"); |
| 268 | |
Steve Naroff | a610eab | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 269 | SS->setBody(BodyStmt, SwitchLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 270 | SwitchStack.pop_back(); |
| 271 | |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 272 | Expr *CondExpr = SS->getCond(); |
| 273 | QualType CondType = CondExpr->getType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 274 | |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 275 | if (!CondType->isIntegerType()) { // C99 6.8.4.2p1 |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 276 | Diag(SwitchLoc, diag::err_typecheck_statement_requires_integer, |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 277 | CondType.getAsString(), CondExpr->getSourceRange()); |
| 278 | return true; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 279 | } |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 280 | |
| 281 | // Get the bitwidth of the switched-on value before promotions. We must |
| 282 | // convert the integer case values to this width before comparison. |
Hartmut Kaiser | 612f174 | 2007-09-16 00:04:22 +0000 | [diff] [blame] | 283 | unsigned CondWidth = |
| 284 | static_cast<unsigned>(Context.getTypeSize(CondType, SwitchLoc)); |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 285 | bool CondIsSigned = CondType->isSignedIntegerType(); |
| 286 | |
| 287 | // Accumulate all of the case values in a vector so that we can sort them |
| 288 | // and detect duplicates. This vector contains the APInt for the case after |
| 289 | // it has been converted to the condition type. |
Chris Lattner | 0ab833c | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 290 | typedef llvm::SmallVector<std::pair<llvm::APSInt, CaseStmt*>, 64> CaseValsTy; |
| 291 | CaseValsTy CaseVals; |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 292 | |
| 293 | // Keep track of any GNU case ranges we see. The APSInt is the low value. |
| 294 | std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRanges; |
| 295 | |
| 296 | DefaultStmt *TheDefaultStmt = 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 297 | |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 298 | bool CaseListIsErroneous = false; |
| 299 | |
| 300 | for (SwitchCase *SC = SS->getSwitchCaseList(); SC; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 301 | SC = SC->getNextSwitchCase()) { |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 302 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 303 | if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC)) { |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 304 | if (TheDefaultStmt) { |
| 305 | Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined); |
| 306 | Diag(TheDefaultStmt->getDefaultLoc(), diag::err_first_label); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 307 | |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 308 | // FIXME: Remove the default statement from the switch block so that |
| 309 | // we'll return a valid AST. This requires recursing down the |
| 310 | // AST and finding it, not something we are set up to do right now. For |
| 311 | // now, just lop the entire switch stmt out of the AST. |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 312 | CaseListIsErroneous = true; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 313 | } |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 314 | TheDefaultStmt = DS; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 315 | |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 316 | } else { |
| 317 | CaseStmt *CS = cast<CaseStmt>(SC); |
| 318 | |
| 319 | // We already verified that the expression has a i-c-e value (C99 |
| 320 | // 6.8.4.2p3) - get that value now. |
| 321 | llvm::APSInt LoVal(32); |
| 322 | CS->getLHS()->isIntegerConstantExpr(LoVal, Context); |
| 323 | |
| 324 | // Convert the value to the same width/sign as the condition. |
| 325 | ConvertIntegerToTypeWarnOnOverflow(LoVal, CondWidth, CondIsSigned, |
| 326 | CS->getLHS()->getLocStart(), |
| 327 | diag::warn_case_value_overflow); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 328 | |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 329 | // If this is a case range, remember it in CaseRanges, otherwise CaseVals. |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 330 | if (CS->getRHS()) |
| 331 | CaseRanges.push_back(std::make_pair(LoVal, CS)); |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 332 | else |
| 333 | CaseVals.push_back(std::make_pair(LoVal, CS)); |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 337 | // Sort all the scalar case values so we can easily detect duplicates. |
| 338 | std::stable_sort(CaseVals.begin(), CaseVals.end()); |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 339 | |
Chris Lattner | 2b1b9a8 | 2007-08-23 14:29:07 +0000 | [diff] [blame] | 340 | if (!CaseVals.empty()) { |
| 341 | for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) { |
| 342 | if (CaseVals[i].first == CaseVals[i+1].first) { |
| 343 | // If we have a duplicate, report it. |
| 344 | Diag(CaseVals[i+1].second->getLHS()->getLocStart(), |
| 345 | diag::err_duplicate_case, CaseVals[i].first.toString()); |
| 346 | Diag(CaseVals[i].second->getLHS()->getLocStart(), |
| 347 | diag::err_duplicate_case_prev); |
| 348 | // FIXME: We really want to remove the bogus case stmt from the substmt, |
| 349 | // but we have no way to do this right now. |
| 350 | CaseListIsErroneous = true; |
| 351 | } |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 354 | |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 355 | // Detect duplicate case ranges, which usually don't exist at all in the first |
| 356 | // place. |
| 357 | if (!CaseRanges.empty()) { |
| 358 | // Sort all the case ranges by their low value so we can easily detect |
| 359 | // overlaps between ranges. |
Chris Lattner | 0ab833c | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 360 | std::stable_sort(CaseRanges.begin(), CaseRanges.end()); |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 361 | |
| 362 | // Scan the ranges, computing the high values and removing empty ranges. |
| 363 | std::vector<llvm::APSInt> HiVals; |
Chris Lattner | 7443e0f | 2007-08-23 17:48:14 +0000 | [diff] [blame] | 364 | for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) { |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 365 | CaseStmt *CR = CaseRanges[i].second; |
| 366 | llvm::APSInt HiVal(32); |
| 367 | CR->getRHS()->isIntegerConstantExpr(HiVal, Context); |
| 368 | |
| 369 | // Convert the value to the same width/sign as the condition. |
| 370 | ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned, |
| 371 | CR->getRHS()->getLocStart(), |
| 372 | diag::warn_case_value_overflow); |
| 373 | |
Chris Lattner | 7443e0f | 2007-08-23 17:48:14 +0000 | [diff] [blame] | 374 | // If the low value is bigger than the high value, the case is empty. |
| 375 | if (CaseRanges[i].first > HiVal) { |
| 376 | Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range, |
| 377 | SourceRange(CR->getLHS()->getLocStart(), |
| 378 | CR->getRHS()->getLocEnd())); |
| 379 | CaseRanges.erase(CaseRanges.begin()+i); |
| 380 | --i, --e; |
| 381 | continue; |
| 382 | } |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 383 | HiVals.push_back(HiVal); |
| 384 | } |
| 385 | |
| 386 | // Rescan the ranges, looking for overlap with singleton values and other |
Chris Lattner | 0ab833c | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 387 | // ranges. Since the range list is sorted, we only need to compare case |
| 388 | // ranges with their neighbors. |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 389 | for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) { |
Chris Lattner | 0ab833c | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 390 | llvm::APSInt &CRLo = CaseRanges[i].first; |
| 391 | llvm::APSInt &CRHi = HiVals[i]; |
| 392 | CaseStmt *CR = CaseRanges[i].second; |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 393 | |
Chris Lattner | 0ab833c | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 394 | // Check to see whether the case range overlaps with any singleton cases. |
| 395 | CaseStmt *OverlapStmt = 0; |
| 396 | llvm::APSInt OverlapVal(32); |
| 397 | |
| 398 | // Find the smallest value >= the lower bound. If I is in the case range, |
| 399 | // then we have overlap. |
| 400 | CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(), |
| 401 | CaseVals.end(), CRLo, |
| 402 | CaseCompareFunctor()); |
| 403 | if (I != CaseVals.end() && I->first < CRHi) { |
| 404 | OverlapVal = I->first; // Found overlap with scalar. |
| 405 | OverlapStmt = I->second; |
| 406 | } |
| 407 | |
| 408 | // Find the smallest value bigger than the upper bound. |
| 409 | I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor()); |
| 410 | if (I != CaseVals.begin() && (I-1)->first >= CRLo) { |
| 411 | OverlapVal = (I-1)->first; // Found overlap with scalar. |
| 412 | OverlapStmt = (I-1)->second; |
| 413 | } |
| 414 | |
| 415 | // Check to see if this case stmt overlaps with the subsequent case range. |
| 416 | if (i && CRLo <= HiVals[i-1]) { |
| 417 | OverlapVal = HiVals[i-1]; // Found overlap with range. |
| 418 | OverlapStmt = CaseRanges[i-1].second; |
| 419 | } |
| 420 | |
| 421 | if (OverlapStmt) { |
| 422 | // If we have a duplicate, report it. |
| 423 | Diag(CR->getLHS()->getLocStart(), |
| 424 | diag::err_duplicate_case, OverlapVal.toString()); |
| 425 | Diag(OverlapStmt->getLHS()->getLocStart(), |
| 426 | diag::err_duplicate_case_prev); |
| 427 | // FIXME: We really want to remove the bogus case stmt from the substmt, |
| 428 | // but we have no way to do this right now. |
| 429 | CaseListIsErroneous = true; |
| 430 | } |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 431 | } |
| 432 | } |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 433 | |
Chris Lattner | 1a4066d | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 434 | // FIXME: If the case list was broken is some way, we don't have a good system |
| 435 | // to patch it up. Instead, just return the whole substmt as broken. |
| 436 | if (CaseListIsErroneous) |
| 437 | return true; |
Chris Lattner | 3429a81 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 438 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 439 | return SS; |
| 440 | } |
| 441 | |
| 442 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 443 | Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, StmtTy *Body) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 444 | Expr *condExpr = (Expr *)Cond; |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 445 | assert(condExpr && "ActOnWhileStmt(): missing expression"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 446 | |
| 447 | DefaultFunctionArrayConversion(condExpr); |
| 448 | QualType condType = condExpr->getType(); |
| 449 | |
| 450 | if (!condType->isScalarType()) // C99 6.8.5p2 |
| 451 | return Diag(WhileLoc, diag::err_typecheck_statement_requires_scalar, |
| 452 | condType.getAsString(), condExpr->getSourceRange()); |
| 453 | |
Steve Naroff | 5d2fff8 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 454 | return new WhileStmt(condExpr, (Stmt*)Body, WhileLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 458 | Sema::ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 459 | SourceLocation WhileLoc, ExprTy *Cond) { |
| 460 | Expr *condExpr = (Expr *)Cond; |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 461 | assert(condExpr && "ActOnDoStmt(): missing expression"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 462 | |
| 463 | DefaultFunctionArrayConversion(condExpr); |
| 464 | QualType condType = condExpr->getType(); |
| 465 | |
| 466 | if (!condType->isScalarType()) // C99 6.8.5p2 |
| 467 | return Diag(DoLoc, diag::err_typecheck_statement_requires_scalar, |
| 468 | condType.getAsString(), condExpr->getSourceRange()); |
| 469 | |
Steve Naroff | 5d2fff8 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 470 | return new DoStmt((Stmt*)Body, condExpr, DoLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 474 | Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chris Lattner | 3332fbd | 2007-08-28 04:55:47 +0000 | [diff] [blame] | 475 | StmtTy *first, ExprTy *second, ExprTy *third, |
| 476 | SourceLocation RParenLoc, StmtTy *body) { |
| 477 | Stmt *First = static_cast<Stmt*>(first); |
| 478 | Expr *Second = static_cast<Expr*>(second); |
| 479 | Expr *Third = static_cast<Expr*>(third); |
| 480 | Stmt *Body = static_cast<Stmt*>(body); |
| 481 | |
Chris Lattner | 0661105 | 2007-08-28 05:03:08 +0000 | [diff] [blame] | 482 | if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) { |
| 483 | // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare |
| 484 | // identifiers for objects having storage class 'auto' or 'register'. |
Steve Naroff | 2591e1b | 2007-09-13 23:52:58 +0000 | [diff] [blame] | 485 | for (ScopedDecl *D = DS->getDecl(); D; D = D->getNextDeclarator()) { |
Chris Lattner | 0661105 | 2007-08-28 05:03:08 +0000 | [diff] [blame] | 486 | BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(D); |
| 487 | if (BVD && !BVD->hasLocalStorage()) |
| 488 | BVD = 0; |
| 489 | if (BVD == 0) |
Steve Naroff | cb59747 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 490 | Diag(dyn_cast<ScopedDecl>(D)->getLocation(), |
| 491 | diag::err_non_variable_decl_in_for); |
Chris Lattner | 0661105 | 2007-08-28 05:03:08 +0000 | [diff] [blame] | 492 | // FIXME: mark decl erroneous! |
| 493 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 494 | } |
| 495 | if (Second) { |
Chris Lattner | 3332fbd | 2007-08-28 04:55:47 +0000 | [diff] [blame] | 496 | DefaultFunctionArrayConversion(Second); |
| 497 | QualType SecondType = Second->getType(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 498 | |
Chris Lattner | 3332fbd | 2007-08-28 04:55:47 +0000 | [diff] [blame] | 499 | if (!SecondType->isScalarType()) // C99 6.8.5p2 |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 500 | return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar, |
Chris Lattner | 3332fbd | 2007-08-28 04:55:47 +0000 | [diff] [blame] | 501 | SecondType.getAsString(), Second->getSourceRange()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 502 | } |
Steve Naroff | 5d2fff8 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 503 | return new ForStmt(First, Second, Third, Body, ForLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | |
| 507 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 508 | Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 509 | IdentifierInfo *LabelII) { |
| 510 | // Look up the record for this label identifier. |
| 511 | LabelStmt *&LabelDecl = LabelMap[LabelII]; |
| 512 | |
| 513 | // If we haven't seen this label yet, create a forward reference. |
| 514 | if (LabelDecl == 0) |
| 515 | LabelDecl = new LabelStmt(LabelLoc, LabelII, 0); |
| 516 | |
Ted Kremenek | a65ad46 | 2007-09-06 17:11:52 +0000 | [diff] [blame] | 517 | return new GotoStmt(LabelDecl, GotoLoc, LabelLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 521 | Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc, |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 522 | ExprTy *DestExp) { |
| 523 | // FIXME: Verify that the operand is convertible to void*. |
| 524 | |
| 525 | return new IndirectGotoStmt((Expr*)DestExp); |
| 526 | } |
| 527 | |
| 528 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 529 | Sema::ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 530 | Scope *S = CurScope->getContinueParent(); |
| 531 | if (!S) { |
| 532 | // C99 6.8.6.2p1: A break shall appear only in or as a loop body. |
| 533 | Diag(ContinueLoc, diag::err_continue_not_in_loop); |
| 534 | return true; |
| 535 | } |
| 536 | |
Steve Naroff | c32a20d | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 537 | return new ContinueStmt(ContinueLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 541 | Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 542 | Scope *S = CurScope->getBreakParent(); |
| 543 | if (!S) { |
| 544 | // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body. |
| 545 | Diag(BreakLoc, diag::err_break_not_in_loop_or_switch); |
| 546 | return true; |
| 547 | } |
| 548 | |
Steve Naroff | c32a20d | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 549 | return new BreakStmt(BreakLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | |
| 553 | Action::StmtResult |
Steve Naroff | 5cbb02f | 2007-09-16 14:56:35 +0000 | [diff] [blame^] | 554 | Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 555 | Expr *RetValExp = static_cast<Expr *>(rex); |
| 556 | QualType lhsType = CurFunctionDecl->getResultType(); |
| 557 | |
| 558 | if (lhsType->isVoidType()) { |
| 559 | if (RetValExp) // C99 6.8.6.4p1 (ext_ since GCC warns) |
| 560 | Diag(ReturnLoc, diag::ext_return_has_expr, |
| 561 | CurFunctionDecl->getIdentifier()->getName(), |
| 562 | RetValExp->getSourceRange()); |
Steve Naroff | c32a20d | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 563 | return new ReturnStmt(ReturnLoc, RetValExp); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 564 | } else { |
| 565 | if (!RetValExp) { |
| 566 | const char *funcName = CurFunctionDecl->getIdentifier()->getName(); |
| 567 | if (getLangOptions().C99) // C99 6.8.6.4p1 (ext_ since GCC warns) |
| 568 | Diag(ReturnLoc, diag::ext_return_missing_expr, funcName); |
| 569 | else // C90 6.6.6.4p4 |
| 570 | Diag(ReturnLoc, diag::warn_return_missing_expr, funcName); |
Steve Naroff | c32a20d | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 571 | return new ReturnStmt(ReturnLoc, (Expr*)0); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | // we have a non-void function with an expression, continue checking |
| 575 | QualType rhsType = RetValExp->getType(); |
| 576 | |
| 577 | // C99 6.8.6.4p3(136): The return statement is not an assignment. The |
| 578 | // overlap restriction of subclause 6.5.16.1 does not apply to the case of |
| 579 | // function return. |
| 580 | AssignmentCheckResult result = CheckSingleAssignmentConstraints(lhsType, |
| 581 | RetValExp); |
Ted Kremenek | 235e1ad | 2007-08-14 18:14:14 +0000 | [diff] [blame] | 582 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 583 | // decode the result (notice that extensions still return a type). |
| 584 | switch (result) { |
| 585 | case Compatible: |
| 586 | break; |
| 587 | case Incompatible: |
| 588 | Diag(ReturnLoc, diag::err_typecheck_return_incompatible, |
| 589 | lhsType.getAsString(), rhsType.getAsString(), |
| 590 | RetValExp->getSourceRange()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 591 | break; |
| 592 | case PointerFromInt: |
| 593 | // check for null pointer constant (C99 6.3.2.3p3) |
| 594 | if (!RetValExp->isNullPointerConstant(Context)) { |
| 595 | Diag(ReturnLoc, diag::ext_typecheck_return_pointer_int, |
| 596 | lhsType.getAsString(), rhsType.getAsString(), |
| 597 | RetValExp->getSourceRange()); |
| 598 | } |
| 599 | break; |
| 600 | case IntFromPointer: |
| 601 | Diag(ReturnLoc, diag::ext_typecheck_return_pointer_int, |
| 602 | lhsType.getAsString(), rhsType.getAsString(), |
| 603 | RetValExp->getSourceRange()); |
| 604 | break; |
| 605 | case IncompatiblePointer: |
| 606 | Diag(ReturnLoc, diag::ext_typecheck_return_incompatible_pointer, |
| 607 | lhsType.getAsString(), rhsType.getAsString(), |
| 608 | RetValExp->getSourceRange()); |
| 609 | break; |
| 610 | case CompatiblePointerDiscardsQualifiers: |
| 611 | Diag(ReturnLoc, diag::ext_typecheck_return_discards_qualifiers, |
| 612 | lhsType.getAsString(), rhsType.getAsString(), |
| 613 | RetValExp->getSourceRange()); |
| 614 | break; |
| 615 | } |
Ted Kremenek | 45925ab | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 616 | |
| 617 | if (RetValExp) CheckReturnStackAddr(RetValExp, lhsType, ReturnLoc); |
| 618 | |
Steve Naroff | c32a20d | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 619 | return new ReturnStmt(ReturnLoc, (Expr*)RetValExp); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 620 | } |
| 621 | |