From 94d9b7ce604ff416a1902cd041f10f4c4a6e72bb Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Wed, 15 Mar 2023 17:35:00 +0100 Subject: [PATCH] [flang] Detect fir.class nested in fir.box as invalid element type Catch invalid element type in fir.box in the verifier so it does not propagate later in lowering. Reviewed By: PeteSteinfeld Differential Revision: https://reviews.llvm.org/D146078 --- flang/lib/Optimizer/Dialect/FIRType.cpp | 2 ++ flang/test/Fir/invalid-types.fir | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp index d9f703a679d4..c25c683b3e7d 100644 --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -456,6 +456,8 @@ static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) { mlir::LogicalResult fir::BoxType::verify(llvm::function_ref emitError, mlir::Type eleTy) { + if (eleTy.isa()) + return emitError() << "invalid element type\n"; // TODO return mlir::success(); } diff --git a/flang/test/Fir/invalid-types.fir b/flang/test/Fir/invalid-types.fir index 67360df27186..18bc9f7b4896 100644 --- a/flang/test/Fir/invalid-types.fir +++ b/flang/test/Fir/invalid-types.fir @@ -167,3 +167,8 @@ func.func private @oth3() -> !fir.vector<10:> // expected-error@+1 {{invalid element type}} func.func private @upe() -> !fir.class> + +// ----- + +// expected-error@+1 {{invalid element type}} +func.func private @upe() -> !fir.box>