From: Chris Lattner Date: Tue, 28 Aug 2007 04:55:47 +0000 (+0000) Subject: If the condition of a for statement is promoted, make sure the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36c4b0ec13453bc003bbac380770b45ae35ef19c;p=clang If the condition of a for statement is promoted, make sure the implicit cast gets linked back into the AST. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41523 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp index f4c5414777..5b4be815c0 100644 --- a/Sema/SemaStmt.cpp +++ b/Sema/SemaStmt.cpp @@ -446,23 +446,27 @@ Sema::ParseDoStmt(SourceLocation DoLoc, StmtTy *Body, Action::StmtResult Sema::ParseForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, - StmtTy *First, ExprTy *Second, ExprTy *Third, - SourceLocation RParenLoc, StmtTy *Body) { + StmtTy *first, ExprTy *second, ExprTy *third, + SourceLocation RParenLoc, StmtTy *body) { + Stmt *First = static_cast(first); + Expr *Second = static_cast(second); + Expr *Third = static_cast(third); + Stmt *Body = static_cast(body); + if (First) { // C99 6.8.5p3: FIXME. Need to hack Parser::ParseForStatement() and // declaration support to create a DeclStmt node. Once this is done, // we can test for DeclStmt vs. Expr (already a sub-class of Stmt). } if (Second) { - Expr *testExpr = (Expr *)Second; - DefaultFunctionArrayConversion(testExpr); - QualType testType = testExpr->getType(); + DefaultFunctionArrayConversion(Second); + QualType SecondType = Second->getType(); - if (!testType->isScalarType()) // C99 6.8.5p2 + if (!SecondType->isScalarType()) // C99 6.8.5p2 return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar, - testType.getAsString(), testExpr->getSourceRange()); + SecondType.getAsString(), Second->getSourceRange()); } - return new ForStmt((Stmt*)First, (Expr*)Second, (Expr*)Third, (Stmt*)Body); + return new ForStmt(First, Second, Third, Body); }