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

Evaluate assume aligned attribute parameters #724

Merged
merged 2 commits into from
Sep 11, 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
5 changes: 5 additions & 0 deletions include/vast/CodeGen/DefaultAttrVisitor.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023-present, Trail of Bits, Inc.

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

View workflow job for this annotation

GitHub Actions / cpp-linter (18, 22.04)

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

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

#pragma once

Expand All @@ -17,6 +17,9 @@
using base = attr_visitor_base< default_attr_visitor >;
using base::base;

default_attr_visitor(mcontext_t &mctx, acontext_t &actx, codegen_builder &bld, visitor_view self, scope_context &scope)
: base(mctx, bld, self, scope), actx(actx) {}

using attr_visitor_base< default_attr_visitor >::Visit;

mlir_attr visit(const clang_attr *attr) { return Visit(attr); }
Expand Down Expand Up @@ -68,6 +71,8 @@
auto make(args_t &&...args) {
return bld.getAttr< attr_t >(std::forward< args_t >(args)...);
}

acontext_t &actx;
};

} // namespace vast::cg
23 changes: 10 additions & 13 deletions lib/vast/CodeGen/DefaultAttrVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,20 @@ namespace vast::cg
}

mlir_attr default_attr_visitor::VisitAssumeAlignedAttr(const clang::AssumeAlignedAttr *attr) {
llvm::APInt alignment, offset;
if (auto alignment_literal = mlir::dyn_cast< clang::IntegerLiteral >(attr->getAlignment())) {
alignment = alignment_literal->getValue();
} else {
VAST_REPORT("assume_aligned attribute with non-trivial expression is not supported");
auto alignment = attr->getAlignment()->getIntegerConstantExpr(actx);
if (!alignment) {
VAST_REPORT("could not evaluate assume aligned attribute alignment value.");
return {};
}
auto offset_expr = attr->getOffset();
if (offset_expr) {
if (auto offset_literal = mlir::dyn_cast< clang::IntegerLiteral >(offset_expr)) {
offset = offset_literal->getValue();
} else {
VAST_REPORT("assume_aligned attribute with non-trivial expression is not supported");
return {};
if (auto offset_expr = attr->getOffset()) {
auto offset = offset_expr->getIntegerConstantExpr(actx);
if (!offset) {
VAST_REPORT("could not evaluate assume aligned attribute offest value.");
return {};
}
return make< hl::AssumeAlignedAttr >(alignment.value(), offset.value());
}
return make< hl::AssumeAlignedAttr >(alignment, offset);
return make< hl::AssumeAlignedAttr >(alignment.value(), llvm::APInt());
}

mlir_attr default_attr_visitor::VisitCountedByAttr(const clang::CountedByAttr *attr) {
Expand Down
2 changes: 1 addition & 1 deletion lib/vast/CodeGen/DefaultVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace vast::cg
}

std::optional< named_attr > default_visitor::visit(const clang_attr *attr, scope_context &scope) {
default_attr_visitor visitor(mctx, bld, self, scope);
default_attr_visitor visitor(mctx, actx, bld, self, scope);
if (auto visited = visitor.visit(attr)) {
auto name = visited.getAbstractAttribute().getName();
return std::make_optional< named_attr >(
Expand Down