[flang] Detect fir.class nested in fir.box as invalid element type
authorValentin Clement <clementval@gmail.com>
Wed, 15 Mar 2023 16:35:00 +0000 (17:35 +0100)
committerValentin Clement <clementval@gmail.com>
Wed, 15 Mar 2023 16:35:57 +0000 (17:35 +0100)
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
flang/test/Fir/invalid-types.fir

index d9f703a..c25c683 100644 (file)
@@ -456,6 +456,8 @@ static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) {
 mlir::LogicalResult
 fir::BoxType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
                      mlir::Type eleTy) {
+  if (eleTy.isa<fir::BaseBoxType>())
+    return emitError() << "invalid element type\n";
   // TODO
   return mlir::success();
 }
index 67360df..18bc9f7 100644 (file)
@@ -167,3 +167,8 @@ func.func private @oth3() -> !fir.vector<10:>
 
 // expected-error@+1 {{invalid element type}}
 func.func private @upe() -> !fir.class<!fir.box<i32>>
+
+// -----
+
+// expected-error@+1 {{invalid element type}}
+func.func private @upe() -> !fir.box<!fir.class<none>>