Skip to content

Commit c9c0f14

Browse files
Propagate locations in box/ref type parsers
1 parent a9afcb0 commit c9c0f14

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,9 +1357,7 @@ llvm::LogicalResult fir::VolatileCastOp::verify() {
13571357
mlir::isa<fir::ReferenceType>(toType));
13581358
bool sameElementType = fir::dyn_cast_ptrOrBoxEleTy(fromType) ==
13591359
fir::dyn_cast_ptrOrBoxEleTy(toType);
1360-
if (fromType == toType ||
1361-
fir::isa_volatile_type(fromType) == fir::isa_volatile_type(toType) ||
1362-
!sameBaseType || !sameElementType)
1360+
if (!sameBaseType || !sameElementType)
13631361
return emitOpError("types must be identical except for volatility ")
13641362
<< fromType << " / " << toType;
13651363
return mlir::success();

flang/lib/Optimizer/Dialect/FIRType.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
136136
auto parseResult = generatedTypeParser(parser, &typeTag, genType);
137137
if (parseResult.has_value())
138138
return genType;
139-
parser.emitError(parser.getNameLoc(), "unknown fir type: ") << typeTag;
139+
parser.emitError(parser.getCurrentLocation(), "unknown fir type: ") << typeTag;
140140
return {};
141141
}
142142

@@ -770,12 +770,13 @@ fir::BoxType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
770770

771771
mlir::Type fir::BoxType::parse(mlir::AsmParser &parser) {
772772
mlir::Type ty;
773-
bool isVolatile;
773+
bool isVolatile = false;
774+
auto loc = parser.getCurrentLocation();
774775
if (parser.parseLess() || parser.parseType(ty) ||
775776
parseOptionalCommaAndKeyword(parser, getVolatileKeyword(), isVolatile) ||
776777
parser.parseGreater())
777778
return {};
778-
return get(ty, isVolatile);
779+
return parser.getChecked<BoxType>(loc, parser.getContext(), ty, isVolatile);
779780
}
780781

781782
void fir::BoxType::print(mlir::AsmPrinter &printer) const {
@@ -1098,12 +1099,13 @@ unsigned fir::RecordType::getFieldIndex(llvm::StringRef ident) {
10981099
// `ref` `<` type (`, volatile` $volatile^)? `>`
10991100
mlir::Type fir::ReferenceType::parse(mlir::AsmParser &parser) {
11001101
mlir::Type ty;
1101-
bool isVolatile;
1102+
bool isVolatile = false;
1103+
auto loc = parser.getCurrentLocation();
11021104
if (parser.parseLess() || parser.parseType(ty) ||
11031105
parseOptionalCommaAndKeyword(parser, getVolatileKeyword(), isVolatile) ||
11041106
parser.parseGreater())
11051107
return {};
1106-
return get(ty, isVolatile);
1108+
return parser.getChecked<ReferenceType>(loc, parser.getContext(), ty, isVolatile);
11071109
}
11081110

11091111
void fir::ReferenceType::print(mlir::AsmPrinter &printer) const {

flang/test/Fir/invalid-types.fir

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,8 @@ func.func private @upe() -> !fir.class<!fir.box<i32>>
159159

160160
// -----
161161

162-
// TODO: why are source locations lost on the error message?
163-
// the error message is printed but without a proper source location.
164-
// expected-error <skipme> @+1 {{invalid element type}}
165-
// func.func private @upe() -> !fir.box<!fir.class<none>>
162+
// expected-error@+1 {{invalid element type}}
163+
func.func private @upe() -> !fir.box<!fir.class<none>>
166164

167165
// -----
168166

0 commit comments

Comments
 (0)