diff --git a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp --- a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp +++ b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp @@ -12,6 +12,7 @@ #include "mlir/Bytecode/BytecodeOpInterface.h" #include "mlir/Bytecode/Encoding.h" #include "mlir/IR/Attributes.h" +#include "mlir/IR/Diagnostics.h" #include "mlir/IR/OpImplementation.h" #include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" @@ -459,6 +460,9 @@ } } + /// Returns true if the section is empty. + bool empty() { return propertiesStorage.empty(); } + private: /// Emit raw data and returns the offset in the internal buffer. /// Data are deduplicated and will be copied in the internal buffer only if @@ -648,7 +652,11 @@ writeStringSection(emitter); // Emit the properties section. - writePropertiesSection(emitter); + if (config.bytecodeVersion <= 5) + writePropertiesSection(emitter); + else if (!propertiesSection.empty()) + return rootOp->emitError( + "unexpected properties emitted incompatible with bytecode <5"); // Write the generated bytecode to the provided output stream. emitter.writeTo(os);