[Mlir-commits] [mlir] 5010b5b - Check type for forward reference definition
Renato Golin
llvmlistbot at llvm.org
Wed May 6 06:34:59 PDT 2020
Author: Renato Golin
Date: 2020-05-06T14:34:18+01:00
New Revision: 5010b5b7e6cf0925465ecaa4111927ee9bcfac67
URL: https://github.com/llvm/llvm-project/commit/5010b5b7e6cf0925465ecaa4111927ee9bcfac67
DIFF: https://github.com/llvm/llvm-project/commit/5010b5b7e6cf0925465ecaa4111927ee9bcfac67.diff
LOG: Check type for forward reference definition
The types of forward references are checked that they match with other
uses, but they do not check they match with the definition.
func @forward_reference_type_check() -> (i8) {
br ^bb2
^bb1:
return %1 : i8
^bb2:
%1 = "bar"() : () -> (f32)
br ^bb1
}
Would be parsed and the use site of '%1' would be silently changed to
'f32'.
This commit adds a test for this case, and a check during parsing for
the types to match.
Patch by Matthew Parkinson <mattpark at microsoft.com>
Closes D79317.
Added:
Modified:
mlir/lib/Parser/Parser.cpp
mlir/test/IR/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 384c69e44a05..ebac3e214931 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -3625,6 +3625,14 @@ ParseResult OperationParser::addDefinition(SSAUseInfo useInfo, Value value) {
.append("previously defined here");
}
+ if (existing.getType() != value.getType()) {
+ return emitError(useInfo.loc)
+ .append("definition of SSA value '", useInfo.name, "#",
+ useInfo.number, "' has type ", value.getType())
+ .attachNote(getEncodedSourceLocation(entries[useInfo.number].second))
+ .append("previously used here with type ", existing.getType());
+ }
+
// If it was a forward reference, update everything that used it to use
// the actual definition instead, delete the forward ref, and remove it
// from our set of forward references we track.
diff --git a/mlir/test/IR/invalid.mlir b/mlir/test/IR/invalid.mlir
index 926c2e3c2857..47fd0b7a371f 100644
--- a/mlir/test/IR/invalid.mlir
+++ b/mlir/test/IR/invalid.mlir
@@ -1512,3 +1512,18 @@ func @duplicate_dictionary_attr_key() {
// expected-error @+1 {{duplicate key in dictionary attribute}}
"foo.op"() {a, a} : () -> ()
}
+
+// -----
+
+func @forward_reference_type_check() -> (i8) {
+ br ^bb2
+
+^bb1:
+ // expected-note @+1 {{previously used here with type 'i8'}}
+ return %1 : i8
+
+^bb2:
+ // expected-error @+1 {{definition of SSA value '%1#0' has type 'f32'}}
+ %1 = "bar"() : () -> (f32)
+ br ^bb1
+}
More information about the Mlir-commits
mailing list