Calling enable_result_type_inference on OperationBuilder may trigger undefined behavior if types cannot be inferred, since mlirOperationCreate returns a nullptr in this case. OperationBuilder::build does not check for nullity, and as such an invalid Operation may be constructed, causing undefined behavior when it is accessed or dropped.
Code to reproduce:
{
let _ = OperationBuilder::new("test", location)
.enable_result_type_inference()
.build();
}
Suggested fix: check for nullity before calling Operation::from_raw in OperationBuilder::build and return a Result<Operation, _> or simply panic.
Calling
enable_result_type_inferenceonOperationBuildermay trigger undefined behavior if types cannot be inferred, sincemlirOperationCreatereturns anullptrin this case.OperationBuilder::builddoes not check for nullity, and as such an invalidOperationmay be constructed, causing undefined behavior when it is accessed or dropped.Code to reproduce:
Suggested fix: check for nullity before calling
Operation::from_rawinOperationBuilder::buildand return aResult<Operation, _>or simply panic.