[flang-commits] [flang] 94d9b7c - [flang] Detect fir.class nested in fir.box as invalid element type

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Mar 15 09:36:05 PDT 2023


Author: Valentin Clement
Date: 2023-03-15T17:35:57+01:00
New Revision: 94d9b7ce604ff416a1902cd041f10f4c4a6e72bb

URL: https://github.com/llvm/llvm-project/commit/94d9b7ce604ff416a1902cd041f10f4c4a6e72bb
DIFF: https://github.com/llvm/llvm-project/commit/94d9b7ce604ff416a1902cd041f10f4c4a6e72bb.diff

LOG: [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

Added: 
    

Modified: 
    flang/lib/Optimizer/Dialect/FIRType.cpp
    flang/test/Fir/invalid-types.fir

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index d9f703a679d4f..c25c683b3e7db 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<mlir::InFlightDiagnostic()> emitError,
                      mlir::Type eleTy) {
+  if (eleTy.isa<fir::BaseBoxType>())
+    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 67360df271868..18bc9f7b4896a 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 at +1 {{invalid element type}}
 func.func private @upe() -> !fir.class<!fir.box<i32>>
+
+// -----
+
+// expected-error at +1 {{invalid element type}}
+func.func private @upe() -> !fir.box<!fir.class<none>>


        


More information about the flang-commits mailing list