Skip to content

Commit 41ebe96

Browse files
committed
[CIR][Asm] Fix parsing of extra(...) attributes in cir.call
The parser was looking for extra(...) before the return type while the pretty-printer put it after the return type. This was breaking the LSP-server for example. Change the parser behavior accordingly.
1 parent 05fb5a2 commit 41ebe96

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,18 @@ static ::mlir::ParseResult parseCallCommon(::mlir::OpAsmParser &parser,
28272827
.failed())
28282828
return ::mlir::failure();
28292829

2830+
if (parser.parseOptionalAttrDict(result.attributes))
2831+
return ::mlir::failure();
2832+
if (parser.parseColon())
2833+
return ::mlir::failure();
2834+
2835+
::mlir::FunctionType opsFnTy;
2836+
if (parser.parseType(opsFnTy))
2837+
return ::mlir::failure();
2838+
operandsTypes = opsFnTy.getInputs();
2839+
allResultTypes = opsFnTy.getResults();
2840+
result.addTypes(allResultTypes);
2841+
28302842
auto &builder = parser.getBuilder();
28312843
Attribute extraAttrs;
28322844
if (::mlir::succeeded(parser.parseOptionalKeyword("extra"))) {
@@ -2843,18 +2855,6 @@ static ::mlir::ParseResult parseCallCommon(::mlir::OpAsmParser &parser,
28432855
}
28442856
result.addAttribute(extraAttrsAttrName, extraAttrs);
28452857

2846-
if (parser.parseOptionalAttrDict(result.attributes))
2847-
return ::mlir::failure();
2848-
if (parser.parseColon())
2849-
return ::mlir::failure();
2850-
2851-
::mlir::FunctionType opsFnTy;
2852-
if (parser.parseType(opsFnTy))
2853-
return ::mlir::failure();
2854-
operandsTypes = opsFnTy.getInputs();
2855-
allResultTypes = opsFnTy.getResults();
2856-
result.addTypes(allResultTypes);
2857-
28582858
if (parser.resolveOperands(ops, operandsTypes, opsLoc, result.operands))
28592859
return ::mlir::failure();
28602860

clang/test/CIR/IR/call.cir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
!s32i = !cir.int<s, 32>
44
!fnptr = !cir.ptr<!cir.func<!s32i (!cir.ptr<!s32i>)>>
55

6+
#fn_attr = #cir<extra({inline = #cir.inline<no>, optnone = #cir.optnone})>
7+
#fn_attr1 = #cir<extra({nothrow = #cir.nothrow})>
8+
69
module {
10+
// Excerpt of std::array<int, 8192ul>::operator[](unsigned long)
11+
cir.func linkonce_odr @_ZNSt5arrayIiLm8192EEixEm(%arg0: !s32i) -> !s32i extra(#fn_attr) {
12+
cir.return %arg0 : !s32i
13+
}
14+
715
cir.func @ind(%fnptr: !fnptr, %a : !s32i) {
816
%r = cir.call %fnptr(%a) : (!fnptr, !s32i) -> !s32i
17+
// Check parse->pretty-print round-trip on extra() attribute
18+
%7 = cir.call @_ZNSt5arrayIiLm8192EEixEm(%a) : (!s32i) -> !s32i extra(#fn_attr1)
919
cir.return
1020
}
1121
}
1222

1323
// CHECK: %0 = cir.call %arg0(%arg1) : (!cir.ptr<!cir.func<!s32i (!cir.ptr<!s32i>)>>, !s32i) -> !s32i
24+
// CHECK: %1 = cir.call @_ZNSt5arrayIiLm8192EEixEm(%arg1) : (!s32i) -> !s32i extra(#fn_attr1)

0 commit comments

Comments
 (0)