[PATCH] D79317: Check type for forward reference definition

Matthew Parkinson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 05:18:21 PDT 2020


mjp41 updated this revision to Diff 261783.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79317/new/

https://reviews.llvm.org/D79317

Files:
  mlir/lib/Parser/Parser.cpp
  mlir/test/IR/invalid.mlir


Index: mlir/test/IR/invalid.mlir
===================================================================
--- mlir/test/IR/invalid.mlir
+++ mlir/test/IR/invalid.mlir
@@ -1496,3 +1496,18 @@
   // 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 specified type 'i8'}}
+  return %1 : i8
+
+^bb2:
+  // expected-error @+1 {{definition of SSA value '%1#0' has type 'f32'}}
+  %1 = "bar"() : () -> (f32)
+  br ^bb1
+}
Index: mlir/lib/Parser/Parser.cpp
===================================================================
--- mlir/lib/Parser/Parser.cpp
+++ mlir/lib/Parser/Parser.cpp
@@ -3622,6 +3622,14 @@
           .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 specified 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79317.261783.patch
Type: text/x-patch
Size: 1404 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200504/0fd4c35b/attachment.bin>


More information about the llvm-commits mailing list