diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index 6bf543cf794b7..8852295f8a06a 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -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( @@ -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()) { diff --git a/clang/test/CIR/IR/func.cir b/clang/test/CIR/IR/func.cir index 10df27b7e168f..d8906ab3e1301 100644 --- a/clang/test/CIR/IR/func.cir +++ b/clang/test/CIR/IR/func.cir @@ -186,3 +186,11 @@ cir.func @Foo_move_assign() special_member<#cir.cxx_assign> { // CHECK: cir.func @Foo_move_assign() special_member<#cir.cxx_assign> { // 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: } diff --git a/clang/test/CIR/IR/invalid-func-attr.cir b/clang/test/CIR/IR/invalid-func-attr.cir new file mode 100644 index 0000000000000..aaaaba7a7bf6f --- /dev/null +++ b/clang/test/CIR/IR/invalid-func-attr.cir @@ -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 + } +}