changeset 67:58d177b06036

fix one line if-else statement bug. goto cs(); and return; are emitted in compound statement now.
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Wed, 12 Feb 2014 00:47:11 +0900
parents 7a5097301ce3
children a37375f10d66
files tools/clang/lib/Parse/ParseStmt.cpp
diffstat 1 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tools/clang/lib/Parse/ParseStmt.cpp	Tue Feb 11 15:35:48 2014 +0900
+++ b/tools/clang/lib/Parse/ParseStmt.cpp	Wed Feb 12 00:47:11 2014 +0900
@@ -1699,6 +1699,9 @@
 ///
 StmtResult Parser::ParseCbCGotoStatement(ParsedAttributesWithRange &Attrs,StmtVector &Stmts) {
   assert(Tok.is(tok::kw_goto) && "Not a goto stmt!");
+  ParseScope CompoundScope(this, Scope::DeclScope);
+  StmtVector CompoundedStmts;
+
   SourceLocation gotoLoc = ConsumeToken();  // eat the 'goto'.
   StmtResult gotoRes;
   Token TokAfterGoto = Tok;
@@ -1712,6 +1715,7 @@
     return StmtError();
   }
   
+  /*
   // don't need return because this code segment caller isn't code segment.
   if (!Actions.getCurFunctionDecl()->getResultType().getTypePtr()->is__CodeType())
     return gotoRes;
@@ -1723,10 +1727,27 @@
   
   if(gotoRes.isUsable())
     Stmts.push_back(gotoRes.release());
-  /* add return; after goto code segment. */
+  // add return; after goto code segment. 
   
   ExprResult R;
   return Actions.ActOnReturnStmt(gotoLoc, R.take());
+  */
+  
+  assert((Attrs.empty() || gotoRes.isInvalid() || gotoRes.isUsable()) &&
+	 "attributes on empty statement");
+  if (!(Attrs.empty() || gotoRes.isInvalid()))
+    gotoRes = Actions.ProcessStmtAttributes(gotoRes.get(), Attrs.getList(), Attrs.Range);
+  if (gotoRes.isUsable())
+    CompoundedStmts.push_back(gotoRes.release());
+
+  if (Actions.getCurFunctionDecl()->getResultType().getTypePtr()->is__CodeType()) {
+    ExprResult retExpr;
+    StmtResult retRes;
+    retRes = Actions.ActOnReturnStmt(gotoLoc, retExpr.take());
+    if (retRes.isUsable())
+      CompoundedStmts.push_back(retRes.release());
+  }
+  return Actions.ActOnCompoundStmt(gotoLoc, Tok.getLocation(), CompoundedStmts, false);
 }
 #endif