Skip to content
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
17 changes: 17 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,20 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
return failure();
}

// Parse the rest of the attributes.
NamedAttrList parsedAttrs;
if (parser.parseOptionalAttrDictWithKeyword(parsedAttrs))
return failure();

for (StringRef disallowed : cir::FuncOp::getAttributeNames()) {
if (parsedAttrs.get(disallowed))
return parser.emitError(loc, "attribute '")
<< disallowed
<< "' should not be specified in the explicit attribute list";
}

state.attributes.append(parsedAttrs);

// Parse the optional function body.
auto *body = state.addRegion();
OptionalParseResult parseResult = parser.parseOptionalRegion(
Expand Down Expand Up @@ -1977,6 +1991,9 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
p << " inline(" << cir::stringifyInlineKind(inlineAttr.getValue()) << ")";
}

function_interface_impl::printFunctionAttributes(
p, *this, cir::FuncOp::getAttributeNames());

// Print the body if this is not an external function.
Region &body = getOperation()->getRegion(0);
if (!body.empty()) {
Expand Down
8 changes: 8 additions & 0 deletions clang/test/CIR/IR/func.cir
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,11 @@ cir.func @Foo_move_assign() special_member<#cir.cxx_assign<!rec_Foo, move>> {
// CHECK: cir.func @Foo_move_assign() special_member<#cir.cxx_assign<!rec_Foo, move>> {
// CHECK: cir.return
// CHECK: }

cir.func @has_attrs() attributes {foo, baz = 5, floof = "flop"} {
cir.return
}

// CHECK: cir.func @has_attrs() attributes {baz = 5 : i64{{.*}}, floof = "flop", foo} {
// CHECK: cir.return
// CHECK: }
11 changes: 11 additions & 0 deletions clang/test/CIR/IR/invalid-func-attr.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: cir-opt %s -verify-diagnostics

module {
cir.func @l0() {
cir.return
}

cir.func @disallowedAttr() attributes {comdat} { // expected-error{{custom op 'cir.func' attribute 'comdat' should not be specified in the explicit attribute list}}
cir.return
}
}