aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Kuderski <kubak@google.com>2023-03-29 12:08:21 -0400
committerJakub Kuderski <kubak@google.com>2023-03-29 12:10:21 -0400
commit16672dba5f05172ce62b609f93a5fc254e37ec4d (patch)
treee7b249ffb27f92dd96637fd811aff6c073e8a974
parent498c88563b7f6379d9e6ae4d89d182756fa1c0bc (diff)
downloadllvm-16672dba5f05172ce62b609f93a5fc254e37ec4d.zip
llvm-16672dba5f05172ce62b609f93a5fc254e37ec4d.tar.gz
llvm-16672dba5f05172ce62b609f93a5fc254e37ec4d.tar.bz2
[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
-rw-r--r--mlir/test/Dialect/SPIRV/IR/target-env.mlir11
-rw-r--r--mlir/test/lib/Dialect/SPIRV/TestAvailability.cpp6
2 files changed, 13 insertions, 4 deletions
diff --git a/mlir/test/Dialect/SPIRV/IR/target-env.mlir b/mlir/test/Dialect/SPIRV/IR/target-env.mlir
index 15e0513..5f3292d 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 fc01d5a..091c7ca 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();