Skip to content

Commit 996c145

Browse files
committed
Address review feedback, add alias parsing
1 parent b9fa4c7 commit 996c145

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -904,13 +904,9 @@ void CIRGenModule::replacePointerTypeArgs(cir::FuncOp oldF, cir::FuncOp newF) {
904904
if (!call)
905905
continue;
906906

907-
mlir::OperandRange argOps = call.getArgs();
908-
mlir::ArrayRef<mlir::Type> funcArgTypes =
909-
newF.getFunctionType().getInputs();
910-
// In the case of variadic functions, the call may have more arguments that
911-
// the function type, so we can't use llvm::enumerate here.
912-
for (unsigned i = 0; i < funcArgTypes.size(); i++) {
913-
if (argOps[i].getType() == funcArgTypes[i])
907+
for (const auto [argOp, fnArgType] :
908+
llvm::zip(call.getArgs(), newF.getFunctionType().getInputs())) {
909+
if (argOp.getType() == fnArgType)
914910
continue;
915911

916912
// The purpose of this entire function is to insert bitcasts in the case

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,11 +1403,27 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
14031403
state.addAttribute(getFunctionTypeAttrName(state.name),
14041404
TypeAttr::get(fnType));
14051405

1406+
bool hasAlias = false;
1407+
mlir::StringAttr aliaseeNameAttr = getAliaseeAttrName(state.name);
1408+
if (parser.parseOptionalKeyword("alias").succeeded()) {
1409+
if (parser.parseLParen().failed())
1410+
return failure();
1411+
mlir::StringAttr aliaseeAttr;
1412+
if (parser.parseOptionalSymbolName(aliaseeAttr).failed())
1413+
return failure();
1414+
state.addAttribute(aliaseeNameAttr, FlatSymbolRefAttr::get(aliaseeAttr));
1415+
if (parser.parseRParen().failed())
1416+
return failure();
1417+
hasAlias = true;
1418+
}
1419+
14061420
// Parse the optional function body.
14071421
auto *body = state.addRegion();
14081422
OptionalParseResult parseResult = parser.parseOptionalRegion(
14091423
*body, arguments, /*enableNameShadowing=*/false);
14101424
if (parseResult.has_value()) {
1425+
if (hasAlias)
1426+
return parser.emitError(loc, "function alias shall not have a body");
14111427
if (failed(*parseResult))
14121428
return failure();
14131429
// Function body was parsed, make sure its not empty.

clang/test/CIR/IR/func.cir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ cir.func @intfunc() -> !s32i {
3232
// CHECK: cir.return %[[VAL]] : !s32i
3333
// CHECK: }
3434

35+
// Should print/parse function aliases.
36+
cir.func @a_empty() alias(@empty)
37+
// CHECK: cir.func @a_empty() alias(@empty)
38+
3539
// int scopes() {
3640
// {
3741
// {

clang/test/CIR/IR/invalid-func.cir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: cir-opt %s -verify-diagnostics
2+
3+
module {
4+
cir.func @l0() {
5+
cir.return
6+
}
7+
8+
cir.func @l1() alias(@l0) { // expected-error {{function alias shall not have a body}}
9+
cir.return
10+
}
11+
}

0 commit comments

Comments
 (0)