changeset 81:97a220dc594f

if __return or __environment used in void function, compiler emit error.
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Wed, 22 Oct 2014 18:26:28 +0900
parents 67baa08a3894
children e218c19a8176
files tools/clang/include/clang/Parse/Parser.h tools/clang/lib/Parse/ParseCbC.cpp
diffstat 2 files changed, 26 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/tools/clang/include/clang/Parse/Parser.h	Thu Sep 25 16:56:18 2014 +0900
+++ b/tools/clang/include/clang/Parse/Parser.h	Wed Oct 22 18:26:28 2014 +0900
@@ -1795,7 +1795,7 @@
       llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback);
 
 #ifndef noCbC
-  bool CreateRetCS(IdentifierInfo* csName);
+  void CreateRetCS(IdentifierInfo* csName);
   void Create__CbC_envStruct(SourceLocation Loc, AccessSpecifier AS);
   IdentifierInfo* CreateIdentifierInfo(const char* Name, SourceLocation Loc);
   Decl* Create__CbC_envBody(Decl* TagDecl, DeclSpec::TST T, SourceLocation Loc, const char* Name);
@@ -1803,7 +1803,7 @@
   ExprResult LookupMemberAndBuildExpr(IdentifierInfo *II, Expr* Base, bool IsArrow);
   StmtResult CreateSjForContinuationWithTheEnv();
   StmtResult CreateAssignmentStmt(IdentifierInfo* LHSII = 0, IdentifierInfo* RHSII = 0, bool LHSisMemberAccess = false,
-				  bool RHShasAmp = false, IdentifierInfo* extraLHSII = 0, IdentifierInfo* extraRHSII = 0);
+                                  bool RHShasAmp = false, IdentifierInfo* extraLHSII = 0, IdentifierInfo* extraRHSII = 0);
   StmtResult CreateDeclStmt(IdentifierInfo *II = 0, bool isRetCS = false, bool copyType = false, DeclSpec::TST valueType = DeclSpec::TST_int, IdentifierInfo* Name = 0);
   IdentifierInfo* CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc);
   ParmVarDecl* CreateParam(IdentifierInfo *II = 0, int pointerNum = 0, DeclSpec::TST T = DeclSpec::TST_int);
@@ -1814,6 +1814,7 @@
   StmtResult CreateComplexStmtRet(IdentifierInfo *II, bool IsAddressOfOperand);
   ExprResult Prepare__retForGotoWithTheEnvExpr();
   ExprResult Prepare__envForGotoWithTheEnvExpr();
+  bool isVoidFunction();
 #endif
 
   bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
--- a/tools/clang/lib/Parse/ParseCbC.cpp	Thu Sep 25 16:56:18 2014 +0900
+++ b/tools/clang/lib/Parse/ParseCbC.cpp	Wed Oct 22 18:26:28 2014 +0900
@@ -92,6 +92,13 @@
 ///             longjmp((int*)(((struct __CbC_environment *)env)->env),1);
 ///         }
 ExprResult Parser::Prepare__retForGotoWithTheEnvExpr(){
+
+  if (isVoidFunction()) { // error check : function type is void or not.
+    unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, "continuation with the environment cannot use in the void function");
+    Diag(Tok, DiagID);
+    return ExprError();
+  }
+
   StmtResult innerRes;
   SourceLocation Loc = Tok.getLocation();
   IdentifierInfo *__CbC_retII = CreateIdentifierInfo(__CBC_RETURN_NAME, Loc);
@@ -105,11 +112,7 @@
   StmtVector CompoundStmts; 
 
   // create code segment for return to C's function
-  if (CreateRetCS(retcsII)) { // error check : function type is void or not.
-    unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, "continuation with the environment cannot use in the void function");
-    Diag(Tok, DiagID);
-    return ExprError();
-  }
+  CreateRetCS(retcsII);
     
   // __code (*__CbC_return)();
   innerRes = CreateDeclStmt(__CbC_retII, true, false, DeclSpec::TST___code);
@@ -152,6 +155,13 @@
 ///           void *ret_p,*env;
 ///         }
 ExprResult Parser::Prepare__envForGotoWithTheEnvExpr(){
+
+  if (isVoidFunction()) { // error check : function type is void or not.
+    unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, "continuation with the environment cannot use in the void function");
+    Diag(Tok, DiagID);
+    return ExprError();
+  }
+
   StmtResult innerRes;
   SourceLocation Loc = Tok.getLocation();
   IdentifierInfo *bufII = CreateIdentifierInfo(__CBC_BUF_NAME, Loc);
@@ -586,12 +596,9 @@
 ///           *(return_type)((struct CbC_environment *)(env))->ret_p = n;
 ///             longjmp((int*)(((struct __CbC_environment *)env)->env),1);
 ///         }
-bool Parser::CreateRetCS(IdentifierInfo *csName){
+void Parser::CreateRetCS(IdentifierInfo *csName){
   const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy();
-  FunctionDecl *CurFunctionDecl = Actions.getCurFunctionDecl();
-  QualType CurFuncResQT = CurFunctionDecl->getReturnType();
-  if (CurFuncResQT.getTypePtr()->isVoidType()) // this function cannot use continuation with the environment.
-    return true;
+  QualType CurFuncResQT = Actions.getCurFunctionDecl()->getReturnType();
   
   Scope *SavedScope = getCurScope();
   DeclContext *SavedContext = Actions.CurContext;
@@ -739,7 +746,6 @@
   Actions.CurScope = SavedScope;
   Actions.CurContext = SavedContext;
   Actions.FunctionScopes.push_back(SavedFSI);
-  return false;
 }
 
 /// IIToExpr - Create ExprResult from IdentifierInfo. 
@@ -870,4 +876,10 @@
       ConsumeToken();
   }
 }
+
+/// isVoidFunction - Return true if current function return type is void.
+bool Parser::isVoidFunction(){
+  return Actions.getCurFunctionDecl()->getReturnType().getTypePtr()->isVoidType();
+}
+
 #endif