From 87a71b15711d743e427d284761a9382a059c4e40 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Wed, 26 Jan 2022 19:07:08 +0300 Subject: [PATCH 1/5] [hir2mpl] AttributedStmt handling --- src/hir2mpl/ast_input/clang/include/ast_op.h | 1 + src/hir2mpl/ast_input/clang/include/ast_parser.h | 1 + src/hir2mpl/ast_input/clang/include/ast_stmt.h | 10 ++++++++++ src/hir2mpl/ast_input/clang/src/ast_parser.cpp | 14 ++++++++++++++ src/hir2mpl/ast_input/clang/src/ast_stmt.cpp | 7 +++++++ 5 files changed, 33 insertions(+) diff --git a/src/hir2mpl/ast_input/clang/include/ast_op.h b/src/hir2mpl/ast_input/clang/include/ast_op.h index cd6ceb4acc..795a9181da 100644 --- a/src/hir2mpl/ast_input/clang/include/ast_op.h +++ b/src/hir2mpl/ast_input/clang/include/ast_op.h @@ -168,6 +168,7 @@ enum ASTStmtOp { kASTStmtGCCAsmStmt, kASTOffsetOfStmt, kASTGenericSelectionExprStmt, + kASTStmtAttributed, }; } // namespace maple #endif // HIR2MPL_AST_INPUT_INCLUDE_AST_OP_H diff --git a/src/hir2mpl/ast_input/clang/include/ast_parser.h b/src/hir2mpl/ast_input/clang/include/ast_parser.h index 07d3559416..7d05e26fc4 100644 --- a/src/hir2mpl/ast_input/clang/include/ast_parser.h +++ b/src/hir2mpl/ast_input/clang/include/ast_parser.h @@ -50,6 +50,7 @@ class ASTParser { ASTStmt *ProcessStmt(MapleAllocator &allocator, const clang::Stmt &stmt); ASTStmt *ProcessFunctionBody(MapleAllocator &allocator, const clang::CompoundStmt &cpdStmt); #define PROCESS_STMT(CLASS) ProcessStmt##CLASS(MapleAllocator&, const clang::CLASS&) + ASTStmt *PROCESS_STMT(AttributedStmt); ASTStmt *PROCESS_STMT(UnaryOperator); ASTStmt *PROCESS_STMT(BinaryOperator); ASTStmt *PROCESS_STMT(CompoundAssignOperator); diff --git a/src/hir2mpl/ast_input/clang/include/ast_stmt.h b/src/hir2mpl/ast_input/clang/include/ast_stmt.h index 06ce39078c..b65724f29e 100644 --- a/src/hir2mpl/ast_input/clang/include/ast_stmt.h +++ b/src/hir2mpl/ast_input/clang/include/ast_stmt.h @@ -14,6 +14,7 @@ */ #ifndef HIR2MPL_AST_INPUT_INCLUDE_AST_STMT_H #define HIR2MPL_AST_INPUT_INCLUDE_AST_STMT_H +#include "clang/AST/Attr.h" #include "ast_op.h" #include "ast_expr.h" #include "feir_stmt.h" @@ -108,6 +109,15 @@ class ASTReturnStmt : public ASTStmt { std::list Emit2FEStmtImpl() const override; }; +class ASTAttributedStmt : public ASTStmt { + public: + ASTAttributedStmt() : ASTStmt(kASTStmtReturn) {} + ~ASTAttributedStmt() = default; + + private: + std::list Emit2FEStmtImpl() const override; +}; + class ASTIfStmt : public ASTStmt { public: ASTIfStmt() : ASTStmt(kASTStmtIf) {} diff --git a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp index 213d75e357..2daf1c51e5 100644 --- a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp +++ b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp @@ -108,6 +108,13 @@ ASTStmt *ASTParser::ProcessStmtCompoundStmt(MapleAllocator &allocator, const cla return astStmt; \ } +#define ATTR_STMT_CASE(CLASS) \ + case clang::Stmt::CLASS##Class: { \ + ASTStmt *astStmt = ProcessStmt##CLASS(allocator, \ + llvm::cast(llvm::cast(stmt))); \ + return astStmt; \ +} + ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &stmt) { switch (stmt.getStmtClass()) { STMT_CASE(UnaryOperator); @@ -143,6 +150,7 @@ ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &st STMT_CASE(GCCAsmStmt); STMT_CASE(OffsetOfExpr); STMT_CASE(GenericSelectionExpr); + ATTR_STMT_CASE(AttributedStmt); default: { CHECK_FATAL(false, "ASTStmt: %s NIY", stmt.getStmtClassName()); return nullptr; @@ -150,6 +158,12 @@ ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &st } } +ASTStmt *ASTParser::ProcessStmtAttributedStmt(MapleAllocator &allocator, const clang::AttributedStmt &attributedStmt) { + ASTAttributedStmt *astAttributedStmt = nullptr; + CHECK_FATAL(astAttributedStmt != nullptr, "astAttributedStmt is nullptr"); + return astAttributedStmt; +} + ASTStmt *ASTParser::ProcessStmtOffsetOfExpr(MapleAllocator &allocator, const clang::OffsetOfExpr &expr) { auto *astStmt = ASTDeclsBuilder::ASTStmtBuilder(allocator); CHECK_FATAL(astStmt != nullptr, "astStmt is nullptr"); diff --git a/src/hir2mpl/ast_input/clang/src/ast_stmt.cpp b/src/hir2mpl/ast_input/clang/src/ast_stmt.cpp index 72dd429e1a..5ceb1262a0 100644 --- a/src/hir2mpl/ast_input/clang/src/ast_stmt.cpp +++ b/src/hir2mpl/ast_input/clang/src/ast_stmt.cpp @@ -329,6 +329,13 @@ std::list ASTNullStmt::Emit2FEStmtImpl() const { return stmts; } +// ---------- ASTAttributeStmt ---------- +std::list ASTAttributedStmt::Emit2FEStmtImpl() const { + //there is no need to handle fallthrough - clang will + std::list stmts; + return stmts; +} + // ---------- ASTDeclStmt ---------- std::list ASTDeclStmt::Emit2FEStmtImpl() const { std::list stmts; -- Gitee From 2d27f903164b4d51df871ee92c7afafabd287a3d Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Wed, 26 Jan 2022 20:13:55 +0300 Subject: [PATCH 2/5] [hir2mpl] AttributedStmt nullptr fix --- src/hir2mpl/ast_input/clang/src/ast_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp index 2daf1c51e5..aa69aa4a2f 100644 --- a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp +++ b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp @@ -159,7 +159,7 @@ ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &st } ASTStmt *ASTParser::ProcessStmtAttributedStmt(MapleAllocator &allocator, const clang::AttributedStmt &attributedStmt) { - ASTAttributedStmt *astAttributedStmt = nullptr; + ASTAttributedStmt *astAttributedStmt = ASTDeclsBuilder::ASTStmtBuilder(allocator); CHECK_FATAL(astAttributedStmt != nullptr, "astAttributedStmt is nullptr"); return astAttributedStmt; } -- Gitee From d931be88c471d8103f216aa961c58b00ddc81b96 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Thu, 27 Jan 2022 11:57:23 +0300 Subject: [PATCH 3/5] AttributedStmt fixes --- src/hir2mpl/ast_input/clang/include/ast_stmt.h | 7 +++---- src/hir2mpl/ast_input/clang/src/ast_parser.cpp | 10 ++-------- src/hir2mpl/ast_input/clang/src/ast_stmt.cpp | 7 ------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/hir2mpl/ast_input/clang/include/ast_stmt.h b/src/hir2mpl/ast_input/clang/include/ast_stmt.h index b65724f29e..d6b82daa5d 100644 --- a/src/hir2mpl/ast_input/clang/include/ast_stmt.h +++ b/src/hir2mpl/ast_input/clang/include/ast_stmt.h @@ -14,7 +14,6 @@ */ #ifndef HIR2MPL_AST_INPUT_INCLUDE_AST_STMT_H #define HIR2MPL_AST_INPUT_INCLUDE_AST_STMT_H -#include "clang/AST/Attr.h" #include "ast_op.h" #include "ast_expr.h" #include "feir_stmt.h" @@ -111,11 +110,11 @@ class ASTReturnStmt : public ASTStmt { class ASTAttributedStmt : public ASTStmt { public: - ASTAttributedStmt() : ASTStmt(kASTStmtReturn) {} - ~ASTAttributedStmt() = default; + ASTAttributedStmt() : ASTStmt(kASTStmtAttributed) {} + ~ASTAttributedStmt() override = default; private: - std::list Emit2FEStmtImpl() const override; + std::list Emit2FEStmtImpl() const override{ return {}; }; }; class ASTIfStmt : public ASTStmt { diff --git a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp index aa69aa4a2f..197a23a475 100644 --- a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp +++ b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp @@ -108,12 +108,6 @@ ASTStmt *ASTParser::ProcessStmtCompoundStmt(MapleAllocator &allocator, const cla return astStmt; \ } -#define ATTR_STMT_CASE(CLASS) \ - case clang::Stmt::CLASS##Class: { \ - ASTStmt *astStmt = ProcessStmt##CLASS(allocator, \ - llvm::cast(llvm::cast(stmt))); \ - return astStmt; \ -} ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &stmt) { switch (stmt.getStmtClass()) { @@ -150,7 +144,7 @@ ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &st STMT_CASE(GCCAsmStmt); STMT_CASE(OffsetOfExpr); STMT_CASE(GenericSelectionExpr); - ATTR_STMT_CASE(AttributedStmt); + STMT_CASE(AttributedStmt); default: { CHECK_FATAL(false, "ASTStmt: %s NIY", stmt.getStmtClassName()); return nullptr; @@ -158,7 +152,7 @@ ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &st } } -ASTStmt *ASTParser::ProcessStmtAttributedStmt(MapleAllocator &allocator, const clang::AttributedStmt &attributedStmt) { +ASTStmt *ASTParser::ProcessStmtAttributedStmt(MapleAllocator &allocator, const clang::AttributedStmt &AttrStmt) { ASTAttributedStmt *astAttributedStmt = ASTDeclsBuilder::ASTStmtBuilder(allocator); CHECK_FATAL(astAttributedStmt != nullptr, "astAttributedStmt is nullptr"); return astAttributedStmt; diff --git a/src/hir2mpl/ast_input/clang/src/ast_stmt.cpp b/src/hir2mpl/ast_input/clang/src/ast_stmt.cpp index 5ceb1262a0..72dd429e1a 100644 --- a/src/hir2mpl/ast_input/clang/src/ast_stmt.cpp +++ b/src/hir2mpl/ast_input/clang/src/ast_stmt.cpp @@ -329,13 +329,6 @@ std::list ASTNullStmt::Emit2FEStmtImpl() const { return stmts; } -// ---------- ASTAttributeStmt ---------- -std::list ASTAttributedStmt::Emit2FEStmtImpl() const { - //there is no need to handle fallthrough - clang will - std::list stmts; - return stmts; -} - // ---------- ASTDeclStmt ---------- std::list ASTDeclStmt::Emit2FEStmtImpl() const { std::list stmts; -- Gitee From 57bda1f4651e1c12b08f69bbde66af063e37c946 Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Fri, 28 Jan 2022 12:13:38 +0300 Subject: [PATCH 4/5] [hir2mpl] Added check for AttributedStmt to be fallthrough --- src/hir2mpl/ast_input/clang/src/ast_parser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp index 197a23a475..1fc2359d36 100644 --- a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp +++ b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp @@ -153,6 +153,7 @@ ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &st } ASTStmt *ASTParser::ProcessStmtAttributedStmt(MapleAllocator &allocator, const clang::AttributedStmt &AttrStmt) { + CHECK_FATAL(strcmp(AttrStmt.getAttrs()[0]->getSpelling(), "fallthrough") == 0 , "AttrStmt is not fallthrough"); ASTAttributedStmt *astAttributedStmt = ASTDeclsBuilder::ASTStmtBuilder(allocator); CHECK_FATAL(astAttributedStmt != nullptr, "astAttributedStmt is nullptr"); return astAttributedStmt; -- Gitee From 702903b45b3cb16070929954bada7c0c05bdbdbc Mon Sep 17 00:00:00 2001 From: antyshevtg Date: Fri, 28 Jan 2022 16:27:38 +0300 Subject: [PATCH 5/5] [hir2mpl] Replaced CHECK_FATAL for fallthrough with ASSERT --- src/hir2mpl/ast_input/clang/src/ast_parser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp index 1fc2359d36..af08eef88c 100644 --- a/src/hir2mpl/ast_input/clang/src/ast_parser.cpp +++ b/src/hir2mpl/ast_input/clang/src/ast_parser.cpp @@ -108,7 +108,6 @@ ASTStmt *ASTParser::ProcessStmtCompoundStmt(MapleAllocator &allocator, const cla return astStmt; \ } - ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &stmt) { switch (stmt.getStmtClass()) { STMT_CASE(UnaryOperator); @@ -153,7 +152,7 @@ ASTStmt *ASTParser::ProcessStmt(MapleAllocator &allocator, const clang::Stmt &st } ASTStmt *ASTParser::ProcessStmtAttributedStmt(MapleAllocator &allocator, const clang::AttributedStmt &AttrStmt) { - CHECK_FATAL(strcmp(AttrStmt.getAttrs()[0]->getSpelling(), "fallthrough") == 0 , "AttrStmt is not fallthrough"); + ASSERT(clang::hasSpecificAttr(AttrStmt.getAttrs()), "AttrStmt is not fallthrough"); ASTAttributedStmt *astAttributedStmt = ASTDeclsBuilder::ASTStmtBuilder(allocator); CHECK_FATAL(astAttributedStmt != nullptr, "astAttributedStmt is nullptr"); return astAttributedStmt; -- Gitee