[Mlir-commits] [mlir] 16672db - [mlir][spirv] Fix null pointer dereference in `--test-spirv-target-env`
Jakub Kuderski
llvmlistbot at llvm.org
Wed Mar 29 09:10:31 PDT 2023
Author: Jakub Kuderski
Date: 2023-03-29T12:10:21-04:00
New Revision: 16672dba5f05172ce62b609f93a5fc254e37ec4d
URL: https://github.com/llvm/llvm-project/commit/16672dba5f05172ce62b609f93a5fc254e37ec4d
DIFF: https://github.com/llvm/llvm-project/commit/16672dba5f05172ce62b609f93a5fc254e37ec4d.diff
LOG: [mlir][spirv] Fix null pointer dereference in `--test-spirv-target-env`
Fixes: https://github.com/llvm/llvm-project/issues/61710
Reviewed By: antiagainst
Differential Revision: https://reviews.llvm.org/D147163
Added:
Modified:
mlir/test/Dialect/SPIRV/IR/target-env.mlir
mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
Removed:
################################################################################
diff --git a/mlir/test/Dialect/SPIRV/IR/target-env.mlir b/mlir/test/Dialect/SPIRV/IR/target-env.mlir
index 15e05130fe5db..5f3292dd6814e 100644
--- a/mlir/test/Dialect/SPIRV/IR/target-env.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/target-env.mlir
@@ -1,4 +1,5 @@
-// RUN: mlir-opt -mlir-disable-threading -test-spirv-target-env %s | FileCheck %s
+// RUN: mlir-opt --split-input-file --verify-diagnostics --mlir-disable-threading \
+// RUN: --test-spirv-target-env %s | FileCheck %s
// Note: The following tests check that a spirv.target_env can properly control
// the conversion target and filter unavailable ops during the conversion.
@@ -32,6 +33,14 @@
// Vulkan memory model is available via extension SPV_KHR_vulkan_memory_model,
// which extensions are incorporated into SPIR-V 1.5.
+
+// expected-error @+1 {{missing 'spirv.target_env' attribute}}
+func.func @main() {
+ return
+}
+
+// -----
+
//===----------------------------------------------------------------------===//
// MaxVersion
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp b/mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
index fc01d5a708f0c..091c7cadd902a 100644
--- a/mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
+++ b/mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
#include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h"
#include "mlir/Pass/Pass.h"
@@ -210,9 +211,8 @@ void ConvertToTargetEnv::runOnOperation() {
MLIRContext *context = &getContext();
func::FuncOp fn = getOperation();
- auto targetEnv = fn.getOperation()
- ->getAttr(spirv::getTargetEnvAttrName())
- .cast<spirv::TargetEnvAttr>();
+ auto targetEnv = dyn_cast_or_null<spirv::TargetEnvAttr>(
+ fn.getOperation()->getAttr(spirv::getTargetEnvAttrName()));
if (!targetEnv) {
fn.emitError("missing 'spirv.target_env' attribute");
return signalPassFailure();
More information about the Mlir-commits
mailing list