[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / mlir / test / lib / IR / TestPrintInvalid.cpp
blob8697918510a580a009c918a8770165aa1a807c2b
1 //===- TestPrintInvalid.cpp - Test printing invalid ops -------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass creates and prints to the standard output an invalid operation and
10 // a valid operation.
12 //===----------------------------------------------------------------------===//
14 #include "mlir/Dialect/Func/IR/FuncOps.h"
15 #include "mlir/IR/BuiltinOps.h"
16 #include "mlir/Pass/Pass.h"
17 #include "llvm/Support/raw_ostream.h"
19 using namespace mlir;
21 namespace {
22 struct TestPrintInvalidPass
23 : public PassWrapper<TestPrintInvalidPass, OperationPass<ModuleOp>> {
24 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestPrintInvalidPass)
26 StringRef getArgument() const final { return "test-print-invalid"; }
27 StringRef getDescription() const final {
28 return "Test printing invalid ops.";
30 void getDependentDialects(DialectRegistry &registry) const override {
31 registry.insert<func::FuncDialect>();
34 void runOnOperation() override {
35 Location loc = getOperation().getLoc();
36 OpBuilder builder(getOperation().getBodyRegion());
37 auto funcOp = builder.create<func::FuncOp>(
38 loc, "test", FunctionType::get(getOperation().getContext(), {}, {}));
39 funcOp.addEntryBlock();
40 // The created function is invalid because there is no return op.
41 llvm::outs() << "Invalid operation:\n" << funcOp << "\n";
42 builder.setInsertionPointToEnd(&funcOp.getBody().front());
43 builder.create<func::ReturnOp>(loc);
44 // Now this function is valid.
45 llvm::outs() << "Valid operation:\n" << funcOp << "\n";
46 funcOp.erase();
49 } // namespace
51 namespace mlir {
52 void registerTestPrintInvalidPass() {
53 PassRegistration<TestPrintInvalidPass>{};
55 } // namespace mlir