Now that modules are also operations, nothing prevents one from defining SSA
values in the module. Doing so in an implicit top-level module, i.e. outside
of a `module` operation, was leading to a crash because the implicit module was
not associated with an SSA name scope. Create a name scope before parsing the
top-level module to fix this.
PiperOrigin-RevId:
262366891
/// This is the top-level module parser.
ParseResult ModuleParser::parseModule(ModuleOp module) {
OperationParser opParser(getState(), module);
+
+ // Module itself is a name scope.
+ opParser.pushSSANameScope();
+
while (1) {
switch (getToken().getKind()) {
default:
bodyBlocks.pop_front();
}
- return success();
+ return opParser.popSSANameScope();
}
// If we got an error token, then the lexer already emitted an error, just
// CHECK-NOT: module {
module {
}
+
+// -----
+
+// Check that the implicit top-level module is also a name scope for SSA
+// values. This should not crash.
+// CHECK: module {
+// CHECK: %{{.*}} = "op"
+// CHECK: }
+%0 = "op"() : () -> i32
+