[PATCH] [mlir][spirv] Fix crash in spirv-lower-abi-attributes
authorJakub Kuderski <kubak@google.com>
Fri, 13 Jan 2023 15:55:04 +0000 (10:55 -0500)
committerGianfranco Costamagna <locutusofborg@debian.org>
Thu, 7 Sep 2023 22:41:35 +0000 (23:41 +0100)
... when the are no SPIR-V env attributes.

Fixes: https://github.com/llvm/llvm-project/issues/59983
Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D141695

Gbp-Pq: Name CVE-2023-29939.patch

mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir

index 6094ad8bf2242cf174dfa682bf4293aa67f1e825..bd98dc625876f37cc39b7561c44a0265de450e19 100644 (file)
@@ -235,7 +235,12 @@ void LowerABIAttributesPass::runOnOperation() {
   spirv::ModuleOp module = getOperation();
   MLIRContext *context = &getContext();
 
-  spirv::TargetEnv targetEnv(spirv::lookupTargetEnv(module));
+  spirv::TargetEnvAttr targetEnvAttr = spirv::lookupTargetEnv(module);
+  if (!targetEnvAttr) {
+    module->emitOpError("missing SPIR-V target env attribute");
+    return signalPassFailure();
+  }
+  spirv::TargetEnv targetEnv(targetEnvAttr);
 
   SPIRVTypeConverter typeConverter(targetEnv);
 
index f3b9caf7a17ea49e2df89fff670f5fcb0c737c2c..98b880a9df10f62e1f629c8309d3b3a21235bb4d 100644 (file)
@@ -29,3 +29,10 @@ spv.module Logical GLSL450 {
 } // end spv.module
 
 } // end module
+
+// -----
+
+module {
+// expected-error@+1 {{'spirv.module' op missing SPIR-V target env attribute}}
+spirv.module Logical GLSL450 {}
+} // end module