Mercurial > hg > CbC > CbC_llvm
changeset 186:f737e363b8f3
check compound scope in ParseCbC
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Jun 2020 10:45:39 +0900 |
parents | 86e770a5ed65 |
children | 4680e0f68448 |
files | clang/lib/Parse/ParseCbC.cpp |
diffstat | 1 files changed, 18 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/clang/lib/Parse/ParseCbC.cpp Tue Jun 02 22:39:12 2020 +0900 +++ b/clang/lib/Parse/ParseCbC.cpp Wed Jun 03 10:45:39 2020 +0900 @@ -12,6 +12,7 @@ #include "clang/Lex/LiteralSupport.h" #include "clang/AST/ASTConsumer.h" #include "clang/Sema/SemaDiagnostic.h" +#include "clang/Sema/ScopeInfo.h" #include <sstream> #include <string> @@ -149,7 +150,6 @@ } // std::unique_ptr<ASTUnit> AST(tooling::buildASTFromCode("({auto x = 1 + 1;})")); - EnterScope(Scope::DeclScope); StmtResult innerRes; SourceLocation Loc = Tok.getLocation(); IdentifierInfo *__CbC_retII = CreateIdentifierInfo("__CbC_cont", Loc); @@ -178,12 +178,12 @@ innerRes = CreateComplexStmtRet(__CbC_retII, false); if (innerRes.isUsable()) CompoundStmts.push_back(innerRes.get()); - + size_t cs = Actions.getCurFunction()->CompoundScopes.size(); Sema::CompoundScopeRAII CompoundScope(Actions); CompoundStmtRes = Actions.ActOnCompoundStmt(Loc,Loc,CompoundStmts,true); + assert( cs == Actions.getCurFunction()->CompoundScopes.size()); // ConsumeToken(); ConsumeAnyToken(); // eat the '__return'. - ExitScope(); return Actions.ActOnStmtExpr(getCurScope(),Loc, CompoundStmtRes.get(), Loc); } @@ -216,7 +216,8 @@ return ExprError(); } - EnterScope(Scope::DeclScope); + size_t cs = Actions.getCurFunction()->CompoundScopes.size(); + Sema::CompoundScopeRAII CompoundScope(Actions); StmtResult innerRes; SourceLocation Loc = Tok.getLocation(); IdentifierInfo *bufII = CreateIdentifierInfo(__CBC_BUF_NAME, Loc); @@ -268,7 +269,8 @@ CompoundStmts.push_back(innerRes.get()); StmtResult CompoundStmtRes = Actions.ActOnCompoundStmt(Loc,Loc,CompoundStmts,true); - ConsumeToken(); // eat the '__environment'. + assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + ConsumeAnyToken(); // eat the '__environment'. Result = Actions.ActOnStmtExpr(getCurScope() ,Loc, CompoundStmtRes.get(), Loc); // cast @@ -282,7 +284,6 @@ DeclaratorInfo.SetIdentifier(nullptr, Tok.getLocation()); DeclaratorInfo.AddTypeInfo(DeclaratorChunk::getPointer(star_DS.getTypeQualifiers(), Loc,star_DS.getConstSpecLoc(),star_DS.getVolatileSpecLoc(), star_DS.getRestrictSpecLoc(),star_DS.getAtomicSpecLoc(),star_DS.getUnalignedSpecLoc()),std::move(star_DS.getAttributes()),SourceLocation()); - ExitScope(); return Actions.ActOnCastExpr(getCurScope(), Loc, DeclaratorInfo, CastTy,Loc, Result.get()); } @@ -517,7 +518,8 @@ ParseScope InnerScope(this, Scope::DeclScope,false); StmtResult StmtRes; - ParseScope CompoundScope(this, Scope::DeclScope); + size_t cs = Actions.getCurFunction()->CompoundScopes.size(); + Sema::CompoundScopeRAII CompoundScope(Actions); PrettyStackTraceLoc CrashInfo(PP.getSourceManager(),Loc,"in create setjmp statement for CbC"); StmtVector innerStmts; StmtResult innerStmtRes; @@ -527,6 +529,7 @@ if (innerStmtRes.isUsable()) innerStmts.push_back(innerStmtRes.get()); StmtRes = Actions.ActOnCompoundStmt(Loc, Loc,innerStmts, false); + assert( cs == Actions.getCurFunction()->CompoundScopes.size()); StmtResult ThenStmt(StmtRes); InnerScope.Exit(); IfScope.Exit(); @@ -771,6 +774,8 @@ starDS.getUnalignedSpecLoc()), std::move(starDS.getAttributes()), SourceLocation()); + size_t cs = Actions.getCurFunction()->CompoundScopes.size(); + Sema::CompoundScopeRAII CompoundScope(Actions); ExprVector ArgExprs2; LHS = LookupNameAndBuildExpr(envII); ArgExprs2.push_back(LHS.get()); @@ -832,8 +837,8 @@ innerR = Actions.ActOnExprStmt(ljExpr); if(innerR.isUsable()) FnStmts.push_back(innerR.get()); - Sema::CompoundScopeRAII CompoundScope(Actions); FnBody = Actions.ActOnCompoundStmt(Loc, Loc, FnStmts, false); + assert( cs == Actions.getCurFunction()->CompoundScopes.size()); BodyScope.Exit(); TheDecl = Actions.ActOnFinishFunctionBody(BodyRes, FnBody.get()); returnDecl = Actions.ConvertDeclToDeclGroup(TheDecl); @@ -1003,7 +1008,6 @@ /// 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'. @@ -1038,7 +1042,11 @@ if (retRes.isUsable()) CompoundedStmts.push_back(retRes.get()); } - return Actions.ActOnCompoundStmt(gotoLoc, Tok.getLocation(), CompoundedStmts, false); + size_t cs = Actions.getCurFunction()->CompoundScopes.size(); + Sema::CompoundScopeRAII CompoundScope(Actions); + StmtResult R = Actions.ActOnCompoundStmt(gotoLoc, Tok.getLocation(), CompoundedStmts, false); + assert( cs == Actions.getCurFunction()->CompoundScopes.size()); + return R; } /// SearchCodeSegmentDeclaration - Read tokens until we get to the specified code segment declaration.