Skip to content

Commit 7365fd2

Browse files
keryelllanza
authored andcommitted
[CIR][Asm] Fix parsing of extra(...) attributes in cir.call (#835)
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 04fb312 commit 7365fd2

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
@@ -2834,6 +2834,18 @@ static ::mlir::ParseResult parseCallCommon(::mlir::OpAsmParser &parser,
28342834
.failed())
28352835
return ::mlir::failure();
28362836

2837+
if (parser.parseOptionalAttrDict(result.attributes))
2838+
return ::mlir::failure();
2839+
if (parser.parseColon())
2840+
return ::mlir::failure();
2841+
2842+
::mlir::FunctionType opsFnTy;
2843+
if (parser.parseType(opsFnTy))
2844+
return ::mlir::failure();
2845+
operandsTypes = opsFnTy.getInputs();
2846+
allResultTypes = opsFnTy.getResults();
2847+
result.addTypes(allResultTypes);
2848+
28372849
auto &builder = parser.getBuilder();
28382850
Attribute extraAttrs;
28392851
if (::mlir::succeeded(parser.parseOptionalKeyword("extra"))) {
@@ -2850,18 +2862,6 @@ static ::mlir::ParseResult parseCallCommon(::mlir::OpAsmParser &parser,
28502862
}
28512863
result.addAttribute(extraAttrsAttrName, extraAttrs);
28522864

2853-
if (parser.parseOptionalAttrDict(result.attributes))
2854-
return ::mlir::failure();
2855-
if (parser.parseColon())
2856-
return ::mlir::failure();
2857-
2858-
::mlir::FunctionType opsFnTy;
2859-
if (parser.parseType(opsFnTy))
2860-
return ::mlir::failure();
2861-
operandsTypes = opsFnTy.getInputs();
2862-
allResultTypes = opsFnTy.getResults();
2863-
result.addTypes(allResultTypes);
2864-
28652865
if (parser.resolveOperands(ops, operandsTypes, opsLoc, result.operands))
28662866
return ::mlir::failure();
28672867

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)