diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1798,6 +1798,13 @@ << *ret.operand_type_begin() << " does not match global type " << getType(); + for (Operation &op : *b) { + auto iface = dyn_cast(op); + if (!iface || !iface.hasNoEffect()) + return op.emitError() + << "ops with side effects not allowed in global initializers"; + } + if (getValueOrNull()) return emitOpError("cannot have both initializer value and region"); } diff --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir --- a/mlir/test/Dialect/LLVMIR/invalid.mlir +++ b/mlir/test/Dialect/LLVMIR/invalid.mlir @@ -1254,7 +1254,17 @@ // ----- func @non_splat_shuffle_on_scalable_vector(%arg0: vector<[4]xf32>) { - // expected-error@+1 {{expected a splat operation for scalable vectors}} + // expected-error@below {{expected a splat operation for scalable vectors}} %0 = llvm.shufflevector %arg0, %arg0 [0 : i32, 0 : i32, 0 : i32, 1 : i32] : vector<[4]xf32>, vector<[4]xf32> return -} \ No newline at end of file +} + +// ----- + +llvm.mlir.global internal @side_effecting_global() : !llvm.struct<(i8)> { + %0 = llvm.mlir.constant(1 : i64) : i64 + // expected-error@below {{ops with side effects not allowed in global initializers}} + %1 = llvm.alloca %0 x !llvm.struct<(i8)> : (i64) -> !llvm.ptr> + %2 = llvm.load %1 : !llvm.ptr> + llvm.return %2 : !llvm.struct<(i8)> +}