Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attributed stmt #714

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/vast/CodeGen/ClangVisitorBase.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/CodeGen/ClangVisitorBase.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on include/vast/CodeGen/ClangVisitorBase.hpp

File include/vast/CodeGen/ClangVisitorBase.hpp does not conform to Custom style guidelines. (lines 94, 95)

#pragma once

Expand Down Expand Up @@ -90,6 +90,12 @@
};
}

auto mk_region_builder(const clang_stmt *stmt) {
return [this, stmt] (auto &bld, auto) {
self.visit(stmt);
};
}

auto mk_optional_region_builder(const clang_stmt *stmt) {
return [this, stmt] (auto &bld, auto) {
if (stmt) self.visit(stmt);
Expand Down
1 change: 1 addition & 0 deletions include/vast/CodeGen/DefaultAttrVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace vast::cg {
mlir_attr VisitMaxFieldAlignmentAttr(const clang::MaxFieldAlignmentAttr *attr);
mlir_attr VisitAvailableOnlyInDefaultEvalMethodAttr(const clang::AvailableOnlyInDefaultEvalMethodAttr *attr);
mlir_attr VisitAvailabilityAttr(const clang::AvailabilityAttr *attr);
mlir_attr VisitFallThroughAttr(const clang::FallThroughAttr *attr);

private:
template< typename attr_t, typename... args_t >
Expand Down
2 changes: 2 additions & 0 deletions include/vast/CodeGen/DefaultStmtVisitor.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in include/vast/CodeGen/DefaultStmtVisitor.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on include/vast/CodeGen/DefaultStmtVisitor.hpp

File include/vast/CodeGen/DefaultStmtVisitor.hpp does not conform to Custom style guidelines. (lines 282)

#pragma once

Expand Down Expand Up @@ -278,6 +278,8 @@

operation VisitInitListExpr(const clang::InitListExpr *expr);
operation VisitImplicitValueInitExpr(const clang::ImplicitValueInitExpr *expr);

operation VisitAttributedStmt(const clang::AttributedStmt *stmt);
protected:
acontext_t &actx;
};
Expand Down
1 change: 1 addition & 0 deletions include/vast/Dialect/HighLevel/HighLevelAttributes.td
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def HighLevel_NoCfCheckAttr : HighLevel_Attr< "NoCfCheck", "nocf_check" >
def HighLevel_AvailableOnlyInDefaultEvalMethodAttr
: HighLevel_Attr< "AvailableOnlyInDefaultEvalMethod", "available_only_in_default_eval_method" >;
def HighLevel_AvailabilityAttr : HighLevel_Attr< "AvailabilityAttr", "availability" >;
def HighLevel_FallthroughAttr : HighLevel_Attr< "Fallthrough", "fallthrough" >;

def HighLevel_AsmLabelAttr
: HighLevel_Attr< "AsmLabel", "asm" >
Expand Down
19 changes: 19 additions & 0 deletions include/vast/Dialect/HighLevel/HighLevelOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1613,4 +1613,23 @@ def HighLevel_StaticAssertDecl
let assemblyFormat = "`failed` `:` $failed $assert (`,` $message^)? attr-dict";
}

def HighLevel_AttributedStmt
: HighLevel_Op< "attributed_stmt", [NoTerminator] >
{
let summary = "Attributed stmt operation.";

let regions = (region AnyRegion:$body);

let skipDefaultBuilders = 1;
let builders = [
OpBuilder< (ins CArg< "builder_callback_ref" >:$bodyBuilder),
[{
InsertionGuard guard($_builder);
build_region($_builder, $_state, bodyBuilder);
}] >
];

let assemblyFormat = [{ attr-dict `:` $body }];
}

#endif // VAST_DIALECT_HIGHLEVEL_IR_HIGHLEVELOPS
3 changes: 3 additions & 0 deletions lib/vast/CodeGen/DefaultAttrVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,7 @@ namespace vast::cg
return make< hl::AvailabilityAttrAttr >();
}

mlir_attr default_attr_visitor::VisitFallThroughAttr(const clang::FallThroughAttr *attr) {
return make< hl::FallthroughAttr >();
}
} // namespace vast::hcg
20 changes: 20 additions & 0 deletions lib/vast/CodeGen/DefaultStmtVisitor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/CodeGen/DefaultStmtVisitor.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

Run clang-format on lib/vast/CodeGen/DefaultStmtVisitor.cpp

File lib/vast/CodeGen/DefaultStmtVisitor.cpp does not conform to Custom style guidelines. (lines 1120, 1121, 1122)

#include "vast/Util/Warnings.hpp"

Expand Down Expand Up @@ -1116,4 +1116,24 @@
.freeze();
}

operation default_stmt_visitor::VisitAttributedStmt(const clang::AttributedStmt *stmt) {
auto attr_stmt = bld.compose< hl::AttributedStmt >()
.bind(self.location(stmt))
.bind(mk_region_builder(stmt->getSubStmt()))
.freeze();

mlir_attr_list attrs;

// This is not handled by default, because statements usually do not have attributes
for (auto attr : stmt->getAttrs()) {
if (auto visited = self.visit(attr)) {
attrs.set(visited->getName(), visited->getValue());
}
}

attr_stmt->setAttrs(attrs);

return attr_stmt;
}

} // namespace vast::cg
17 changes: 17 additions & 0 deletions test/vast/Dialect/HighLevel/attr-stmt-a.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o - | %file-check %s
// RUN: %vast-cc1 -vast-emit-mlir=hl %s -o %t && %vast-opt %t | diff -B %t -

void f() {
int x;
switch (1) {
case 1:
x = 1;
// CHECK: hl.attributed_stmt {hl.fallthrough = #hl.fallthrough} : {
// CHECK: hl.null
// CHECK: }
[[fallthrough]];
case 2:
x = 2;
break;
}
}
17 changes: 0 additions & 17 deletions test/vast/Dialect/Unsupported/fallthrough.cpp

This file was deleted.