[flang-commits] [flang] c3e5f50 - [flang][fir] Add FIR Types parser diagnostic tests + cleanup
via flang-commits
flang-commits at lists.llvm.org
Fri Mar 5 11:58:51 PST 2021
Author: Valentin Clement
Date: 2021-03-05T14:58:44-05:00
New Revision: c3e5f504a0c592dd28f869f9a74cc9f480a3c7a5
URL: https://github.com/llvm/llvm-project/commit/c3e5f504a0c592dd28f869f9a74cc9f480a3c7a5
DIFF: https://github.com/llvm/llvm-project/commit/c3e5f504a0c592dd28f869f9a74cc9f480a3c7a5.diff
LOG: [flang][fir] Add FIR Types parser diagnostic tests + cleanup
Add diagnostic tests for Types parsers and remove duplicated diagnostics handled by the MLIR
parser.
Reviewed By: schweitz
Differential Revision: https://reviews.llvm.org/D97643
Added:
flang/test/Fir/invalid-types.fir
Modified:
flang/lib/Optimizer/Dialect/FIRType.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index d3b9a2fdb05b..eb347a963120 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -30,11 +30,8 @@ namespace {
template <typename TYPE>
TYPE parseIntSingleton(mlir::DialectAsmParser &parser) {
int kind = 0;
- if (parser.parseLess() || parser.parseInteger(kind) ||
- parser.parseGreater()) {
- parser.emitError(parser.getCurrentLocation(), "kind value expected");
+ if (parser.parseLess() || parser.parseInteger(kind) || parser.parseGreater())
return {};
- }
return TYPE::get(parser.getBuilder().getContext(), kind);
}
@@ -51,10 +48,8 @@ TYPE parseRankSingleton(mlir::DialectAsmParser &parser) {
template <typename TYPE>
TYPE parseTypeSingleton(mlir::DialectAsmParser &parser) {
mlir::Type ty;
- if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) {
- parser.emitError(parser.getCurrentLocation(), "type expected");
+ if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater())
return {};
- }
return TYPE::get(ty);
}
@@ -67,8 +62,8 @@ static bool isaIntegerType(mlir::Type ty) {
bool verifyRecordMemberType(mlir::Type ty) {
return !(ty.isa<BoxType>() || ty.isa<BoxCharType>() ||
ty.isa<BoxProcType>() || ty.isa<ShapeType>() ||
- ty.isa<ShapeShiftType>() || ty.isa<SliceType>() ||
- ty.isa<FieldType>() || ty.isa<LenType>() ||
+ ty.isa<ShapeShiftType>() || ty.isa<ShiftType>() ||
+ ty.isa<SliceType>() || ty.isa<FieldType>() || ty.isa<LenType>() ||
ty.isa<ReferenceType>() || ty.isa<TypeDescType>());
}
@@ -119,8 +114,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
mlir::DialectAsmParser &parser) {
llvm::StringRef typeNameLit;
if (mlir::failed(parser.parseKeyword(&typeNameLit)))
- return mlir::Type();
-
+ return {};
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
}
@@ -279,10 +273,8 @@ bool fir::isa_unknown_size_box(mlir::Type t) {
mlir::Type BoxProcType::parse(mlir::MLIRContext *context,
mlir::DialectAsmParser &parser) {
mlir::Type ty;
- if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) {
- parser.emitError(parser.getCurrentLocation(), "type expected");
+ if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater())
return {};
- }
return get(context, ty);
}
@@ -315,10 +307,8 @@ static bool canBePointerOrHeapElementType(mlir::Type eleTy) {
mlir::Type fir::BoxType::parse(mlir::MLIRContext *context,
mlir::DialectAsmParser &parser) {
mlir::Type ofTy;
- if (parser.parseLess() || parser.parseType(ofTy)) {
- parser.emitError(parser.getCurrentLocation(), "expected type parameter");
+ if (parser.parseLess() || parser.parseType(ofTy))
return {};
- }
mlir::AffineMapAttr map;
if (!parser.parseOptionalComma()) {
@@ -327,9 +317,8 @@ mlir::Type fir::BoxType::parse(mlir::MLIRContext *context,
return {};
}
}
- if (parser.parseGreater()) {
+ if (parser.parseGreater())
return {};
- }
return get(ofTy, map);
}
@@ -354,13 +343,7 @@ fir::BoxType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
mlir::Type fir::BoxCharType::parse(mlir::MLIRContext *context,
mlir::DialectAsmParser &parser) {
- int kind = 0;
- if (parser.parseLess() || parser.parseInteger(kind) ||
- parser.parseGreater()) {
- parser.emitError(parser.getCurrentLocation(), "kind value expected");
- return {};
- }
- return get(context, kind);
+ return parseKindSingleton<fir::BoxCharType>(parser);
}
void fir::BoxCharType::print(mlir::DialectAsmPrinter &printer) const {
@@ -384,16 +367,13 @@ CharacterType fir::BoxCharType::getEleTy() const {
mlir::Type fir::CharacterType::parse(mlir::MLIRContext *context,
mlir::DialectAsmParser &parser) {
int kind = 0;
- if (parser.parseLess() || parser.parseInteger(kind)) {
- parser.emitError(parser.getCurrentLocation(), "kind value expected");
+ if (parser.parseLess() || parser.parseInteger(kind))
return {};
- }
CharacterType::LenType len = 1;
if (mlir::succeeded(parser.parseOptionalComma())) {
if (mlir::succeeded(parser.parseOptionalQuestion())) {
len = fir::CharacterType::unknownLen();
} else if (!mlir::succeeded(parser.parseInteger(len))) {
- parser.emitError(parser.getCurrentLocation(), "len value expected");
return {};
}
}
@@ -537,11 +517,8 @@ fir::RealType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
mlir::Type fir::RecordType::parse(mlir::MLIRContext *context,
mlir::DialectAsmParser &parser) {
llvm::StringRef name;
- if (parser.parseLess() || parser.parseKeyword(&name)) {
- parser.emitError(parser.getNameLoc(),
- "expected a identifier as name of derived type");
+ if (parser.parseLess() || parser.parseKeyword(&name))
return {};
- }
RecordType result = RecordType::get(parser.getBuilder().getContext(), name);
RecordType::TypeList lenParamList;
@@ -558,10 +535,8 @@ mlir::Type fir::RecordType::parse(mlir::MLIRContext *context,
if (parser.parseOptionalComma())
break;
}
- if (parser.parseRParen()) {
- parser.emitError(parser.getNameLoc(), "expected ')'");
+ if (parser.parseRParen())
return {};
- }
}
RecordType::TypeList typeList;
@@ -578,16 +553,12 @@ mlir::Type fir::RecordType::parse(mlir::MLIRContext *context,
if (parser.parseOptionalComma())
break;
}
- if (parser.parseRBrace()) {
- parser.emitError(parser.getNameLoc(), "expected '}'");
+ if (parser.parseRBrace())
return {};
- }
}
- if (parser.parseGreater()) {
- parser.emitError(parser.getNameLoc(), "expected '>' in type type");
+ if (parser.parseGreater())
return {};
- }
if (lenParamList.empty() && typeList.empty())
return result;
@@ -697,25 +668,18 @@ mlir::LogicalResult fir::ReferenceType::verify(
// bounds ::= `?` | int-lit
mlir::Type fir::SequenceType::parse(mlir::MLIRContext *context,
mlir::DialectAsmParser &parser) {
- if (parser.parseLess()) {
- parser.emitError(parser.getNameLoc(), "expecting '<'");
+ if (parser.parseLess())
return {};
- }
SequenceType::Shape shape;
if (parser.parseOptionalStar()) {
- if (parser.parseDimensionList(shape, /*allowDynamic=*/true)) {
- parser.emitError(parser.getNameLoc(), "invalid shape");
+ if (parser.parseDimensionList(shape, /*allowDynamic=*/true))
return {};
- }
} else if (parser.parseColon()) {
- parser.emitError(parser.getNameLoc(), "expected ':'");
return {};
}
mlir::Type eleTy;
- if (parser.parseType(eleTy) || parser.parseGreater()) {
- parser.emitError(parser.getNameLoc(), "expecting element type");
+ if (parser.parseType(eleTy) || parser.parseGreater())
return {};
- }
mlir::AffineMapAttr map;
if (!parser.parseOptionalComma())
if (parser.parseAttribute(map)) {
@@ -876,10 +840,8 @@ mlir::Type fir::VectorType::parse(mlir::MLIRContext *context,
int64_t len = 0;
mlir::Type eleTy;
if (parser.parseLess() || parser.parseInteger(len) || parser.parseColon() ||
- parser.parseType(eleTy) || parser.parseGreater()) {
- parser.emitError(parser.getNameLoc(), "invalid vector type");
+ parser.parseType(eleTy) || parser.parseGreater())
return {};
- }
return fir::VectorType::get(len, eleTy);
}
diff --git a/flang/test/Fir/invalid-types.fir b/flang/test/Fir/invalid-types.fir
new file mode 100644
index 000000000000..929ef68558b8
--- /dev/null
+++ b/flang/test/Fir/invalid-types.fir
@@ -0,0 +1,169 @@
+// Test the FIR types parser diagnostics
+// RUN: fir-opt -split-input-file -verify-diagnostics %s
+
+// expected-error at +1 {{expected non-function type}}
+func private @box3() -> !fir.boxproc<>
+
+// -----
+
+// expected-error at +2 {{expected non-function type}}
+// expected-error at +1 {{expected affine map}}
+func private @box1() -> !fir.box<!fir.array<?xf32>, >
+
+// -----
+
+// expected-error at +1 {{expected non-function type}}
+func private @box1() -> !fir.box<>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @box2() -> !fir.boxchar<>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @it6() -> !fir.char<>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @it6() -> !fir.char<2, >
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @it3() -> !fir.complex<>
+
+// -----
+
+// expected-error at +1 {{expected non-function type}}
+func private @mem3() -> !fir.heap<>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @it1() -> !fir.int<A>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @it1() -> !fir.logical<b>
+
+// -----
+
+// expected-error at +1 {{expected non-function type}}
+func private @mem3() -> !fir.ptr<>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @mem3() -> !fir.real<>
+
+// -----
+
+// expected-error at +1 {{expected valid keyword}}
+func private @mem3() -> !fir.type<>
+
+// -----
+
+// expected-error at +2 {{expected valid keyword}}
+// expected-error at +1 {{expected LEN parameter list}}
+func private @dvd4() -> !fir.type<derived4()>
+
+// -----
+
+// expected-error at +2 {{expected ':'}}
+// expected-error at +1 {{expected LEN parameter list}}
+func private @dvd4() -> !fir.type<derived4(p)>
+
+// -----
+
+// expected-error at +2 {{expected non-function type}}
+// expected-error at +1 {{expected LEN parameter list}}
+func private @dvd4() -> !fir.type<derived4(p:)>
+
+// -----
+
+// expected-error at +2 {{expected valid keyword}}
+// expected-error at +1 {{expected field type list}}
+func private @dvd4() -> !fir.type<derived4(p:i8){}>
+
+// -----
+
+// expected-error at +2 {{expected ':'}}
+// expected-error at +1 {{expected field type list}}
+func private @dvd4() -> !fir.type<derived4(p:i8){f1}>
+
+// -----
+
+// expected-error at +2 {{expected non-function type}}
+// expected-error at +1 {{expected field type list}}
+func private @dvd4() -> !fir.type<derived4(p:i8){f1:f2}>
+
+// -----
+
+// expected-error at +2 {{expected valid keyword}}
+// expected-error at +1 {{expected field type list}}
+func private @dvd4() -> !fir.type<derived4(p:i8){f1:i32,}>
+
+// -----
+
+// expected-error at +2 {{expected valid keyword}}
+// expected-error at +1 {{expected field type list}}
+func private @dvd4() -> !fir.type<derived4(p:i8){,}>
+
+// -----
+
+// expected-error at +1 {{expected non-function type}}
+func private @mem3() -> !fir.ref<>
+
+// -----
+
+// expected-error at +1 {{expected ':'}}
+func private @arr1() -> !fir.array<*>
+
+// -----
+
+// expected-error at +1 {{expected non-function type}}
+func private @arr1() -> !fir.array<*:>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @oth1() -> !fir.shape<>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @oth1() -> !fir.shapeshift<>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @oth1() -> !fir.shift<>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @oth1() -> !fir.slice<>
+
+// -----
+
+// expected-error at +1 {{expected non-function type}}
+func private @oth3() -> !fir.tdesc<xx>
+
+// -----
+
+// expected-error at +1 {{expected integer value}}
+func private @oth3() -> !fir.vector<>
+
+// -----
+
+// expected-error at +1 {{expected ':'}}
+func private @oth3() -> !fir.vector<10>
+
+// -----
+
+// expected-error at +1 {{expected non-function type}}
+func private @oth3() -> !fir.vector<10:>
More information about the flang-commits
mailing list