Skip to content

Commit f9c0515

Browse files
authored
[CIR] Delete FuncOp::verifyType (#1421)
Get rid of the function `FuncOp::verifyType`. The function performed three checks: 1. Check that `isa<cir::FuncType>(getFunctionType())`. This is a tautology that is always true, since the return type of `getFunctionType()` is already `cir::FuncType`. 2. Report an error if `type.isVarArg() && type.getNumInputs() == 0`, i.e. when a variadic function has no named parameters. That check is incorrect. In C++, variadic functions don't need to have any named parameters. `void f(...) { }` is legal in C++ and ClangIR needs to be able to compile it. 3. Report an error when the return type is `void`. This check is correct (`void` return is represented as no return in MLIR), but it is redundant. This is already checked in `FuncType::verify`. Since `FuncOp::verifyType` serves no useful purpose, delete it, along with the test for `int variadic(...)` that was in `clang/test/CIR/IR/invalid.cir`.
1 parent ab1d10b commit f9c0515

File tree

3 files changed

+0
-32
lines changed

3 files changed

+0
-32
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

-6
Original file line numberDiff line numberDiff line change
@@ -3597,12 +3597,6 @@ def FuncOp : CIR_Op<"func", [
35973597
return getFunctionType().getReturnTypes();
35983598
}
35993599

3600-
/// Hook for OpTrait::FunctionOpInterfaceTrait, called after verifying that
3601-
/// the 'type' attribute is present and checks if it holds a function type.
3602-
/// Ensures getType, getNumFuncArguments, and getNumFuncResults can be
3603-
/// called safely.
3604-
llvm::LogicalResult verifyType();
3605-
36063600
//===------------------------------------------------------------------===//
36073601
// SymbolOpInterface Methods
36083602
//===------------------------------------------------------------------===//

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

-19
Original file line numberDiff line numberDiff line change
@@ -2588,25 +2588,6 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
25882588
}
25892589
}
25902590

2591-
// Hook for OpTrait::FunctionLike, called after verifying that the 'type'
2592-
// attribute is present. This can check for preconditions of the
2593-
// getNumArguments hook not failing.
2594-
LogicalResult cir::FuncOp::verifyType() {
2595-
auto type = getFunctionType();
2596-
if (!isa<cir::FuncType>(type))
2597-
return emitOpError("requires '" + getFunctionTypeAttrName().str() +
2598-
"' attribute of function type");
2599-
if (!getNoProto() && type.isVarArg() && type.getNumInputs() == 0)
2600-
return emitError()
2601-
<< "prototyped function must have at least one non-variadic input";
2602-
if (auto rt = type.getReturnTypes();
2603-
!rt.empty() && mlir::isa<cir::VoidType>(rt.front()))
2604-
return emitOpError("The return type for a function returning void should "
2605-
"be empty instead of an explicit !cir.void");
2606-
2607-
return success();
2608-
}
2609-
26102591
// Verifies linkage types
26112592
// - functions don't have 'common' linkage
26122593
// - external functions have 'external' or 'extern_weak' linkage

clang/test/CIR/IR/invalid.cir

-7
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,6 @@ module {
623623

624624
// -----
625625

626-
module {
627-
// expected-error@+1 {{prototyped function must have at least one non-variadic input}}
628-
cir.func private @variadic(...) -> !cir.int<s, 32>
629-
}
630-
631-
// -----
632-
633626
module {
634627
// expected-error@+1 {{custom op 'cir.func' variadic arguments must be in the end of the argument list}}
635628
cir.func @variadic(..., !cir.int<s, 32>) -> !cir.int<s, 32>

0 commit comments

Comments
 (0)