# HG changeset patch # User Shinji KONO # Date 1623032892 -32400 # Node ID b7591485f4cdc3154b3f23cd602b887e8944dbab # Parent e348f3e5c8b2be2d75212c6888d32de9eed931df fix MacroDefLength diff -r e348f3e5c8b2 -r b7591485f4cd clang/include/clang/Parse/Parser.h --- a/clang/include/clang/Parse/Parser.h Sat Jun 05 15:35:13 2021 +0900 +++ b/clang/include/clang/Parse/Parser.h Mon Jun 07 11:28:12 2021 +0900 @@ -2070,6 +2070,7 @@ StmtResult ParseGotoStatement(); #ifndef noCbC StmtResult ParseCbCGotoStatement(ParsedAttributesWithRange &Attrs,StmtVector &Stmts); + void CompileFromString(const char *str, StmtVector &CompoundStmts); #endif StmtResult ParseContinueStatement(); StmtResult ParseBreakStatement(); diff -r e348f3e5c8b2 -r b7591485f4cd clang/lib/Lex/Preprocessor.cpp --- a/clang/lib/Lex/Preprocessor.cpp Sat Jun 05 15:35:13 2021 +0900 +++ b/clang/lib/Lex/Preprocessor.cpp Mon Jun 07 11:28:12 2021 +0900 @@ -1438,23 +1438,26 @@ Token Preprocessor::ReadFromString(const char *src , SourceLocation Loc) { // Push the ( "string" ) tokens into the token stream. MacroInfo *MI = AllocateMacroInfo(Loc); - Token Tok,FirstTok,Result; + Token Tok; bool Invalid = false; std::unique_ptr lx(new Lexer(CurLexer->getFileID(),getSourceManager().getBuffer(CurLexer->getFileID(), Loc, &Invalid),*this)); lx->InitLexer(src,src,src + strlen(src)); lx->Lex(Tok); - FirstTok = Tok; CurLexer.swap(lx); + int i = 0; while (Tok.getKind() != tok::TokenKind::eof) { Tok.setLocation(Loc); MI->AddTokenToBody(Tok); - Lex(Tok); + Lex(Tok); i++; } + Tok.setLocation(Loc); + MI->AddTokenToBody(Tok); i++; + MI->DefinitionLength = i; CurLexer = std::move(lx); CurPPLexer = CurLexer.get(); - EnterMacro(Result, Loc, MI , 0 ); - CurTokenLexer->MacroExpansionStart = Loc; - return Result; + EnterMacro(Tok, Loc, MI , 0 ); + CurTokenLexer->MacroDefLength = i; + return Tok; } #endif diff -r e348f3e5c8b2 -r b7591485f4cd clang/lib/Parse/ParseCbC.cpp --- a/clang/lib/Parse/ParseCbC.cpp Sat Jun 05 15:35:13 2021 +0900 +++ b/clang/lib/Parse/ParseCbC.cpp Mon Jun 07 11:28:12 2021 +0900 @@ -206,6 +206,25 @@ /// struct __CbC_env{ /// void *ret_p,*env; /// } + +void Parser::CompileFromString(const char *str, StmtVector &CompoundStmts){ + SourceLocation Loc = Tok.getLocation(); + Token TokSave = Tok; + SourceLocation PLocSave = PrevTokLocation; + PP.ReadFromString(str,Loc); + ConsumeAnyToken(); + while(! Tok.is(tok::eof)) { + StmtVector Stmts; + StmtResult innerRes; + innerRes = ParseStatementOrDeclaration(Stmts,( ParsedStmtContext::Compound | ParsedStmtContext::AllowDeclarationsInC)); + if (innerRes.isUsable()) + CompoundStmts.push_back(innerRes.get()); + } + ConsumeAnyToken(); + Tok = TokSave ; + PrevTokLocation= PLocSave ; +} + ExprResult Parser::Prepare__envForGotoWithTheEnvExpr(){ if (isVoidFunction()) { // error check : function type is void or not. @@ -241,18 +260,7 @@ CompoundStmts.push_back(innerRes.get()); ConsumeAnyToken(); // eat the '__environment'. - Token TokSave = Tok; - SourceLocation PLocSave = PrevTokLocation; - // jmp_buf env_buf; --> int env_buf[64]; - PP.ReadFromString("int env_buf[64];",Loc); - ConsumeAnyToken(); - // innerRes = CreateDeclStmt(bufII, false, false, 64, DeclSpec::TST_typename, CreateIdentifierInfo("int", Loc)); - StmtVector Stmts; - innerRes = ParseStatementOrDeclaration(Stmts,( ParsedStmtContext::Compound | ParsedStmtContext::AllowDeclarationsInC)); - Tok = TokSave ; - PrevTokLocation= PLocSave ; - if (innerRes.isUsable()) - CompoundStmts.push_back(innerRes.get()); + CompileFromString("int env_buf[64];",CompoundStmts); // 4*64 is enough for every arch right now // __CbC_environment.ret_p = &retval; innerRes = CreateAssignmentStmt(__CbC_envII, retvalII, true, true, ret_pII);